class AttributesTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Common/AttributesTest.php \Drupal\Tests\Core\Common\AttributesTest
Tests the Drupal\Core\Template\Attribute functionality.
@group Common
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\Common\AttributesTest
Expanded class hierarchy of AttributesTest
File
- core/
tests/ Drupal/ Tests/ Core/ Common/ AttributesTest.php, line 18 - Contains \Drupal\Tests\Core\Common\AttributesTest.
Namespace
Drupal\Tests\Core\CommonView source
class AttributesTest extends UnitTestCase {
/**
* Provides data for the Attribute test.
*
* @return array
*/
public function providerTestAttributeData() {
return array(
// Verify that special characters are HTML encoded.
array(
array(
'&"\'<>' => 'value',
),
' &"'<>="value"',
'HTML encode attribute names.',
),
array(
array(
'title' => '&"\'<>',
),
' title="&"'<>"',
'HTML encode attribute values.',
),
// Verify multi-value attributes are concatenated with spaces.
array(
array(
'class' => array(
'first',
'last',
),
),
' class="first last"',
'Concatenate multi-value attributes.',
),
// Verify boolean attribute values are rendered correctly.
array(
array(
'disabled' => TRUE,
),
' disabled',
'Boolean attribute is rendered.',
),
array(
array(
'disabled' => FALSE,
),
'',
'Boolean attribute is not rendered.',
),
// Verify empty attribute values are rendered.
array(
array(
'alt' => '',
),
' alt=""',
'Empty attribute value #1.',
),
array(
array(
'alt' => NULL,
),
'',
'Null attribute value #2.',
),
// Verify multiple attributes are rendered.
array(
array(
'id' => 'id-test',
'class' => array(
'first',
'last',
),
'alt' => 'Alternate',
),
' id="id-test" class="first last" alt="Alternate"',
'Multiple attributes.',
),
// Verify empty attributes array is rendered.
array(
array(),
'',
'Empty attributes array.',
),
);
}
/**
* Tests casting an Attribute object to a string.
*
* @see \Drupal\Core\Template\Attribute::__toString()
*
* @dataProvider providerTestAttributeData
*/
function testDrupalAttributes($attributes, $expected, $message) {
$this
->assertSame($expected, (string) new Attribute($attributes), $message);
}
/**
* Test attribute iteration
*/
public function testAttributeIteration() {
$attribute = new Attribute(array(
'key1' => 'value1',
));
foreach ($attribute as $value) {
$this
->assertSame((string) $value, 'value1', 'Iterate over attribute.');
}
}
/**
* Test AttributeValueBase copy.
*/
public function testAttributeValueBaseCopy() {
$original_attributes = new Attribute([
'checked' => TRUE,
'class' => [
'who',
'is',
'on',
],
'id' => 'first',
]);
$attributes['selected'] = $original_attributes['checked'];
$attributes['id'] = $original_attributes['id'];
$attributes = new Attribute($attributes);
$this
->assertSame((string) $original_attributes, ' checked class="who is on" id="first"', 'Original boolean value used with original name.');
$this
->assertSame((string) $attributes, ' selected id="first"', 'Original boolean value used with new name.');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AttributesTest:: |
public | function | Provides data for the Attribute test. | |
AttributesTest:: |
public | function | Test attribute iteration | |
AttributesTest:: |
public | function | Test AttributeValueBase copy. | |
AttributesTest:: |
function | Tests casting an Attribute object to a string. | ||
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 259 |