diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php index 20ccc2b..22ed1b2 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php @@ -194,6 +194,20 @@ function testRegistryRebuild() { } /** + * Tests automatic drupal_render_children() for 'render element' theme hooks. + */ + function testDrupalRenderChildren() { + $element = array( + '#theme' => 'theme_test_render_element_children', + 'child' => array( + '#markup' => 'Foo', + ), + ); + + $this->assertIdentical(theme('theme_test_render_element_children', $element), 'Foo', 'drupal_render() calls drupal_render_children() when rendering a render element.'); + } + + /** * Tests theme can provide classes. */ function testClassLoading() { diff --git a/core/modules/system/tests/modules/theme_test/theme_test.module b/core/modules/system/tests/modules/theme_test/theme_test.module index 137fdfc..c35f964 100644 --- a/core/modules/system/tests/modules/theme_test/theme_test.module +++ b/core/modules/system/tests/modules/theme_test/theme_test.module @@ -17,6 +17,9 @@ function theme_test_theme($existing, $type, $theme, $path) { $items['theme_test_foo'] = array( 'variables' => array('foo' => NULL), ); + $items['theme_test_render_element_children'] = array( + 'render element' => 'element', + ); return $items; } @@ -172,3 +175,17 @@ function theme_theme_test_foo($variables) { return $variables['foo']; } +/** + * Theme function for testing automatic drupal_render_children() behaviour. + * + * Theme hooks defining a 'render element' add an internal '#render_children' + * property. When this property is found, drupal_render() returns + * drupal_render_children() to prevent infinite recursion. + * + * @param array $variables + * An associative array containing: + * - element: An associative array containing the properties of the element. + */ +function theme_theme_test_render_element_children($variables) { + return drupal_render($variables['element']); +}