function AttributesTest::testAttributeValueBaseCopy

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Common/AttributesTest.php \Drupal\Tests\Core\Common\AttributesTest::testAttributeValueBaseCopy()
  2. 8.9.x core/tests/Drupal/Tests/Core/Common/AttributesTest.php \Drupal\Tests\Core\Common\AttributesTest::testAttributeValueBaseCopy()
  3. 11.x core/tests/Drupal/Tests/Core/Common/AttributesTest.php \Drupal\Tests\Core\Common\AttributesTest::testAttributeValueBaseCopy()

Tests AttributeValueBase copy.

File

core/tests/Drupal/Tests/Core/Common/AttributesTest.php, line 74

Class

AttributesTest
Tests the <a href="/api/drupal/core%21lib%21Drupal%21Core%21Template%21Attribute.php/class/Attribute/10" title="Collects, sanitizes, and renders HTML attributes." class="local">Drupal\Core\Template\Attribute</a> functionality.

Namespace

Drupal\Tests\Core\Common

Code

public function testAttributeValueBaseCopy() {
    $original_attributes = new Attribute([
        'checked' => TRUE,
        'class' => [
            'who',
            'is',
            'on',
        ],
        'id' => 'first',
    ]);
    $attributes['selected'] = $original_attributes['checked'];
    $attributes['id'] = $original_attributes['id'];
    $attributes = new Attribute($attributes);
    $this->assertSame(' checked class="who is on" id="first"', (string) $original_attributes, 'Original boolean value used with original name.');
    $this->assertSame(' selected id="first"', (string) $attributes, 'Original boolean value used with new name.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.