View source
<?php
namespace Drupal\system\Tests\Database;
class SelectTableSortDefaultTest extends DatabaseWebTestBase {
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.');
}
}
function testTableSortQueryFirst() {
$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_first/', 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'], format_string('Items appear in the correct order sorting by @field @sort.', array(
'@field' => $sort['field'],
'@sort' => $sort['sort'],
)));
$this
->assertEqual($last->task, $sort['last'], format_string('Items appear in the correct order sorting by @field @sort.', array(
'@field' => $sort['field'],
'@sort' => $sort['sort'],
)));
}
}
function testTableSortDefaultSort() {
$this
->drupalGet('database_test/tablesort_default_sort');
$this
->assertText(t('Username'));
$this
->assertLinkByHref('database_test/tablesort_default_sort');
$this
->assertPattern('/\\<a.*title\\=\\"' . t('sort by Username') . '\\".*\\>/');
}
}