function EntityQueryTest::testTableSort
Same name in other branches
- 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php \Drupal\KernelTests\Core\Entity\EntityQueryTest::testTableSort()
- 10 core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php \Drupal\KernelTests\Core\Entity\EntityQueryTest::testTableSort()
- 11.x core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php \Drupal\KernelTests\Core\Entity\EntityQueryTest::testTableSort()
Tests tablesort().
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityQueryTest.php, line 491
Class
- EntityQueryTest
- Tests Entity Query functionality.
Namespace
Drupal\KernelTests\Core\EntityCode
public function testTableSort() {
// While ordering on bundles do not give us a definite order, we can still
// assert that all entities from one bundle are after the other as the
// order dictates.
$request = Request::createFromGlobals();
$request->query
->replace([
'sort' => 'asc',
'order' => 'Type',
]);
\Drupal::getContainer()->get('request_stack')
->push($request);
$header = [
'id' => [
'data' => 'Id',
'specifier' => 'id',
],
'type' => [
'data' => 'Type',
'specifier' => 'type',
],
];
$this->queryResults = array_values($this->storage
->getQuery()
->accessCheck(FALSE)
->tableSort($header)
->execute());
$this->assertBundleOrder('asc');
$request->query
->add([
'sort' => 'desc',
]);
\Drupal::getContainer()->get('request_stack')
->push($request);
$header = [
'id' => [
'data' => 'Id',
'specifier' => 'id',
],
'type' => [
'data' => 'Type',
'specifier' => 'type',
],
];
$this->queryResults = array_values($this->storage
->getQuery()
->accessCheck(FALSE)
->tableSort($header)
->execute());
$this->assertBundleOrder('desc');
// Ordering on ID is definite, however.
$request->query
->add([
'order' => 'Id',
]);
\Drupal::getContainer()->get('request_stack')
->push($request);
$this->queryResults = $this->storage
->getQuery()
->accessCheck(FALSE)
->tableSort($header)
->execute();
$this->assertResult(range(15, 1));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.