function SelectPagerDefaultTest::testElementNumbers
Same name in other branches
- 9 core/modules/system/tests/src/Functional/Database/SelectPagerDefaultTest.php \Drupal\Tests\system\Functional\Database\SelectPagerDefaultTest::testElementNumbers()
- 10 core/modules/system/tests/src/Functional/Database/SelectPagerDefaultTest.php \Drupal\Tests\system\Functional\Database\SelectPagerDefaultTest::testElementNumbers()
- 11.x core/modules/system/tests/src/Functional/Database/SelectPagerDefaultTest.php \Drupal\Tests\system\Functional\Database\SelectPagerDefaultTest::testElementNumbers()
Confirms that every pager gets a valid, non-overlapping element ID.
File
-
core/
modules/ system/ tests/ src/ Functional/ Database/ SelectPagerDefaultTest.php, line 137
Class
- SelectPagerDefaultTest
- Tests the pager query select extender.
Namespace
Drupal\Tests\system\Functional\DatabaseCode
public function testElementNumbers() {
$request = Request::createFromGlobals();
$request->query
->replace([
'page' => '3, 2, 1, 0',
]);
\Drupal::getContainer()->get('request_stack')
->push($request);
$connection = Database::getConnection();
$name = $connection->select('test', 't')
->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
->element(2)
->fields('t', [
'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 = $connection->select('test', 't')
->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
->element(1)
->fields('t', [
'name',
])
->orderBy('age')
->limit(1)
->execute()
->fetchField();
$this->assertEqual($name, 'George', 'Pager query #2 with a specified element ID returned the correct results.');
$name = $connection->select('test', 't')
->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
->fields('t', [
'name',
])
->orderBy('age')
->limit(1)
->execute()
->fetchField();
$this->assertEqual($name, 'John', 'Pager query #3 with a generated element ID returned the correct results.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.