TwigRawTest.php in Drupal 10
File
core/modules/system/tests/src/Kernel/Theme/TwigRawTest.php
View source
<?php
namespace Drupal\Tests\system\Kernel\Theme;
use Drupal\KernelTests\KernelTestBase;
class TwigRawTest extends KernelTestBase {
protected static $modules = [
'twig_theme_test',
];
public function testAutoescapeRaw() {
$test = [
'#theme' => 'twig_raw_test',
'#script' => '<script>alert("This alert is real because I will put it through the raw filter!");</script>',
];
$rendered = \Drupal::service('renderer')
->renderRoot($test);
$this
->setRawContent($rendered);
$this
->assertRaw('<script>alert("This alert is real because I will put it through the raw filter!");</script>');
}
public function testAutoescape() {
$script = '<script>alert("This alert is unreal!");</script>';
$build = [
'#theme' => 'twig_autoescape_test',
'#script' => $script,
];
$rendered = \Drupal::service('renderer')
->renderRoot($build);
$this
->setRawContent($rendered);
$this
->assertEscaped($script);
}
}