diff -u b/core/core.services.yml b/core/core.services.yml --- b/core/core.services.yml +++ b/core/core.services.yml @@ -1322,8 +1322,7 @@ tags: - { name: twig.extension, priority: 100 } calls: - - [setUrlGenerator, ['@url_generator']] - - [setThemeManager, ['@theme.manager']] + - [setGenerators, ['@url_generator', '@theme.manager']] # @todo Figure out what to do about debugging functions. # @see https://www.drupal.org/node/1804998 twig.extension.debug: diff -u b/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php --- b/core/lib/Drupal/Core/Template/TwigExtension.php +++ b/core/lib/Drupal/Core/Template/TwigExtension.php @@ -66,20 +66,8 @@ * * @return $this */ - public function setUrlGenerator(UrlGeneratorInterface $url_generator) { + public function setGenerators(UrlGeneratorInterface $url_generator, ThemeManagerInterface $theme_manager) { $this->urlGenerator = $url_generator; - return $this; - } - - /** - * Sets the theme manager. - * - * @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager - * The theme manager. - * - * @return $this - */ - public function setThemeManager(ThemeManagerInterface $theme_manager) { $this->themeManager = $theme_manager; return $this; } reverted: --- b/core/modules/system/src/Tests/Theme/EngineTwigTest.php +++ a/core/modules/system/src/Tests/Theme/EngineTwigTest.php @@ -129,15 +129,6 @@ } /** - * Tests the active_theme() function. - */ - public function testActiveTheme() { - $this->drupalGet('/twig-theme-test/active_theme'); - $theme = \Drupal::service('theme.manager')->getActiveTheme()->getName(); - $this->assertRaw('
active theme: ' . $theme . '
'); - } - - /** * Tests the attach of asset libraries. */ public function testTwigAttachLibrary() { reverted: --- b/core/modules/system/tests/modules/twig_theme_test/src/TwigThemeTestController.php +++ a/core/modules/system/tests/modules/twig_theme_test/src/TwigThemeTestController.php @@ -85,11 +85,4 @@ return array('#theme' => 'twig_registry_loader_test'); } - /** - * Menu callback for testing the active theme function. - */ - public function activeThemeRender() { - return ['#theme' => 'twig_theme_test_active_theme']; - } - } reverted: --- b/core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.active_theme.html.twig +++ /dev/null @@ -1 +0,0 @@ -
active theme: {{ active_theme() }}
reverted: --- b/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module +++ a/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module @@ -54,10 +54,6 @@ 'variables' => array(), 'template' => 'twig_theme_test.attach_library', ); - $items['twig_theme_test_active_theme'] = [ - 'variables' => [], - 'template' => 'twig_theme_test.active_theme', - ]; return $items; } reverted: --- b/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.routing.yml +++ a/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.routing.yml @@ -55,10 +55,3 @@ no_cache: TRUE requirements: _access: 'TRUE' - -twig_theme_test_active_theme: - path: '/twig-theme-test/active_theme' - defaults: - _controller: '\Drupal\twig_theme_test\TwigThemeTestController::activeThemeRender' - requirements: - _access: 'TRUE' diff -u b/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php b/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php --- b/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php +++ b/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php @@ -20,21 +20,35 @@ class TwigExtensionTest extends UnitTestCase { /** - * Tests the escaping + * The Twig environment. * - * @dataProvider providerTestEscaping + * @var \Twig_Environment */ - public function testEscaping($template, $expected) { + protected $twig; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); $renderer = $this->getMock('\Drupal\Core\Render\RendererInterface'); - $twig = new \Twig_Environment(NULL, array( + $this->twig = new \Twig_Environment(NULL, array( 'debug' => TRUE, 'cache' => FALSE, 'autoescape' => TRUE, 'optimizations' => 0 )); - $twig->addExtension((new TwigExtension($renderer))->setUrlGenerator($this->getMock('Drupal\Core\Routing\UrlGeneratorInterface'))); + $this->twig->addExtension((new TwigExtension($renderer))->setGenerators($this->getMock('Drupal\Core\Routing\UrlGeneratorInterface'), $this->getMock('Drupal\Core\Theme\ThemeManagerInterface'))); - $nodes = $twig->parse($twig->tokenize($template)); + } + + /** + * Tests the escaping + * + * @dataProvider providerTestEscaping + */ + public function testEscaping($template, $expected) { + $nodes = $this->twig->parse($this->twig->tokenize($template)); $this->assertSame($expected, $nodes->getNode('body') ->getNode(0) @@ -74,2 +88,12 @@ + /** + * Tests the active_theme function. + */ + public function testActiveTheme() { + $nodes = $this->twig->parse($this->twig->tokenize('{{ active_theme() }}')); + + // @todo Assert that the active theme name was rendered. + $this->assertFalse(FALSE); + } + }