function ViewsAddDefaultPaginationHeaderTest::testViewsPostUpdatePaginationHeadingLevel

Same name and namespace in other branches
  1. 11.x core/modules/views/tests/src/Functional/Update/ViewsAddDefaultPaginationHeaderTest.php \Drupal\Tests\views\Functional\Update\ViewsAddDefaultPaginationHeaderTest::testViewsPostUpdatePaginationHeadingLevel()

Tests the upgrade path adding pagination_heading_level.

File

core/modules/views/tests/src/Functional/Update/ViewsAddDefaultPaginationHeaderTest.php, line 47

Class

ViewsAddDefaultPaginationHeaderTest
Tests the addition of the pagination_heading_level setting.

Namespace

Drupal\Tests\views\Functional\Update

Code

public function testViewsPostUpdatePaginationHeadingLevel() : void {
  $view = View::load('add_pagination_heading');
  $data = $view->toArray();
  $counter = 0;
  foreach ($data['display'] as $display) {
    if (array_key_exists('pager', $display['display_options'])) {
      $pager = $display['display_options']['pager'];
      // The pager has type and options so we need to ensure we are reviewing options.
      if (is_array($pager) && array_key_exists('options', $pager)) {
        $this->assertArrayNotHasKey('pagination_heading_level', $pager['options']);
        $counter++;
      }
    }
  }
  $this->assertGreaterThan(0, $counter);
  $this->runUpdates();
  $view = View::load('add_pagination_heading');
  $data = $view->toArray();
  $allow_pager_type_update = [
    'mini',
    'full',
  ];
  $counterHasPager = 0;
  $counterNoPager = 0;
  foreach ($data['display'] as $display) {
    if (array_key_exists('pager', $display['display_options'])) {
      $pager = $display['display_options']['pager'];
      // The pager has type and options so we need to ensure we are reviewing options.
      if (is_array($pager) && array_key_exists('options', $pager)) {
        // We need different assertions for the different types of pagers.
        // We ensure we get the whole pager handler.
        if (in_array($pager['type'], $allow_pager_type_update)) {
          $this->assertArrayHasKey('pagination_heading_level', $pager['options']);
          $counterHasPager++;
        }
        else {
          $this->assertArrayNotHasKey('pagination_heading_level', $pager['options']);
          $counterNoPager++;
        }
      }
    }
  }
  $this->assertGreaterThan(0, $counterHasPager);
  $this->assertGreaterThan(0, $counterNoPager);
}

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