You are here

function DatabaseSelectPagerDefaultTestCase::testElementNumbers in Drupal 7

Confirm that every pager gets a valid non-overlaping element ID.

File

modules/simpletest/tests/database_test.test, line 2507

Class

DatabaseSelectPagerDefaultTestCase

Code

function testElementNumbers() {
  $_GET['page'] = '3, 2, 1, 0';
  $name = db_select('test', 't')
    ->extend('PagerDefault')
    ->element(2)
    ->fields('t', array(
    'name',
  ))
    ->orderBy('age')
    ->limit(1)
    ->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.
  $name = db_select('test', 't')
    ->extend('PagerDefault')
    ->element(1)
    ->fields('t', array(
    'name',
  ))
    ->orderBy('age')
    ->limit(1)
    ->execute()
    ->fetchField();
  $this
    ->assertEqual($name, 'George', 'Pager query #2 with a specified element ID returned the correct results.');
  $name = db_select('test', 't')
    ->extend('PagerDefault')
    ->fields('t', array(
    'name',
  ))
    ->orderBy('age')
    ->limit(1)
    ->execute()
    ->fetchField();
  $this
    ->assertEqual($name, 'John', 'Pager query #3 with a generated element ID returned the correct results.');
  unset($_GET['page']);
}