X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fsystem%2Fsrc%2FTests%2FDatabase%2FSelectTableSortDefaultTest.php;fp=web%2Fcore%2Fmodules%2Fsystem%2Fsrc%2FTests%2FDatabase%2FSelectTableSortDefaultTest.php;h=97a676b162826e113cb90afa7e35eafc3d1135d6;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/system/src/Tests/Database/SelectTableSortDefaultTest.php b/web/core/modules/system/src/Tests/Database/SelectTableSortDefaultTest.php new file mode 100644 index 000000000..97a676b16 --- /dev/null +++ b/web/core/modules/system/src/Tests/Database/SelectTableSortDefaultTest.php @@ -0,0 +1,87 @@ + 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'], + // more elements here + + ]; + + foreach ($sorts as $sort) { + $this->drupalGet('database_test/tablesort/', ['query' => ['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.'); + } + } + + /** + * Confirms precedence of tablesorts headers. + * + * If a tablesort's orderByHeader is called before another orderBy, then its + * header happens first. + */ + public function testTableSortQueryFirst() { + $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'], + // more elements here + + ]; + + foreach ($sorts as $sort) { + $this->drupalGet('database_test/tablesort_first/', ['query' => ['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.', ['@field' => $sort['field'], '@sort' => $sort['sort']])); + $this->assertEqual($last->task, $sort['last'], format_string('Items appear in the correct order sorting by @field @sort.', ['@field' => $sort['field'], '@sort' => $sort['sort']])); + } + } + + /** + * Confirms that tableselect is rendered without error. + * + * Specifically that no sort is set in a tableselect, and that header links + * are correct. + */ + public function testTableSortDefaultSort() { + $this->drupalGet('database_test/tablesort_default_sort'); + + // Verify that the table was displayed. Just the header is checked for + // because if there were any fatal errors or exceptions in displaying the + // sorted table, it would not print the table. + $this->assertText(t('Username')); + + // Verify that the header links are built properly. + $this->assertLinkByHref('database_test/tablesort_default_sort'); + $this->assertPattern('/\/'); + } + +}