You are here

public function AreaTest::testRenderEmptyHeaderFooter in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Tests/Handler/AreaTest.php \Drupal\views\Tests\Handler\AreaTest::testRenderEmptyHeaderFooter()

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

File

core/modules/views/src/Tests/Handler/AreaTest.php, line 121
Contains \Drupal\views\Tests\Handler\AreaTest.

Class

AreaTest
Tests the plugin base of the area handler.

Namespace

Drupal\views\Tests\Handler

Code

public function testRenderEmptyHeaderFooter() {
  $view = Views::getView('test_example_area');
  $view
    ->initHandlers();

  // Set example empty text.
  $view->empty['test_example']->options['string'] = '<p>' . $this
    ->randomMachineName() . '</p>';
  $xpath = '//div[contains(@class, :class)]';

  // Verify that the empty header and footer sections have not been rendered.
  $output = $view
    ->preview();
  $html = $this->container
    ->get('renderer')
    ->renderRoot($output);
  $this
    ->setRawContent($html);
  $this
    ->assertEqual(0, count($this
    ->xpath($xpath, [
    ':class' => 'view-header',
  ])));
  $this
    ->assertEqual(0, count($this
    ->xpath($xpath, [
    ':class' => 'view-footer',
  ])));

  // Set example header text.
  $view->header['test_example']->options['string'] = '<p>' . $this
    ->randomMachineName() . '</p>';
  $view->header['test_example']->options['empty'] = TRUE;

  // Set example footer text.
  $view->footer['test_example']->options['string'] = '<p>' . $this
    ->randomMachineName() . '</p>';
  $view->footer['test_example']->options['empty'] = TRUE;

  // Verify that the header and footer sections have been rendered.
  $output = $view
    ->preview();
  $html = $this->container
    ->get('renderer')
    ->renderRoot($output);
  $this
    ->setRawContent($html);
  $this
    ->assertEqual(1, count($this
    ->xpath($xpath, [
    ':class' => 'view-header',
  ])));
  $this
    ->assertEqual(1, count($this
    ->xpath($xpath, [
    ':class' => 'view-footer',
  ])));
}