commit 3d7a434820b9f4077258f6e39d0529fb22b1578f Author: Joel Pittet Date: Sun Nov 9 12:22:11 2014 -0800 I moved the value method to the AttributeValueBase, and tested boolean in constructor which passes locally, and used short array syntax. diff --git a/core/lib/Drupal/Core/Template/AttributeArray.php b/core/lib/Drupal/Core/Template/AttributeArray.php index 61c968f..190c898 100644 --- a/core/lib/Drupal/Core/Template/AttributeArray.php +++ b/core/lib/Drupal/Core/Template/AttributeArray.php @@ -87,13 +87,6 @@ public function getIterator() { } /** - * Returns the whole array. - */ - public function value() { - return $this->value; - } - - /** * Exchange the array for another one. * * @see ArrayObject::exchangeArray diff --git a/core/lib/Drupal/Core/Template/AttributeBoolean.php b/core/lib/Drupal/Core/Template/AttributeBoolean.php index d3d4a45..4e9ea67 100644 --- a/core/lib/Drupal/Core/Template/AttributeBoolean.php +++ b/core/lib/Drupal/Core/Template/AttributeBoolean.php @@ -39,13 +39,6 @@ public function render() { } /** - * Returns the boolean value. - */ - public function value() { - return $this->value; - } - - /** * Implements the magic __toString() method. */ public function __toString() { diff --git a/core/lib/Drupal/Core/Template/AttributeValueBase.php b/core/lib/Drupal/Core/Template/AttributeValueBase.php index 197b199..ed4dfc3 100644 --- a/core/lib/Drupal/Core/Template/AttributeValueBase.php +++ b/core/lib/Drupal/Core/Template/AttributeValueBase.php @@ -62,6 +62,13 @@ public function render() { } /** + * Returns the raw value. + */ + public function value() { + return $this->value; + } + + /** * Implements the magic __toString() method. */ abstract function __toString(); diff --git a/core/tests/Drupal/Tests/Core/Template/AttributeTest.php b/core/tests/Drupal/Tests/Core/Template/AttributeTest.php index b195618..fcf8601 100644 --- a/core/tests/Drupal/Tests/Core/Template/AttributeTest.php +++ b/core/tests/Drupal/Tests/Core/Template/AttributeTest.php @@ -65,9 +65,9 @@ public function testSetAttribute() { $attribute = new Attribute(); // Test adding various attributes. - $attributes = array('alt', 'id', 'src', 'title', 'value'); + $attributes = ['alt', 'id', 'src', 'title', 'value']; foreach ($attributes as $key) { - foreach (array('kitten', '') as $value) { + foreach (['kitten', ''] as $value) { $attribute = new Attribute(); $attribute->setAttribute($key, $value); $this->assertEquals($value, $attribute[$key]); @@ -76,13 +76,18 @@ public function testSetAttribute() { // Test adding array to class. $attribute = new Attribute(); - $attribute->setAttribute('class', array('kitten', 'cat')); - $this->assertArrayEquals(array('kitten', 'cat'), $attribute['class']->value()); + $attribute->setAttribute('class', ['kitten', 'cat']); + $this->assertArrayEquals(['kitten', 'cat'], $attribute['class']->value()); // Test adding boolean attributes. $attribute = new Attribute(); $attribute['checked'] = TRUE; $this->assertTrue($attribute['checked']->value()); + + // Test adding boolean attributes through the constructor. + $attribute = new Attribute(['selected' => TRUE, 'checked' => FALSE]); + $this->assertTrue($attribute['selected']->value()); + $this->assertFalse($attribute['checked']->value()); } /** @@ -90,14 +95,14 @@ public function testSetAttribute() { * @covers ::removeAttribute() */ public function testRemoveAttribute() { - $attributes = array( + $attributes = [ 'alt' => 'Alternative text', 'id' => 'bunny', 'src' => 'zebra', 'style' => 'color: pink;', 'title' => 'kitten', 'value' => 'ostrich', - ); + ]; $attribute = new Attribute($attributes); // Single value.