class TwigRawTest
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Kernel/Theme/TwigRawTest.php \Drupal\Tests\system\Kernel\Theme\TwigRawTest
- 10 core/modules/system/tests/src/Kernel/Theme/TwigRawTest.php \Drupal\Tests\system\Kernel\Theme\TwigRawTest
- 8.9.x core/modules/system/tests/src/Kernel/Theme/TwigRawTest.php \Drupal\Tests\system\Kernel\Theme\TwigRawTest
Tests Twig 'raw' filter.
@group Theme
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\system\Kernel\Theme\TwigRawTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of TwigRawTest
File
-
core/
modules/ system/ tests/ src/ Kernel/ Theme/ TwigRawTest.php, line 12
Namespace
Drupal\Tests\system\Kernel\ThemeView source
class TwigRawTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'twig_theme_test',
];
/**
* Tests the raw filter inside an autoescape tag.
*/
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>');
}
/**
* Tests autoescaping of unsafe content.
*
* This is one of the most important tests in Drupal itself in terms of
* security.
*/
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);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.