diff --git a/core/lib/Drupal/Component/Attribute/Attribute.php b/core/lib/Drupal/Component/Attribute/Attribute.php index 532ad9d..0d2db3b 100644 --- a/core/lib/Drupal/Component/Attribute/Attribute.php +++ b/core/lib/Drupal/Component/Attribute/Attribute.php @@ -317,7 +317,7 @@ public function toArray() { /** * Implements the magic __clone() method. */ - public function __clone() { + public function __clone() { foreach ($this->storage as $name => $value) { $this->storage[$name] = clone $value; } diff --git a/core/lib/Drupal/Component/Attribute/AttributeArray.php b/core/lib/Drupal/Component/Attribute/AttributeArray.php index 25bec95..085a0aa 100644 --- a/core/lib/Drupal/Component/Attribute/AttributeArray.php +++ b/core/lib/Drupal/Component/Attribute/AttributeArray.php @@ -89,13 +89,13 @@ public function getIterator() { /** * Exchange the array for another one. * - * @see ArrayObject::exchangeArray - * * @param array $input * The array input to replace the internal value. * * @return array * The old array value. + * + * @see ArrayObject::exchangeArray */ public function exchangeArray($input) { $old = $this->value; diff --git a/core/lib/Drupal/Component/Attribute/AttributeValueBase.php b/core/lib/Drupal/Component/Attribute/AttributeValueBase.php index 1163db2..0b17627 100644 --- a/core/lib/Drupal/Component/Attribute/AttributeValueBase.php +++ b/core/lib/Drupal/Component/Attribute/AttributeValueBase.php @@ -70,6 +70,6 @@ public function value() { /** * Implements the magic __toString() method. */ - abstract function __toString(); + public abstract function __toString(); } diff --git a/core/lib/Drupal/Core/Template/Attribute.php b/core/lib/Drupal/Core/Template/Attribute.php index 23f63d6..83a9a7c 100644 --- a/core/lib/Drupal/Core/Template/Attribute.php +++ b/core/lib/Drupal/Core/Template/Attribute.php @@ -10,7 +10,9 @@ use Drupal\Component\Attribute\Attribute as ComponentAttribute; /** + * Collects, sanitizes, and renders HTML attributes. + * * @deprecated in Drupal 8.2.0, will be removed before Drupal 9.0.0. * Use \Drupal\Component\Attribute\Attribute. */ -class Attribute extends ComponentAttribute { } +class Attribute extends ComponentAttribute {} diff --git a/core/lib/Drupal/Core/Template/AttributeArray.php b/core/lib/Drupal/Core/Template/AttributeArray.php index 9af0058..fb36fdf 100644 --- a/core/lib/Drupal/Core/Template/AttributeArray.php +++ b/core/lib/Drupal/Core/Template/AttributeArray.php @@ -10,7 +10,9 @@ use Drupal\Component\Attribute\AttributeArray as ComponentAttributeArray; /** + * A class that defines a type of Attribute that can be added to as an array. + * * @deprecated in Drupal 8.2.0, will be removed before Drupal 9.0.0. * Use \Drupal\Component\Attribute\AttributeArray. */ -class AttributeArray extends ComponentAttributeArray { } +class AttributeArray extends ComponentAttributeArray {} diff --git a/core/lib/Drupal/Core/Template/AttributeBoolean.php b/core/lib/Drupal/Core/Template/AttributeBoolean.php index e7993e9..b03d130 100644 --- a/core/lib/Drupal/Core/Template/AttributeBoolean.php +++ b/core/lib/Drupal/Core/Template/AttributeBoolean.php @@ -10,7 +10,9 @@ use Drupal\Component\Attribute\AttributeBoolean as ComponentAttributeBoolean; /** + * A class that defines a type of boolean HTML attribute. + * * @deprecated in Drupal 8.2.0, will be removed before Drupal 9.0.0. * Use \Drupal\Component\Attribute\AttributeBoolean. */ -class AttributeBoolean extends ComponentAttributeBoolean { } +class AttributeBoolean extends ComponentAttributeBoolean {} diff --git a/core/lib/Drupal/Core/Template/AttributeString.php b/core/lib/Drupal/Core/Template/AttributeString.php index c5bdedc..75445a2 100644 --- a/core/lib/Drupal/Core/Template/AttributeString.php +++ b/core/lib/Drupal/Core/Template/AttributeString.php @@ -10,7 +10,9 @@ use Drupal\Component\Attribute\AttributeString as ComponentAttributeString; /** + * A class that represents most standard HTML attributes. + * * @deprecated in Drupal 8.2.0, will be removed before Drupal 9.0.0. * Use \Drupal\Component\Attribute\AttributeString. */ -class AttributeString extends ComponentAttributeString { } +class AttributeString extends ComponentAttributeString {} diff --git a/core/lib/Drupal/Core/Template/AttributeValueBase.php b/core/lib/Drupal/Core/Template/AttributeValueBase.php index 50407b7..68f142b 100644 --- a/core/lib/Drupal/Core/Template/AttributeValueBase.php +++ b/core/lib/Drupal/Core/Template/AttributeValueBase.php @@ -10,7 +10,9 @@ use Drupal\Component\Attribute\AttributeValueBase as ComponentAttributeValueBase; /** + * Defines the base class for an attribute type. + * * @deprecated in Drupal 8.2.0, will be removed before Drupal 9.0.0. * Use \Drupal\Component\Attribute\AttributeValueBase. */ -abstract class AttributeValueBase extends ComponentAttributeValueBase { } +abstract class AttributeValueBase extends ComponentAttributeValueBase {} diff --git a/core/tests/Drupal/Tests/Component/Attribute/AttributeTest.php b/core/tests/Drupal/Tests/Component/Attribute/AttributeTest.php index 8f1379c..16d47a2 100644 --- a/core/tests/Drupal/Tests/Component/Attribute/AttributeTest.php +++ b/core/tests/Drupal/Tests/Component/Attribute/AttributeTest.php @@ -79,6 +79,7 @@ public function testRemove() { /** * Tests setting attributes. + * * @covers ::setAttribute */ public function testSetAttribute() { @@ -107,6 +108,7 @@ public function testSetAttribute() { /** * Tests removing attributes. + * * @covers ::removeAttribute */ public function testRemoveAttribute() { @@ -146,6 +148,7 @@ public function testRemoveAttribute() { /** * Tests adding class attributes with the AttributeArray helper method. + * * @covers ::addClass */ public function testAddClasses() { @@ -189,20 +192,30 @@ public function testAddClasses() { // Add an array of classes. $attribute->addClass(array('red', 'green', 'blue')); - $this->assertArrayEquals(array('banana', 'aa', 'xx', 'yy', 'red', 'green', 'blue'), $attribute['class']->value()); + $this->assertArrayEquals( + array('banana', 'aa', 'xx', 'yy', 'red', 'green', 'blue'), + $attribute['class']->value() + ); // Add an array of duplicate classes. - $attribute->addClass(array('red', 'green', 'blue'), array('aa', 'aa', 'banana'), 'yy'); + $attribute->addClass( + array('red', 'green', 'blue'), + array('aa', 'aa', 'banana'), + 'yy' + ); $this->assertEquals('banana aa xx yy red green blue', (string) $attribute['class']); } /** * Tests removing class attributes with the AttributeArray helper method. + * * @covers ::removeClass */ public function testRemoveClasses() { // Add duplicate class to ensure that both duplicates are removed. - $classes = array('example-class', 'aa', 'xx', 'yy', 'red', 'green', 'blue', 'red'); + $classes = array( + 'example-class', 'aa', 'xx', 'yy', 'red', 'green', 'blue', 'red', + ); $attribute = new Attribute(array('class' => $classes)); // Remove one class. @@ -229,6 +242,7 @@ public function testRemoveClasses() { /** * Tests checking for class names with the Attribute method. + * * @covers ::hasClass */ public function testHasClass() { @@ -244,6 +258,7 @@ public function testHasClass() { /** * Tests removing class attributes with the Attribute helper methods. + * * @covers ::removeClass * @covers ::addClass */ @@ -256,12 +271,15 @@ public function testChainAddRemoveClasses() { ->removeClass(array('red', 'green', 'pink')) ->addClass(array('apple', 'lime', 'grapefruit')) ->addClass(array('banana')); - $expected = array('example-class', 'blue', 'apple', 'lime', 'grapefruit', 'banana'); + $expected = array( + 'example-class', 'blue', 'apple', 'lime', 'grapefruit', 'banana', + ); $this->assertArrayEquals($expected, $attribute['class']->value(), 'Attributes chained'); } /** * Tests the twig calls to the Attribute. + * * @dataProvider providerTestAttributeClassHelpers * * @covers ::removeClass @@ -276,7 +294,7 @@ public function testTwigAddRemoveClasses($template, $expected, $seed_attributes } /** - * Provides tests data for testEscaping + * Provides tests data for testEscaping. * * @return array * An array of test data each containing of a twig template string, @@ -342,27 +360,40 @@ public function testIterate() { * Tests printing of an attribute. */ public function testPrint() { - $attribute = new Attribute(array('class' => array('example-class'), 'id' => 'example-id', 'enabled' => TRUE)); + $attribute = new Attribute(array( + 'class' => array('example-class'), + 'id' => 'example-id', + 'enabled' => TRUE, + )); $content = $this->randomMachineName(); $html = '' . $content . ''; $this->assertClass('example-class', $html); $this->assertNoClass('example-class2', $html); - $this->assertID('example-id', $html); - $this->assertNoID('example-id2', $html); + $this->assertId('example-id', $html); + $this->assertNoId('example-id2', $html); $this->assertTrue(strpos($html, 'enabled') !== FALSE); } /** + * Tests attribute values. + * * @covers ::createAttributeValue + * * @dataProvider providerTestAttributeValues */ public function testAttributeValues(array $attributes, $expected) { $this->assertEquals($expected, (new Attribute($attributes))->__toString()); } + /** + * Provides test data for testAttributeValues. + * + * @return array + * An array of test data. + */ public function providerTestAttributeValues() { $data = []; @@ -386,7 +417,7 @@ public function providerTestAttributeValues() { */ protected function assertClass($class, $html) { $xpath = "//*[@class='$class']"; - self::assertTrue((bool) $this->getXPathResultCount($xpath, $html)); + self::assertTrue((bool) $this->getXpathResultCount($xpath, $html)); } /** @@ -399,7 +430,7 @@ protected function assertClass($class, $html) { */ protected function assertNoClass($class, $html) { $xpath = "//*[@class='$class']"; - self::assertFalse((bool) $this->getXPathResultCount($xpath, $html)); + self::assertFalse((bool) $this->getXpathResultCount($xpath, $html)); } /** @@ -410,9 +441,9 @@ protected function assertNoClass($class, $html) { * @param string $html * The HTML snippet to check. */ - protected function assertID($id, $html) { + protected function assertId($id, $html) { $xpath = "//*[@id='$id']"; - self::assertTrue((bool) $this->getXPathResultCount($xpath, $html)); + self::assertTrue((bool) $this->getXpathResultCount($xpath, $html)); } /** @@ -423,9 +454,9 @@ protected function assertID($id, $html) { * @param string $html * The HTML snippet to check. */ - protected function assertNoID($id, $html) { + protected function assertNoId($id, $html) { $xpath = "//*[@id='$id']"; - self::assertFalse((bool) $this->getXPathResultCount($xpath, $html)); + self::assertFalse((bool) $this->getXpathResultCount($xpath, $html)); } /** @@ -439,8 +470,8 @@ protected function assertNoID($id, $html) { * @return int * The number of results that are found. */ - protected function getXPathResultCount($query, $html) { - $document = new \DOMDocument; + protected function getXpathResultCount($query, $html) { + $document = new \DOMDocument(); $document->loadHTML($html); $xpath = new \DOMXPath($document); @@ -458,6 +489,10 @@ public function testStorage() { } +/** + * Implementation of MarkupInterface to use in tests. + */ class TestMarkup implements MarkupInterface, \Countable { use MarkupTrait; + }