public function PagerTest::testNormalPager in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/views/src/Tests/Plugin/PagerTest.php \Drupal\views\Tests\Plugin\PagerTest::testNormalPager()
Tests the normal pager.
File
- core/
modules/ views/ src/ Tests/ Plugin/ PagerTest.php, line 211 - Contains \Drupal\views\Tests\Plugin\PagerTest.
Class
- PagerTest
- Tests the pluggable pager system.
Namespace
Drupal\views\Tests\PluginCode
public function testNormalPager() {
// Create 11 nodes and make sure that everyone is returned.
// We create 11 nodes, because the default pager plugin had 10 items per page.
$this
->drupalCreateContentType(array(
'type' => 'page',
));
for ($i = 0; $i < 11; $i++) {
$this
->drupalCreateNode();
}
$view = Views::getView('test_pager_full');
$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 = Views::getView('test_pager_full');
$view
->setDisplay();
$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 = Views::getView('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 = Views::getView('test_pager_full');
$view
->setDisplay();
$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
->getItemsPerPage(), 0);
$this
->assertEqual(count($view->result), 11);
// Test pager cache contexts.
$this
->drupalGet('test_pager_full');
$this
->assertCacheContexts([
'languages:language_interface',
'theme',
'timezone',
'url.query_args',
'user.node_grants:view',
]);
}