public function XBBCodeFilterTest::testAttributes in Extensible BBCode 4.0.x
Same name and namespace in other branches
- 8.3 tests/src/Kernel/XBBCodeFilterTest.php \Drupal\Tests\xbbcode\Kernel\XBBCodeFilterTest::testAttributes()
Test the parsing of attributes.
File
- tests/
src/ Kernel/ XBBCodeFilterTest.php, line 102
Class
- XBBCodeFilterTest
- Test the filter.
Namespace
Drupal\Tests\xbbcode\KernelCode
public function testAttributes() : void {
// Generate some attribute values with whitespace, quotes and backslashes.
$values = [
$this
->randomString() . '\'"\'" \\\\',
'\'"\'" \\\\' . $this
->randomString(),
$this
->randomString() . '\'"\'" ]\\\\' . $this
->randomString(),
];
$keys = [
$this
->randomMachineName(),
$this
->randomMachineName(),
$this
->randomMachineName(),
];
// Embed a string with single quotes, no quotes and double quotes,
// each time escaping all the required characters.
$string = $keys[0] . "='" . preg_replace('/[\\\\\']/', '\\\\\\0', $values[0]) . "' " . $keys[1] . '=' . preg_replace('/[\\\\\\"\'\\s\\[\\]]/', '\\\\\\0', $values[1]) . ' ' . $keys[2] . '="' . preg_replace('/[\\\\\\"]/', '\\\\\\0', $values[2]) . '"';
$content = $this
->randomString() . '[v=';
$text = "[test_plugin {$string}]{$content}[/test_plugin]";
$markup = check_markup($text, 'xbbcode_test');
$expected_markup = '<span data-' . $keys[0] . '="' . Html::escape($values[0]) . '" ' . 'data-' . $keys[1] . '="' . Html::escape($values[1]) . '" ' . 'data-' . $keys[2] . '="' . Html::escape($values[2]) . '">' . '{prepared:' . Html::escape($content) . '}</span>';
self::assertEquals($expected_markup, $markup);
}