You are here

public function XBBCodeStandardTest::testTags in Extensible BBCode 4.0.x

Same name and namespace in other branches
  1. 8.3 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 60

Class

XBBCodeStandardTest
Test the standard tags provided by XBBCode.

Namespace

Drupal\Tests\xbbcode_standard\Kernel

Code

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];
    static::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']);
  }
}