<?php
namespace Drupal\Tests\Core\Common;
use Drupal\Core\Template\Attribute;
use Drupal\Tests\UnitTestCase;
class AttributesTest extends UnitTestCase {
public static function getInfo() {
return array(
'name' => 'HTML Attributes',
'description' => 'Tests the Drupal\\Core\\Template\\Attribute functionality.',
'group' => 'Common',
);
}
public function providerTestAttributeData() {
return array(
array(
array(
'title' => '&"\'<>',
),
' title="&"'<>"',
'HTML encode attribute values.',
),
array(
array(
'class' => array(
'first',
'last',
),
),
' class="first last"',
'Concatenate multi-value attributes.',
),
array(
array(
'alt' => '',
),
' alt=""',
'Empty attribute value #1.',
),
array(
array(
'alt' => NULL,
),
' alt=""',
'Empty attribute value #2.',
),
array(
array(
'id' => 'id-test',
'class' => array(
'first',
'last',
),
'alt' => 'Alternate',
),
' id="id-test" class="first last" alt="Alternate"',
'Multiple attributes.',
),
array(
array(),
'',
'Empty attributes array.',
),
);
}
function testDrupalAttributes($attributes, $expected, $message) {
$this
->assertSame($expected, (string) new Attribute($attributes), $message);
}
public function testAttributeIteration() {
$attribute = new Attribute(array(
'key1' => 'value1',
));
foreach ($attribute as $value) {
$this
->assertSame((string) $value, 'value1', 'Iterate over attribute.');
}
}
}