function PagerTest::testActiveClass

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Pager/PagerTest.php \Drupal\Tests\system\Functional\Pager\PagerTest::testActiveClass()
  2. 8.9.x core/modules/system/tests/src/Functional/Pager/PagerTest.php \Drupal\Tests\system\Functional\Pager\PagerTest::testActiveClass()
  3. 11.x 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 61

Class

PagerTest
Tests pager functionality.

Namespace

Drupal\Tests\system\Functional\Pager

Code

public function testActiveClass() : void {
    // 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($this->getAbsoluteUrl(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');
}

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