function FieldKernelTest::testRewrite
Same name in other branches
- 9 core/modules/views/tests/src/Kernel/Handler/FieldKernelTest.php \Drupal\Tests\views\Kernel\Handler\FieldKernelTest::testRewrite()
- 8.9.x core/modules/views/tests/src/Kernel/Handler/FieldKernelTest.php \Drupal\Tests\views\Kernel\Handler\FieldKernelTest::testRewrite()
- 10 core/modules/views/tests/src/Kernel/Handler/FieldKernelTest.php \Drupal\Tests\views\Kernel\Handler\FieldKernelTest::testRewrite()
Tests general rewriting of the output.
File
-
core/
modules/ views/ tests/ src/ Kernel/ Handler/ FieldKernelTest.php, line 138
Class
- FieldKernelTest
- Tests the generic field handler.
Namespace
Drupal\Tests\views\Kernel\HandlerCode
public function testRewrite() : void {
/** @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'];
// Don't check the rewrite checkbox, so the text shouldn't appear.
$id_field->options['alter']['text'] = $random_text = $this->randomMachineName();
$output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
return $id_field->theme($row);
});
$this->assertNotSubString($output, $random_text);
$id_field->options['alter']['alter_text'] = TRUE;
$output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
return $id_field->theme($row);
});
$this->assertSubString($output, $random_text);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.