You are here

public function AttributeTest::testChainAddRemoveClasses in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Template/AttributeTest.php \Drupal\Tests\Core\Template\AttributeTest::testChainAddRemoveClasses()
  2. 9 core/tests/Drupal/Tests/Core/Template/AttributeTest.php \Drupal\Tests\Core\Template\AttributeTest::testChainAddRemoveClasses()

Tests removing class attributes with the Attribute helper methods. @covers ::removeClass @covers ::addClass

File

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

Class

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

Namespace

Drupal\Tests\Core\Template

Code

public function testChainAddRemoveClasses() {
  $attribute = new Attribute([
    'class' => [
      'example-class',
      'red',
      'green',
      'blue',
    ],
  ]);
  $attribute
    ->removeClass([
    'red',
    'green',
    'pink',
  ])
    ->addClass([
    'apple',
    'lime',
    'grapefruit',
  ])
    ->addClass([
    'banana',
  ]);
  $expected = [
    'example-class',
    'blue',
    'apple',
    'lime',
    'grapefruit',
    'banana',
  ];
  $this
    ->assertEquals($expected, $attribute['class']
    ->value(), 'Attributes chained');
}