function SelectTableSortDefaultTest::testTableSortQuery in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/Database/SelectTableSortDefaultTest.php \Drupal\system\Tests\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/ src/ Tests/ Database/ SelectTableSortDefaultTest.php, line 23 - Contains \Drupal\system\Tests\Database\SelectTableSortDefaultTest.
Class
- SelectTableSortDefaultTest
- Tests the tablesort query extender.
Namespace
Drupal\system\Tests\DatabaseCode
function testTableSortQuery() {
$sorts = array(
array(
'field' => t('Task ID'),
'sort' => 'desc',
'first' => 'perform at superbowl',
'last' => 'eat',
),
array(
'field' => t('Task ID'),
'sort' => 'asc',
'first' => 'eat',
'last' => 'perform at superbowl',
),
array(
'field' => t('Task'),
'sort' => 'asc',
'first' => 'code',
'last' => 'sleep',
),
array(
'field' => t('Task'),
'sort' => 'desc',
'first' => 'sleep',
'last' => 'code',
),
);
foreach ($sorts as $sort) {
$this
->drupalGet('database_test/tablesort/', array(
'query' => array(
'order' => $sort['field'],
'sort' => $sort['sort'],
),
));
$data = json_decode($this
->getRawContent());
$first = array_shift($data->tasks);
$last = array_pop($data->tasks);
$this
->assertEqual($first->task, $sort['first'], 'Items appear in the correct order.');
$this
->assertEqual($last->task, $sort['last'], 'Items appear in the correct order.');
}
}