3 namespace Drupal\Tests\views\Kernel\Handler;
5 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
6 use Drupal\views\Views;
9 * Tests the generic entity area handler.
12 * @see \Drupal\views\Plugin\views\area\Entity
14 class AreaEmptyTest extends ViewsKernelTestBase {
19 public static $modules = ['node'];
24 protected function setUp($import_test_views = TRUE) {
26 $this->installEntitySchema('node');
32 protected function viewsData() {
33 $data = parent::viewsData();
34 $data['views']['test_example'] = [
35 'title' => 'Test Example area',
36 'help' => 'A area handler which just exists for tests.',
38 'id' => 'test_example',
46 * Views used by this test.
50 public static $testViews = ['test_example_area'];
53 * Tests that the header and footer areas are not rendered if empty.
55 public function testRenderEmptyHeaderFooter() {
56 $view = Views::getView('test_example_area');
57 $view->initHandlers();
59 // Set example empty text.
60 $empty_text = $this->randomMachineName();
61 $empty_header = $this->randomMachineName();
62 $empty_footer = $this->randomMachineName();
65 $view->empty['test_example']->options['string'] = '<p>' . $empty_text . '</p>';
66 // Set example header text.
67 $view->header['test_example']->options['string'] = '<p>' . $empty_header . '</p>';
68 // Set example footer text.
69 $view->footer['test_example']->options['string'] = '<p>' . $empty_footer . '</p>';
71 // Verify that the empty header and footer sections have not been rendered.
72 $view->setDisplay('default');
73 $this->executeView($view);
74 $output = $view->render();
75 $output = \Drupal::service('renderer')->renderRoot($output);
76 $this->setRawContent($output);
77 $this->assertText($empty_text);
78 $this->assertNoText($empty_header);
79 $this->assertNoText($empty_footer);
81 // Enable displaying the header and footer when the View is empty.
82 $view->header['test_example']->options['empty'] = TRUE;
83 $view->footer['test_example']->options['empty'] = TRUE;
85 // Verify that the header and footer sections have been rendered.
86 $this->executeView($view);
87 $output = $view->render();
88 $output = \Drupal::service('renderer')->renderRoot($output);
89 $this->setRawContent($output);
90 $this->assertText($empty_header);
91 $this->assertText($empty_footer);