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..11432f7 100644 --- a/modules/simpletest/tests/theme.test +++ b/modules/simpletest/tests/theme.test @@ -354,3 +354,37 @@ class ThemeFastTestCase extends DrupalWebTestCase { $this->assertText('registry not initialized', t('The registry was not initialized')); } } + +/** + * Unit tests for theme_html_tag(). + */ +class ThemeHtmlTag extends DrupalUnitTestCase { + public static function getInfo() { + return array( + 'name' => 'Theme HTML Tag', + 'description' => 'Tests theme_html_tag() built-in theme functions.', + 'group' => 'Theme', + ); + } + + /** + * 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.')); + + // 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.')); + + // 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.')); + } +}