Index: common.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/common.test,v
retrieving revision 1.3
diff -u -p -r1.3 common.test
--- common.test	21 Aug 2008 19:36:38 -0000	1.3
+++ common.test	28 Aug 2008 08:46:19 -0000
@@ -137,3 +137,44 @@ class DrupalHTTPRequestTestCase extends 
     $this->assertEqual($unable_to_parse->error, 'unable to parse URL', t('Returned with unable to parse URL error.'));
   }
 }
+
+/**
+ * Test tablesorting functions.
+ */
+class TablesortTestCase extends DrupalWebTestCase {
+  /**
+   * Implementation of getInfo().
+   */
+  function getInfo() {
+    return array(
+      'name' => t('Drupal tablesort'),
+      'description' => t("Performs tests on Drupal's tablesorting."),
+      'group' => t('System')
+    );
+  }
+
+  function testTablesortHeaderCellClass() {
+	$cell = array('field' => '', 'data' => '', 'class' => 'red');
+	$header = array();
+	$ts = array('name' => '', 'sort' => 'asc', 'query_string' => '');
+	$new_cell = tablesort_header($cell, $header, $ts);
+    $this->assertEqual($new_cell['class'], "red active");
+
+	unset($cell['class']);
+	$new_cell = tablesort_header($cell, $header, $ts);
+    $this->assertEqual($new_cell['class'], "active");
+  }
+
+  function testTablesortHeaderQueryString() {
+	$cell = array('field' => '', 'data' => '');
+	$header = array();
+	$ts = array('name' => '', 'sort' => 'asc', 'query_string' => 'name=value');
+	$new_cell = tablesort_header($cell, $header, $ts);
+    $this->assertTrue(preg_match('/&amp;name=value/', $new_cell['data']), t("Ampersand prepended"));
+
+	$old_data = str_replace("&amp;name=value", "", $new_cell['data']);
+	$ts['query_string'] = '';
+	$new_cell = tablesort_header($cell, $header, $ts);
+    $this->assertEqual($new_cell['data'], $old_data, t("Query string not appended"));
+  }
+}
