summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests/database_test.module
diff options
context:
space:
mode:
Diffstat (limited to 'modules/simpletest/tests/database_test.module')
-rw-r--r--modules/simpletest/tests/database_test.module90
1 files changed, 90 insertions, 0 deletions
diff --git a/modules/simpletest/tests/database_test.module b/modules/simpletest/tests/database_test.module
index 573075078..2c1d22597 100644
--- a/modules/simpletest/tests/database_test.module
+++ b/modules/simpletest/tests/database_test.module
@@ -48,6 +48,19 @@ function database_test_menu() {
'access callback' => TRUE,
'page callback' => 'database_test_db_query_temporary',
);
+ $items['database_test/pager_query_even'] = array(
+ 'access callback' => TRUE,
+ 'page callback' => 'database_test_even_pager_query',
+ );
+ $items['database_test/pager_query_odd'] = array(
+ 'access callback' => TRUE,
+ 'page callback' => 'database_test_odd_pager_query',
+ );
+ $items['database_test/tablesort'] = array(
+ 'access callback' => TRUE,
+ 'page callback' => 'database_test_tablesort',
+ );
+
return $items;
}
@@ -66,3 +79,80 @@ function database_test_db_query_temporary() {
));
exit;
}
+
+/**
+ * Run a pager query and return the results.
+ *
+ * This function does care about the page GET parameter, as set by the
+ * simpletest HTTP call.
+ */
+function database_test_even_pager_query($limit) {
+
+ $query = db_select('test', 't');
+ $query
+ ->fields('t', array('name'))
+ ->orderBy('age');
+
+ // This should result in 2 pages of results.
+ $query = $query->extend('PagerDefault')->limit($limit);
+
+ $names = $query->execute()->fetchCol();
+
+ drupal_json(array(
+ 'names' => $names,
+ ));
+ exit;
+}
+
+/**
+ * Run a pager query and return the results.
+ *
+ * This function does care about the page GET parameter, as set by the
+ * simpletest HTTP call.
+ */
+function database_test_odd_pager_query($limit) {
+
+ $query = db_select('test_task', 't');
+ $query
+ ->fields('t', array('task'))
+ ->orderBy('pid');
+
+ // This should result in 4 pages of results.
+ $query = $query->extend('PagerDefault')->limit($limit);
+
+ $names = $query->execute()->fetchCol();
+
+ drupal_json(array(
+ 'names' => $names,
+ ));
+ exit;
+}
+
+/**
+ * Run a tablesort query and return the results.
+ *
+ * This function does care about the page GET parameter, as set by the
+ * simpletest HTTP call.
+ */
+function database_test_tablesort() {
+ $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')->setHeader($header);
+
+ // We need all the results at once to check the sort.
+ $tasks = $query->execute()->fetchAll();
+
+ drupal_json(array(
+ 'tasks' => $tasks,
+ ));
+ exit;
+} \ No newline at end of file