function AttributeTest::testAdd

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Template/AttributeTest.php \Drupal\Tests\Core\Template\AttributeTest::testAdd()
  2. 8.9.x core/tests/Drupal/Tests/Core/Template/AttributeTest.php \Drupal\Tests\Core\Template\AttributeTest::testAdd()
  3. 10 core/tests/Drupal/Tests/Core/Template/AttributeTest.php \Drupal\Tests\Core\Template\AttributeTest::testAdd()

Tests adding new values to an existing part of the attribute.

File

core/tests/Drupal/Tests/Core/Template/AttributeTest.php, line 63

Class

AttributeTest
@coversDefaultClass \Drupal\Core\Template\Attribute @group Template

Namespace

Drupal\Tests\Core\Template

Code

public function testAdd() : void {
    $attribute = new Attribute([
        'class' => [
            'example-class',
        ],
    ]);
    $attribute['class'][] = 'other-class';
    $this->assertEquals(new AttributeArray('class', [
        'example-class',
        'other-class',
    ]), $attribute['class']);
}

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