You are here

public function TwigExtensionTest::testActiveTheme in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php \Drupal\Tests\Core\Template\TwigExtensionTest::testActiveTheme()
  2. 10 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 143

Class

TwigExtensionTest
Tests the twig extension.

Namespace

Drupal\Tests\Core\Template

Code

public function testActiveTheme() {
  $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);
}