function DatabaseSelectPagerDefaultTestCase::testElementNumbers
Confirm that every pager gets a valid non-overlaping element ID.
File
-
modules/
simpletest/ tests/ database_test.test, line 2677
Class
Code
function testElementNumbers() {
$_GET['page'] = '3, 2, 1, 0';
$query = db_select('test', 't')->extend('PagerDefault');
$query->element(2)
->fields('t', array(
'name',
))
->orderBy('age')
->limit(1);
$this->assertEqual(2, $query->getElement());
$name = $query->execute()
->fetchField();
$this->assertEqual($name, 'Paul', 'Pager query #1 with a specified element ID returned the correct results.');
// Setting an element smaller than the previous one
// should not overwrite the pager $maxElement with a smaller value.
$query = db_select('test', 't')->extend('PagerDefault');
$query->element(1)
->fields('t', array(
'name',
))
->orderBy('age')
->limit(1);
$this->assertEqual(1, $query->getElement());
$name = $query->execute()
->fetchField();
$this->assertEqual($name, 'George', 'Pager query #2 with a specified element ID returned the correct results.');
$query = db_select('test', 't')->extend('PagerDefault');
$query->fields('t', array(
'name',
))
->orderBy('age')
->limit(1);
$this->assertEqual(3, $query->getElement());
$name = $query->execute()
->fetchField();
$this->assertEqual($name, 'John', 'Pager query #3 with a generated element ID returned the correct results.');
unset($_GET['page']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.