Skip to content

Commit

Permalink
Add unit tests for template inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
Usbac committed Feb 12, 2024
1 parent e807e26 commit 6cd36ca
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/fixtures/views/inheritance_child.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php $this->extend('inheritance_parent.html') ?>
<?php $this->sectionStart('head') ?><title>Document</title><?php $this->sectionEnd() ?>
<?php $this->sectionStart('body') ?><div><?= $message ?></div><?php $this->sectionEnd() ?>
13 changes: 13 additions & 0 deletions tests/fixtures/views/inheritance_parent.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<head>
<?php $this->sectionStart('head') ?>
<?php $this->sectionEnd() ?>
</head>
<body>
<?php $this->sectionStart('body') ?>
<?php $this->sectionEnd() ?>
</body>
</html>
<?php $this->sectionStart('extra') ?>
<script></script>
<?php $this->sectionEnd() ?>
8 changes: 8 additions & 0 deletions tests/unit/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ public function prettyName($name)

$this->assertEquals("Hello, Mr Alex.\n", $view->get('hello2.html', [ 'name' => 'Alex' ]));
}

public function testInheritance(): void
{
$view = new \Aurora\System\View(dirname(__DIR__) . '/fixtures/views');

$this->assertEquals("<!DOCTYPE html>\n<head>\n<title>Document</title></head>\n<body>\n<div>Lorem ipsum</div></body>\n</html>\n<script></script>\n",
$view->get('inheritance_child.html', [ 'message' => 'Lorem ipsum' ]));
}
}

0 comments on commit 6cd36ca

Please sign in to comment.