From 21f243c08cbe8a2a31ac402d50d038c0cb2238a2 Mon Sep 17 00:00:00 2001 From: Natan Felles Date: Tue, 20 Feb 2024 14:27:42 -0300 Subject: [PATCH] Update Views tests --- tests/Debug/ViewCollectorTest.php | 1 + tests/ViewTest.php | 55 ++++++++++++++++++++-------- tests/Views/home/repeat-includes.php | 14 +++++++ 3 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 tests/Views/home/repeat-includes.php diff --git a/tests/Debug/ViewCollectorTest.php b/tests/Debug/ViewCollectorTest.php index b883cca..6c34282 100644 --- a/tests/Debug/ViewCollectorTest.php +++ b/tests/Debug/ViewCollectorTest.php @@ -29,6 +29,7 @@ protected function setUp() : void $this->collector = new ViewCollector(); $this->debugger->addCollector($this->collector, 'View'); $this->view = new View(); + $this->view->setInstanceName('default'); $this->view->setDebugCollector($this->collector); } diff --git a/tests/ViewTest.php b/tests/ViewTest.php index 9fd2185..8bb4cad 100644 --- a/tests/ViewTest.php +++ b/tests/ViewTest.php @@ -21,6 +21,7 @@ final class ViewTest extends TestCase protected function setUp() : void { $this->view = new ViewMock(__DIR__ . '/Views'); + $this->view->setInstanceName('default'); } public function testBaseDir() : void @@ -293,11 +294,11 @@ public function testDebugBlock() : void $this->setDebugCollector(); $contents = $this->view->render('home/index'); self::assertStringContainsString( - '', + '', $contents ); self::assertStringContainsString( - '', + '', $contents ); } @@ -307,20 +308,42 @@ public function testDebugInclude() : void $this->setDebugCollector(); $contents = $this->view->render('home/index'); self::assertStringContainsString( - '', + '', $contents ); self::assertStringContainsString( - '', + '', $contents ); $contents = $this->view->render('home/without-prefix'); self::assertStringContainsString( - '', + '', $contents ); self::assertStringContainsString( - '', + '', + $contents + ); + } + + public function testDebugIncludeRepeated() : void + { + $this->setDebugCollector(); + $contents = $this->view->render('home/repeat-includes'); + self::assertStringContainsString( + '', + $contents + ); + self::assertStringContainsString( + '', + $contents + ); + self::assertStringContainsString( + '', + $contents + ); + self::assertStringContainsString( + '', $contents ); } @@ -330,11 +353,11 @@ public function testDebugRender() : void $this->setDebugCollector(); $contents = $this->view->render('home/index'); self::assertStringContainsString( - '', + '', $contents ); self::assertStringContainsString( - '', + '', $contents ); } @@ -347,22 +370,22 @@ public function testDebugComments() : void $contents = $this->view->render('comments'); self::assertSame( <<<'EOL' - - + +

Layout Default

- + CONTENTS - + - + - + - - + + EOL, $contents ); diff --git a/tests/Views/home/repeat-includes.php b/tests/Views/home/repeat-includes.php new file mode 100644 index 0000000..60f95b8 --- /dev/null +++ b/tests/Views/home/repeat-includes.php @@ -0,0 +1,14 @@ +extends('_layouts/default', 'contents'); +?> +

Home Index

+
Foo bar baz
+
+ include('_includes/footer') ?> +
+
+ include('_includes/footer') ?> +