Index: modules/simpletest/simpletest.info
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.info,v
retrieving revision 1.26
diff -u -p -r1.26 simpletest.info
--- modules/simpletest/simpletest.info	22 Oct 2010 16:36:14 -0000	1.26
+++ modules/simpletest/simpletest.info	30 Nov 2010 06:03:22 -0000
@@ -35,6 +35,7 @@ files[] = tests/path.test
 files[] = tests/registry.test
 files[] = tests/schema.test
 files[] = tests/session.test
+files[] = tests/tablesort.test
 files[] = tests/theme.test
 files[] = tests/unicode.test
 files[] = tests/update.test
Index: modules/simpletest/tests/tablesort.test
===================================================================
RCS file: modules/simpletest/tests/tablesort.test
diff -N modules/simpletest/tests/tablesort.test
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/simpletest/tests/tablesort.test	30 Nov 2010 06:03:22 -0000
@@ -0,0 +1,114 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Various tablesort tests.
+ */
+
+/**
+ * Test unicode handling features implemented in unicode.inc.
+ */
+class TableSortTest extends DrupalUnitTestCase {
+
+  /**
+   * Storage for initial value of $_GET.
+   *
+   * @var array
+   */
+  protected $GET = array();
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Tablesort',
+      'description' => 'Tests table sorting.',
+      'group' => 'System',
+    );
+  }
+
+  function setUp() {
+    // Save the original $_GET to be restored later.
+    $this->GET = $_GET;
+
+    parent::setUp();
+  }
+
+  function tearDown() {
+    // Revert $_GET.
+    $_GET = $this->GET;
+
+    parent::tearDown();
+  }
+
+  /**
+   * Test tablesort_init().
+   */
+  function testTableSortInit() {
+
+    // Test simple table headers.
+    $header = array('foo', 'bar', 'baz');
+    $_GET = array('q' => 'jahwohl');
+    $expected_ts = array(
+      'name' => 'foo',
+      'sql' => '',
+      'sort' => 'asc',
+      'query' => array(),
+    );
+    $ts = tablesort_init($header);
+    $this->verbose(t('$ts: <pre>%ts</pre>', array('%ts' => filter_xss_admin(var_export($ts, TRUE)))));
+    $this->assertEqual($ts, $expected_ts, t('Simple table headers sorted correctly.'));
+
+    // Test with simple table header plus $_GET parameters.
+    $_GET = array(
+      'q' => 'jahwohl',
+      'sort' => 'bar',
+      'order' => 'DESC',
+      'alpha' => 'beta',
+    );
+    $expected_ts['query'] = array('alpha' => 'beta');
+    $ts = tablesort_init($header);
+    $this->verbose(t('$ts: <pre>%ts</pre>', array('%ts' => filter_xss_admin(var_export($ts, TRUE)))));
+    $this->assertEqual($ts, $expected_ts, t('Simple table headers plus $_GET parameters sorted correctly.'));
+
+    // Test complex table headers.
+    $header = array(
+      'foo',
+      array(
+        'data' => '1',
+        'field' => 'one',
+        'sort' => 'asc',
+        'colspan' => 1,
+      ),
+      array(
+        'data' => '2',
+        'field' => 'two',
+        'sort' => 'desc',
+      ),
+    );
+    $_GET = array('q' => 'jahwohl');
+    $ts = tablesort_init($header);
+    $expected_ts = array(
+      'name' => '2',
+      'sql' => 'two',
+      'sort' => 'desc',
+      'query' => array(),
+    );
+    $this->verbose(t('$ts: <pre>%ts</pre>', array('%ts' => filter_xss_admin(var_export($ts, TRUE)))));
+    $this->assertEqual($ts, $expected_ts, t('Complex table headers sorted correctly.'));
+
+    // Test with complex table header plus $_GET parameters.
+    $_GET = array(
+      'q' => 'jahwohl',
+      'sort' => 'bar',
+      'order' => 'DESC',
+      'alpha' => 'beta',
+    );
+    $expected_ts['query'] = array('alpha' => 'beta');
+    $expected_ts['sort'] = 'asc';
+    $ts = tablesort_init($header);
+    $this->verbose(t('$ts: <pre>%ts</pre>', array('%ts' => filter_xss_admin(var_export($ts, TRUE)))));
+    $this->assertEqual($ts, $expected_ts, t('Complex table headers plus $_GET parameters sorted correctly.'));
+    unset($_GET['sort'], $_GET['order'], $_GET['alpha']);
+
+  }
+}
