Mercurial > hg > isophonics-drupal-site
comparison core/modules/system/src/Tests/Theme/TwigRawTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\system\Tests\Theme; | |
4 | |
5 use Drupal\simpletest\WebTestBase; | |
6 | |
7 /** | |
8 * Tests Twig 'raw' filter. | |
9 * | |
10 * @group Theme | |
11 */ | |
12 class TwigRawTest extends WebTestBase { | |
13 | |
14 /** | |
15 * Modules to enable. | |
16 * | |
17 * @var array | |
18 */ | |
19 public static $modules = ['twig_theme_test']; | |
20 | |
21 /** | |
22 * Tests the raw filter inside an autoescape tag. | |
23 */ | |
24 public function testAutoescapeRaw() { | |
25 $test = [ | |
26 '#theme' => 'twig_raw_test', | |
27 '#script' => '<script>alert("This alert is real because I will put it through the raw filter!");</script>', | |
28 ]; | |
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>'); | |
32 } | |
33 | |
34 /** | |
35 * Tests autoescaping of unsafe content. | |
36 * | |
37 * This is one of the most important tests in Drupal itself in terms of | |
38 * security. | |
39 */ | |
40 public function testAutoescape() { | |
41 $script = '<script>alert("This alert is unreal!");</script>'; | |
42 $build = [ | |
43 '#theme' => 'twig_autoescape_test', | |
44 '#script' => $script, | |
45 ]; | |
46 $rendered = \Drupal::service('renderer')->renderRoot($build); | |
47 $this->setRawContent($rendered); | |
48 $this->assertEscaped($script); | |
49 } | |
50 | |
51 } |