function ViewsViewFieldStatusTest::testFieldWithoutEntity
Tests that a field of a handler without an entity has no marker.
File
-
core/
themes/ default_admin/ tests/ src/ Kernel/ ViewsViewFieldStatusTest.php, line 216
Class
- ViewsViewFieldStatusTest
- Tests the publication status marker of views status fields.
Namespace
Drupal\Tests\default_admin\KernelCode
public function testFieldWithoutEntity() : void {
// The 'status' column of the views test table is handled by the 'boolean'
// field plugin, which is not an entity field handler and has no entity to
// read a publication state from.
$storage = View::create([
'id' => 'test_status_without_entity',
'label' => 'test_status_without_entity',
'module' => 'views',
'base_table' => 'views_test_data',
'base_field' => 'id',
]);
$executable = $storage->getExecutable();
$executable->newDisplay('default', 'Default', 'default');
$display = $executable->displayHandlers
->get('default');
$display->setOption('pager', [
'type' => 'none',
'options' => [
'offset' => 0,
],
]);
$display->setOption('fields', [
'status' => [
'id' => 'status',
'table' => 'views_test_data',
'field' => 'status',
'plugin_id' => 'boolean',
'type' => 'custom',
'type_custom_true' => 'live',
'type_custom_false' => 'draft',
],
]);
$storage->save();
$view = Views::getView('test_status_without_entity');
$this->executeView($view);
$this->assertCount(5, $view->result);
foreach ($view->result as $row) {
$output = $this->renderStatusField($view, $row);
$this->assertStringNotContainsString('marker', $output);
$this->assertContains($output, [
'live',
'draft',
]);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.