function FieldKernelTest::testRewriteHtmlWithTokens
Same name in other branches
- 8.9.x core/modules/views/tests/src/Kernel/Handler/FieldKernelTest.php \Drupal\Tests\views\Kernel\Handler\FieldKernelTest::testRewriteHtmlWithTokens()
- 10 core/modules/views/tests/src/Kernel/Handler/FieldKernelTest.php \Drupal\Tests\views\Kernel\Handler\FieldKernelTest::testRewriteHtmlWithTokens()
- 11.x core/modules/views/tests/src/Kernel/Handler/FieldKernelTest.php \Drupal\Tests\views\Kernel\Handler\FieldKernelTest::testRewriteHtmlWithTokens()
Tests rewriting of the output with HTML.
File
-
core/
modules/ views/ tests/ src/ Kernel/ Handler/ FieldKernelTest.php, line 163
Class
- FieldKernelTest
- Tests the generic field handler.
Namespace
Drupal\Tests\views\Kernel\HandlerCode
public function testRewriteHtmlWithTokens() {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$view = Views::getView('test_view');
$view->initHandlers();
$this->executeView($view);
$row = $view->result[0];
$id_field = $view->field['id'];
$id_field->options['alter']['text'] = '<p>{{ id }}</p>';
$id_field->options['alter']['alter_text'] = TRUE;
$output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
return $id_field->theme($row);
});
$this->assertSubString($output, '<p>1</p>');
// Add a non-safe HTML tag and make sure this gets removed.
$id_field->options['alter']['text'] = '<p>{{ id }} <script>alert("Script removed")</script></p>';
$id_field->options['alter']['alter_text'] = TRUE;
$output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
return $id_field->theme($row);
});
$this->assertSubString($output, '<p>1 alert("Script removed")</p>');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.