commit d26753d7b159355e2600c65e682679eab0c6a5b3 Author: Joel Pittet Date: Sat Aug 2 21:08:49 2014 -0700 cleanup docblocks and use assertNotContains and assertArrayEquals diff --git a/core/lib/Drupal/Core/Template/Attribute.php b/core/lib/Drupal/Core/Template/Attribute.php index 00b3142..7372c63 100644 --- a/core/lib/Drupal/Core/Template/Attribute.php +++ b/core/lib/Drupal/Core/Template/Attribute.php @@ -119,8 +119,10 @@ public function offsetExists($name) { /** * Adds the argument values by merging them on to the value array. * - * @return \Drupal\Core\Template\Attribute - * The attribute with the class arguments added. + * @param mixed ... + * Classes arguments to add. + * + * @return $this */ public function addClass() { $args = func_get_args(); @@ -131,6 +133,7 @@ public function addClass() { // values or one or more array arguments. $classes = array_merge($classes, (array) $arg); } + // Merge if there are values, just add them otherwise. if (isset($this->storage['class']) && $this->storage['class'] instanceOf AttributeArray) { // Merge the values passed in from the class value array. @@ -151,8 +154,10 @@ public function addClass() { /** * Removes the argument values from the value array. * - * @return \Drupal\Core\Template\Attribute - * The attribute with the class arguments removed. + * @param mixed ... + * Classes arguments to remove. + * + * @return $this */ public function removeClass() { // With no class attribute, there is no need to remove. diff --git a/core/lib/Drupal/Core/Template/AttributeArray.php b/core/lib/Drupal/Core/Template/AttributeArray.php index a204f4b..c432ba0 100644 --- a/core/lib/Drupal/Core/Template/AttributeArray.php +++ b/core/lib/Drupal/Core/Template/AttributeArray.php @@ -88,7 +88,7 @@ public function value() { * * @see ArrayObject::exchangeArray * - * @param array $input + * @param array $input * The array input to replace the internal value. * * @return array diff --git a/core/tests/Drupal/Tests/Core/Template/AttributeTest.php b/core/tests/Drupal/Tests/Core/Template/AttributeTest.php index f698e82..0a9859d 100644 --- a/core/tests/Drupal/Tests/Core/Template/AttributeTest.php +++ b/core/tests/Drupal/Tests/Core/Template/AttributeTest.php @@ -62,24 +62,24 @@ public function testRemove() { * @covers ::addClass() */ public function testAddClasses() { - // Add empty Attribute object with no classes. $attribute = new Attribute(); + // Add one class on empty attribute. $attribute->addClass('banana'); - $this->assertEquals(new AttributeArray('class', array('banana')), $attribute['class']); + $this->assertArrayEquals(array('banana'), $attribute['class']->value()); // Add one class. $attribute->addClass('aa'); - $this->assertEquals(new AttributeArray('class', array('banana', 'aa')), $attribute['class']); + $this->assertArrayEquals(array('banana', 'aa'), $attribute['class']->value()); // Add multiple classes. $attribute->addClass('xx', 'yy'); - $this->assertEquals(new AttributeArray('class', array('banana', 'aa', 'xx', 'yy')), $attribute['class']); + $this->assertArrayEquals(array('banana', 'aa', 'xx', 'yy'), $attribute['class']->value()); // Add an array of classes. $attribute->addClass(array('red', 'green', 'blue')); - $this->assertEquals(new AttributeArray('class', array('banana', 'aa', 'xx', 'yy', 'red', 'green', 'blue')), $attribute['class']); + $this->assertArrayEquals(array('banana', 'aa', 'xx', 'yy', 'red', 'green', 'blue'), $attribute['class']->value()); } /** @@ -92,15 +92,15 @@ public function testRemoveClasses() { // Remove one class. $attribute->removeClass('example-class'); - $this->assertFalse(in_array('example-class', $attribute['class']->value())); + $this->assertNotContains('example-class', $attribute['class']->value()); // Remove multiple classes. $attribute->removeClass('xx', 'yy'); - $this->assertFalse(in_array(array('xx', 'yy'), $attribute['class']->value())); + $this->assertNotContains(array('xx', 'yy'), $attribute['class']->value()); // Remove an array of classes. $attribute->removeClass(array('red', 'green', 'blue')); - $this->assertFalse(in_array(array('red', 'green', 'blue'), $attribute['class']->value())); + $this->assertNotContains(array('red', 'green', 'blue'), $attribute['class']->value()); } /**