function HTMLRestrictionsTest::providerConvenienceConstructors
Same name in other branches
- 9 core/modules/ckeditor5/tests/src/Unit/HTMLRestrictionsTest.php \Drupal\Tests\ckeditor5\Unit\HTMLRestrictionsTest::providerConvenienceConstructors()
- 11.x core/modules/ckeditor5/tests/src/Unit/HTMLRestrictionsTest.php \Drupal\Tests\ckeditor5\Unit\HTMLRestrictionsTest::providerConvenienceConstructors()
File
-
core/
modules/ ckeditor5/ tests/ src/ Unit/ HTMLRestrictionsTest.php, line 260
Class
- HTMLRestrictionsTest
- @coversDefaultClass \Drupal\ckeditor5\HTMLRestrictions @group ckeditor5
Namespace
Drupal\Tests\ckeditor5\UnitCode
public static function providerConvenienceConstructors() : \Generator {
// All empty cases.
(yield 'empty string' => [
'',
[],
]);
(yield 'empty array' => [
implode(' ', []),
[],
]);
(yield 'whitespace string' => [
' ',
[],
]);
// Some nonsense cases.
(yield 'nonsense string' => [
'Hello there, this looks nothing like a HTML restriction.',
[],
]);
(yield 'nonsense array #1' => [
implode(' ', [
'foo',
'bar',
]),
[],
]);
(yield 'nonsense array #2' => [
implode(' ', [
'foo' => TRUE,
'bar' => FALSE,
]),
[],
]);
// Single tag cases.
(yield 'tag without attributes' => [
'<a>',
[
'a' => FALSE,
],
]);
(yield 'tag with wildcard attribute' => [
'<a *>',
[
'a' => TRUE,
],
]);
(yield 'tag with single attribute allowing any value' => [
'<a target>',
[
'a' => [
'target' => TRUE,
],
],
]);
(yield 'tag with single attribute allowing any value unnecessarily explicitly' => [
'<a target="*">',
[
'a' => [
'target' => TRUE,
],
],
]);
(yield 'tag with single attribute allowing single specific value' => [
'<a target="_blank">',
[
'a' => [
'target' => [
'_blank' => TRUE,
],
],
],
]);
(yield 'tag with single attribute allowing multiple specific values' => [
'<a target="_self _blank">',
[
'a' => [
'target' => [
'_self' => TRUE,
'_blank' => TRUE,
],
],
],
]);
(yield 'tag with single attribute allowing multiple specific values (reverse order)' => [
'<a target="_blank _self">',
[
'a' => [
'target' => [
'_blank' => TRUE,
'_self' => TRUE,
],
],
],
]);
(yield 'tag with two attributes' => [
'<a target class>',
[
'a' => [
'target' => TRUE,
'class' => TRUE,
],
],
]);
(yield 'tag with allowed attribute value that happen to be numbers' => [
'<ol type="1 A I">',
[
'ol' => [
'type' => [
1 => TRUE,
'A' => TRUE,
'I' => TRUE,
],
],
],
]);
(yield 'tag with allowed attribute value that happen to be numbers (reversed)' => [
'<ol type="I A 1">',
[
'ol' => [
'type' => [
'I' => TRUE,
'A' => TRUE,
1 => TRUE,
],
],
],
]);
(yield 'tag with two attributes, spread across declarations' => [
'<a target> <a class>',
[
'a' => [
'target' => TRUE,
'class' => TRUE,
],
],
]);
(yield 'tag with conflicting attribute config, allow one attribute and forbid all attributes' => [
'<a target> <a>',
[
'a' => [
'target' => TRUE,
],
],
]);
(yield 'tag with conflicting attribute config, allow one attribute and allow all attributes' => [
'<a *> <a target>',
[
'a' => TRUE,
],
]);
(yield 'tag attribute configuration spread across declarations' => [
'<a target="_blank"> <a target="_self"> <a target="_*">',
[
'a' => [
'target' => [
'_blank' => TRUE,
'_self' => TRUE,
'_*' => TRUE,
],
],
],
]);
(yield 'tag attribute configuration spread across declarations, allow all attributes values' => [
'<a target> <a target="_blank"> <a target="_self"> <a target="_*">',
[
'a' => [
'target' => TRUE,
],
],
]);
// Multiple tag cases.
(yield 'two tags' => [
'<a> <p>',
[
'a' => FALSE,
'p' => FALSE,
],
]);
(yield 'two tags (reverse order)' => [
'<p> <a>',
[
'p' => FALSE,
'a' => FALSE,
],
]);
// Wildcard tag, attribute and attribute value.
(yield '$text-container' => [
'<$text-container class="text-align-left text-align-center text-align-right text-align-justify">',
[],
[
'$text-container' => [
'class' => [
'text-align-left' => TRUE,
'text-align-center' => TRUE,
'text-align-right' => TRUE,
'text-align-justify' => TRUE,
],
],
],
]);
(yield '$text-container, with attribute values spread across declarations' => [
'<$text-container class="text-align-left"> <$text-container class="text-align-center"> <$text-container class="text-align-right"> <$text-container class="text-align-justify">',
[],
[
'$text-container' => [
'class' => [
'text-align-left' => TRUE,
'text-align-center' => TRUE,
'text-align-right' => TRUE,
'text-align-justify' => TRUE,
],
],
],
]);
(yield '$text-container + one concrete tag to resolve into' => [
'<p> <$text-container class="text-align-left text-align-center text-align-right text-align-justify">',
[
'p' => [
'class' => [
'text-align-left' => TRUE,
'text-align-center' => TRUE,
'text-align-right' => TRUE,
'text-align-justify' => TRUE,
],
],
],
[
'p' => FALSE,
'$text-container' => [
'class' => [
'text-align-left' => TRUE,
'text-align-center' => TRUE,
'text-align-right' => TRUE,
'text-align-justify' => TRUE,
],
],
],
]);
(yield '$text-container + two concrete tag to resolve into' => [
'<p> <$text-container class="text-align-left text-align-center text-align-right text-align-justify"> <div>',
[
'p' => [
'class' => [
'text-align-left' => TRUE,
'text-align-center' => TRUE,
'text-align-right' => TRUE,
'text-align-justify' => TRUE,
],
],
'div' => [
'class' => [
'text-align-left' => TRUE,
'text-align-center' => TRUE,
'text-align-right' => TRUE,
'text-align-justify' => TRUE,
],
],
],
[
'p' => FALSE,
'div' => FALSE,
'$text-container' => [
'class' => [
'text-align-left' => TRUE,
'text-align-center' => TRUE,
'text-align-right' => TRUE,
'text-align-justify' => TRUE,
],
],
],
]);
(yield '$text-container + one concrete tag to resolve into that already allows a subset of attributes: concrete less permissive than wildcard' => [
'<p class="text-align-left"> <$text-container class="text-align-left text-align-center text-align-right text-align-justify">',
[
'p' => [
'class' => [
'text-align-left' => TRUE,
'text-align-center' => TRUE,
'text-align-right' => TRUE,
'text-align-justify' => TRUE,
],
],
],
[
'p' => [
'class' => [
'text-align-left' => TRUE,
],
],
'$text-container' => [
'class' => [
'text-align-left' => TRUE,
'text-align-center' => TRUE,
'text-align-right' => TRUE,
'text-align-justify' => TRUE,
],
],
],
]);
(yield '$text-container + one concrete tag to resolve into that already allows all attribute values: concrete more permissive than wildcard' => [
'<p class> <$text-container class="text-align-left text-align-center text-align-right text-align-justify">',
[
'p' => [
'class' => TRUE,
],
],
[
'p' => [
'class' => TRUE,
],
'$text-container' => [
'class' => [
'text-align-left' => TRUE,
'text-align-center' => TRUE,
'text-align-right' => TRUE,
'text-align-justify' => TRUE,
],
],
],
]);
(yield '$text-container + one concrete tag to resolve into that already allows all attributes: concrete more permissive than wildcard' => [
'<p *> <$text-container class="text-align-left text-align-center text-align-right text-align-justify">',
[
'p' => TRUE,
],
[
'p' => TRUE,
'$text-container' => [
'class' => [
'text-align-left' => TRUE,
'text-align-center' => TRUE,
'text-align-right' => TRUE,
'text-align-justify' => TRUE,
],
],
],
]);
(yield '<drupal-media data-*>' => [
'<drupal-media data-*>',
[
'drupal-media' => [
'data-*' => TRUE,
],
],
]);
(yield '<drupal-media foo-*-bar>' => [
'<drupal-media foo-*-bar>',
[
'drupal-media' => [
'foo-*-bar' => TRUE,
],
],
]);
(yield '<drupal-media *-foo>' => [
'<drupal-media *-foo>',
[
'drupal-media' => [
'*-foo' => TRUE,
],
],
]);
(yield '<h2 id="jump-*">' => [
'<h2 id="jump-*">',
[
'h2' => [
'id' => [
'jump-*' => TRUE,
],
],
],
]);
// Attribute restrictions that match the global attribute restrictions
// should be omitted from concrete tags.
(yield '<p> <* foo>' => [
'<p> <* foo>',
[
'p' => FALSE,
'*' => [
'foo' => TRUE,
],
],
]);
(yield '<p foo> <* foo> results in <p> getting simplified' => [
'<p foo> <* foo>',
[
'p' => FALSE,
'*' => [
'foo' => TRUE,
],
],
]);
(yield '<* foo> <p foo> results in <p> getting simplified' => [
'<* foo> <p foo>',
[
'p' => FALSE,
'*' => [
'foo' => TRUE,
],
],
]);
(yield '<p foo bar> <* foo> results in <p> getting simplified' => [
'<p foo bar> <* foo>',
[
'p' => [
'bar' => TRUE,
],
'*' => [
'foo' => TRUE,
],
],
]);
(yield '<* foo> <p foo bar> results in <p> getting simplified' => [
'<* foo> <p foo bar>',
[
'p' => [
'bar' => TRUE,
],
'*' => [
'foo' => TRUE,
],
],
]);
(yield '<p foo="a b"> + <* foo="b a"> results in <p> getting simplified' => [
'<p foo="a b"> <* foo="b a">',
[
'p' => FALSE,
'*' => [
'foo' => [
'b' => TRUE,
'a' => TRUE,
],
],
],
]);
(yield '<* foo="b a"> <p foo="a b"> results in <p> getting simplified' => [
'<* foo="b a"> <p foo="a b">',
[
'p' => FALSE,
'*' => [
'foo' => [
'b' => TRUE,
'a' => TRUE,
],
],
],
]);
(yield '<p foo="a b" bar> + <* foo="b a"> results in <p> getting simplified' => [
'<p foo="a b" bar> <* foo="b a">',
[
'p' => [
'bar' => TRUE,
],
'*' => [
'foo' => [
'b' => TRUE,
'a' => TRUE,
],
],
],
]);
(yield '<* foo="b a"> <p foo="a b" bar> results in <p> getting simplified' => [
'<* foo="b a"> <p foo="a b" bar>',
[
'p' => [
'bar' => TRUE,
],
'*' => [
'foo' => [
'b' => TRUE,
'a' => TRUE,
],
],
],
]);
(yield '<p foo="a b c"> + <* foo="b a"> results in <p> getting simplified' => [
'<p foo="a b c"> <* foo="b a">',
[
'p' => [
'foo' => [
'c' => TRUE,
],
],
'*' => [
'foo' => [
'b' => TRUE,
'a' => TRUE,
],
],
],
]);
(yield '<* foo="b a"> <p foo="a b c"> results in <p> getting simplified' => [
'<* foo="b a"> <p foo="a b c">',
[
'p' => [
'foo' => [
'c' => TRUE,
],
],
'*' => [
'foo' => [
'b' => TRUE,
'a' => TRUE,
],
],
],
]);
// Attribute restrictions that match the global attribute restrictions
// should be omitted from wildcard tags.
(yield '<p> <$text-container foo> <* foo> results in <$text-container> getting simplified' => [
'<p> <$text-container foo> <* foo>',
[
'p' => FALSE,
'*' => [
'foo' => TRUE,
],
],
[
'p' => FALSE,
'$text-container' => FALSE,
'*' => [
'foo' => TRUE,
],
],
]);
(yield '<* foo> <text-container foo> <p> results in <$text-container> getting stripped' => [
'<* foo> <p> <$text-container foo>',
[
'p' => FALSE,
'*' => [
'foo' => TRUE,
],
],
[
'p' => FALSE,
'*' => [
'foo' => TRUE,
],
'$text-container' => FALSE,
],
]);
(yield '<p> <$text-container foo bar> <* foo> results in <$text-container> getting simplified' => [
'<p> <$text-container foo bar> <* foo>',
[
'p' => [
'bar' => TRUE,
],
'*' => [
'foo' => TRUE,
],
],
[
'p' => FALSE,
'$text-container' => [
'bar' => TRUE,
],
'*' => [
'foo' => TRUE,
],
],
]);
(yield '<* foo> <$text-container foo bar> <p> results in <$text-container> getting simplified' => [
'<* foo> <$text-container foo bar> <p>',
[
'p' => [
'bar' => TRUE,
],
'*' => [
'foo' => TRUE,
],
],
[
'p' => FALSE,
'*' => [
'foo' => TRUE,
],
'$text-container' => [
'bar' => TRUE,
],
],
]);
(yield '<p> <$text-container foo="a b"> + <* foo="b a"> results in <$text-container> getting simplified' => [
'<p> <$text-container foo="a b"> <* foo="b a">',
[
'p' => FALSE,
'*' => [
'foo' => [
'b' => TRUE,
'a' => TRUE,
],
],
],
[
'p' => FALSE,
'$text-container' => FALSE,
'*' => [
'foo' => [
'b' => TRUE,
'a' => TRUE,
],
],
],
]);
(yield '<* foo="b a"> <p> <$text-container foo="a b"> results in <$text-container> getting simplified' => [
'<* foo="b a"> <p> <$text-container foo="a b">',
[
'p' => FALSE,
'*' => [
'foo' => [
'b' => TRUE,
'a' => TRUE,
],
],
],
[
'p' => FALSE,
'*' => [
'foo' => [
'b' => TRUE,
'a' => TRUE,
],
],
'$text-container' => FALSE,
],
]);
(yield '<p> <$text-container foo="a b" bar> + <* foo="b a"> results in <$text-container> getting simplified' => [
'<p> <$text-container foo="a b" bar> <* foo="b a">',
[
'p' => [
'bar' => TRUE,
],
'*' => [
'foo' => [
'b' => TRUE,
'a' => TRUE,
],
],
],
[
'p' => FALSE,
'$text-container' => [
'bar' => TRUE,
],
'*' => [
'foo' => [
'b' => TRUE,
'a' => TRUE,
],
],
],
]);
(yield '<* foo="b a"> <p> <$text-container foo="a b" bar> results in <$text-container> getting simplified' => [
'<* foo="b a"> <p> <$text-container foo="a b" bar>',
[
'p' => [
'bar' => TRUE,
],
'*' => [
'foo' => [
'b' => TRUE,
'a' => TRUE,
],
],
],
[
'p' => FALSE,
'*' => [
'foo' => [
'b' => TRUE,
'a' => TRUE,
],
],
'$text-container' => [
'bar' => TRUE,
],
],
]);
(yield '<p> <$text-container foo="a b c"> + <* foo="b a"> results in <$text-container> getting simplified' => [
'<p> <$text-container foo="a b c"> <* foo="b a">',
[
'p' => [
'foo' => [
'c' => TRUE,
],
],
'*' => [
'foo' => [
'b' => TRUE,
'a' => TRUE,
],
],
],
[
'p' => FALSE,
'$text-container' => [
'foo' => [
'c' => TRUE,
],
],
'*' => [
'foo' => [
'b' => TRUE,
'a' => TRUE,
],
],
],
]);
(yield '<* foo="b a"> <p> <$text-container foo="a b c"> results in <$text-container> getting simplified' => [
'<* foo="b a"> <p> <$text-container foo="a b c">',
[
'p' => [
'foo' => [
'c' => TRUE,
],
],
'*' => [
'foo' => [
'b' => TRUE,
'a' => TRUE,
],
],
],
[
'p' => FALSE,
'*' => [
'foo' => [
'b' => TRUE,
'a' => TRUE,
],
],
'$text-container' => [
'foo' => [
'c' => TRUE,
],
],
],
]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.