Index: modules/simpletest/tests/theme.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/theme.test,v
retrieving revision 1.22
diff -u -p -r1.22 theme.test
--- modules/simpletest/tests/theme.test	6 Oct 2010 13:38:40 -0000	1.22
+++ modules/simpletest/tests/theme.test	10 Oct 2010 22:07:11 -0000
@@ -157,6 +157,87 @@ class ThemeTableUnitTest extends DrupalW
     $this->assertRaw('<thead><tr><th>Header 1</th>', t('Table header was printed.'));
   }

+  /**
+   * Tests if correct sort links are generated for headers where requested and
+   * if the "active" class is set correctly.
+   */
+  function testThemeTableSort() {
+    $header = array(
+      array(
+        'data' => 'Header12',
+        'field' => 'a',
+        'sort' => 'asc',
+        'colspan' => 2,
+      ),
+      'Header3',
+      array(
+        'data' => 'Header4',
+        'field' => 'b',
+      ),
+      array(
+        'data' => 'Header5',
+        'field' => 'c',
+      ),
+    );
+    $rows = array(
+      array(
+        array('data' => 'Column1', 'rowspan' => 2,),
+        'Column2',
+        array('data' => 'Column34', 'colspan' => 2,),
+        'Column5',
+      ),
+      array(
+        'Row2Column2',
+        'Row2Column3',
+        'Row2Column4',
+        'Row2Column5',
+      ),
+    );
+    $this->content = theme('table', array('header' => $header, 'rows' => $rows));
+    debug($this->content);
+    $this->assertRaw('sort=desc&amp;order=Header12', t('Correct link for active sort-column.'));
+    $this->assertTrue(preg_match('#<th [^>]*class="active"([^<]|<[^/])+Header12#', $this->content), t('Correct class in header for active sort-column.'));
+    $this->assertNoRaw('order=Header3', t('No link for normal column.'));
+    $this->assertRaw('sort=asc&amp;order=Header4', t('Correct link for inactive sort-column.'));
+    $this->assertFalse(preg_match('#<th [^>]*class="active"([^<]|<[^/])+Header4#', $this->content), t('No class in header for inactive sort-column.'));
+    $this->assertNoRaw(' data="', t('"!attr" not set as HTML attribute.', array('!attr' => 'data')));
+    $this->assertNoRaw(' field="', t('"!attr" not set as HTML attribute.', array('!attr' => 'field')));
+    $this->assertNoRaw(' sort="', t('"!attr" not set as HTML attribute.', array('!attr' => 'sort')));
+    $this->assertRaw(' class="active">Column1</td>', t('Correct class set on active column !num.', array('!num' => 1)));
+    $this->assertRaw(' class="active">Column2</td>', t('Correct class set on active column !num.', array('!num' => 2)));
+    $this->assertRaw(' class="active">Row2Column2</td>', t('Correct class set on active column !num of second row.', array('!num' => 2)));
+    $this->assertNoRaw(' class="active">Row2Column3</td>', t('No class set on inactive column !num of second row.', array('!num' => 3)));
+
+    $_GET['sort'] = 'asc';
+    $_GET['order'] = 'Header4';
+    $this->content = theme('table', array('header' => $header, 'rows' => $rows));
+    debug($this->content);
+    $this->assertRaw('sort=asc&amp;order=Header12', t('Correct link for inactive sort-column.'));
+    $this-> assertFalse(preg_match('#<th [^>]*class="active"([^<]|<[^/])+Header12#', $this->content), t('No class in header for inactive sort-column.'));
+    $this->assertRaw('sort=desc&amp;order=Header4', t('Correct link for active sort-column.'));
+    $this-> assertTrue(preg_match('#<th [^>]*class="active"([^<]|<[^/])+Header4#', $this->content), t('Correct class in header for active sort-column.'));
+    $this->assertNoRaw(' class="active">Column1</td>', t('No class set on inactive column !num.', array('!num' => 1)));
+    $this->assertRaw(' class="active">Column34</td>', t('Correct class set on active column with colspan.', array('!num' => 1)));
+    $this->assertRaw(' class="active">Row2Column4</td>', t('Correct class set on active column !num of second row.', array('!num' => 4)));
+    $this->assertNoRaw(' class="active">Row2Column5</td>', t('No class set on inactive column !num of second row.', array('!num' => 5)));
+
+    $_GET['sort'] = 'desc';
+    $_GET['order'] = 'Header5';
+    $this->content = theme('table', array('header' => $header, 'rows' => $rows));
+    debug($this->content);
+    $this->assertRaw('sort=asc&amp;order=Header12', t('Correct link for inactive sort-column.'));
+    $this-> assertFalse(preg_match('#<th [^>]*class="active"([^<]|<[^/])+Header12#', $this->content), t('No class in header for inactive sort-column.'));
+    $this->assertRaw('sort=asc&amp;order=Header5', t('Correct link for active sort-column.'));
+    $this-> assertTrue(preg_match('#<th [^>]*class="active"([^<]|<[^/])+Header5#', $this->content), t('Correct class in header for active sort-column.'));
+    $this->assertNoRaw(' class="active">Column1</td>', t('No class set on first column.'));
+    $this->assertRaw(' class="active">Column5</td>', t('Correct class set on active column.'));
+    $this->assertNoRaw(' class="active">Row2Column4</td>', t('No class set on inactive column !num of second row.', array('!num' => 4)));
+    $this->assertRaw(' class="active">Row2Column5</td>', t('Correct class set on active column !num of second row.', array('!num' => 5)));
+
+    unset($_GET['sort'], $_GET['order']);
+  }
+
+
 }

 /**
