function HTMLRestrictionsTest::providerConstruct

Same name in other branches
  1. 10 core/modules/ckeditor5/tests/src/Unit/HTMLRestrictionsTest.php \Drupal\Tests\ckeditor5\Unit\HTMLRestrictionsTest::providerConstruct()
  2. 11.x core/modules/ckeditor5/tests/src/Unit/HTMLRestrictionsTest.php \Drupal\Tests\ckeditor5\Unit\HTMLRestrictionsTest::providerConstruct()

File

core/modules/ckeditor5/tests/src/Unit/HTMLRestrictionsTest.php, line 30

Class

HTMLRestrictionsTest
@coversDefaultClass \Drupal\ckeditor5\HTMLRestrictions @group ckeditor5

Namespace

Drupal\Tests\ckeditor5\Unit

Code

public function providerConstruct() : \Generator {
    // Fundamental structure.
    (yield 'INVALID: list instead of key-value pairs' => [
        [
            '<foo>',
            '<bar>',
        ],
        'An array of key-value pairs must be provided, with HTML tag names as keys.',
    ]);
    // Invalid HTML tag names.
    (yield 'INVALID: key-value pairs now, but invalid keys due to angular brackets' => [
        [
            '<foo>' => '',
            '<bar> ' => '',
        ],
        '"<foo>" is not a HTML tag name, it is an actual HTML tag. Omit the angular brackets.',
    ]);
    (yield 'INVALID: no more angular brackets, but still leading or trailing whitespace' => [
        [
            'foo' => '',
            'bar ' => '',
        ],
        'The "bar " HTML tag contains trailing or leading whitespace.',
    ]);
    (yield 'INVALID: invalid character range' => [
        [
            '🦙' => '',
        ],
        '"🦙" is not a valid HTML tag name.',
    ]);
    (yield 'INVALID: invalid custom element name' => [
        [
            'foo-bar' => '',
            '1-foo-bar' => '',
        ],
        '"1-foo-bar" is not a valid HTML tag name.',
    ]);
    (yield 'INVALID: unknown wildcard element name' => [
        [
            '$foo' => TRUE,
        ],
        '"$foo" is not a valid HTML tag name.',
    ]);
    // Invalid HTML tag attribute name restrictions.
    (yield 'INVALID: keys valid, but not yet the values' => [
        [
            'foo' => '',
            'bar' => '',
        ],
        'The value for the "foo" HTML tag is neither a boolean nor an array of attribute restrictions.',
    ]);
    (yield 'INVALID: keys valid, values can be arrays … but not empty arrays' => [
        [
            'foo' => [],
            'bar' => [],
        ],
        'The value for the "foo" HTML tag is an empty array. This is not permitted, specify FALSE instead to indicate no attributes are allowed. Otherwise, list allowed attributes.',
    ]);
    (yield 'INVALID: keys valid, values invalid attribute restrictions' => [
        [
            'foo' => [
                'baz',
            ],
            'bar' => [
                ' qux',
            ],
        ],
        'The "foo" HTML tag has attribute restrictions, but it is not an array of key-value pairs, with HTML tag attribute names as keys.',
    ]);
    (yield 'INVALID: keys valid, values invalid attribute restrictions due to invalid attribute name' => [
        [
            'foo' => [
                'baz' => '',
            ],
            'bar' => [
                ' qux' => '',
            ],
        ],
        'The "bar" HTML tag has an attribute restriction " qux" which contains whitespace. Omit the whitespace.',
    ]);
    (yield 'INVALID: keys valid, values invalid attribute restrictions due to broad wildcard instead of prefix/infix/suffix wildcard attribute name' => [
        [
            'foo' => [
                '*' => TRUE,
            ],
        ],
        'The "foo" HTML tag has an attribute restriction "*". This implies all attributes are allowed. Remove the attribute restriction instead, or use a prefix (`*-foo`), infix (`*-foo-*`) or suffix (`foo-*`) wildcard restriction instead.',
    ]);
    // Invalid HTML tag attribute value restrictions.
    (yield 'INVALID: keys valid, values invalid attribute restrictions due to empty strings' => [
        [
            'foo' => [
                'baz' => '',
            ],
            'bar' => [
                'qux' => '',
            ],
        ],
        'The "foo" HTML tag has an attribute restriction "baz" which is neither TRUE nor an array of attribute value restrictions.',
    ]);
    (yield 'INVALID: keys valid, values invalid attribute restrictions due to an empty array of allowed attribute values' => [
        [
            'foo' => [
                'baz' => TRUE,
            ],
            'bar' => [
                'qux' => [],
            ],
        ],
        'The "bar" HTML tag has an attribute restriction "qux" which is set to the empty array. This is not permitted, specify either TRUE to allow all attribute values, or list the attribute value restrictions.',
    ]);
    (yield 'INVALID: keys valid, values invalid attribute restrictions due to a list of allowed attribute values' => [
        [
            'foo' => [
                'baz' => TRUE,
            ],
            'bar' => [
                'qux' => [
                    'a',
                    'b',
                ],
            ],
        ],
        'The "bar" HTML tag has attribute restriction "qux", but it is not an array of key-value pairs, with HTML tag attribute values as keys and TRUE as values.',
    ]);
    (yield 'INVALID: keys valid, values invalid attribute restrictions due to broad wildcard instead of prefix/infix/suffix wildcard allowed attribute value' => [
        [
            'foo' => [
                'bar' => [
                    '*' => TRUE,
                ],
            ],
        ],
        'The "foo" HTML tag has an attribute restriction "bar" with a "*" allowed attribute value. This implies all attributes values are allowed. Remove the attribute value restriction instead, or use a prefix (`*-foo`), infix (`*-foo-*`) or suffix (`foo-*`) wildcard restriction instead.',
    ]);
    // Valid values.
    (yield 'VALID: keys valid, boolean attribute restriction values: also valid' => [
        [
            'foo' => TRUE,
            'bar' => FALSE,
        ],
        NULL,
    ]);
    (yield 'VALID: keys valid, array attribute restriction values: also valid' => [
        [
            'foo' => [
                'baz' => TRUE,
            ],
            'bar' => [
                'qux' => [
                    'a' => TRUE,
                    'b' => TRUE,
                ],
            ],
        ],
        NULL,
    ]);
    // Invalid global attribute `*` HTML tag restrictions.
    (yield 'INVALID: global attribute tag allowing no attributes' => [
        [
            '*' => FALSE,
        ],
        'The value for the special "*" global attribute HTML tag must be an array of attribute restrictions.',
    ]);
    (yield 'INVALID: global attribute tag allowing any attribute' => [
        [
            '*' => TRUE,
        ],
        'The value for the special "*" global attribute HTML tag must be an array of attribute restrictions.',
    ]);
    // Valid global attribute `*` HTML tag restrictions.
    (yield 'VALID: global attribute tag with attribute allowed' => [
        [
            '*' => [
                'foo' => TRUE,
            ],
        ],
        NULL,
    ]);
    (yield 'VALID: global attribute tag with attribute forbidden' => [
        [
            '*' => [
                'foo' => FALSE,
            ],
        ],
        NULL,
    ]);
    (yield 'VALID: global attribute tag with attribute allowed, specific attribute values allowed' => [
        [
            '*' => [
                'foo' => [
                    'a' => TRUE,
                    'b' => TRUE,
                ],
            ],
        ],
        NULL,
    ]);
    (yield 'VALID BUT NOT YET SUPPORTED: global attribute tag with attribute allowed, specific attribute values forbidden' => [
        [
            '*' => [
                'foo' => [
                    'a' => FALSE,
                    'b' => FALSE,
                ],
            ],
        ],
        'The "*" HTML tag has attribute restriction "foo", but it is not an array of key-value pairs, with HTML tag attribute values as keys and TRUE as values.',
    ]);
    // Invalid overrides of globally disallowed attributes.
    (yield 'INVALID: <foo bar> when "bar" is globally disallowed' => [
        [
            'foo' => [
                'bar' => TRUE,
            ],
            '*' => [
                'bar' => FALSE,
                'baz' => TRUE,
            ],
        ],
        'The attribute restrictions in "<foo bar>" are allowing attributes "bar" that are disallowed by the special "*" global attribute restrictions',
    ]);
    (yield 'INVALID: <foo style> when "style" is globally disallowed' => [
        [
            'foo' => [
                'style' => TRUE,
            ],
            '*' => [
                'bar' => FALSE,
                'baz' => TRUE,
                'style' => FALSE,
            ],
        ],
        'The attribute restrictions in "<foo style>" are allowing attributes "bar", "style" that are disallowed by the special "*" global attribute restrictions',
    ]);
    (yield 'INVALID: <foo on*> when "on*" is globally disallowed' => [
        [
            'foo' => [
                'on*' => TRUE,
            ],
            '*' => [
                'bar' => FALSE,
                'baz' => TRUE,
                'style' => FALSE,
                'on*' => FALSE,
            ],
        ],
        'The attribute restrictions in "<foo on*>" are allowing attributes "bar", "style", "on*" that are disallowed by the special "*" global attribute restrictions',
    ]);
    (yield 'INVALID: <foo ontouch> when "on" is globally disallowed' => [
        [
            'foo' => [
                'ontouch' => TRUE,
            ],
            '*' => [
                'bar' => FALSE,
                'baz' => TRUE,
                'style' => FALSE,
                'on*' => FALSE,
            ],
        ],
        'The attribute restrictions in "<foo ontouch>" are allowing attributes "bar", "style", "on*" that are disallowed by the special "*" global attribute restrictions',
    ]);
}

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