You are here

public function PagerTest::testActiveClass in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/Pager/PagerTest.php \Drupal\Tests\system\Functional\Pager\PagerTest::testActiveClass()

Tests markup and CSS classes of pager links.

File

core/modules/system/tests/src/Functional/Pager/PagerTest.php, line 58

Class

PagerTest
Tests pager functionality.

Namespace

Drupal\Tests\system\Functional\Pager

Code

public function testActiveClass() {

  // Verify first page.
  $this
    ->drupalGet('admin/reports/dblog');
  $current_page = 0;
  $this
    ->assertPagerItems($current_page);

  // Verify any page but first/last.
  $current_page++;
  $this
    ->drupalGet('admin/reports/dblog', [
    'query' => [
      'page' => $current_page,
    ],
  ]);
  $this
    ->assertPagerItems($current_page);

  // Verify last page.
  $element = $this
    ->assertSession()
    ->elementExists('xpath', '//li[contains(@class, "pager__item--last")]/a');
  preg_match('@page=(\\d+)@', $element
    ->getAttribute('href'), $matches);
  $current_page = (int) $matches[1];
  $this
    ->drupalGet($GLOBALS['base_root'] . parse_url($this
    ->getUrl())['path'] . $element
    ->getAttribute('href'), [
    'external' => TRUE,
  ]);
  $this
    ->assertPagerItems($current_page);

  // Verify the pager does not render on a list without pagination.
  $this
    ->drupalGet('admin/config/media/image-styles');
  $this
    ->assertSession()
    ->elementNotExists('css', '.pager');
}