.../lib/Drupal/system/Tests/Theme/ThemeTest.php | 22 ++++++++++++++++++++ .../templates/theme-test-render-element.tpl.php | 1 + .../tests/modules/theme_test/theme_test.module | 10 +++++++++ 3 files changed, 33 insertions(+) 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..cdf5d7b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php @@ -36,6 +36,28 @@ function setUp() { } /** + * Test attribute merging. + * + * Render arrays that use a render element and templates (and hence call + * template_preprocess()) must ensure the attributes at different occassions + * are all merged correctly: + * - $variables['attributes'] as passed in to theme() + * - the render element's #attributes + * - any attributes set in the template's preprocessing function + */ + function testAttributeMerging() { + $output = theme('theme_test_render_element', array( + 'elements' => array( + '#attributes' => array('data-foo' => 'bar'), + ), + 'attributes' => array( + 'id' => 'bazinga', + ), + )); + $this->assertIdentical($output, '
' . "\n"); + } + + /** * Test function theme_get_suggestions() for SA-CORE-2009-003. */ function testThemeSuggestions() { diff --git a/core/modules/system/tests/modules/theme_test/templates/theme-test-render-element.tpl.php b/core/modules/system/tests/modules/theme_test/templates/theme-test-render-element.tpl.php new file mode 100644 index 0000000..f301d31 --- /dev/null +++ b/core/modules/system/tests/modules/theme_test/templates/theme-test-render-element.tpl.php @@ -0,0 +1 @@ +> 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..c51eb0c 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,10 @@ function theme_test_theme($existing, $type, $theme, $path) { $items['theme_test_foo'] = array( 'variables' => array('foo' => NULL), ); + $items['theme_test_render_element'] = array( + 'render element' => 'elements', + 'template' => 'theme-test-render-element', + ); return $items; } @@ -172,3 +176,9 @@ function theme_theme_test_foo($variables) { return $variables['foo']; } +/** + * Process variables for theme-test-render-element.tpl.php. + */ +function template_preprocess_theme_test_render_element(&$variables) { + $variables['attributes']['data-variables-are-preprocessed'] = TRUE; +}