summaryrefslogtreecommitdiff
path: root/tests/Unit/Renderer
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2019-07-21 13:32:45 +0200
committerGitHub <noreply@github.com>2019-07-21 13:32:45 +0200
commitd4d4b409b6fd96ca297af323936b8922d45b6eda (patch)
tree6c8efa1a1e429f3965820838796cb4b97cd2df11 /tests/Unit/Renderer
parentd5bf7fd065a5ea93dea9fd55e6ac225ee062a3db (diff)
parent51a3c6eb44a5dbdf9d7a3cfac678f0d29b0d3eef (diff)
Merge pull request #622 from MyIgel/controllers
AuthController (login, logout), use templating, replaced gettext, input validation
Diffstat (limited to 'tests/Unit/Renderer')
-rw-r--r--tests/Unit/Renderer/EngineTest.php25
-rw-r--r--tests/Unit/Renderer/HtmlEngineTest.php5
-rw-r--r--tests/Unit/Renderer/Stub/EngineImplementation.php32
-rw-r--r--tests/Unit/Renderer/Twig/Extensions/TranslationTest.php2
-rw-r--r--tests/Unit/Renderer/TwigEngineTest.php12
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);
}