function TwigExtensionTest::testSafeStringEscaping
Same name and namespace in other branches
- 11.x core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php \Drupal\Tests\Core\Template\TwigExtensionTest::testSafeStringEscaping()
- 10 core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php \Drupal\Tests\Core\Template\TwigExtensionTest::testSafeStringEscaping()
- 9 core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php \Drupal\Tests\Core\Template\TwigExtensionTest::testSafeStringEscaping()
- 8.9.x core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php \Drupal\Tests\Core\Template\TwigExtensionTest::testSafeStringEscaping()
Tests the escaping of objects implementing MarkupInterface.
@legacy-covers ::escapeFilter
File
-
core/
tests/ Drupal/ Tests/ Core/ Template/ TwigExtensionTest.php, line 229
Class
- TwigExtensionTest
- Tests the twig extension.
Namespace
Drupal\Tests\Core\TemplateCode
public function testSafeStringEscaping() : void {
$loader = new FilesystemLoader();
$twig = new Environment($loader, [
'debug' => TRUE,
'cache' => FALSE,
'autoescape' => 'html',
'optimizations' => 0,
]);
// TwigExtension should return objects that implement MarkupInterface cast
// to a string, but without any sanitization.
$html = '<div>Some text</div>';
$markup_object = Markup::create($html);
$this->assertSame($html, $this->systemUnderTest
->escapeFilter($twig, $markup_object, 'html', 'UTF-8', TRUE));
// Ensure objects that do not implement MarkupInterface are escaped.
$string_object = new TwigExtensionTestString("<script>alert('here');</script>");
$this->assertSame('<script>alert('here');</script>', $this->systemUnderTest
->escapeFilter($twig, $string_object, 'html', 'UTF-8', TRUE));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.