public function ThemeTest::testAttributeMerging in Drupal 10
Same name and namespace in other branches
- 8 core/modules/system/tests/src/Kernel/Theme/ThemeTest.php \Drupal\Tests\system\Kernel\Theme\ThemeTest::testAttributeMerging()
- 9 core/modules/system/tests/src/Kernel/Theme/ThemeTest.php \Drupal\Tests\system\Kernel\Theme\ThemeTest::testAttributeMerging()
Tests attribute merging.
Render arrays that use a render element and templates (and hence call template_preprocess()) must ensure the attributes at different occasions are all merged correctly:
- $variables['attributes'] as passed in to the theme hook implementation.
- the render element's #attributes
- any attributes set in the template's preprocessing function
File
- core/
modules/ system/ tests/ src/ Kernel/ Theme/ ThemeTest.php, line 39
Class
- ThemeTest
- Tests low-level theme functions.
Namespace
Drupal\Tests\system\Kernel\ThemeCode
public function testAttributeMerging() {
$theme_test_render_element = [
'elements' => [
'#attributes' => [
'data-foo' => 'bar',
],
],
'attributes' => [
'id' => 'bazinga',
],
];
$this
->assertThemeOutput('theme_test_render_element', $theme_test_render_element, '<div id="bazinga" data-foo="bar" data-variables-are-preprocessed></div>' . "\n");
}