function SourceEditingTest::testAllowingExtraAttributes

Same name in other branches
  1. 9 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.

File

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

Class

SourceEditingTest
@coversDefaultClass \Drupal\ckeditor5\Plugin\CKEditor5Plugin\SourceEditing @covers \Drupal\ckeditor5\Plugin\CKEditor5PluginManager::getCKEditor5PluginConfig @group ckeditor5 @group #slow @internal

Namespace

Drupal\Tests\ckeditor5\FunctionalJavascript

Code

public function testAllowingExtraAttributes() : void {
    $original_text_editor = Editor::load('test_format');
    $original_text_format = FilterFormat::load('test_format');
    $allowed_elements = HTMLRestrictions::fromTextFormat($original_text_format);
    $filter_html_config = $original_text_format->filters('filter_html')
        ->getConfiguration();
    foreach ($this->providerAllowingExtraAttributes() as $data) {
        $text_editor = clone $original_text_editor;
        $text_format = clone $original_text_format;
        [
            $original_markup,
            $expected_markup,
            $allowed_elements_string,
        ] = $data;
        // Allow creating additional HTML using SourceEditing.
        $settings = $text_editor->getSettings();
        if ($allowed_elements_string) {
            $settings['plugins']['ckeditor5_sourceEditing']['allowed_tags'][] = $allowed_elements_string;
        }
        $text_editor->setSettings($settings);
        $new_config = $filter_html_config;
        if ($allowed_elements_string) {
            // Keep the allowed HTML tags in sync.
            $updated_allowed_tags = $allowed_elements->merge(HTMLRestrictions::fromString($allowed_elements_string));
            $new_config['settings']['allowed_html'] = $updated_allowed_tags->toFilterHtmlAllowedTagsString();
        }
        $text_format->setFilterConfig('filter_html', $new_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->doTestAllowingExtraAttributes($original_markup, $expected_markup, $allowed_elements_string);
    }
}

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