diff --git a/tests/src/Template/TwigExtensionTest.php b/tests/src/Template/TwigExtensionTest.php new file mode 100644 index 0000000..7bb5f05 --- /dev/null +++ b/tests/src/Template/TwigExtensionTest.php @@ -0,0 +1,74 @@ +renderer = PhpunitCompatibilityTrait::createMock('\Drupal\Core\Render\RendererInterface'); + + $this->systemUnderTest = new TwigExtension($this->renderer); + } + + /** + * Tests creating #theme render arrays within a Twig template. + * + * @covers ::theme + */ + public function testTheme() { + $loader = new StringLoader(); + $twig = new \Twig_Environment($loader); + $twig->addExtension($this->systemUnderTest); + + $result = $twig->render( + '{{ theme("item_list", { "items": list }) }}', + [ + 'list' => ['this', 'list'], + ] + ); + $expected = ''; + $this->assertEquals($expected, $result); + + // Test nested render array. + $result = $twig->render( + '{{ theme("item_list", { "items": [ link ] }) }}', + [ + 'link' => [ + '#type' => 'link', + '#title' => 'example link', + '#url' => 'https://example.com', + ], + ] + ); + $expected = ''; + $this->assertEquals($expected, $result); + } + +}