function TwigExtensionTest::testActiveTheme

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php \Drupal\Tests\Core\Template\TwigExtensionTest::testActiveTheme()
  2. 8.9.x core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php \Drupal\Tests\Core\Template\TwigExtensionTest::testActiveTheme()
  3. 11.x core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php \Drupal\Tests\Core\Template\TwigExtensionTest::testActiveTheme()

Tests the active_theme function.

File

core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php, line 151

Class

TwigExtensionTest
Tests the twig extension.

Namespace

Drupal\Tests\Core\Template

Code

public function testActiveTheme() : void {
    $active_theme = $this->getMockBuilder('\\Drupal\\Core\\Theme\\ActiveTheme')
        ->disableOriginalConstructor()
        ->getMock();
    $active_theme->expects($this->once())
        ->method('getName')
        ->willReturn('test_theme');
    $this->themeManager
        ->expects($this->once())
        ->method('getActiveTheme')
        ->willReturn($active_theme);
    $loader = new StringLoader();
    $twig = new Environment($loader);
    $twig->addExtension($this->systemUnderTest);
    $result = $twig->render('{{ active_theme() }}');
    $this->assertEquals('test_theme', $result);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.