Verified Commit e28a98ac authored by Théodore Biadala's avatar Théodore Biadala
Browse files

Issue #3467853 by catch, smustgrave: Use API methods to create filter/editor...

Issue #3467853 by catch, smustgrave: Use API methods to create filter/editor in CKEditor5Test when not explicitly testing the UI

(cherry picked from commit ec27dec3)
parent 9e2ca2c7
Loading
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -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.
+1 −1
Original line number Diff line number Diff line
@@ -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');

+1 −1
Original line number Diff line number Diff line
@@ -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');
+4 −6
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ public function testExistingContent(): void {
    $assert_session->responseNotContains('<p>This is test content</p>');
    $assert_session->responseContains('&lt;p&gt;This is test content&lt;/p&gt;');

    $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');
+27 −3
Original line number Diff line number Diff line
@@ -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();
  }

  /**