You are here

public function TwigExtensionTest::testEscaping 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::testEscaping()
  2. 10 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 91

Class

TwigExtensionTest
Tests the twig extension.

Namespace

Drupal\Tests\Core\Template

Code

public function testEscaping($template, $expected) {
  $loader = new FilesystemLoader();
  $twig = new Environment($loader, [
    'debug' => TRUE,
    'cache' => FALSE,
    'autoescape' => 'html',
    'optimizations' => 0,
  ]);
  $twig
    ->addExtension($this->systemUnderTest);
  $name = '__string_template_test__';
  $nodes = $twig
    ->parse($twig
    ->tokenize(new Source($template, $name)));
  $this
    ->assertSame($expected, $nodes
    ->getNode('body')
    ->getNode(0)
    ->getNode('expr') instanceof FilterExpression);
}