public function TwigExtensionTest::testSafeStringEscaping in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php \Drupal\Tests\Core\Template\TwigExtensionTest::testSafeStringEscaping()
Tests the escaping of objects implementing MarkupInterface.
@covers ::escapeFilter
File
- core/
tests/ Drupal/ Tests/ Core/ Template/ TwigExtensionTest.php, line 160 - Contains \Drupal\Tests\Core\Template\TwigExtensionTest.
Class
- TwigExtensionTest
- Tests the twig extension.
Namespace
Drupal\Tests\Core\TemplateCode
public function testSafeStringEscaping() {
$renderer = $this
->getMock('\\Drupal\\Core\\Render\\RendererInterface');
$twig = new \Twig_Environment(NULL, array(
'debug' => TRUE,
'cache' => FALSE,
'autoescape' => 'html',
'optimizations' => 0,
));
$twig_extension = new TwigExtension($renderer);
// By default, TwigExtension will attempt to cast objects to strings.
// Ensure objects that implement MarkupInterface are unchanged.
$safe_string = $this
->getMock('\\Drupal\\Component\\Render\\MarkupInterface');
$this
->assertSame($safe_string, $twig_extension
->escapeFilter($twig, $safe_string, '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>', $twig_extension
->escapeFilter($twig, $string_object, 'html', 'UTF-8', TRUE));
}