diff --git a/core/modules/ckeditor5/tests/src/FunctionalJavascript/AdminUiTest.php b/core/modules/ckeditor5/tests/src/FunctionalJavascript/AdminUiTest.php index dcc358b739f0cd4f3d1602fbb6665829ab2c3248..69c708759a6cca1199533e7018582ed92b5cce45 100644 --- a/core/modules/ckeditor5/tests/src/FunctionalJavascript/AdminUiTest.php +++ b/core/modules/ckeditor5/tests/src/FunctionalJavascript/AdminUiTest.php @@ -29,8 +29,8 @@ class AdminUiTest extends CKEditor5TestBase { public function testSettingsOnlyFireAjaxWithCkeditor5(): void { $page = $this->getSession()->getPage(); $assert_session = $this->assertSession(); - $this->addNewTextFormat($page, $assert_session); - $this->addNewTextFormat($page, $assert_session, 'unicorn'); + $this->addNewTextFormat(); + $this->addNewTextFormat('unicorn'); $this->drupalGet('admin/config/content/formats/manage/ckeditor5'); @@ -184,7 +184,7 @@ public function testImageUploadSettingsAreValidated(): void { $page = $this->getSession()->getPage(); $assert_session = $this->assertSession(); - $this->addNewTextFormat($page, $assert_session); + $this->addNewTextFormat(); $this->drupalGet('admin/config/content/formats/manage/ckeditor5'); // Add the image plugin to the CKEditor 5 toolbar. @@ -233,7 +233,7 @@ public function testMessagesDoNotAccumulate(): void { $page = $this->getSession()->getPage(); $assert_session = $this->assertSession(); - $this->addNewTextFormat($page, $assert_session); + $this->addNewTextFormat(); $this->drupalGet('admin/config/content/formats/manage/ckeditor5'); // Add the source editing plugin to the CKEditor 5 toolbar. diff --git a/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5OffCanvasTest.php b/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5OffCanvasTest.php index 212584749ec1d02fb9a5254999488ad07efdebbf..f52ebb874c5e19014b53e84ca261634c5b67e8be 100644 --- a/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5OffCanvasTest.php +++ b/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5OffCanvasTest.php @@ -28,7 +28,7 @@ public function testOffCanvasStyles(): void { $assert_session = $this->assertSession(); $page = $this->getSession()->getPage(); - $this->addNewTextFormat($page, $assert_session); + $this->addNewTextFormat(); $this->drupalGet('/ckeditor5_test/off_canvas'); diff --git a/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5ReadOnlyModeTest.php b/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5ReadOnlyModeTest.php index bec3961ec4625301be10bc295537f4aaf8132af9..fd62a633aad44c2510d1b9f4eb4f625237d0e75f 100644 --- a/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5ReadOnlyModeTest.php +++ b/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5ReadOnlyModeTest.php @@ -55,7 +55,7 @@ protected function setUp(): void { public function testReadOnlyMode(): void { $page = $this->getSession()->getPage(); $assert_session = $this->assertSession(); - $this->addNewTextFormat($page, $assert_session); + $this->addNewTextFormat(); // Check that both CKEditor 5 fields are editable. $this->drupalGet('node/add'); diff --git a/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5Test.php b/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5Test.php index 9584aaa446c94284cd6fda74f91317ef6664653b..d4ff63e53fd5b6fdf9744e7d18e9dffcc6ea4c3a 100644 --- a/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5Test.php +++ b/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5Test.php @@ -53,7 +53,7 @@ public function testExistingContent(): void { $assert_session->responseNotContains('<p>This is test content</p>'); $assert_session->responseContains('<p>This is test content</p>'); - $this->addNewTextFormat($page, $assert_session); + $this->addNewTextFormat(); // Change the node to use the new text format. $this->drupalGet('node/1/edit'); @@ -152,7 +152,7 @@ public function testHeadingsPlugin(): void { $page = $this->getSession()->getPage(); $assert_session = $this->assertSession(); - $this->addNewTextFormat($page, $assert_session); + $this->addNewTextFormat(); $this->drupalGet('admin/config/content/formats/manage/ckeditor5'); $this->assertHtmlEsqueFieldValueEquals('filters[filter_html][settings][allowed_html]', '<br> <p> <h2> <h3> <h4> <h5> <h6> <strong> <em>'); @@ -612,8 +612,7 @@ public function testEmphasis(): void { $page->fillField('body[0][value]', '<p>This is a <em>test!</em></p>'); $page->pressButton('Save'); - $this->createNewTextFormat($page, $assert_session); - $this->saveNewTextFormat($page, $assert_session); + $this->addNewTextFormat(); $this->drupalGet('node/1/edit'); $page->selectFieldOption('body[0][format]', 'ckeditor5'); @@ -743,8 +742,7 @@ public function testFilterHtmlAllowedGlobalAttributes(): void { $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->addNewTextFormat(); $this->drupalGet('node/1/edit'); $page->selectFieldOption('body[0][format]', 'ckeditor5'); diff --git a/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5TestBase.php b/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5TestBase.php index 51a9fa6ba3e3402cc2a9fd20a668921f0d7b87ac..e60801c04738b61bf096f4c680b584a61a117005 100644 --- a/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5TestBase.php +++ b/core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5TestBase.php @@ -5,7 +5,10 @@ namespace Drupal\Tests\ckeditor5\FunctionalJavascript; use Behat\Mink\Element\TraversableElement; +use Drupal\editor\Entity\Editor; +use Drupal\filter\Entity\FilterFormat; use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\user\RoleInterface; // cspell:ignore esque @@ -48,9 +51,30 @@ protected function setUp(): void { /** * Add and save a new text format using CKEditor 5. */ - public function addNewTextFormat($page, $assert_session, $name = 'ckeditor5') { - $this->createNewTextFormat($page, $assert_session, $name); - $this->saveNewTextFormat($page, $assert_session); + protected function addNewTextFormat($name = 'ckeditor5'): void { + FilterFormat::create([ + 'format' => $name, + 'roles' => [RoleInterface::AUTHENTICATED_ID], + 'name' => $name, + 'filters' => [ + 'filter_html' => [ + 'status' => TRUE, + 'settings' => [ + 'allowed_html' => '<br> <p> <h2> <h3> <h4> <h5> <h6> <strong> <em>', + ], + ], + 'filter_align' => ['status' => TRUE], + 'filter_caption' => ['status' => TRUE], + ], + ])->save(); + + Editor::create([ + 'editor' => $name, + 'format' => $name, + 'image_upload' => [ + 'status' => FALSE, + ], + ])->save(); } /**