public function PagerTest::testNormalPager in Drupal 10
Same name and namespace in other branches
- 8 core/modules/views/tests/src/Functional/Plugin/PagerTest.php \Drupal\Tests\views\Functional\Plugin\PagerTest::testNormalPager()
- 9 core/modules/views/tests/src/Functional/Plugin/PagerTest.php \Drupal\Tests\views\Functional\Plugin\PagerTest::testNormalPager()
Tests the normal pager.
File
- core/
modules/ views/ tests/ src/ Functional/ Plugin/ PagerTest.php, line 300
Class
- PagerTest
- Tests the pluggable pager system.
Namespace
Drupal\Tests\views\Functional\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([
'type' => 'page',
]);
for ($i = 0; $i < 11; $i++) {
$this
->drupalCreateNode();
}
$view = Views::getView('test_pager_full');
$this
->executeView($view);
$this
->assertCount(5, $view->result, 'Make sure that only a certain count of items is returned');
// Setup and test an offset.
$view = Views::getView('test_pager_full');
$view
->setDisplay();
$pager = [
'type' => 'full',
'options' => [
'offset' => 8,
'items_per_page' => 5,
],
];
$view->display_handler
->setOption('pager', $pager);
$this
->executeView($view);
$this
->assertCount(3, $view->result, '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
->assertCount(11, $view->result, 'All items are return');
// TODO test number of pages.
// Test items per page = 0.
// Setup and test an offset.
$view = Views::getView('test_pager_full');
$view
->setDisplay();
$pager = [
'type' => 'full',
'options' => [
'offset' => 0,
'items_per_page' => 0,
],
];
$view->display_handler
->setOption('pager', $pager);
$this
->executeView($view);
$this
->assertEquals(0, $view->pager
->getItemsPerPage());
$this
->assertCount(11, $view->result);
// Test pager cache contexts.
$this
->drupalGet('test_pager_full');
$this
->assertCacheContexts([
'languages:language_interface',
'theme',
'timezone',
'url.query_args',
'user.node_grants:view',
]);
}