function ViewsPreprocessTest::testCssClassCleaning
Same name in other branches
- 9 core/modules/views/tests/src/Kernel/ViewsPreprocessTest.php \Drupal\Tests\views\Kernel\ViewsPreprocessTest::testCssClassCleaning()
- 8.9.x core/modules/views/tests/src/Kernel/ViewsPreprocessTest.php \Drupal\Tests\views\Kernel\ViewsPreprocessTest::testCssClassCleaning()
- 11.x core/modules/views/tests/src/Kernel/ViewsPreprocessTest.php \Drupal\Tests\views\Kernel\ViewsPreprocessTest::testCssClassCleaning()
Tests css classes on displays are cleaned correctly.
File
-
core/
modules/ views/ tests/ src/ Kernel/ ViewsPreprocessTest.php, line 39
Class
- ViewsPreprocessTest
- Tests the preprocessing functionality in views.theme.inc.
Namespace
Drupal\Tests\views\KernelCode
public function testCssClassCleaning() : void {
\Drupal::service('theme_installer')->install([
'test_theme',
]);
$this->config('system.theme')
->set('default', 'test_theme')
->save();
$entity = EntityTest::create();
$entity->save();
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$view = Views::getView('test_preprocess');
$build = $view->buildRenderable();
$renderer->renderRoot($build);
$this->assertStringContainsString('class="entity-test--default entity-test__default', (string) $build['#markup']);
$view->destroy();
$view->setDisplay('display_2');
$build = $view->buildRenderable();
$renderer->renderRoot($build);
$markup = (string) $build['#markup'];
$this->assertStringContainsString('css_class: entity-test--default and-another-class entity-test__default', $markup);
$this->assertStringContainsString('attributes: class="entity-test--default and-another-class entity-test__default', $markup);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.