Issue #2347511 by davidhernandez, lauriii, rpayanm, kasn: Add method to test if class attribute has class on Attribute object.
parent
4493d029c8
commit
1d8f7c546e
|
@ -188,6 +188,24 @@ class Attribute implements \ArrayAccess, \IteratorAggregate {
|
|||
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 @@ class AttributeTest extends UnitTestCase {
|
|||
$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()
|
||||
|
|
Loading…
Reference in New Issue