function AttributesTest::providerTestAttributeData

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Common/AttributesTest.php \Drupal\Tests\Core\Common\AttributesTest::providerTestAttributeData()
  2. 8.9.x core/tests/Drupal/Tests/Core/Common/AttributesTest.php \Drupal\Tests\Core\Common\AttributesTest::providerTestAttributeData()
  3. 10 core/tests/Drupal/Tests/Core/Common/AttributesTest.php \Drupal\Tests\Core\Common\AttributesTest::providerTestAttributeData()

Provides data for the Attribute test.

Return value

array

File

core/tests/Drupal/Tests/Core/Common/AttributesTest.php, line 22

Class

AttributesTest
Tests the <a href="/api/drupal/core%21lib%21Drupal%21Core%21Template%21Attribute.php/class/Attribute/11.x" title="Collects, sanitizes, and renders HTML attributes." class="local">Drupal\Core\Template\Attribute</a> functionality.

Namespace

Drupal\Tests\Core\Common

Code

public static function providerTestAttributeData() {
    return [
        // Verify that special characters are HTML encoded.
[
            [
                '&"\'<>' => 'value',
            ],
            ' &amp;&quot;&#039;&lt;&gt;="value"',
            'HTML encode attribute names.',
        ],
        [
            [
                'title' => '&"\'<>',
            ],
            ' title="&amp;&quot;&#039;&lt;&gt;"',
            'HTML encode attribute values.',
        ],
        // Verify multi-value attributes are concatenated with spaces.
[
            [
                'class' => [
                    'first',
                    'last',
                ],
            ],
            ' class="first last"',
            'Concatenate multi-value attributes.',
        ],
        // Verify boolean attribute values are rendered correctly.
[
            [
                'disabled' => TRUE,
            ],
            ' disabled',
            'Boolean attribute is rendered.',
        ],
        [
            [
                'disabled' => FALSE,
            ],
            '',
            'Boolean attribute is not rendered.',
        ],
        // Verify empty attribute values are rendered.
[
            [
                'alt' => '',
            ],
            ' alt=""',
            'Empty attribute value #1.',
        ],
        [
            [
                'alt' => NULL,
            ],
            '',
            'Null attribute value #2.',
        ],
        // Verify multiple attributes are rendered.
[
            [
                'id' => 'id-test',
                'class' => [
                    'first',
                    'last',
                ],
                'alt' => 'Alternate',
            ],
            ' id="id-test" class="first last" alt="Alternate"',
            'Multiple attributes.',
        ],
        // Verify empty attributes array is rendered.
[
            [],
            '',
            'Empty attributes array.',
        ],
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.