2
0

PurePlateTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace Test\Michel\Renderer;
  3. use Michel\Renderer\PurePlate;
  4. use Michel\UniTester\TestCase;
  5. final class PurePlateTest extends TestCase
  6. {
  7. private PurePlate $renderer;
  8. protected function setUp(): void
  9. {
  10. $this->renderer = new PurePlate(__DIR__ . '/views');
  11. }
  12. protected function tearDown(): void
  13. {
  14. }
  15. protected function execute(): void
  16. {
  17. $this->testRenderBasicView();
  18. $this->testRenderViewWithLayout();
  19. $this->testRenderViewWithBlock();
  20. $this->testRenderViewWithExtendingBlock();
  21. $this->testStartAndEndBlocks();
  22. $this->testRenderViewNotFound();
  23. }
  24. public function testRenderBasicView(): void
  25. {
  26. $expectedOutput = 'Hello, World!';
  27. $output = $this->renderer->render('test.php', ['message' => 'Hello, World!']);
  28. $this->assertEquals($expectedOutput, $output);
  29. }
  30. public function testRenderViewWithLayout(): void
  31. {
  32. $expectedOutput = '<!DOCTYPE html><html lang="fr"><head><title></title></head><body class="body"></body></html>';
  33. $output = $this->renderer->render('test_layout.php');
  34. $this->assertEquals($expectedOutput, $output);
  35. }
  36. public function testRenderViewWithBlock(): void
  37. {
  38. $expectedOutput = '';
  39. $output = $this->renderer->render('test_block.php');
  40. $this->assertEquals($expectedOutput, $output);
  41. }
  42. public function testRenderViewWithExtendingBlock(): void
  43. {
  44. $expectedOutput = '<!DOCTYPE html><html lang="fr"><head><title>Page Title</title></head><body class="body">Page Content</body></html>';
  45. $output = $this->renderer->render('test_extends.php');
  46. $this->assertEquals($expectedOutput, $output);
  47. }
  48. public function testStartAndEndBlocks(): void
  49. {
  50. $this->renderer->startBlock('content');
  51. echo 'Block Content';
  52. $this->renderer->endBlock();
  53. $expectedOutput = 'Block Content';
  54. $output = $this->renderer->block('content');
  55. $this->assertEquals($expectedOutput, $output);
  56. }
  57. public function testRenderViewNotFound(): void
  58. {
  59. $this->expectException(\InvalidArgumentException::class, function () {
  60. $this->renderer->render('non_existent_template.php');
  61. });
  62. }
  63. }