You are here

public function HTMLRestrictionsTest::testConvenienceConstructors in Drupal 10

@covers ::fromString() @covers ::fromTextFormat() @covers ::fromFilterPluginInstance() @dataProvider providerConvenienceConstructors

File

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

Class

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

Namespace

Drupal\Tests\ckeditor5\Unit

Code

public function testConvenienceConstructors($input, array $expected, ?array $expected_raw = NULL) : void {
  $expected_raw = $expected_raw ?? $expected;

  // ::fromString()
  $this
    ->assertSame($expected, HTMLRestrictions::fromString($input)
    ->getAllowedElements());
  $this
    ->assertSame($expected_raw, HTMLRestrictions::fromString($input)
    ->getAllowedElements(FALSE));

  // ::fromTextFormat()
  $text_format = $this
    ->prophesize(FilterFormatInterface::class);
  $text_format
    ->getHTMLRestrictions()
    ->willReturn([
    'allowed' => $expected_raw,
  ]);
  $this
    ->assertSame($expected, HTMLRestrictions::fromTextFormat($text_format
    ->reveal())
    ->getAllowedElements());
  $this
    ->assertSame($expected_raw, HTMLRestrictions::fromTextFormat($text_format
    ->reveal())
    ->getAllowedElements(FALSE));

  // @see \Drupal\filter\Plugin\Filter\FilterHtml::getHTMLRestrictions()
  $filter_html_additional_expectations = [
    '*' => [
      'style' => FALSE,
      'on*' => FALSE,
      'lang' => TRUE,
      'dir' => [
        'ltr' => TRUE,
        'rtl' => TRUE,
      ],
    ],
  ];

  // ::fromFilterPluginInstance()
  $filter_plugin_instance = $this
    ->prophesize(FilterInterface::class);
  $filter_plugin_instance
    ->getHTMLRestrictions()
    ->willReturn([
    'allowed' => $expected_raw + $filter_html_additional_expectations,
  ]);
  $this
    ->assertSame($expected + $filter_html_additional_expectations, HTMLRestrictions::fromFilterPluginInstance($filter_plugin_instance
    ->reveal())
    ->getAllowedElements());
  $this
    ->assertSame($expected_raw + $filter_html_additional_expectations, HTMLRestrictions::fromFilterPluginInstance($filter_plugin_instance
    ->reveal())
    ->getAllowedElements(FALSE));
}