function PagerTest::testPagerQueryParametersAndCacheContext

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Pager/PagerTest.php \Drupal\Tests\system\Functional\Pager\PagerTest::testPagerQueryParametersAndCacheContext()
  2. 10 core/modules/system/tests/src/Functional/Pager/PagerTest.php \Drupal\Tests\system\Functional\Pager\PagerTest::testPagerQueryParametersAndCacheContext()
  3. 11.x core/modules/system/tests/src/Functional/Pager/PagerTest.php \Drupal\Tests\system\Functional\Pager\PagerTest::testPagerQueryParametersAndCacheContext()

Test proper functioning of the query parameters and the pager cache context.

File

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

Class

PagerTest
Tests pager functionality.

Namespace

Drupal\Tests\system\Functional\Pager

Code

public function testPagerQueryParametersAndCacheContext() {
    // First page.
    $this->drupalGet('pager-test/query-parameters');
    $this->assertText(t('Pager calls: 0'), 'Initial call to pager shows 0 calls.');
    $this->assertText('[url.query_args.pagers:0]=0.0');
    $this->assertCacheContext('url.query_args');
    // Go to last page, the count of pager calls need to go to 1.
    $elements = $this->xpath('//li[contains(@class, :class)]/a', [
        ':class' => 'pager__item--last',
    ]);
    $elements[0]->click();
    $this->assertText(t('Pager calls: 1'), 'First link call to pager shows 1 calls.');
    $this->assertText('[url.query_args.pagers:0]=0.60');
    $this->assertCacheContext('url.query_args');
    // Reset counter to 0.
    $this->drupalGet('pager-test/query-parameters');
    // Go back to first page, the count of pager calls need to go to 2.
    $elements = $this->xpath('//li[contains(@class, :class)]/a', [
        ':class' => 'pager__item--last',
    ]);
    $elements[0]->click();
    $elements = $this->xpath('//li[contains(@class, :class)]/a', [
        ':class' => 'pager__item--first',
    ]);
    $elements[0]->click();
    $this->assertText(t('Pager calls: 2'), 'Second link call to pager shows 2 calls.');
    $this->assertText('[url.query_args.pagers:0]=0.0');
    $this->assertCacheContext('url.query_args');
}

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