diff --git a/core/modules/system/src/Tests/Theme/TwigLoaderTest.php b/core/modules/system/src/Tests/Theme/TwigLoaderTest.php new file mode 100644 index 0000000..91de1e4 --- /dev/null +++ b/core/modules/system/src/Tests/Theme/TwigLoaderTest.php @@ -0,0 +1,39 @@ +loadTemplate('kittens'); + $this->assertEqual($template->render(array()), 'kittens', 'Passing "kittens" to the custom Twig loader returns "kittens".'); + + $template = $environment->loadTemplate('meow'); + $this->assertEqual($template->render(array()), 'cats', 'Passing something other than "kittens" to the custom Twig loader returns "cats".'); + } + +} diff --git a/core/modules/system/src/Tests/Theme/TwigRegistryLoaderTest.php b/core/modules/system/src/Tests/Theme/TwigRegistryLoaderTest.php new file mode 100644 index 0000000..589632b --- /dev/null +++ b/core/modules/system/src/Tests/Theme/TwigRegistryLoaderTest.php @@ -0,0 +1,70 @@ +install(array('test_theme_twig_registry_loader')); + $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 the Drupal theme registry. + */ + public function testTemplateDiscovery() { + $this->assertTwigTemplate($this->twig->resolveTemplate('block.html.twig'), 'Found block.html.twig in block module.'); + } + + /** + * Tests template extension and includes using the Drupal theme registry. + */ + public function testTwigNamespaces() { + // Test the module-provided extend and insert templates. + $this->drupalGet('twig-theme-test/registry-loader'); + $this->assertText('This line is from twig_theme_test/templates/twig-registry-loader-test-extend.html.twig'); + $this->assertText('This line is from twig_theme_test/templates/twig-registry-loader-test-include.html.twig'); + + // Enable a theme that overrides the extend and insert templates to ensure + // they are picked up by the registry loader. + $this->config('system.theme') + ->set('default', 'test_theme_twig_registry_loader') + ->save(); + $this->drupalGet('twig-theme-test/registry-loader'); + $this->assertText('This line is from test_theme_twig_registry_loader/templates/twig-registry-loader-test-extend.html.twig'); + $this->assertText('This line is from test_theme_twig_registry_loader/templates/twig-registry-loader-test-include.html.twig'); + } + +} diff --git a/core/modules/system/tests/modules/twig_loader_test/src/Loader/TestLoader.php b/core/modules/system/tests/modules/twig_loader_test/src/Loader/TestLoader.php new file mode 100644 index 0000000..9f32969 --- /dev/null +++ b/core/modules/system/tests/modules/twig_loader_test/src/Loader/TestLoader.php @@ -0,0 +1,50 @@ + 'twig_registry_loader_test'); + } + } diff --git a/core/modules/system/tests/modules/twig_theme_test/templates/twig-registry-loader-test-extend.html.twig b/core/modules/system/tests/modules/twig_theme_test/templates/twig-registry-loader-test-extend.html.twig new file mode 100644 index 0000000..e18e68e --- /dev/null +++ b/core/modules/system/tests/modules/twig_theme_test/templates/twig-registry-loader-test-extend.html.twig @@ -0,0 +1,5 @@ +This line is from twig_theme_test/templates/twig-registry-loader-test-extend.html.twig + +{% block content %} +This text is in a block. +{% endblock %} diff --git a/core/modules/system/tests/modules/twig_theme_test/templates/twig-registry-loader-test-include.html.twig b/core/modules/system/tests/modules/twig_theme_test/templates/twig-registry-loader-test-include.html.twig new file mode 100644 index 0000000..438fd2b --- /dev/null +++ b/core/modules/system/tests/modules/twig_theme_test/templates/twig-registry-loader-test-include.html.twig @@ -0,0 +1 @@ +This line is from twig_theme_test/templates/twig-registry-loader-test-include.html.twig diff --git a/core/modules/system/tests/modules/twig_theme_test/templates/twig-registry-loader-test.html.twig b/core/modules/system/tests/modules/twig_theme_test/templates/twig-registry-loader-test.html.twig new file mode 100644 index 0000000..a3723b5 --- /dev/null +++ b/core/modules/system/tests/modules/twig_theme_test/templates/twig-registry-loader-test.html.twig @@ -0,0 +1,5 @@ +{% extends "twig-registry-loader-test-extend.html.twig" %} + +{% block content %} + {% include "twig-registry-loader-test-include.html.twig" %} +{% endblock %} 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 4a415cd..e42b020 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 @@ -19,6 +19,15 @@ function twig_theme_test_theme($existing, $type, $theme, $path) { 'variables' => array(), 'template' => 'twig_namespace_test', ); + $items['twig_registry_loader_test'] = array( + 'variables' => array(), + ); + $items['twig_registry_loader_test_include'] = array( + 'variables' => array(), + ); + $items['twig_registry_loader_test_extend'] = array( + 'variables' => array(), + ); $items['twig_raw_test'] = array( 'variables' => array('script' => ''), ); 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 d2abf91..4d30bb9 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 @@ -32,3 +32,10 @@ twig_theme_test_file_url: _controller: '\Drupal\twig_theme_test\TwigThemeTestController::fileUrlRender' requirements: _access: 'TRUE' + +twig_theme_test_registry_loader: + path: '/twig-theme-test/registry-loader' + defaults: + _controller: '\Drupal\twig_theme_test\TwigThemeTestController::registryLoaderRender' + requirements: + _access: 'TRUE' diff --git a/core/modules/system/tests/themes/test_theme_twig_registry_loader/templates/twig-registry-loader-test-extend.html.twig b/core/modules/system/tests/themes/test_theme_twig_registry_loader/templates/twig-registry-loader-test-extend.html.twig new file mode 100644 index 0000000..e1a9eee --- /dev/null +++ b/core/modules/system/tests/themes/test_theme_twig_registry_loader/templates/twig-registry-loader-test-extend.html.twig @@ -0,0 +1,5 @@ +This line is from test_theme_twig_registry_loader/templates/twig-registry-loader-test-extend.html.twig + +{% block content %} +This text is in a block. +{% endblock %} diff --git a/core/modules/system/tests/themes/test_theme_twig_registry_loader/templates/twig-registry-loader-test-include.html.twig b/core/modules/system/tests/themes/test_theme_twig_registry_loader/templates/twig-registry-loader-test-include.html.twig new file mode 100644 index 0000000..3a1f395 --- /dev/null +++ b/core/modules/system/tests/themes/test_theme_twig_registry_loader/templates/twig-registry-loader-test-include.html.twig @@ -0,0 +1 @@ +This line is from test_theme_twig_registry_loader/templates/twig-registry-loader-test-include.html.twig diff --git a/core/modules/system/tests/themes/test_theme_twig_registry_loader/test_theme_twig_registry_loader.info.yml b/core/modules/system/tests/themes/test_theme_twig_registry_loader/test_theme_twig_registry_loader.info.yml new file mode 100644 index 0000000..9ee01c5 --- /dev/null +++ b/core/modules/system/tests/themes/test_theme_twig_registry_loader/test_theme_twig_registry_loader.info.yml @@ -0,0 +1,5 @@ +name: 'Twig registry loader test' +type: theme +description: 'Support module for Twig registry loader testing.' +version: VERSION +core: 8.x diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php index dd03a1f..db6f39f 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php @@ -42,6 +42,25 @@ public function testProcessNoConsumers() { } /** + * Tests a required consumer with no handlers. + * + * @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException + * @expectedExceptionMessage At least one service tagged with 'consumer_id' is required. + * @covers ::process + */ + public function testProcessRequiredHandlers() { + $container = $this->buildContainer(); + $container + ->register('consumer_id', __NAMESPACE__ . '\ValidConsumer') + ->addTag('service_collector', array( + 'required' => TRUE, + )); + + $handler_pass = new TaggedHandlersPass(); + $handler_pass->process($container); + } + + /** * Tests consumer with missing interface in non-production environment. * * @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException