3 namespace Drupal\system\Tests\Theme;
5 use Drupal\simpletest\WebTestBase;
8 * Tests Twig 'raw' filter.
12 class TwigRawTest extends WebTestBase {
19 public static $modules = ['twig_theme_test'];
22 * Tests the raw filter inside an autoescape tag.
24 public function testAutoescapeRaw() {
26 '#theme' => 'twig_raw_test',
27 '#script' => '<script>alert("This alert is real because I will put it through the raw filter!");</script>',
29 $rendered = \Drupal::service('renderer')->renderRoot($test);
30 $this->setRawContent($rendered);
31 $this->assertRaw('<script>alert("This alert is real because I will put it through the raw filter!");</script>');
35 * Tests autoescaping of unsafe content.
37 * This is one of the most important tests in Drupal itself in terms of
40 public function testAutoescape() {
41 $script = '<script>alert("This alert is unreal!");</script>';
43 '#theme' => 'twig_autoescape_test',
46 $rendered = \Drupal::service('renderer')->renderRoot($build);
47 $this->setRawContent($rendered);
48 $this->assertEscaped($script);