You are here

public function TwigExtensionTest::testEscaping 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::testEscaping()

Tests the escaping

@dataProvider providerTestEscaping

File

core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php, line 32
Contains \Drupal\Tests\Core\Template\TwigExtensionTest.

Class

TwigExtensionTest
Tests the twig extension.

Namespace

Drupal\Tests\Core\Template

Code

public function testEscaping($template, $expected) {
  $renderer = $this
    ->getMock('\\Drupal\\Core\\Render\\RendererInterface');
  $twig = new \Twig_Environment(NULL, array(
    'debug' => TRUE,
    'cache' => FALSE,
    'autoescape' => 'html',
    'optimizations' => 0,
  ));
  $twig
    ->addExtension((new TwigExtension($renderer))
    ->setUrlGenerator($this
    ->getMock('Drupal\\Core\\Routing\\UrlGeneratorInterface')));
  $nodes = $twig
    ->parse($twig
    ->tokenize($template));
  $this
    ->assertSame($expected, $nodes
    ->getNode('body')
    ->getNode(0)
    ->getNode('expr') instanceof \Twig_Node_Expression_Filter);
}