public function PagerTest::testPagerApi in Drupal 8
Same name and namespace in other branches
- 9 core/modules/views/tests/src/Functional/Plugin/PagerTest.php \Drupal\Tests\views\Functional\Plugin\PagerTest::testPagerApi()
Test the api functions on the view object.
File
- core/
modules/ views/ tests/ src/ Functional/ Plugin/ PagerTest.php, line 324
Class
- PagerTest
- Tests the pluggable pager system.
Namespace
Drupal\Tests\views\Functional\PluginCode
public function testPagerApi() {
$view = Views::getView('test_pager_full');
$view
->setDisplay();
// On the first round don't initialize the pager.
$this
->assertEqual($view
->getItemsPerPage(), NULL, 'If the pager is not initialized and no manual override there is no items per page.');
$rand_number = rand(1, 5);
$view
->setItemsPerPage($rand_number);
$this
->assertEqual($view
->getItemsPerPage(), $rand_number, 'Make sure getItemsPerPage uses the settings of setItemsPerPage.');
$this
->assertEqual($view
->getOffset(), NULL, 'If the pager is not initialized and no manual override there is no offset.');
$rand_number = rand(1, 5);
$view
->setOffset($rand_number);
$this
->assertEqual($view
->getOffset(), $rand_number, 'Make sure getOffset uses the settings of setOffset.');
$this
->assertEqual($view
->getCurrentPage(), NULL, 'If the pager is not initialized and no manual override there is no current page.');
$rand_number = rand(1, 5);
$view
->setCurrentPage($rand_number);
$this
->assertEqual($view
->getCurrentPage(), $rand_number, 'Make sure getCurrentPage uses the settings of set_current_page.');
$view
->destroy();
// On this round enable the pager.
$view
->initDisplay();
$view
->initQuery();
$view
->initPager();
$this
->assertEqual($view
->getItemsPerPage(), 5, 'Per default the view has 5 items per page.');
$rand_number = rand(1, 5);
$view
->setItemsPerPage($rand_number);
$rand_number = rand(6, 11);
$view->pager
->setItemsPerPage($rand_number);
$this
->assertEqual($view
->getItemsPerPage(), $rand_number, 'Make sure getItemsPerPage uses the settings of setItemsPerPage.');
$this
->assertEqual($view
->getOffset(), 0, 'Per default a view has a 0 offset.');
$rand_number = rand(1, 5);
$view
->setOffset($rand_number);
$rand_number = rand(6, 11);
$view->pager
->setOffset($rand_number);
$this
->assertEqual($view
->getOffset(), $rand_number, 'Make sure getOffset uses the settings of setOffset.');
$this
->assertEqual($view
->getCurrentPage(), 0, 'Per default the current page is 0.');
$rand_number = rand(1, 5);
$view
->setCurrentPage($rand_number);
$rand_number = rand(6, 11);
$view->pager
->setCurrentPage($rand_number);
$this
->assertEqual($view
->getCurrentPage(), $rand_number, 'Make sure getCurrentPage uses the settings of set_current_page.');
// Set an invalid page and make sure the method takes care about it.
$view
->setCurrentPage(-1);
$this
->assertEqual($view
->getCurrentPage(), 0, 'Make sure setCurrentPage always sets a valid page number.');
}