summaryrefslogtreecommitdiff
path: root/kolab.org/www/drupal-7.15/sites/all/modules/views/tests/views_pager.test
diff options
context:
space:
mode:
Diffstat (limited to 'kolab.org/www/drupal-7.15/sites/all/modules/views/tests/views_pager.test')
-rw-r--r--kolab.org/www/drupal-7.15/sites/all/modules/views/tests/views_pager.test112
1 files changed, 90 insertions, 22 deletions
diff --git a/kolab.org/www/drupal-7.15/sites/all/modules/views/tests/views_pager.test b/kolab.org/www/drupal-7.15/sites/all/modules/views/tests/views_pager.test
index 9c3cf3e..fef4915 100644
--- a/kolab.org/www/drupal-7.15/sites/all/modules/views/tests/views_pager.test
+++ b/kolab.org/www/drupal-7.15/sites/all/modules/views/tests/views_pager.test
@@ -2,10 +2,13 @@
/**
* @file
- * Tests the pluggable pager system.
+ * Definition of ViewsPagerTest.
*/
-class ViewsPagerTest extends DrupalWebTestCase {
+/**
+ * Tests the pluggable pager system.
+ */
+class ViewsPagerTest extends ViewsSqlTest {
public static function getInfo() {
return array(
'name' => 'Pager',
@@ -114,7 +117,7 @@ class ViewsPagerTest extends DrupalWebTestCase {
}
/**
- * Test the none-pager-query.
+ * Tests the none-pager-query.
*/
public function testNoLimit() {
// Create 11 nodes and make sure that everyone is returned.
@@ -124,8 +127,7 @@ class ViewsPagerTest extends DrupalWebTestCase {
}
$view = $this->viewsPagerNoLimit();
$view->set_display('default');
- $view->pre_execute();
- $view->execute();
+ $this->executeView($view);
$this->assertEqual(count($view->result), 11, 'Make sure that every item is returned in the result');
$view->destroy();
@@ -141,8 +143,7 @@ class ViewsPagerTest extends DrupalWebTestCase {
),
);
$view->display_handler->set_option('pager', $pager);
- $view->pre_execute();
- $view->execute();
+ $this->executeView($view);
$this->assertEqual(count($view->result), 8, 'Make sure that every item beside the first three is returned in the result');
@@ -174,8 +175,27 @@ class ViewsPagerTest extends DrupalWebTestCase {
return $view;
}
+ public function testViewTotalRowsWithoutPager() {
+ $this->createNodes(23);
+
+ $view = $this->viewsPagerNoLimit();
+ $view->get_total_rows = TRUE;
+ $view->set_display('default');
+ $this->executeView($view);
+
+ $this->assertEqual($view->total_rows, 23, "'total_rows' is calculated when pager type is 'none' and 'get_total_rows' is TRUE.");
+ }
+
+ public function createNodes($count) {
+ if ($count >= 0) {
+ for ($i = 0; $i < $count; $i++) {
+ $this->drupalCreateNode();
+ }
+ }
+ }
+
/**
- * Test the some pager plugin.
+ * Tests the some pager plugin.
*/
public function testLimit() {
// Create 11 nodes and make sure that everyone is returned.
@@ -185,7 +205,7 @@ class ViewsPagerTest extends DrupalWebTestCase {
}
$view = $this->viewsPagerLimit();
$view->set_display('default');
- $view->execute();
+ $this->executeView($view);
$this->assertEqual(count($view->result), 5, 'Make sure that only a certain count of items is returned');
$view->destroy();
@@ -201,8 +221,7 @@ class ViewsPagerTest extends DrupalWebTestCase {
),
);
$view->display_handler->set_option('pager', $pager);
- $view->pre_execute();
- $view->execute();
+ $this->executeView($view);
$this->assertEqual(count($view->result), 3, 'Make sure that only a certain count of items is returned');
// Check some public functions.
@@ -235,7 +254,7 @@ class ViewsPagerTest extends DrupalWebTestCase {
}
/**
- * Test the normal pager.
+ * Tests the normal pager.
*/
public function testNormalPager() {
// Create 11 nodes and make sure that everyone is returned.
@@ -245,8 +264,7 @@ class ViewsPagerTest extends DrupalWebTestCase {
}
$view = $this->viewsPagerFull();
$view->set_display('default');
- $view->pre_execute();
- $view->execute();
+ $this->executeView($view);
$this->assertEqual(count($view->result), 5, 'Make sure that only a certain count of items is returned');
$view->destroy();
@@ -262,15 +280,13 @@ class ViewsPagerTest extends DrupalWebTestCase {
),
);
$view->display_handler->set_option('pager', $pager);
- $view->pre_execute();
- $view->execute();
+ $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->viewPagerFullZeroItemsPerPage();
$view->set_display('default');
- $view->pre_execute();
- $view->execute();
+ $this->executeView($view);
$this->assertEqual(count($view->result), 11, 'All items are return');
@@ -292,7 +308,7 @@ class ViewsPagerTest extends DrupalWebTestCase {
);
$view->display_handler->set_option('pager', $pager);
- $view->execute();
+ $this->executeView($view);
$this->assertEqual($view->query->pager->get_items_per_page(), 0);
$this->assertEqual(count($view->result), 11);
}
@@ -402,14 +418,14 @@ class ViewsPagerTest extends DrupalWebTestCase {
}
/**
- * Test the minipager.
+ * Tests the minipager.
*/
public function testMiniPager() {
// the functionality is the same as the normal pager, so i don't know what to test here.
}
/**
- * Test rendering with NULL pager.
+ * Tests rendering with NULL pager.
*/
public function testRenderNullPager() {
// Create 11 nodes and make sure that everyone is returned.
@@ -419,10 +435,62 @@ class ViewsPagerTest extends DrupalWebTestCase {
}
$view = $this->viewsPagerFullFields();
$view->set_display('default');
- $view->execute();
+ $this->executeView($view);
$view->use_ajax = TRUE; // force the value again here
$view->query->pager = NULL;
$output = $view->render();
$this->assertEqual(preg_match('/<ul class="pager">/', $output), 0, t('The pager is not rendered.'));
}
+
+ /**
+ * Test the api functions on the view object.
+ */
+ 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.');
+
+ }
}