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. 8.9.x 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()

Tests pager query parameters and cache context.

File

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

Class

PagerTest
Tests pager functionality.

Namespace

Drupal\Tests\system\Functional\Pager

Code

public function testPagerQueryParametersAndCacheContext() : void {
    // First page.
    $this->drupalGet('pager-test/query-parameters');
    $this->assertSession()
        ->pageTextContains('Pager calls: 0');
    $this->assertSession()
        ->pageTextContains('[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.
    $this->assertSession()
        ->elementExists('xpath', '//li[contains(@class, "pager__item--last")]/a')
        ->click();
    $this->assertSession()
        ->pageTextContains('Pager calls: 1');
    $this->assertSession()
        ->pageTextContains('[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.
    $this->assertSession()
        ->elementExists('xpath', '//li[contains(@class, "pager__item--last")]/a')
        ->click();
    $this->assertSession()
        ->elementExists('xpath', '//li[contains(@class, "pager__item--first")]/a')
        ->click();
    $this->assertSession()
        ->pageTextContains('Pager calls: 2');
    $this->assertSession()
        ->pageTextContains('[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.