diff -u b/core/lib/Drupal/Core/Template/AttributeArray.php b/core/lib/Drupal/Core/Template/AttributeArray.php --- b/core/lib/Drupal/Core/Template/AttributeArray.php +++ b/core/lib/Drupal/Core/Template/AttributeArray.php @@ -72,7 +72,8 @@ /** * Adds the argument values by merging them on to the value array. * - * @return $this + * @return \Drupal\Core\Template\AttributeArray + * The attribute array with the arguments added. */ public function add() { $args = func_get_args(); @@ -91,7 +92,8 @@ /** * Removes the argument values from the value array. * - * @return $this + * @return \Drupal\Core\Template\AttributeArray + * The attribute array with the arguments removed. */ public function remove() { $args = func_get_args(); interdiff impossible; taking evasive action reverted: --- b/core/tests/Drupal/Tests/Core/Template/AttributeTest.php +++ a/core/tests/Drupal/Tests/Core/Template/AttributeTest.php @@ -66,56 +66,6 @@ $this->assertFalse(isset($attribute['class'])); } - - /** - * Tests adding class attributes with the AttributeArray helper method. - */ - public function testAddClasses() { - $attribute = new Attribute(array('class' => array('example-class'))); - - // Add one class. - $attribute['class']->add('aa'); - $this->assertEquals(new AttributeArray('class', array('example-class', 'aa')), $attribute['class']); - - // Add multiple classes. - $attribute['class']->add('xx', 'yy'); - $this->assertEquals(new AttributeArray('class', array('example-class', 'aa', 'xx', 'yy')), $attribute['class']); - - // Add an array of classes. - $attribute['class']->add(array('red', 'green', 'blue')); - $this->assertEquals(new AttributeArray('class', array('example-class', 'aa', 'xx', 'yy', 'red', 'green', 'blue')), $attribute['class']); - - } - - /** - * Tests removing class attributes with the AttributeArray helper method. - */ - public function testRemoveClasses() { - $attribute = new Attribute(array('class' => array('example-class', 'aa', 'xx', 'yy', 'red', 'green', 'blue'))); - - // Remove one class. - $attribute['class']->remove('example-class'); - $this->assertFalse(in_array('example-class', $attribute['class']->value())); - - // Remove multiple classes. - $attribute['class']->remove('xx', 'yy'); - $this->assertFalse(in_array(array('xx', 'yy'), $attribute['class']->value())); - - // Remove an array of classes. - $attribute['class']->remove(array('red', 'green', 'blue')); - $this->assertFalse(in_array(array('red', 'green', 'blue'), $attribute['class']->value())); - } - - /** - * Tests removing class attributes with the AttributeArray helper method. - */ - public function testChainAddRemoveClasses() { - $attribute = new Attribute(array('class' => array('example-class', 'red', 'green', 'blue'))); - unset($attribute['class']); - $this->assertFalse(isset($attribute['class'])); - } - - /** * Tests iterating on the values of the attribute. */ unchanged: --- a/core/tests/Drupal/Tests/Core/Template/AttributeTest.php +++ b/core/tests/Drupal/Tests/Core/Template/AttributeTest.php @@ -57,6 +57,72 @@ public function testRemove() { $this->assertFalse(isset($attribute['class'])); } + + /** + * Tests adding class attributes with the AttributeArray helper method. + */ + public function testAddClasses() { + $attribute = new Attribute(array('class' => array('example-class'))); + + // Add one class. + $attribute['class']->add('aa'); + $this->assertEquals(new AttributeArray('class', array('example-class', 'aa')), $attribute['class']); + + // Add multiple classes. + $attribute['class']->add('xx', 'yy'); + $this->assertEquals( + new AttributeArray( + 'class', + array('example-class', 'aa', 'xx', 'yy')), + $attribute['class'] + ); + + // Add an array of classes. + $attribute['class']->add(array('red', 'green', 'blue')); + $this->assertEquals( + new AttributeArray( + 'class', + array('example-class', 'aa', 'xx', 'yy', 'red', 'green', 'blue') + ), + $attribute['class'] + ); + + } + + /** + * Tests removing class attributes with the AttributeArray helper method. + */ + public function testRemoveClasses() { + $attribute = new Attribute( + array( + 'class' => array('example-class', 'aa', 'xx', 'yy', 'red', 'green', 'blue'), + ) + ); + + // Remove one class. + $attribute['class']->remove('example-class'); + $this->assertFalse(in_array('example-class', $attribute['class']->value())); + + // Remove multiple classes. + $attribute['class']->remove('xx', 'yy'); + $this->assertFalse(in_array(array('xx', 'yy'), $attribute['class']->value())); + + // Remove an array of classes. + $attribute['class']->remove(array('red', 'green', 'blue')); + $this->assertFalse(in_array(array('red', 'green', 'blue'), $attribute['class']->value())); + } + + /** + * Tests removing class attributes with the AttributeArray helper method. + */ + public function testChainAddRemoveClasses() { + $attribute = new Attribute( + array('class' => array('example-class', 'red', 'green', 'blue')) + ); + unset($attribute['class']); + $this->assertFalse(isset($attribute['class'])); + } + /** * Tests iterating on the values of the attribute. */