public function DisplayTest::testOutputIsEmpty in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/views/src/Tests/Plugin/DisplayTest.php \Drupal\views\Tests\Plugin\DisplayTest::testOutputIsEmpty()
Tests the outputIsEmpty method on the display.
File
- core/
modules/ views/ src/ Tests/ Plugin/ DisplayTest.php, line 315 - Contains \Drupal\views\Tests\Plugin\DisplayTest.
Class
- DisplayTest
- Tests the basic display plugin.
Namespace
Drupal\views\Tests\PluginCode
public function testOutputIsEmpty() {
$view = Views::getView('test_display_empty');
$this
->executeView($view);
$this
->assertTrue(count($view->result) > 0, 'Ensure the result of the view is not empty.');
$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 = array(
'table' => 'views_test_data',
'field' => 'id',
'id' => 'id',
'value' => array(
'value' => 7297,
),
);
$view
->setHandler('default', 'filter', 'id', $item);
$this
->executeView($view);
$this
->assertFalse(count($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
->assertFalse(count($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
->assertFalse(count($view->result), 'Ensure the result of the view is empty.');
$this
->assertTrue($view->display_handler
->outputIsEmpty(), 'Ensure the view output is marked as empty.');
}