diff --git a/includes/theme.inc b/includes/theme.inc index 3287073f380d42da8510d14708fd05d987497329..f592891ac14305b1ffbc3009f9b51dbe1400ee32 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 f1e1bd58b86ad65a1c556500017d4e414d3066ab..53557e361a0381113a1a21b0f61ec3ee548b2276 100644 --- a/modules/simpletest/tests/theme.test +++ b/modules/simpletest/tests/theme.test @@ -354,3 +354,29 @@ 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 meta tag generation + $tag['element'] = array('#tag' => 'meta', '#attributes' => array('name' => 'description', 'content' => 'Drupal test')); + $this->assertEqual('<meta name="description" content="Drupal test" />'."\n", theme_html_tag($tag), t('Test auto-closure meta tag generation.')); + + // Test title tag generation + $tag['element'] = array('#tag' => 'title', '#value' => 'title test'); + $this->assertEqual('<title>title test</title>'."\n", theme_html_tag($tag), t('Test title tag generation.')); + } +}