Commit 1d8f7c54 authored by alexpott's avatar alexpott

Issue #2347511 by davidhernandez, lauriii, rpayanm, kasn: Add method to test...

Issue #2347511 by davidhernandez, lauriii, rpayanm, kasn: Add method to test if class attribute has class on Attribute object.
parent 4493d029
......@@ -188,6 +188,24 @@ public function removeClass() {
return $this;
}
/**
* Checks if the class array has the given CSS class.
*
* @param string $class
* The CSS class to check for.
*
* @return bool
* Returns TRUE if the class exists, or FALSE otherwise.
*/
public function hasClass($class) {
if (isset($this->storage['class']) && $this->storage['class'] instanceOf AttributeArray) {
return in_array($class, $this->storage['class']->value());
}
else {
return FALSE;
}
}
/**
* Implements the magic __toString() method.
*/
......
......@@ -140,6 +140,21 @@ public function testRemoveClasses() {
$this->assertEmpty((string) $attribute);
}
/**
* Tests checking for class names with the Attribute method.
* @covers ::hasClass()
*/
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'));
}
/**
* Tests removing class attributes with the Attribute helper methods.
* @covers ::removeClass()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment