function 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[[api-linebreak]] @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.