From 6cd36ca8ad26ece5cebd65fd847be599bd20c1b5 Mon Sep 17 00:00:00 2001 From: Alejandro Date: Mon, 12 Feb 2024 00:26:25 -0400 Subject: [PATCH] Add unit tests for template inheritance --- tests/fixtures/views/inheritance_child.html | 3 +++ tests/fixtures/views/inheritance_parent.html | 13 +++++++++++++ tests/unit/ViewTest.php | 8 ++++++++ 3 files changed, 24 insertions(+) create mode 100644 tests/fixtures/views/inheritance_child.html create mode 100644 tests/fixtures/views/inheritance_parent.html diff --git a/tests/fixtures/views/inheritance_child.html b/tests/fixtures/views/inheritance_child.html new file mode 100644 index 0000000..eb5a3db --- /dev/null +++ b/tests/fixtures/views/inheritance_child.html @@ -0,0 +1,3 @@ +extend('inheritance_parent.html') ?> +sectionStart('head') ?>DocumentsectionEnd() ?> +sectionStart('body') ?>
sectionEnd() ?> diff --git a/tests/fixtures/views/inheritance_parent.html b/tests/fixtures/views/inheritance_parent.html new file mode 100644 index 0000000..d921f8f --- /dev/null +++ b/tests/fixtures/views/inheritance_parent.html @@ -0,0 +1,13 @@ + + +sectionStart('head') ?> +sectionEnd() ?> + + +sectionStart('body') ?> +sectionEnd() ?> + + +sectionStart('extra') ?> + +sectionEnd() ?> diff --git a/tests/unit/ViewTest.php b/tests/unit/ViewTest.php index 97c038c..2b87d76 100644 --- a/tests/unit/ViewTest.php +++ b/tests/unit/ViewTest.php @@ -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("\n\nDocument\n\n
Lorem ipsum
\n\n\n", + $view->get('inheritance_child.html', [ 'message' => 'Lorem ipsum' ])); + } }