public function SelectTableSortDefaultTest::testTableSortQuery in Drupal 9
Same name and namespace in other branches
- 8 core/modules/system/tests/src/Functional/Database/SelectTableSortDefaultTest.php \Drupal\Tests\system\Functional\Database\SelectTableSortDefaultTest::testTableSortQuery()
- 10 core/modules/system/tests/src/Functional/Database/SelectTableSortDefaultTest.php \Drupal\Tests\system\Functional\Database\SelectTableSortDefaultTest::testTableSortQuery()
Confirms that a tablesort query returns the correct results.
Note that we have to make an HTTP request to a test page handler because the pager depends on GET parameters.
File
- core/
modules/ system/ tests/ src/ Functional/ Database/ SelectTableSortDefaultTest.php, line 25
Class
- SelectTableSortDefaultTest
- Tests the tablesort query extender.
Namespace
Drupal\Tests\system\Functional\DatabaseCode
public function testTableSortQuery() {
$sorts = [
[
'field' => t('Task ID'),
'sort' => 'desc',
'first' => 'perform at superbowl',
'last' => 'eat',
],
[
'field' => t('Task ID'),
'sort' => 'asc',
'first' => 'eat',
'last' => 'perform at superbowl',
],
[
'field' => t('Task'),
'sort' => 'asc',
'first' => 'code',
'last' => 'sleep',
],
[
'field' => t('Task'),
'sort' => 'desc',
'first' => 'sleep',
'last' => 'code',
],
];
foreach ($sorts as $sort) {
$this
->drupalGet('database_test/tablesort/', [
'query' => [
'order' => $sort['field'],
'sort' => $sort['sort'],
],
]);
$data = json_decode($this
->getSession()
->getPage()
->getContent());
$first = array_shift($data->tasks);
$last = array_pop($data->tasks);
$this
->assertEquals($sort['first'], $first->task, 'Items appear in the correct order.');
$this
->assertEquals($sort['last'], $last->task, 'Items appear in the correct order.');
}
}