diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php index 2c7230d..9c2090a 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php @@ -19,7 +19,7 @@ class DisplayTest extends PluginTestBase { * * @var array */ - public static $testViews = array('test_filter_groups', 'test_get_attach_displays', 'test_view', 'test_display_more'); + public static $testViews = array('test_filter_groups', 'test_get_attach_displays', 'test_view', 'test_display_more', 'test_display_empty'); /** * Modules to enable. @@ -197,4 +197,47 @@ public function testReadMore() { $this->assertEqual($more_text, $expected_more_text, 'The right more text is chosen.'); } + /** + * Tests the outputIsEmpty method on the display. + */ + public function testOutputIsEmpty() { + $view = views_get_view('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->setItem('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->removeItem('default', 'empty', 'area'); + $item = $view->getItem('default', 'header', 'area'); + $item['empty'] = TRUE; + $view->setItem('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->getItem('default', 'header', 'area'); + $item['empty'] = FALSE; + $view->setItem('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.'); + } + } diff --git a/core/modules/views/tests/views_test_config/test_views/views.view.test_display_empty.yml b/core/modules/views/tests/views_test_config/test_views/views.view.test_display_empty.yml new file mode 100644 index 0000000..e0768d4 --- /dev/null +++ b/core/modules/views/tests/views_test_config/test_views/views.view.test_display_empty.yml @@ -0,0 +1,44 @@ +base_table: views_test_data +core: '8' +description: '' +status: '1' +display: + default: + display_options: + defaults: + fields: '0' + pager: '0' + pager_options: '0' + sorts: '0' + fields: + id: + field: id + id: id + relationship: none + table: views_test_data + plugin_id: numeric + pager: + options: + offset: '0' + type: none + pager_options: { } + header: + area: + field: area + id: area + table: views + plugin_id: text + empty: + area: + field: area + id: area + table: views + plugin_id: text + display_plugin: default + display_title: Master + id: default + position: '0' +human_name: '' +langcode: en +id: test_display_empty +tag: ''