class ViewsPreprocessTest
Same name and namespace in other branches
- 11.x core/modules/views/tests/src/Kernel/ViewsPreprocessTest.php \Drupal\Tests\views\Kernel\ViewsPreprocessTest
Tests the preprocessing functionality in views.theme.inc.
@group views
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\views\Kernel\ViewsKernelTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait implements \Drupal\KernelTests\KernelTestBase
- class \Drupal\Tests\views\Kernel\ViewsPreprocessTest implements \Drupal\Tests\views\Kernel\ViewsKernelTestBase
- class \Drupal\Tests\views\Kernel\ViewsKernelTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait implements \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of ViewsPreprocessTest
File
-
core/
modules/ views/ tests/ src/ Kernel/ ViewsPreprocessTest.php, line 13
Namespace
Drupal\Tests\views\KernelView source
class ViewsPreprocessTest extends ViewsKernelTestBase {
/**
* {@inheritdoc}
*/
public static $testViews = [
'test_preprocess',
];
/**
* {@inheritdoc}
*/
protected static $modules = [
'entity_test',
'user',
'node',
];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) : void {
parent::setUp();
$this->installEntitySchema('entity_test');
}
/**
* Tests css classes on displays are cleaned correctly.
*/
public function testCssClassCleaning() {
\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.