Commit 804af828 authored by webchick's avatar webchick

Issue #2083941 by dawehner: Fixed \Drupal\Core\Theme\Attribute->value() is...

Issue #2083941 by dawehner: Fixed \Drupal\Core\Theme\Attribute->value() is named wrong and does not work.
parent 027b0f9e
......@@ -6,6 +6,7 @@
*/
namespace Drupal\Core\Template;
use Drupal\Component\Utility\String;
/**
......@@ -103,7 +104,7 @@ public function __toString() {
$return = '';
foreach ($this->storage as $name => $value) {
if (!$value->printed()) {
$rendered = is_object($value) ? $value->render() : (check_plain($name) . ' = "' . check_plain($value) . '"');
$rendered = is_object($value) ? $value->render() : (String::checkPlain($name) . ' = "' . String::checkPlain($value) . '"');
if ($rendered) {
$return .= " $rendered";
}
......@@ -133,8 +134,8 @@ public function getIterator() {
/**
* Returns the whole array.
*/
public function value() {
return $this->value;
public function storage() {
return $this->storage;
}
}
......@@ -6,6 +6,7 @@
*/
namespace Drupal\Core\Template;
use Drupal\Component\Utility\String;
/**
* A class that defines a type of boolean HTML attribute.
......@@ -41,7 +42,7 @@ public function render() {
*/
public function __toString() {
$this->printed = TRUE;
return $this->value === FALSE ? '' : check_plain($this->name);
return $this->value === FALSE ? '' : String::checkPlain($this->name);
}
}
<?php
/**
* @file
* Contains \Drupal\Tests\Core\Template\AttributeTest.
*/
namespace Drupal\Tests\Core\Template;
use Drupal\Core\Template\Attribute;
use Drupal\Core\Template\AttributeArray;
use Drupal\Core\Template\AttributeString;
use Drupal\Tests\UnitTestCase;
/**
* Tests the template attribute class.
*
* @see \Drupal\Core\Template\Attribute
*/
class AttributeTest extends UnitTestCase {
public static function getInfo() {
return array(
'name' => 'Attribute class',
'description' => 'Tests the template attribute class.',
'group' => 'Template',
);
}
/**
* Tests the constructor of the attribute class.
*/
public function testConstructor() {
$attribute = new Attribute(array('class' => array('example-class')));
$this->assertTrue(isset($attribute['class']));
$this->assertEquals(new AttributeArray('class', array('example-class')), $attribute['class']);
}
/**
* Tests set of values.
*/
public function testSet() {
$attribute = new Attribute();
$attribute['class'] = array('example-class');
$this->assertTrue(isset($attribute['class']));
$this->assertEquals(new AttributeArray('class', array('example-class')), $attribute['class']);
}
/**
* Tests adding new values to an existing part of the attribute.
*/
public function testAdd() {
$attribute = new Attribute(array('class' => array('example-class')));
$attribute['class'][] = 'other-class';
$this->assertEquals(new AttributeArray('class', array('example-class', 'other-class')), $attribute['class']);
}
/**
* Tests removing of values.
*/
public function testRemove() {
$attribute = new Attribute(array('class' => array('example-class')));
unset($attribute['class']);
$this->assertFalse(isset($attribute['class']));
}
/**
* Tests iterating on the values of the attribute.
*/
public function testIterate() {
$attribute = new Attribute(array('class' => array('example-class'), 'id' => 'example-id'));
$counter = 0;
foreach ($attribute as $key => $value) {
if ($counter == 0) {
$this->assertEquals('class', $key);
$this->assertEquals(new AttributeArray('class', array('example-class')), $value);
}
if ($counter == 1) {
$this->assertEquals('id', $key);
$this->assertEquals(new AttributeString('id', 'example-id'), $value);
}
$counter++;
}
}
/**
* Tests printing of an attribute.
*/
public function testPrint() {
$attribute = new Attribute(array('class' => array('example-class'), 'id' => 'example-id', 'enabled' => TRUE));
$html = '<div' . (string) $attribute . '></div>';
$this->assertSelectEquals('div.example-class', '', 1, $html);
$this->assertSelectEquals('div.example-class2', '', 0, $html);
$this->assertSelectEquals('div#example-id', '', 1, $html);
$this->assertSelectEquals('div#example-id2', '', 0, $html);
$this->assertTrue(strpos($html, 'enabled') !== FALSE);
}
/**
* Tests the storage method.
*/
public function testStorage() {
$attribute = new Attribute(array('class' => array('example-class')));
$this->assertEquals(array('class' => new AttributeArray('class', array('example-class'))), $attribute->storage());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment