public function FieldKernelTest::testArgumentTokens in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/views/src/Tests/Handler/FieldKernelTest.php \Drupal\views\Tests\Handler\FieldKernelTest::testArgumentTokens()
Tests the arguments tokens on field level.
File
- core/
modules/ views/ src/ Tests/ Handler/ FieldKernelTest.php, line 179 - Contains \Drupal\views\Tests\Handler\FieldKernelTest.
Class
- FieldKernelTest
- Tests the generic field handler.
Namespace
Drupal\views\Tests\HandlerCode
public function testArgumentTokens() {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$view = Views::getView('test_field_argument_tokens');
$this
->executeView($view, [
'{{ { "#pre_render": ["views_test_data_test_pre_render_function"]} }}',
]);
$name_field_0 = $view->field['name'];
// Test the old style tokens.
$name_field_0->options['alter']['alter_text'] = TRUE;
$name_field_0->options['alter']['text'] = '%1 !1';
$row = $view->result[0];
$output = $renderer
->executeInRenderContext(new RenderContext(), function () use ($name_field_0, $row) {
return $name_field_0
->advancedRender($row);
});
$this
->assertFalse(strpos((string) $output, 'views_test_data_test_pre_render_function executed') !== FALSE, 'Ensure that the pre_render function was not executed');
$this
->assertEqual('%1 !1', (string) $output, "Ensure that old style placeholders aren't replaced");
// This time use new style tokens but ensure that we still don't allow
// arbitrary code execution.
$name_field_0->options['alter']['alter_text'] = TRUE;
$name_field_0->options['alter']['text'] = '{{ arguments.null }} {{ raw_arguments.null }}';
$row = $view->result[0];
$output = $renderer
->executeInRenderContext(new RenderContext(), function () use ($name_field_0, $row) {
return $name_field_0
->advancedRender($row);
});
$this
->assertFalse(strpos((string) $output, 'views_test_data_test_pre_render_function executed') !== FALSE, 'Ensure that the pre_render function was not executed');
$this
->assertEqual('{{ { "#pre_render": ["views_test_data_test_pre_render_function"]} }} {{ { "#pre_render": ["views_test_data_test_pre_render_function"]} }}', (string) $output, 'Ensure that new style placeholders are replaced');
}