1 views_pager.test ViewsPagerTest::testPagerApi()

Test the api functions on the view object.

File

core/modules/views/tests/views_pager.test, line 432
Definition of ViewsPagerTest.

Class

ViewsPagerTest
Tests the pluggable pager system.

Code

function testPagerApi() {
  $view = $this->viewsPagerFull();
  // On the first round don't initialize the pager.

  $this->assertEqual($view->get_items_per_page(), NULL, 'If the pager is not initialized and no manual override there is no items per page.');
  $rand_number = rand(1, 5);
  $view->set_items_per_page($rand_number);
  $this->assertEqual($view->get_items_per_page(), $rand_number, 'Make sure get_items_per_page uses the settings of set_items_per_page.');

  $this->assertEqual($view->get_offset(), NULL, 'If the pager is not initialized and no manual override there is no offset.');
  $rand_number = rand(1, 5);
  $view->set_offset($rand_number);
  $this->assertEqual($view->get_offset(), $rand_number, 'Make sure get_offset uses the settings of set_offset.');

  $this->assertEqual($view->get_current_page(), NULL, 'If the pager is not initialized and no manual override there is no current page.');
  $rand_number = rand(1, 5);
  $view->set_current_page($rand_number);
  $this->assertEqual($view->get_current_page(), $rand_number, 'Make sure get_current_page uses the settings of set_current_page.');

  $view->destroy();

  // On this round enable the pager.
  $view->init_display();
  $view->init_query();
  $view->init_pager();

  $this->assertEqual($view->get_items_per_page(), 5, 'Per default the view has 5 items per page.');
  $rand_number = rand(1, 5);
  $view->set_items_per_page($rand_number);
  $rand_number = rand(6, 11);
  $view->query->pager->set_items_per_page($rand_number);
  $this->assertEqual($view->get_items_per_page(), $rand_number, 'Make sure get_items_per_page uses the settings of set_items_per_page.');

  $this->assertEqual($view->get_offset(), 0, 'Per default a view has a 0 offset.');
  $rand_number = rand(1, 5);
  $view->set_offset($rand_number);
  $rand_number = rand(6, 11);
  $view->query->pager->set_offset($rand_number);
  $this->assertEqual($view->get_offset(), $rand_number, 'Make sure get_offset uses the settings of set_offset.');

  $this->assertEqual($view->get_current_page(), 0, 'Per default the current page is 0.');
  $rand_number = rand(1, 5);
  $view->set_current_page($rand_number);
  $rand_number = rand(6, 11);
  $view->query->pager->set_current_page($rand_number);
  $this->assertEqual($view->get_current_page(), $rand_number, 'Make sure get_current_page uses the settings of set_current_page.');

}