diff options
Diffstat (limited to 'tests/Unit/Renderer')
-rw-r--r-- | tests/Unit/Renderer/EngineTest.php | 25 | ||||
-rw-r--r-- | tests/Unit/Renderer/HtmlEngineTest.php | 5 | ||||
-rw-r--r-- | tests/Unit/Renderer/Stub/EngineImplementation.php | 32 | ||||
-rw-r--r-- | tests/Unit/Renderer/Twig/Extensions/TranslationTest.php | 2 | ||||
-rw-r--r-- | tests/Unit/Renderer/TwigEngineTest.php | 12 |
5 files changed, 67 insertions, 9 deletions
diff --git a/tests/Unit/Renderer/EngineTest.php b/tests/Unit/Renderer/EngineTest.php new file mode 100644 index 00000000..659d85c5 --- /dev/null +++ b/tests/Unit/Renderer/EngineTest.php @@ -0,0 +1,25 @@ +<?php + +namespace Engelsystem\Test\Unit\Renderer; + +use Engelsystem\Test\Unit\Renderer\Stub\EngineImplementation; +use PHPUnit\Framework\TestCase; + +class EngineTest extends TestCase +{ + /** + * @covers \Engelsystem\Renderer\Engine::share + */ + public function testShare() + { + $engine = new EngineImplementation(); + $engine->share(['foo' => ['bar' => 'baz', 'lorem' => 'ipsum']]); + $engine->share(['foo' => ['lorem' => 'dolor']]); + $engine->share('key', 'value'); + + $this->assertEquals( + ['foo' => ['bar' => 'baz', 'lorem' => 'dolor'], 'key' => 'value'], + $engine->getSharedData() + ); + } +} diff --git a/tests/Unit/Renderer/HtmlEngineTest.php b/tests/Unit/Renderer/HtmlEngineTest.php index 4a31e4bc..f76e7528 100644 --- a/tests/Unit/Renderer/HtmlEngineTest.php +++ b/tests/Unit/Renderer/HtmlEngineTest.php @@ -16,11 +16,12 @@ class HtmlEngineTest extends TestCase public function testGet() { $engine = new HtmlEngine(); + $engine->share('shared_data', 'tester'); - $file = $this->createTempFile('<div>%main_content%</div>'); + $file = $this->createTempFile('<div>%main_content% is a %shared_data%</div>'); $data = $engine->get($file, ['main_content' => 'Lorem ipsum dolor sit']); - $this->assertEquals('<div>Lorem ipsum dolor sit</div>', $data); + $this->assertEquals('<div>Lorem ipsum dolor sit is a tester</div>', $data); } /** diff --git a/tests/Unit/Renderer/Stub/EngineImplementation.php b/tests/Unit/Renderer/Stub/EngineImplementation.php new file mode 100644 index 00000000..fc436569 --- /dev/null +++ b/tests/Unit/Renderer/Stub/EngineImplementation.php @@ -0,0 +1,32 @@ +<?php + +namespace Engelsystem\Test\Unit\Renderer\Stub; + +use Engelsystem\Renderer\Engine; + +class EngineImplementation extends Engine +{ + /** + * @inheritdoc + */ + public function get(string $path, array $data = []): string + { + return ''; + } + + /** + * @inheritdoc + */ + public function canRender(string $path): bool + { + return true; + } + + /** + * @return array + */ + public function getSharedData(): array + { + return $this->sharedData; + } +} diff --git a/tests/Unit/Renderer/Twig/Extensions/TranslationTest.php b/tests/Unit/Renderer/Twig/Extensions/TranslationTest.php index 18705683..0b055c44 100644 --- a/tests/Unit/Renderer/Twig/Extensions/TranslationTest.php +++ b/tests/Unit/Renderer/Twig/Extensions/TranslationTest.php @@ -2,7 +2,7 @@ namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions; -use Engelsystem\Helpers\Translator; +use Engelsystem\Helpers\Translation\Translator; use Engelsystem\Renderer\Twig\Extensions\Translation; use PHPUnit\Framework\MockObject\MockObject; use Twig_Extensions_TokenParser_Trans as TranslationTokenParser; diff --git a/tests/Unit/Renderer/TwigEngineTest.php b/tests/Unit/Renderer/TwigEngineTest.php index 9d0618f1..5e5e59d9 100644 --- a/tests/Unit/Renderer/TwigEngineTest.php +++ b/tests/Unit/Renderer/TwigEngineTest.php @@ -20,16 +20,16 @@ class TwigEngineTest extends TestCase $twig = $this->createMock(Twig::class); $path = 'foo.twig'; - $data = ['lorem' => 'ipsum']; - $twig->expects($this->once()) ->method('render') - ->with($path, $data) - ->willReturn('LoremIpsum!'); + ->with($path, ['lorem' => 'ipsum', 'shared' => 'data']) + ->willReturn('LoremIpsum data!'); $engine = new TwigEngine($twig); - $return = $engine->get($path, $data); - $this->assertEquals('LoremIpsum!', $return); + $engine->share('shared', 'data'); + + $return = $engine->get($path, ['lorem' => 'ipsum']); + $this->assertEquals('LoremIpsum data!', $return); } |