You are here

public function TwigExtensionTest::testActiveTheme in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 83
Contains \Drupal\Tests\Core\Template\TwigExtensionTest.

Class

TwigExtensionTest
Tests the twig extension.

Namespace

Drupal\Tests\Core\Template

Code

public function testActiveTheme() {
  $renderer = $this
    ->getMock('\\Drupal\\Core\\Render\\RendererInterface');
  $extension = new TwigExtension($renderer);
  $theme_manager = $this
    ->getMock('\\Drupal\\Core\\Theme\\ThemeManagerInterface');
  $active_theme = $this
    ->getMockBuilder('\\Drupal\\Core\\Theme\\ActiveTheme')
    ->disableOriginalConstructor()
    ->getMock();
  $active_theme
    ->expects($this
    ->once())
    ->method('getName')
    ->willReturn('test_theme');
  $theme_manager
    ->expects($this
    ->once())
    ->method('getActiveTheme')
    ->willReturn($active_theme);
  $extension
    ->setThemeManager($theme_manager);
  $loader = new \Twig_Loader_String();
  $twig = new \Twig_Environment($loader);
  $twig
    ->addExtension($extension);
  $result = $twig
    ->render('{{ active_theme() }}');
  $this
    ->assertEquals('test_theme', $result);
}