X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fsystem%2Ftests%2Fsrc%2FKernel%2FTheme%2FTwigNamespaceTest.php;fp=web%2Fcore%2Fmodules%2Fsystem%2Ftests%2Fsrc%2FKernel%2FTheme%2FTwigNamespaceTest.php;h=4ffd2558f0744d5a466f7965453499f8320f9118;hp=0000000000000000000000000000000000000000;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/modules/system/tests/src/Kernel/Theme/TwigNamespaceTest.php b/web/core/modules/system/tests/src/Kernel/Theme/TwigNamespaceTest.php new file mode 100644 index 000000000..4ffd2558f --- /dev/null +++ b/web/core/modules/system/tests/src/Kernel/Theme/TwigNamespaceTest.php @@ -0,0 +1,62 @@ +install(['test_theme', 'bartik']); + $this->twig = \Drupal::service('twig'); + } + + /** + * Checks to see if a value is a twig template. + */ + public function assertTwigTemplate($value, $message = '', $group = 'Other') { + $this->assertTrue($value instanceof \Twig_Template, $message, $group); + } + + /** + * Tests template discovery using namespaces. + */ + public function testTemplateDiscovery() { + // Tests resolving namespaced templates in modules. + $this->assertTwigTemplate($this->twig->resolveTemplate('@node/node.html.twig'), 'Found node.html.twig in node module.'); + + // Tests resolving namespaced templates in themes. + $this->assertTwigTemplate($this->twig->resolveTemplate('@bartik/page.html.twig'), 'Found page.html.twig in Bartik theme.'); + } + + /** + * Tests template extension and includes using namespaces. + */ + public function testTwigNamespaces() { + // Test twig @extends and @include in template files. + $test = ['#theme' => 'twig_namespace_test']; + $this->setRawContent(\Drupal::service('renderer')->renderRoot($test)); + + $this->assertText('This line is from twig_namespace_a/templates/test.html.twig'); + $this->assertText('This line is from twig_namespace_b/templates/test.html.twig'); + } + +}