function PagerTest::testPager

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Functional/Wizard/PagerTest.php \Drupal\Tests\views\Functional\Wizard\PagerTest::testPager()
  2. 8.9.x core/modules/views/tests/src/Functional/Wizard/PagerTest.php \Drupal\Tests\views\Functional\Wizard\PagerTest::testPager()
  3. 10 core/modules/views/tests/src/Functional/Wizard/PagerTest.php \Drupal\Tests\views\Functional\Wizard\PagerTest::testPager()

Tests the pager option.

File

core/modules/views/tests/src/Functional/Wizard/PagerTest.php, line 22

Class

PagerTest
Tests the ability of the views wizard to create views without a pager.

Namespace

Drupal\Tests\views\Functional\Wizard

Code

public function testPager() : void {
    // Create nodes, each with a different creation time so that we have
    // conditions that are meaningful for the use of a pager.
    $this->drupalCreateContentType([
        'type' => 'page',
    ]);
    for ($i = 0; $i < 12; $i++) {
        $this->drupalCreateNode([
            'created' => \Drupal::time()->getRequestTime() - $i,
        ]);
    }
    // Make a View that uses a pager.
    $path_with_pager = 'test-view-with-pager';
    $this->createViewAtPath($path_with_pager, TRUE);
    $this->drupalGet($path_with_pager);
    // This technique for finding the existence of a pager
    // matches that used in Drupal\views_ui\Tests\PreviewTest.php.
    $this->assertSession()
        ->elementExists('xpath', '//ul[contains(@class, "pager__items")]/li');
    // Make a View that does not have a pager.
    $path_with_no_pager = 'test-view-without-pager';
    $this->createViewAtPath($path_with_no_pager, FALSE);
    $this->drupalGet($path_with_no_pager);
    $this->assertSession()
        ->elementNotExists('xpath', '//ul[contains(@class, "pager__items")]/li');
}

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