You are here

public function AttributeTest::testHasClass 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::testHasClass()
  2. 9 core/tests/Drupal/Tests/Core/Template/AttributeTest.php \Drupal\Tests\Core\Template\AttributeTest::testHasClass()

Tests checking for class names with the Attribute method. @covers ::hasClass

File

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

Class

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

Namespace

Drupal\Tests\Core\Template

Code

public function testHasClass() {

  // Test an attribute without any classes.
  $attribute = new Attribute();
  $this
    ->assertFalse($attribute
    ->hasClass('a-class-nowhere-to-be-found'));

  // Add a class to check for.
  $attribute
    ->addClass('we-totally-have-this-class');

  // Check that this class exists.
  $this
    ->assertTrue($attribute
    ->hasClass('we-totally-have-this-class'));
}