function StyleFieldsTest::testInlineFields
Same name in other branches
- 9 core/modules/views/tests/src/Kernel/Plugin/StyleFieldsTest.php \Drupal\Tests\views\Kernel\Plugin\StyleFieldsTest::testInlineFields()
- 8.9.x core/modules/views/tests/src/Kernel/Plugin/StyleFieldsTest.php \Drupal\Tests\views\Kernel\Plugin\StyleFieldsTest::testInlineFields()
- 10 core/modules/views/tests/src/Kernel/Plugin/StyleFieldsTest.php \Drupal\Tests\views\Kernel\Plugin\StyleFieldsTest::testInlineFields()
Tests inline fields and separator.
File
-
core/
modules/ views/ tests/ src/ Kernel/ Plugin/ StyleFieldsTest.php, line 27
Class
- StyleFieldsTest
- Tests fields style functionality.
Namespace
Drupal\Tests\views\Kernel\PluginCode
public function testInlineFields() : void {
$renderer = $this->container
->get('renderer');
$view = Views::getView('test_view');
$view->setDisplay();
// Test using an HTML separator.
$row = $view->display_handler
->getOption('row');
$row['options'] = [
'inline' => [
'age' => 'age',
'id' => 'id',
'name' => 'name',
],
'separator' => '<br />',
];
$view->display_handler
->setOption('row', $row);
$view->initDisplay();
$view->initStyle();
$output = $view->preview();
$output = $renderer->renderRoot($output);
$this->assertStringContainsString('<div class="views-row"><span class="views-field views-field-age"><span class="field-content">25</span></span><br /><span class="views-field views-field-id"><span class="field-content">1</span></span><br /><span class="views-field views-field-name"><span class="field-content">John</span></span></div>', (string) $output);
$view->destroy();
// Check that unsafe separators are stripped.
$view->setDisplay();
$row = $view->display_handler
->getOption('row');
$row['options'] = [
'inline' => [
'age' => 'age',
'id' => 'id',
'name' => 'name',
],
'separator' => '<script>alert("escape me!")</script>',
];
$view->display_handler
->setOption('row', $row);
$view->initDisplay();
$view->initStyle();
$output = $view->preview();
$output = $renderer->renderRoot($output);
$this->assertStringNotContainsString('<script>', (string) $output);
$this->assertStringContainsString('alert("escape me!")', (string) $output);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.