Skip to content

Commit

Permalink
Update Views tests
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfelles committed Feb 20, 2024
1 parent 16912d8 commit 21f243c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 16 deletions.
1 change: 1 addition & 0 deletions tests/Debug/ViewCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
55 changes: 39 additions & 16 deletions tests/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -293,11 +294,11 @@ public function testDebugBlock() : void
$this->setDebugCollector();
$contents = $this->view->render('home/index');
self::assertStringContainsString(
'<!-- Block start: home/index::contents -->',
'<!-- DEBUG-VIEW START default:home/index::contents -->',
$contents
);
self::assertStringContainsString(
'<!-- Block end: home/index::contents -->',
'<!-- DEBUG-VIEW ENDED default:home/index::contents -->',
$contents
);
}
Expand All @@ -307,20 +308,42 @@ public function testDebugInclude() : void
$this->setDebugCollector();
$contents = $this->view->render('home/index');
self::assertStringContainsString(
'<!-- Include start: _includes/footer -->',
'<!-- DEBUG-VIEW START default:_includes/footer -->',
$contents
);
self::assertStringContainsString(
'<!-- Include end: _includes/footer -->',
'<!-- DEBUG-VIEW ENDED default:_includes/footer -->',
$contents
);
$contents = $this->view->render('home/without-prefix');
self::assertStringContainsString(
'<!-- Include start: _includes/footer -->',
'<!-- DEBUG-VIEW START default:_includes/footer -->',
$contents
);
self::assertStringContainsString(
'<!-- Include end: _includes/footer -->',
'<!-- DEBUG-VIEW ENDED default:_includes/footer -->',
$contents
);
}

public function testDebugIncludeRepeated() : void
{
$this->setDebugCollector();
$contents = $this->view->render('home/repeat-includes');
self::assertStringContainsString(
'<!-- DEBUG-VIEW START default:_includes/footer -->',
$contents
);
self::assertStringContainsString(
'<!-- DEBUG-VIEW ENDED default:_includes/footer -->',
$contents
);
self::assertStringContainsString(
'<!-- DEBUG-VIEW START default:_includes/footer:2 -->',
$contents
);
self::assertStringContainsString(
'<!-- DEBUG-VIEW ENDED default:_includes/footer:2 -->',
$contents
);
}
Expand All @@ -330,11 +353,11 @@ public function testDebugRender() : void
$this->setDebugCollector();
$contents = $this->view->render('home/index');
self::assertStringContainsString(
'<!-- Render start: home/index -->',
'<!-- DEBUG-VIEW START default:home/index -->',
$contents
);
self::assertStringContainsString(
'<!-- Render end: home/index -->',
'<!-- DEBUG-VIEW ENDED default:home/index -->',
$contents
);
}
Expand All @@ -347,22 +370,22 @@ public function testDebugComments() : void
$contents = $this->view->render('comments');
self::assertSame(
<<<'EOL'
<!-- Render start: comments -->
<!-- Layout start: _layouts/default -->
<!-- DEBUG-VIEW START default:comments -->
<!-- DEBUG-VIEW START default:_layouts/default -->
<h1>Layout Default</h1>
<!-- Block start: comments::contents -->
<!-- DEBUG-VIEW START default:comments::contents -->
CONTENTS
<!-- Include start: _includes/footer -->
<!-- DEBUG-VIEW START default:_includes/footer -->
<footer>Footer</footer>
<!-- Include end: _includes/footer -->
<!-- DEBUG-VIEW ENDED default:_includes/footer -->
<!-- Block end: comments::contents -->
<!-- DEBUG-VIEW ENDED default:comments::contents -->
<!-- Layout end: _layouts/default -->
<!-- Render end: comments -->
<!-- DEBUG-VIEW ENDED default:_layouts/default -->
<!-- DEBUG-VIEW ENDED default:comments -->
EOL,
$contents
);
Expand Down
14 changes: 14 additions & 0 deletions tests/Views/home/repeat-includes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* @var Framework\MVC\View $view
*/
$view->extends('_layouts/default', 'contents');
?>
<h2>Home Index</h2>
<div>Foo bar baz</div>
<div>
<?= $view->include('_includes/footer') ?>
</div>
<div>
<?= $view->include('_includes/footer') ?>
</div>

0 comments on commit 21f243c

Please sign in to comment.