Skip to content

Commit

Permalink
Add unit tests for Pages route
Browse files Browse the repository at this point in the history
  • Loading branch information
rougin committed Nov 9, 2024
1 parent d6f345d commit a7b4654
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 52 deletions.
10 changes: 5 additions & 5 deletions app/plates/board.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?= $layout->load('main', compact('link', 'plate')) ?>
<?php echo $layout->load('main', compact('link', 'plate')) ?>

<?= $block->body() ?>
<?= $plate->add('navbar', compact('link')) ?>
<?php echo $block->body() ?>
<?php echo $plate->add('navbar', compact('link')) ?>

<div class="p-5 bg-body-tertiary">
<div class="container">
Expand All @@ -19,7 +19,7 @@
<span class="fw-bold">Creating a new Page</span>
</div>
<div class="card-body">
<p>Kindly select the <a href="<?= $link->set('/pages') ?>">Pages</a> link from the navigation bar on top then select the <code class="p-1 bg-dark text-white rounded">Create New Page</code> button to create a new page.</p>
<p>Kindly select the <a href="<?php echo $link->set('/pages') ?>">Pages</a> link from the navigation bar on top then select the <code class="p-1 bg-dark text-white rounded">Create New Page</code> button to create a new page.</p>
</div>
</div>
</div>
Expand All @@ -36,4 +36,4 @@
</div>
</div>
</div>
<?= $block->end() ?>
<?php echo $block->end() ?>
30 changes: 15 additions & 15 deletions app/plates/editor.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?= $layout->load('main', compact('link', 'plate')) ?>
<?php echo $layout->load('main', compact('link', 'plate')) ?>

<?= $block->set('styles') ?>
<?php echo $block->set('styles') ?>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">
<?= $block->end() ?>
<?php echo $block->end() ?>

<?= $block->body() ?>
<?= $plate->add('navbar', compact('link')) ?>
<?php echo $block->body() ?>
<?php echo $plate->add('navbar', compact('link')) ?>

<div x-data="editor">
<div class="container my-3">
<a href="<?= $link->set('/pages') ?>" class="btn btn-outline-dark shadow-lg" :disabled="loading">Back to Pages</a>
<a href="<?php echo $link->set('/pages') ?>" class="btn btn-outline-dark shadow-lg" :disabled="loading">Back to Pages</a>
<button type="button" class="btn btn-dark shadow-lg" @click="save()" :disabled="loading">Save Details</button>
</div>

Expand All @@ -19,10 +19,10 @@
<div class="row">
<?php foreach ($fields as $field): ?>
<div class="col-sm-3 mb-3">
<label for="<?= $field ?>" class="form-label mb-0"><?= ucfirst($field) ?></label>
<input type="text" name="<?= $field ?>" class="form-control" x-model="input.<?= $field ?>" :disabled="loading">
<template x-if="error.<?= $field ?>">
<p class="text-danger small mb-0" x-text="error.<?= $field ?>[0]"></p>
<label for="<?php echo $field ?>" class="form-label mb-0"><?= ucfirst($field) ?></label>
<input type="text" name="<?php echo $field ?>" class="form-control" x-model="input.<?php echo $field ?>" :disabled="loading">
<template x-if="error.<?php echo $field ?>">
<p class="text-danger small mb-0" x-text="error.<?php echo $field ?>[0]"></p>
</template>
</div>
<?php endforeach ?>
Expand Down Expand Up @@ -69,15 +69,15 @@
</div>
</div>
</div>
<?= $block->end() ?>
<?php echo $block->end() ?>

<?= $block->set('scripts') ?>
<?php echo $block->set('scripts') ?>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>

<script>
let editor = <?= $data ?>
let editor = <?php echo $data ?>

const link = '<?= $link->set('/pages/' . $page['id']) ?>'
const link = '<?php echo $link->set('/pages/' . $page['id']) ?>'

editor.error = {}

Expand Down Expand Up @@ -123,4 +123,4 @@
})
}
</script>
<?= $block->end() ?>
<?php echo $block->end() ?>
8 changes: 4 additions & 4 deletions app/plates/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css">
<?= $block->add('styles') ?>
<?php echo $block->add('styles') ?>
<style type="text/css">
html, body { font-family: 'Roboto'; }
.ex-pointer { cursor: pointer; }
</style>
</head>
<body>
<?= $block->content() ?>
<?php echo $block->content() ?>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js"></script>
<script defer src="https://unpkg.com/axios/dist/axios.min.js"></script>

<?= $plate->add('modal/build', compact('link')) ?>
<?php echo $plate->add('modal/build', compact('link')) ?>

<?= $block->add('scripts') ?>
<?php echo $block->add('scripts') ?>
</body>
</html>
2 changes: 1 addition & 1 deletion app/plates/modal/build.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

self.loading = true

const link = '<?= $link->set('/build') ?>'
const link = '<?php echo $link->set('/build') ?>'

self.error = null

Expand Down
2 changes: 1 addition & 1 deletion app/plates/modal/script.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
const link = '<?= $link->set('/pages') ?>'
const link = '<?php echo $link->set('/pages') ?>'

const modal =
{
Expand Down
4 changes: 2 additions & 2 deletions app/plates/navbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<?php if ($link->isCurrent('/')): ?>
<div class="nav-link active">Dashboard</div>
<?php else: ?>
<a class="nav-link" href="<?= $link->set('/') ?>">Dashboard</a>
<a class="nav-link" href="<?php echo $link->set('/') ?>">Dashboard</a>
<?php endif ?>
</li>
<li class="nav-item">
<?php if ($link->isCurrent('pages')): ?>
<div class="nav-link active">Pages</div>
<?php else: ?>
<a class="nav-link" href="<?= $link->set('/pages') ?>">Pages</a>
<a class="nav-link" href="<?php echo $link->set('/pages') ?>">Pages</a>
<?php endif ?>
</li>
</ul>
Expand Down
22 changes: 11 additions & 11 deletions app/plates/pages.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?= $layout->load('main', compact('link', 'plate')) ?>
<?php echo $layout->load('main', compact('link', 'plate')) ?>

<?= $block->body() ?>
<?= $plate->add('navbar', compact('block', 'link')) ?>
<?php echo $block->body() ?>
<?php echo $plate->add('navbar', compact('block', 'link')) ?>

<div class="container my-3">
<button type="button" class="btn btn-dark shadow-lg" data-bs-toggle="modal" data-bs-target="#create-page-modal">
Create New Page
</button>

<?= $plate->add('modal/plate') ?>
<?php echo $plate->add('modal/plate') ?>
</div>

<div class="container mb-5">
Expand All @@ -29,12 +29,12 @@
<?php foreach ($items as $item): ?>
<tr>
<td>
<a href="<?= $link->set('/pages/' . $item['id']) ?>"><?= $item['name'] ?></a>
<a href="<?php echo $link->set('/pages/' . $item['id']) ?>"><?php echo $item['name'] ?></a>
</td>
<td>
<a href="<?= $url->set($item['link']) ?>" target="_blank"><?= $item['link'] ?></a>
<a href="<?php echo $url->set($item['link']) ?>" target="_blank"><?php echo $item['link'] ?></a>
</td>
<td><?= $str->truncate($item['description']) ?></td>
<td><?php echo $str->truncate($item['description']) ?></td>
<td><?= isset($item['tags']) ? $item['tags'] : '' ?></td>
<td><?= date('d M Y h:i:s A', $item['created_at']) ?></td>
</tr>
Expand All @@ -45,8 +45,8 @@
</div>
</div>
</div>
<?= $block->end() ?>
<?php echo $block->end() ?>

<?= $block->set('scripts') ?>
<?= $plate->add('modal/script', compact('link')) ?>
<?= $block->end() ?>
<?php echo $block->set('scripts') ?>
<?php echo $plate->add('modal/script', compact('link')) ?>
<?php echo $block->end() ?>
10 changes: 4 additions & 6 deletions src/Checks/PageCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class PageCheck extends Check
*/
public function __construct(PageDepot $page, $id = null)
{
$this->id = $id;
$this->id = $id ? (int) $id : null;

$this->page = $page;
}
Expand Down Expand Up @@ -83,9 +83,9 @@ public function valid(array $data = null)
$this->setError('link', 'URL Link already exists');
}

if ($this->id)
if ($this->id && $page)
{
if ($page && $page->getLink() !== $link)
if ($page->getId() !== $this->id)
{
$this->setError('link', 'URL Link already exists');
}
Expand All @@ -100,9 +100,7 @@ public function valid(array $data = null)

if ($this->id && $page)
{
$pageName = strtolower((string) $page->getName());

if ($pageName !== strtolower($name))
if ($page->getId() !== $this->id)
{
$this->setError('name', 'Page Title already exists');
}
Expand Down
Loading

0 comments on commit a7b4654

Please sign in to comment.