function HTMLRestrictionsTest::providerRepresentations

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

File

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

Class

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

Namespace

Drupal\Tests\ckeditor5\Unit

Code

public static function providerRepresentations() : \Generator {
    (yield 'empty set' => [
        HTMLRestrictions::emptySet(),
        [],
        '',
        [],
    ]);
    (yield 'only tags' => [
        new HTMLRestrictions([
            'a' => FALSE,
            'p' => FALSE,
            'br' => FALSE,
        ]),
        [
            '<a>',
            '<p>',
            '<br>',
        ],
        '<a> <p> <br>',
        [
            [
                'name' => 'a',
            ],
            [
                'name' => 'p',
            ],
            [
                'name' => 'br',
            ],
        ],
    ]);
    (yield 'single tag with multiple attributes allowing all values' => [
        new HTMLRestrictions([
            'script' => [
                'src' => TRUE,
                'defer' => TRUE,
            ],
        ]),
        [
            '<script src defer>',
        ],
        '<script src defer>',
        [
            [
                'name' => 'script',
                'attributes' => [
                    [
                        'key' => 'src',
                        'value' => TRUE,
                    ],
                    [
                        'key' => 'defer',
                        'value' => TRUE,
                    ],
                ],
            ],
        ],
    ]);
    (yield '$text-container wildcard' => [
        new HTMLRestrictions([
            '$text-container' => [
                'class' => TRUE,
                'data-llama' => TRUE,
            ],
            'div' => FALSE,
            'span' => FALSE,
            'p' => [
                'id' => TRUE,
            ],
        ]),
        [
            '<$text-container class data-llama>',
            '<div>',
            '<span>',
            '<p id>',
        ],
        '<div class data-llama> <span> <p id class data-llama>',
        [
            [
                'name' => 'div',
                'classes' => TRUE,
                'attributes' => [
                    [
                        'key' => 'data-llama',
                        'value' => TRUE,
                    ],
                ],
            ],
            [
                'name' => 'span',
            ],
            [
                'name' => 'p',
                'attributes' => [
                    [
                        'key' => 'id',
                        'value' => TRUE,
                    ],
                    [
                        'key' => 'data-llama',
                        'value' => TRUE,
                    ],
                ],
                'classes' => TRUE,
            ],
        ],
    ]);
    (yield 'realistic' => [
        new HTMLRestrictions([
            'a' => [
                'href' => TRUE,
                'hreflang' => [
                    'en' => TRUE,
                    'fr' => TRUE,
                ],
            ],
            'p' => [
                'data-*' => TRUE,
                'class' => [
                    'block' => TRUE,
                ],
            ],
            'br' => FALSE,
        ]),
        [
            '<a href hreflang="en fr">',
            '<p data-* class="block">',
            '<br>',
        ],
        '<a href hreflang="en fr"> <p data-* class="block"> <br>',
        [
            [
                'name' => 'a',
                'attributes' => [
                    [
                        'key' => 'href',
                        'value' => TRUE,
                    ],
                    [
                        'key' => 'hreflang',
                        'value' => [
                            'regexp' => [
                                'pattern' => '/^(en|fr)$/',
                            ],
                        ],
                    ],
                ],
            ],
            [
                'name' => 'p',
                'attributes' => [
                    [
                        'key' => [
                            'regexp' => [
                                'pattern' => '/^data-.*$/',
                            ],
                        ],
                        'value' => TRUE,
                    ],
                ],
                'classes' => [
                    'regexp' => [
                        'pattern' => '/^(block)$/',
                    ],
                ],
            ],
            [
                'name' => 'br',
            ],
        ],
    ]);
    // Wildcard tag, attribute and attribute value.
    (yield '$text-container' => [
        new HTMLRestrictions([
            'p' => FALSE,
            '$text-container' => [
                'data-*' => TRUE,
            ],
        ]),
        [
            '<p>',
            '<$text-container data-*>',
        ],
        '<p data-*>',
        [
            [
                'name' => 'p',
                'attributes' => [
                    [
                        'key' => [
                            'regexp' => [
                                'pattern' => '/^data-.*$/',
                            ],
                        ],
                        'value' => TRUE,
                    ],
                ],
            ],
        ],
    ]);
    (yield '<drupal-media data-*>' => [
        new HTMLRestrictions([
            'drupal-media' => [
                'data-*' => TRUE,
            ],
        ]),
        [
            '<drupal-media data-*>',
        ],
        '<drupal-media data-*>',
        [
            [
                'name' => 'drupal-media',
                'attributes' => [
                    [
                        'key' => [
                            'regexp' => [
                                'pattern' => '/^data-.*$/',
                            ],
                        ],
                        'value' => TRUE,
                    ],
                ],
            ],
        ],
    ]);
    (yield '<drupal-media foo-*-bar>' => [
        new HTMLRestrictions([
            'drupal-media' => [
                'foo-*-bar' => TRUE,
            ],
        ]),
        [
            '<drupal-media foo-*-bar>',
        ],
        '<drupal-media foo-*-bar>',
        [
            [
                'name' => 'drupal-media',
                'attributes' => [
                    [
                        'key' => [
                            'regexp' => [
                                'pattern' => '/^foo-.*-bar$/',
                            ],
                        ],
                        'value' => TRUE,
                    ],
                ],
            ],
        ],
    ]);
    (yield '<drupal-media *-bar>' => [
        new HTMLRestrictions([
            'drupal-media' => [
                '*-bar' => TRUE,
            ],
        ]),
        [
            '<drupal-media *-bar>',
        ],
        '<drupal-media *-bar>',
        [
            [
                'name' => 'drupal-media',
                'attributes' => [
                    [
                        'key' => [
                            'regexp' => [
                                'pattern' => '/^.*-bar$/',
                            ],
                        ],
                        'value' => TRUE,
                    ],
                ],
            ],
        ],
    ]);
    (yield '<h2 id="jump-*">' => [
        new HTMLRestrictions([
            'h2' => [
                'id' => [
                    'jump-*' => TRUE,
                ],
            ],
        ]),
        [
            '<h2 id="jump-*">',
        ],
        '<h2 id="jump-*">',
        [
            [
                'name' => 'h2',
                'attributes' => [
                    [
                        'key' => 'id',
                        'value' => [
                            'regexp' => [
                                'pattern' => '/^(jump-.*)$/',
                            ],
                        ],
                    ],
                ],
            ],
        ],
    ]);
    (yield '<ol type="1 A">' => [
        new HTMLRestrictions([
            'ol' => [
                'type' => [
                    '1' => TRUE,
                    'A' => TRUE,
                ],
            ],
        ]),
        [
            '<ol type="1 A">',
        ],
        '<ol type="1 A">',
        [
            [
                'name' => 'ol',
                'attributes' => [
                    [
                        'key' => 'type',
                        'value' => [
                            'regexp' => [
                                'pattern' => '/^(1|A)$/',
                            ],
                        ],
                    ],
                ],
            ],
        ],
    ]);
}

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