function ThemeTest::testAttributeMerging

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

File

drupal/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php, line 48
Definition of Drupal\system\Tests\Theme\ThemeTest.

Class

ThemeTest
Tests low-level theme functions.

Namespace

Drupal\system\Tests\Theme

Code

function testAttributeMerging() {
  $output = theme('theme_test_render_element', array(
    'elements' => array(
      '#attributes' => array(
        'data-foo' => 'bar',
      ),
    ),
    'attributes' => array(
      'id' => 'bazinga',
    ),
  ));
  $this
    ->assertIdentical($output, '<div id="bazinga" data-foo="bar" data-variables-are-preprocessed></div>' . "\n");
}