function AttributeTest::testHasClass

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Template/AttributeTest.php \Drupal\Tests\Core\Template\AttributeTest::testHasClass()
  2. 10 core/tests/Drupal/Tests/Core/Template/AttributeTest.php \Drupal\Tests\Core\Template\AttributeTest::testHasClass()
  3. 11.x 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'));
}

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