diff --git a/includes/theme.inc b/includes/theme.inc index 3287073..f592891 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -1902,11 +1902,12 @@ function theme_feed_icon($variables) { */ function theme_html_tag($variables) { $element = $variables['element']; + $attributes = isset($element['#attributes']) ? drupal_attributes($element['#attributes']) : ''; if (!isset($element['#value'])) { - return '<' . $element['#tag'] . drupal_attributes($element['#attributes']) . " />\n"; + return '<' . $element['#tag'] . $attributes . " />\n"; } else { - $output = '<' . $element['#tag'] . drupal_attributes($element['#attributes']) . '>'; + $output = '<' . $element['#tag'] . $attributes . '>'; if (isset($element['#value_prefix'])) { $output .= $element['#value_prefix']; } diff --git a/modules/simpletest/tests/theme.test b/modules/simpletest/tests/theme.test index f1e1bd5..542e1a4 100644 --- a/modules/simpletest/tests/theme.test +++ b/modules/simpletest/tests/theme.test @@ -101,6 +101,27 @@ class ThemeUnitTest extends DrupalWebTestCase { $this->drupalGet('theme-test/suggestion'); variable_set('preprocess_css', 0); } + + /** + * Test function theme_html_tag() + */ + function testThemeHtmlTag() { + // Test auto-closure br tag + $tag['element'] = array('#tag' => 'br'); + $this->assertEqual('
'."\n", theme_html_tag($tag), t('Test auto-closure for br tag.').theme_html_tag($tag) ); + + // Test auto-closure hr tag with attributes + $tag['element'] = array('#tag' => 'hr', '#attributes' => array('class' => 'class1') ); + $this->assertEqual('
'."\n", theme_html_tag($tag), t('Test auto-closure for hr tag with a class.')); + + // Test p tag with value + $tag['element'] = array('#tag' => 'p', '#value' => 'test'); + $this->assertEqual('

test

'."\n", theme_html_tag($tag), t('Test p tag generation.').theme_html_tag($tag)); + + // Test h2 tag with value and attributes + $tag['element'] = array('#tag' => 'h2', '#value' => 'title test', '#attributes' => array('title' => 'title h2')); + $this->assertEqual('

title test

'."\n", theme_html_tag($tag), t('Test h2 tag generation with title attribute.')); + } } /**