diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-05-22 11:33:18 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-05-22 11:33:18 +0000 |
commit | dc4d421be78c471017fd8cf0d3b7986147844dab (patch) | |
tree | e33372f2f943eb1e32fff5922eed372b4b944184 /modules/simpletest | |
parent | ef14b0df899a07fc002398040fffdfae8a09ad66 (diff) | |
download | brdo-dc4d421be78c471017fd8cf0d3b7986147844dab.tar.gz brdo-dc4d421be78c471017fd8cf0d3b7986147844dab.tar.bz2 |
- Patch #396284 by Berdir, chx, jcfiala, csevb10 et al: make sure to order by table headers first, before ordering by other fields.
Diffstat (limited to 'modules/simpletest')
-rw-r--r-- | modules/simpletest/tests/database_test.module | 35 | ||||
-rw-r--r-- | modules/simpletest/tests/database_test.test | 26 |
2 files changed, 60 insertions, 1 deletions
diff --git a/modules/simpletest/tests/database_test.module b/modules/simpletest/tests/database_test.module index 2c1d22597..fdb660dc0 100644 --- a/modules/simpletest/tests/database_test.module +++ b/modules/simpletest/tests/database_test.module @@ -60,6 +60,10 @@ function database_test_menu() { 'access callback' => TRUE, 'page callback' => 'database_test_tablesort', ); + $items['database_test/tablesort_first'] = array( + 'access callback' => TRUE, + 'page callback' => 'database_test_tablesort_first', + ); return $items; } @@ -146,7 +150,36 @@ function database_test_tablesort() { $query ->fields('t', array('tid', 'pid', 'task', 'priority')); - $query = $query->extend('TableSort')->setHeader($header); + $query = $query->extend('TableSort')->orderByHeader($header); + + // We need all the results at once to check the sort. + $tasks = $query->execute()->fetchAll(); + + drupal_json(array( + 'tasks' => $tasks, + )); + exit; +} + +/** + * Run a tablesort query with a second order_by after and return the results. + * + * This function does care about the page GET parameter, as set by the + * simpletest HTTP call. + */ +function database_test_tablesort_first() { + $header = array( + 'tid' => array('data' => t('Task ID'), 'field' => 'tid', 'sort' => 'desc'), + 'pid' => array('data' => t('Person ID'), 'field' => 'pid'), + 'task' => array('data' => t('Task'), 'field' => 'task'), + 'priority' => array('data' => t('Priority'), 'field' => 'priority', ), + ); + + $query = db_select('test_task', 't'); + $query + ->fields('t', array('tid', 'pid', 'task', 'priority')); + + $query = $query->extend('TableSort')->orderByHeader($header)->orderBy('priority'); // We need all the results at once to check the sort. $tasks = $query->execute()->fetchAll(); diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test index 590e9c102..2fa7f6c8f 100644 --- a/modules/simpletest/tests/database_test.test +++ b/modules/simpletest/tests/database_test.test @@ -1769,6 +1769,32 @@ class DatabaseSelectTableSortDefaultTestCase extends DatabaseTestCase { $this->assertEqual($last->task, $sort['last'], t('Items appear in the correct order.')); } } + + /** + * Confirm that if a tablesort's orderByHeader is called before another orderBy, that the header happens first. + * + */ + 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'), + // more elements here + + ); + + foreach ($sorts as $sort) { + $this->drupalGet('database_test/tablesort_first/', array('query' => array('order' => $sort['field'], 'sort' => $sort['sort']))); + $data = json_decode($this->drupalGetContent()); + + $first = array_shift($data->tasks); + $last = array_pop($data->tasks); + + $this->assertEqual($first->task, $sort['first'], t('Items appear in the correct order sorting by @field @sort.', array('@field' => $sort['field'], '@sort' => $sort['sort']))); + $this->assertEqual($last->task, $sort['last'], t('Items appear in the correct order sorting by @field @sort.', array('@field' => $sort['field'], '@sort' => $sort['sort']))); + } + } } /** |