function DisplayTest::testOutputIsEmpty
Same name in other branches
- 8.9.x core/modules/views/tests/src/Functional/Plugin/DisplayTest.php \Drupal\Tests\views\Functional\Plugin\DisplayTest::testOutputIsEmpty()
- 10 core/modules/views/tests/src/Functional/Plugin/DisplayTest.php \Drupal\Tests\views\Functional\Plugin\DisplayTest::testOutputIsEmpty()
- 11.x core/modules/views/tests/src/Functional/Plugin/DisplayTest.php \Drupal\Tests\views\Functional\Plugin\DisplayTest::testOutputIsEmpty()
Tests the outputIsEmpty method on the display.
File
-
core/
modules/ views/ tests/ src/ Functional/ Plugin/ DisplayTest.php, line 376
Class
- DisplayTest
- Tests the basic display plugin.
Namespace
Drupal\Tests\views\Functional\PluginCode
public function testOutputIsEmpty() {
$view = Views::getView('test_display_empty');
$this->executeView($view);
$this->assertNotEmpty($view->result);
$this->assertFalse($view->display_handler
->outputIsEmpty(), 'Ensure the view output is marked as not empty.');
$view->destroy();
// Add a filter, so the view result is empty.
$view->setDisplay('default');
$item = [
'table' => 'views_test_data',
'field' => 'id',
'id' => 'id',
'value' => [
'value' => 7297,
],
];
$view->setHandler('default', 'filter', 'id', $item);
$this->executeView($view);
$this->assertEmpty($view->result, 'Ensure the result of the view is empty.');
$this->assertFalse($view->display_handler
->outputIsEmpty(), 'Ensure the view output is marked as not empty, because the empty text still appears.');
$view->destroy();
// Remove the empty area, but mark the header area to still appear.
$view->removeHandler('default', 'empty', 'area');
$item = $view->getHandler('default', 'header', 'area');
$item['empty'] = TRUE;
$view->setHandler('default', 'header', 'area', $item);
$this->executeView($view);
$this->assertEmpty($view->result, 'Ensure the result of the view is empty.');
$this->assertFalse($view->display_handler
->outputIsEmpty(), 'Ensure the view output is marked as not empty, because the header text still appears.');
$view->destroy();
// Hide the header on empty results.
$item = $view->getHandler('default', 'header', 'area');
$item['empty'] = FALSE;
$view->setHandler('default', 'header', 'area', $item);
$this->executeView($view);
$this->assertEmpty($view->result, 'Ensure the result of the view is empty.');
$this->assertTrue($view->display_handler
->outputIsEmpty(), 'Ensure the view output is marked as empty.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.