.../CKEditor5AllowedTagsTest.php | 11 +++---- .../src/FunctionalJavascript/CKEditor5Test.php | 36 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5AllowedTagsTest.php b/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5AllowedTagsTest.php index f67242f4e6..80b0636fcf 100644 --- a/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5AllowedTagsTest.php +++ b/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5AllowedTagsTest.php @@ -435,7 +435,7 @@ public function testFullHtml() { // Add a node with text rendered via the Plain Text format. $this->drupalGet('node/add'); $page->fillField('title[0][value]', 'My test content'); - $page->fillField('body[0][value]', '
'); + $page->fillField('body[0][value]', ''); $page->pressButton('Save'); // Configure Full HTML text format to use CKEditor 5. @@ -458,8 +458,7 @@ public function testFullHtml() { // But note that the `style` attribute was stripped by // \Drupal\editor\EditorXssFilter\Standard. - var_dump($this->getRawContent()); - $assert_session->responseContains(''); + $assert_session->responseContains(''); // Ensure attributes are retained after enabling link plugin. $this->drupalGet('admin/config/content/formats/manage/full_html'); @@ -471,7 +470,7 @@ public function testFullHtml() { $this->drupalGet('node/1/edit'); $page->pressButton('Save'); - $assert_session->responseContains(''); + $assert_session->responseContains(''); // Configure Basic HTML text format to use CKE5 and enable the link plugin. $this->drupalGet('admin/config/content/formats/manage/basic_html'); @@ -493,8 +492,8 @@ public function testFullHtml() { $page->pressButton('Save'); // The `style` and foo` attributes should have been removed, as should the - // `` tag. But the `dir="ltr"` attribute should have been retained. - $assert_session->responseContains(''); + // `` tag. + $assert_session->responseContains(''); } } diff --git a/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5Test.php b/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5Test.php index 7a8dcb56c4..c01c81a360 100644 --- a/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5Test.php +++ b/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5Test.php @@ -8,6 +8,7 @@ use Drupal\file\Entity\File; use Drupal\filter\Entity\FilterFormat; use Drupal\node\Entity\Node; +use Drupal\Tests\ckeditor5\Traits\CKEditor5TestTrait; use Drupal\Tests\TestFileCreationTrait; use Drupal\user\RoleInterface; use Symfony\Component\Validator\ConstraintViolation; @@ -22,6 +23,7 @@ */ class CKEditor5Test extends CKEditor5TestBase { + use CKEditor5TestTrait; use TestFileCreationTrait; /** @@ -432,4 +434,38 @@ public function testEmphasis() { $assert_session->responseContains('This is a test!
'); } + /** + * 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 \Drupal\filter\Plugin\Filter\FilterHtml::getHTMLRestrictions() + */ + 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'); + $page->fillField('body[0][value]', 'Hello World>
مرحبا بالعالم
'); + $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'); + + $assert_session->responseContains('Hello World>
مرحبا بالعالم
'); + } + }