function CKEditor5Test::testFilterHtmlAllowedGlobalAttributes

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

Ensures that CKEditor 5 retains filter_html's allowed global attributes.

FilterHtml always forbids the `style` and `on*` attributes, and always allows the `lang` attribute (with any value) and the `dir` attribute (with either `ltr` or `rtl` as value). It's important that those last two attributes are guaranteed to be retained.

See also

\Drupal\filter\Plugin\Filter\FilterHtml::getHTMLRestrictions()

ckeditor5_globalAttributeDir

ckeditor5_globalAttributeLang

https://html.spec.whatwg.org/multipage/dom.html#global-attributes

File

core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5Test.php, line 691

Class

CKEditor5Test
Tests for CKEditor 5.

Namespace

Drupal\Tests\ckeditor5\FunctionalJavascript

Code

public function testFilterHtmlAllowedGlobalAttributes() : void {
    $page = $this->getSession()
        ->getPage();
    $assert_session = $this->assertSession();
    // Add a node with text rendered via the Plain Text format.
    $this->drupalGet('node/add');
    $page->fillField('title[0][value]', 'Multilingual Hello World');
    // cSpell:disable-next-line
    $page->fillField('body[0][value]', '<p dir="ltr" lang="en">Hello World</p><p dir="rtl" lang="ar">مرحبا بالعالم</p>');
    $page->pressButton('Save');
    $this->createNewTextFormat($page, $assert_session);
    $this->saveNewTextFormat($page, $assert_session);
    $this->drupalGet('node/1/edit');
    $page->selectFieldOption('body[0][format]', 'ckeditor5');
    $this->assertNotEmpty($assert_session->waitForText('Change text format?'));
    $page->pressButton('Continue');
    $this->waitForEditor();
    $page->pressButton('Save');
    // @todo Remove the expected `xml:lang` attributes in https://www.drupal.org/project/drupal/issues/1333730
    // cSpell:disable-next-line
    $assert_session->responseContains('<p dir="ltr" lang="en" xml:lang="en">Hello World</p><p dir="rtl" lang="ar" xml:lang="ar">مرحبا بالعالم</p>');
}

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