You are here

public function PagerTest::testNormalPager in Views (for Drupal 7) 8.3

Tests the normal pager.

File

lib/Drupal/views/Tests/Plugin/PagerTest.php, line 197
Definition of Drupal\views\Tests\Plugin\PagerTest.

Class

PagerTest
Tests the pluggable pager system.

Namespace

Drupal\views\Tests\Plugin

Code

public function testNormalPager() {
  $saved_view = $this
    ->createViewFromConfig('test_pager_full');

  // Create 11 nodes and make sure that everyone is returned.
  // We create 11 nodes, because the default pager plugin had 10 items per page.
  for ($i = 0; $i < 11; $i++) {
    $this
      ->drupalCreateNode();
  }
  $view = $saved_view
    ->cloneView();
  $this
    ->executeView($view);
  $this
    ->assertEqual(count($view->result), 5, 'Make sure that only a certain count of items is returned');

  // Setup and test a offset.
  $view = $this
    ->getView($saved_view);
  $pager = array(
    'type' => 'full',
    'options' => array(
      'offset' => 8,
      'items_per_page' => 5,
    ),
  );
  $view->display_handler
    ->setOption('pager', $pager);
  $this
    ->executeView($view);
  $this
    ->assertEqual(count($view->result), 3, 'Make sure that only a certain count of items is returned');

  // Test items per page = 0
  $view = $this
    ->createViewFromConfig('test_view_pager_full_zero_items_per_page');
  $this
    ->executeView($view);
  $this
    ->assertEqual(count($view->result), 11, 'All items are return');

  // TODO test number of pages.
  // Test items per page = 0.
  // Setup and test a offset.
  $view = $this
    ->getView($saved_view);
  $pager = array(
    'type' => 'full',
    'options' => array(
      'offset' => 0,
      'items_per_page' => 0,
    ),
  );
  $view->display_handler
    ->setOption('pager', $pager);
  $this
    ->executeView($view);
  $this
    ->assertEqual($view->pager
    ->get_items_per_page(), 0);
  $this
    ->assertEqual(count($view->result), 11);
}