Index: modules/simpletest/tests/common.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/common.test,v
retrieving revision 1.4
diff -u -p -r1.4 common.test
--- modules/simpletest/tests/common.test	29 Aug 2008 14:45:19 -0000	1.4
+++ modules/simpletest/tests/common.test	1 Sep 2008 19:35:19 -0000
@@ -144,3 +144,52 @@ class DrupalHTTPRequestTestCase extends 
     $this->assertTitle(variable_get('site_name', 'Drupal'), t('Site title matches.'));
   }
 }
+
+/**
+ * Test tablesorting functions.
+ */
+class TablesortTestCase extends DrupalWebTestCase {
+
+  /**
+   * Implementation of getInfo().
+   */
+  function getInfo() {
+    return array(
+      'name' => t('Drupal tablesort'),
+      'description' => t("Performs unit testing on Drupal's tablesorting."),
+      'group' => t('System')
+    );
+  }
+
+  /**
+   * Tests the handling of cell classes by Drupal's tablesort API. The 'active'
+   * class should be appended if the cell is active.
+   */
+  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');
+  }
+
+  /**
+   * Tests the handling of additional query strings by Druapl's tablesort API.
+   */
+  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 to query string.'));
+
+    $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.'));
+  }
+}
\ No newline at end of file
