function AreaEmptyTest::testRenderEmptyHeaderFooter

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Kernel/Handler/AreaEmptyTest.php \Drupal\Tests\views\Kernel\Handler\AreaEmptyTest::testRenderEmptyHeaderFooter()
  2. 8.9.x core/modules/views/tests/src/Kernel/Handler/AreaEmptyTest.php \Drupal\Tests\views\Kernel\Handler\AreaEmptyTest::testRenderEmptyHeaderFooter()
  3. 11.x core/modules/views/tests/src/Kernel/Handler/AreaEmptyTest.php \Drupal\Tests\views\Kernel\Handler\AreaEmptyTest::testRenderEmptyHeaderFooter()

Tests that the header and footer areas are not rendered if empty.

File

core/modules/views/tests/src/Kernel/Handler/AreaEmptyTest.php, line 57

Class

AreaEmptyTest
Tests the generic entity area handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testRenderEmptyHeaderFooter() : void {
  $view = Views::getView('test_example_area');
  $view->initHandlers();
  // Set example empty text.
  $empty_text = $this->randomMachineName();
  $empty_header = $this->randomMachineName();
  $empty_footer = $this->randomMachineName();
  // Set empty text.
  $view->empty['test_example']->options['string'] = '<p>' . $empty_text . '</p>';
  // Set example header text.
  $view->header['test_example']->options['string'] = '<p>' . $empty_header . '</p>';
  // Set example footer text.
  $view->footer['test_example']->options['string'] = '<p>' . $empty_footer . '</p>';
  // Verify that the empty header and footer sections have not been rendered.
  $view->setDisplay('default');
  $this->executeView($view);
  $output = $view->render();
  $output = \Drupal::service('renderer')->renderRoot($output);
  $this->setRawContent($output);
  $this->assertText($empty_text);
  $this->assertNoText($empty_header);
  $this->assertNoText($empty_footer);
  // Enable displaying the header and footer when the View is empty.
  $view->header['test_example']->options['empty'] = TRUE;
  $view->footer['test_example']->options['empty'] = TRUE;
  // Verify that the header and footer sections have been rendered.
  $this->executeView($view);
  $output = $view->render();
  $output = \Drupal::service('renderer')->renderRoot($output);
  $this->setRawContent($output);
  $this->assertText($empty_header);
  $this->assertText($empty_footer);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.