From bc7940aa6a876eeaaa301f54747091166f995b09 Mon Sep 17 00:00:00 2001 From: David Rothstein Date: Sun, 2 Nov 2014 14:57:43 -0500 Subject: Issue #2058761 by kirby14, thedavidmeister: PHP notice when #attributes is not set with #theme_wrappers 'container'. --- modules/simpletest/tests/theme.test | 98 ++++++++++++++++++++++++++++++++----- 1 file changed, 85 insertions(+), 13 deletions(-) (limited to 'modules/simpletest') diff --git a/modules/simpletest/tests/theme.test b/modules/simpletest/tests/theme.test index 328afec44..f1a743e00 100644 --- a/modules/simpletest/tests/theme.test +++ b/modules/simpletest/tests/theme.test @@ -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() { return array( - 'name' => 'Theme HTML Tag', - 'description' => 'Tests theme_html_tag() built-in theme functions.', + 'name' => 'Render element types', + 'description' => 'Tests the markup of core render element types passed to drupal_render().', '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 assertElements($elements) { + foreach($elements as $element) { + $this->assertIdentical(drupal_render($element['value']), $element['expected'], '"' . $element['name'] . '" input rendered correctly by drupal_render().'); + } + } + + /** + * Tests system #type 'container'. + */ + 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' => '
foo
', + ), + // 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' => '
foo
', + ), + ); + + $this->assertElements($elements); + } + + /** + * Tests system #type 'html_tag'. */ - function testThemeHtmlTag() { - // Test auto-closure meta tag generation - $tag['element'] = array('#tag' => 'meta', '#attributes' => array('name' => 'description', 'content' => 'Drupal test')); - $this->assertEqual(''."\n", theme_html_tag($tag), 'Test auto-closure meta tag generation.'); - - // Test title tag generation - $tag['element'] = array('#tag' => 'title', '#value' => 'title test'); - $this->assertEqual('title test'."\n", theme_html_tag($tag), 'Test title tag generation.'); + 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' => '' . "\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 test' . "\n", + ), + ); + + $this->assertElements($elements); } } -- cgit v1.2.3