You are here

function SelectPagerDefaultTest::testElementNumbers in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Database/SelectPagerDefaultTest.php \Drupal\system\Tests\Database\SelectPagerDefaultTest::testElementNumbers()

Confirms that every pager gets a valid, non-overlapping element ID.

File

core/modules/system/src/Tests/Database/SelectPagerDefaultTest.php, line 132
Contains \Drupal\system\Tests\Database\SelectPagerDefaultTest.

Class

SelectPagerDefaultTest
Tests the pager query select extender.

Namespace

Drupal\system\Tests\Database

Code

function testElementNumbers() {
  $request = Request::createFromGlobals();
  $request->query
    ->replace(array(
    'page' => '3, 2, 1, 0',
  ));
  \Drupal::getContainer()
    ->get('request_stack')
    ->push($request);
  $name = db_select('test', 't')
    ->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
    ->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('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
    ->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('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
    ->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.');
}