You are here

public function PagerTest::testPager in Drupal 8

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()

Tests the pager option.

File

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

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() {

  // 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' => REQUEST_TIME - $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.
  $elements = $this
    ->xpath('//ul[contains(@class, :class)]/li', [
    ':class' => 'pager__items',
  ]);
  $this
    ->assertTrue(!empty($elements), 'Full pager found.');

  // 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);
  $elements = $this
    ->xpath('//ul[contains(@class, :class)]/li', [
    ':class' => 'pager__items',
  ]);
  $this
    ->assertTrue(empty($elements), 'Full pager not found.');
}