public function XBBCodeStandardTest::testTags in Extensible BBCode 8.3
Same name and namespace in other branches
- 4.0.x standard/tests/src/Kernel/XBBCodeStandardTest.php \Drupal\Tests\xbbcode_standard\Kernel\XBBCodeStandardTest::testTags()
Test all of the tags installed by this module.
File
- standard/
tests/ src/ Kernel/ XBBCodeStandardTest.php, line 62
Class
- XBBCodeStandardTest
- Class XBBCodeStandardTest.
Namespace
Drupal\Tests\xbbcode_standard\KernelCode
public function testTags() : void {
// Ten iterations, just in case of weird edge cases.
for ($i = 0; $i < 10; $i++) {
foreach ($this
->getTags() as $case) {
$expected = self::stripSpaces($case[1]);
$actual = self::stripSpaces(check_markup($case[0], 'xbbcode_test'));
static::assertEquals($expected, $actual);
}
// The spoiler tag generates a random dynamic value.
$input = $this
->randomString(2048) . '>\'"; email@example.com http://example.com/';
$input = str_replace('<', '', $input);
$escaped = Html::escape($input);
$bbcode = "[spoiler]{$input}[/spoiler]";
$element = $this
->checkMarkup($bbcode, 'xbbcode_test');
preg_match('/id="xbbcode-spoiler-(\\d+)"/', $element['#markup'], $match);
$key = $match[1];
$this
->assertNotNull($key);
$expected = "<input id=\"xbbcode-spoiler-{$key}\" type=\"checkbox\" class=\"xbbcode-spoiler\" />" . "<label class=\"xbbcode-spoiler\" for=\"xbbcode-spoiler-{$key}\">{$escaped}</label>";
static::assertEquals($expected, $element['#markup']);
}
}