function AttributeTest::testRemoveAttribute

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

Tests removing attributes. @covers ::removeAttribute

File

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

Class

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

Namespace

Drupal\Tests\Core\Template

Code

public function testRemoveAttribute() : void {
    $attributes = [
        'alt' => 'Alternative text',
        'id' => 'bunny',
        'src' => 'zebra',
        'style' => 'color: pink;',
        'title' => 'kitten',
        'value' => 'ostrich',
        'checked' => TRUE,
    ];
    $attribute = new Attribute($attributes);
    // Single value.
    $attribute->removeAttribute('alt');
    $this->assertEmpty($attribute['alt']);
    // Multiple values.
    $attribute->removeAttribute('id', 'src');
    $this->assertEmpty($attribute['id']);
    $this->assertEmpty($attribute['src']);
    // Single value in array.
    $attribute->removeAttribute([
        'style',
    ]);
    $this->assertEmpty($attribute['style']);
    // Boolean value.
    $attribute->removeAttribute('checked');
    $this->assertEmpty($attribute['checked']);
    // Multiple values in array.
    $attribute->removeAttribute([
        'title',
        'value',
    ]);
    $this->assertEmpty((string) $attribute);
}

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