function SourceEditingTest::testAllowingExtraAttributes

Same name and namespace in other branches
  1. 10 core/modules/ckeditor5/tests/src/FunctionalJavascript/SourceEditingTest.php \Drupal\Tests\ckeditor5\FunctionalJavascript\SourceEditingTest::testAllowingExtraAttributes()
  2. 11.x core/modules/ckeditor5/tests/src/FunctionalJavascript/SourceEditingTest.php \Drupal\Tests\ckeditor5\FunctionalJavascript\SourceEditingTest::testAllowingExtraAttributes()

Tests allowing extra attributes on already supported tags using GHS.

@dataProvider providerAllowingExtraAttributes

File

core/modules/ckeditor5/tests/src/FunctionalJavascript/SourceEditingTest.php, line 177

Class

SourceEditingTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21ckeditor5%21src%21Plugin%21CKEditor5Plugin%21SourceEditing.php/class/SourceEditing/9" title="CKEditor 5 Source Editing plugin configuration." class="local">\Drupal\ckeditor5\Plugin\CKEditor5Plugin\SourceEditing</a> @covers <a href="/api/drupal/core%21modules%21ckeditor5%21src%21Plugin%21CKEditor5PluginManager.php/function/CKEditor5PluginManager%3A%3AgetCKEditor5PluginConfig/9" title="Gets the configuration for the CKEditor 5 plugins enabled in this editor." class="local">\Drupal\ckeditor5\Plugin\CKEditor5PluginManager::getCKEditor5PluginConfig</a>() @group ckeditor5 @internal

Namespace

Drupal\Tests\ckeditor5\FunctionalJavascript

Code

public function testAllowingExtraAttributes(string $original_markup, string $expected_markup, ?string $allowed_elements_string = NULL) {
    $this->host->body->value = $original_markup;
    $this->host
        ->save();
    if ($allowed_elements_string) {
        // Allow creating additional HTML using SourceEditing.
        $text_editor = Editor::load('test_format');
        $settings = $text_editor->getSettings();
        $settings['plugins']['ckeditor5_sourceEditing']['allowed_tags'][] = $allowed_elements_string;
        $text_editor->setSettings($settings);
        // Keep the allowed HTML tags in sync.
        $text_format = FilterFormat::load('test_format');
        $allowed_elements = HTMLRestrictions::fromTextFormat($text_format);
        $updated_allowed_tags = $allowed_elements->merge(HTMLRestrictions::fromString($allowed_elements_string));
        $filter_html_config = $text_format->filters('filter_html')
            ->getConfiguration();
        $filter_html_config['settings']['allowed_html'] = $updated_allowed_tags->toFilterHtmlAllowedTagsString();
        $text_format->setFilterConfig('filter_html', $filter_html_config);
        // Verify the text format and editor are still a valid pair.
        $this->assertSame([], array_map(function (ConstraintViolation $v) {
            return (string) $v->getMessage();
        }, iterator_to_array(CKEditor5::validatePair($text_editor, $text_format))));
        // If valid, save both.
        $text_format->save();
        $text_editor->save();
    }
    $this->drupalGet($this->host
        ->toUrl('edit-form'));
    $this->waitForEditor();
    $this->assertSame($expected_markup, $this->getEditorDataAsHtmlString());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.