Issue #2058761 by kirby14, thedavidmeister: PHP notice when #attributes is not set with #theme_wrappers 'container'.
parent
f68c6ce849
commit
bc7940aa6a
|
@ -3311,6 +3311,8 @@ function form_process_container($element, &$form_state) {
|
||||||
*/
|
*/
|
||||||
function theme_container($variables) {
|
function theme_container($variables) {
|
||||||
$element = $variables['element'];
|
$element = $variables['element'];
|
||||||
|
// Ensure #attributes is set.
|
||||||
|
$element += array('#attributes' => array());
|
||||||
|
|
||||||
// Special handling for form elements.
|
// Special handling for form elements.
|
||||||
if (isset($element['#array_parents'])) {
|
if (isset($element['#array_parents'])) {
|
||||||
|
|
|
@ -425,28 +425,100 @@ class ThemeFastTestCase extends DrupalWebTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for theme_html_tag().
|
* Tests the markup of core render element types passed to drupal_render().
|
||||||
*/
|
*/
|
||||||
class ThemeHtmlTag extends DrupalUnitTestCase {
|
class RenderElementTypesTestCase extends DrupalWebTestCase {
|
||||||
public static function getInfo() {
|
public static function getInfo() {
|
||||||
return array(
|
return array(
|
||||||
'name' => 'Theme HTML Tag',
|
'name' => 'Render element types',
|
||||||
'description' => 'Tests theme_html_tag() built-in theme functions.',
|
'description' => 'Tests the markup of core render element types passed to drupal_render().',
|
||||||
'group' => 'Theme',
|
'group' => 'Theme',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test function theme_html_tag()
|
* Asserts that an array of elements is rendered properly.
|
||||||
|
*
|
||||||
|
* @param array $elements
|
||||||
|
* An array of associative arrays describing render elements and their
|
||||||
|
* expected markup. Each item in $elements must contain the following:
|
||||||
|
* - 'name': This human readable description will be displayed on the test
|
||||||
|
* results page.
|
||||||
|
* - 'value': This is the render element to test.
|
||||||
|
* - 'expected': This is the expected markup for the element in 'value'.
|
||||||
*/
|
*/
|
||||||
function testThemeHtmlTag() {
|
function assertElements($elements) {
|
||||||
// Test auto-closure meta tag generation
|
foreach($elements as $element) {
|
||||||
$tag['element'] = array('#tag' => 'meta', '#attributes' => array('name' => 'description', 'content' => 'Drupal test'));
|
$this->assertIdentical(drupal_render($element['value']), $element['expected'], '"' . $element['name'] . '" input rendered correctly by drupal_render().');
|
||||||
$this->assertEqual('<meta name="description" content="Drupal test" />'."\n", theme_html_tag($tag), 'Test auto-closure meta tag generation.');
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Test title tag generation
|
/**
|
||||||
$tag['element'] = array('#tag' => 'title', '#value' => 'title test');
|
* Tests system #type 'container'.
|
||||||
$this->assertEqual('<title>title test</title>'."\n", theme_html_tag($tag), 'Test title tag generation.');
|
*/
|
||||||
|
function testContainer() {
|
||||||
|
$elements = array(
|
||||||
|
// Basic container with no attributes.
|
||||||
|
array(
|
||||||
|
'name' => "#type 'container' with no HTML attributes",
|
||||||
|
'value' => array(
|
||||||
|
'#type' => 'container',
|
||||||
|
'child' => array(
|
||||||
|
'#markup' => 'foo',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'expected' => '<div>foo</div>',
|
||||||
|
),
|
||||||
|
// Container with a class.
|
||||||
|
array(
|
||||||
|
'name' => "#type 'container' with a class HTML attribute",
|
||||||
|
'value' => array(
|
||||||
|
'#type' => 'container',
|
||||||
|
'child' => array(
|
||||||
|
'#markup' => 'foo',
|
||||||
|
),
|
||||||
|
'#attributes' => array(
|
||||||
|
'class' => 'bar',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'expected' => '<div class="bar">foo</div>',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertElements($elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests system #type 'html_tag'.
|
||||||
|
*/
|
||||||
|
function testHtmlTag() {
|
||||||
|
$elements = array(
|
||||||
|
// Test auto-closure meta tag generation.
|
||||||
|
array(
|
||||||
|
'name' => "#type 'html_tag' auto-closure meta tag generation",
|
||||||
|
'value' => array(
|
||||||
|
'#type' => 'html_tag',
|
||||||
|
'#tag' => 'meta',
|
||||||
|
'#attributes' => array(
|
||||||
|
'name' => 'description',
|
||||||
|
'content' => 'Drupal test',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'expected' => '<meta name="description" content="Drupal test" />' . "\n",
|
||||||
|
),
|
||||||
|
// Test title tag generation.
|
||||||
|
array(
|
||||||
|
'name' => "#type 'html_tag' title tag generation",
|
||||||
|
'value' => array(
|
||||||
|
'#type' => 'html_tag',
|
||||||
|
'#tag' => 'title',
|
||||||
|
'#value' => 'title test',
|
||||||
|
),
|
||||||
|
'expected' => '<title>title test</title>' . "\n",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertElements($elements);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue