diff options
-rw-r--r-- | includes/theme.inc | 10 | ||||
-rw-r--r-- | modules/simpletest/tests/theme.test | 11 |
2 files changed, 16 insertions, 5 deletions
diff --git a/includes/theme.inc b/includes/theme.inc index f8ebbffb7..6f436df02 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -1663,6 +1663,11 @@ function theme_table($variables) { } } + // Add the 'empty' row message if available. + if (!count($rows) && $empty) { + $rows[] = array(array('data' => $empty, 'colspan' => count($header), 'class' => array('empty', 'message'))); + } + // Format the table header: if (count($header)) { $ts = tablesort_init($header); @@ -1680,11 +1685,6 @@ function theme_table($variables) { $ts = array(); } - // Add the 'empty' row message if available. - if (!count($rows) && $empty) { - $rows[] = array(array('data' => $empty, 'colspan' => count($header), 'class' => array('empty', 'message'))); - } - // Format the table rows: if (count($rows)) { $output .= "<tbody>\n"; diff --git a/modules/simpletest/tests/theme.test b/modules/simpletest/tests/theme.test index c46dc9d93..d3ba6f9bb 100644 --- a/modules/simpletest/tests/theme.test +++ b/modules/simpletest/tests/theme.test @@ -95,6 +95,17 @@ class ThemeTableUnitTest extends DrupalWebTestCase { $this->assertNoRaw('sticky-enabled', t('Table does not have a class of sticky-enabled because $sticky = FALSE.')); drupal_static_reset('drupal_add_js'); } + + /** + * Tests that the table header is printed even if there are no rows. And that + * the empty text is displayed correctly. + */ + function testThemeTableWithEmptyMessage() { + $header = array(t('Header 1'), t('Header 2')); + $this->content = theme('table', array('header' => $header, 'rows' => array(), 'empty' => t('No strings available.'))); + $this->assertRaw('<tr class="odd"><td colspan="2" class="empty message">No strings available.</td>', t('Correct colspan was set on empty message.')); + $this->assertRaw('<thead><tr><th>Header 1</th>', t('Table header was printed.')); + } } /** |