diff --git a/core/modules/system/tests/modules/twig_theme_test/src/TwigThemeTestController.php b/core/modules/system/tests/modules/twig_theme_test/src/TwigThemeTestController.php index 1e995c58f754c5441b8abaeafd350c97327a3c1f..fcaf319368ad5070e986d2aafff2d5e8d0e0effe 100644 --- a/core/modules/system/tests/modules/twig_theme_test/src/TwigThemeTestController.php +++ b/core/modules/system/tests/modules/twig_theme_test/src/TwigThemeTestController.php @@ -104,4 +104,11 @@ public function renderable() { ]; } + /** + * Renders for testing the embed tag in a Twig template. + */ + public function embedTagRender() { + return ['#theme' => 'twig_theme_test_embed_tag']; + } + } diff --git a/core/modules/system/tests/modules/twig_theme_test/templates/twig-theme-test-embed-tag-embedded.html.twig b/core/modules/system/tests/modules/twig_theme_test/templates/twig-theme-test-embed-tag-embedded.html.twig new file mode 100644 index 0000000000000000000000000000000000000000..63d7f477cbb9683ca3e24bb6f02344c28396749b --- /dev/null +++ b/core/modules/system/tests/modules/twig_theme_test/templates/twig-theme-test-embed-tag-embedded.html.twig @@ -0,0 +1 @@ +This line is from twig_theme_test/templates/twig-theme-test-embed-tag-embedded.html.twig diff --git a/core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.embed_tag.html.twig b/core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.embed_tag.html.twig new file mode 100644 index 0000000000000000000000000000000000000000..035c3784e4e7bfd071f5a7c5cd2de3dd8e6da24b --- /dev/null +++ b/core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.embed_tag.html.twig @@ -0,0 +1,3 @@ +{% embed "@twig_theme_test/twig-theme-test-embed-tag-embedded.html.twig" %} + +{% endembed %} diff --git a/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module b/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module index a8b4086203ad844160a9e5fcd064be20e3644b5d..31a1a4693043bb1f400476fad0b95ba7c42a6a68 100644 --- a/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module +++ b/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module @@ -73,6 +73,10 @@ function twig_theme_test_theme($existing, $type, $theme, $path) { ], 'template' => 'twig_theme_test.renderable', ]; + $items['twig_theme_test_embed_tag'] = [ + 'variables' => [], + 'template' => 'twig_theme_test.embed_tag', + ]; return $items; } diff --git a/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.routing.yml b/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.routing.yml index df665c346431b652f805a69f448c5f5e0e6540dc..e671d70fbbf73c71d3543cbdd925bb0fb6291fa6 100644 --- a/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.routing.yml +++ b/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.routing.yml @@ -69,3 +69,10 @@ twig_theme_test_renderable: _controller: '\Drupal\twig_theme_test\TwigThemeTestController::renderable' requirements: _access: 'TRUE' + +twig_theme_test_embed_tag: + path: '/twig-theme-test/embed-tag' + defaults: + _controller: '\Drupal\twig_theme_test\TwigThemeTestController::embedTagRender' + requirements: + _access: 'TRUE' diff --git a/core/modules/system/tests/src/Functional/Theme/TwigEnvironmentTest.php b/core/modules/system/tests/src/Functional/Theme/TwigEnvironmentTest.php new file mode 100644 index 0000000000000000000000000000000000000000..26f47e9068eb3c1fbd25949c43cfba2e327b211d --- /dev/null +++ b/core/modules/system/tests/src/Functional/Theme/TwigEnvironmentTest.php @@ -0,0 +1,30 @@ +<?php + +namespace Drupal\Tests\system\Functional\Theme; + +use Drupal\Tests\BrowserTestBase; + +/** + * Tests Twig environment. + * + * @group Theme + */ +class TwigEnvironmentTest extends BrowserTestBase { + + /** + * {@inheritdoc} + */ + protected static $modules = ['twig_theme_test']; + + /** + * Tests template class loading with Twig embed. + */ + public function testTwigEmbed() { + $assert_session = $this->assertSession(); + // Test the Twig embed tag. + $this->drupalGet('twig-theme-test/embed-tag'); + $assert_session->statusCodeEquals(200); + $assert_session->responseContains('This line is from twig_theme_test/templates/twig-theme-test-embed-tag-embedded.html.twig'); + } + +}