function AdminUiTest::testSettingsOnlyFireAjaxWithCkeditor5

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

Confirm settings only trigger AJAX when select value is CKEditor 5.

File

core/modules/ckeditor5/tests/src/FunctionalJavascript/AdminUiTest.php, line 27

Class

AdminUiTest
Tests for CKEditor 5 in the admin UI.

Namespace

Drupal\Tests\ckeditor5\FunctionalJavascript

Code

public function testSettingsOnlyFireAjaxWithCkeditor5() {
    $page = $this->getSession()
        ->getPage();
    $assert_session = $this->assertSession();
    $this->addNewTextFormat($page, $assert_session);
    $this->addNewTextFormat($page, $assert_session, 'unicorn');
    $this->drupalGet('admin/config/content/formats/manage/ckeditor5');
    // Enable media embed to trigger an AJAX rebuild.
    $this->assertTrue($page->hasUncheckedField('filters[media_embed][status]'));
    $this->assertSame(0, $this->getAjaxResponseCount());
    $page->checkField('filters[media_embed][status]');
    $assert_session->assertWaitOnAjaxRequest();
    $this->assertSame(1, $this->getAjaxResponseCount());
    // Perform the same steps as above with CKEditor, and confirm AJAX callbacks
    // are not triggered on settings changes.
    $this->drupalGet('admin/config/content/formats/manage/unicorn');
    // Enable media embed to confirm a format not using CKEditor 5 will not
    // trigger an AJAX rebuild.
    $this->assertTrue($page->hasUncheckedField('filters[media_embed][status]'));
    $page->checkField('filters[media_embed][status]');
    $this->assertSame(0, $this->getAjaxResponseCount());
    // Confirm that AJAX updates happen when attempting to switch to CKEditor 5,
    // even if prevented from doing so by validation.
    $this->drupalGet('admin/config/content/formats/add');
    $page->fillField('name', 'trigger validator');
    $assert_session->waitForText('Machine name');
    $page->checkField('roles[authenticated]');
    // Enable a filter that is incompatible with CKEditor 5, so validation is
    // triggered when attempting to switch.
    $incompatible_filter_name = 'filters[filter_incompatible][status]';
    $this->assertTrue($page->hasUncheckedField($incompatible_filter_name));
    $page->checkField($incompatible_filter_name);
    $this->assertSame(0, $this->getAjaxResponseCount());
    $page->selectFieldOption('editor[editor]', 'ckeditor5');
    $assert_session->assertWaitOnAjaxRequest();
    $this->assertSame(1, $this->getAjaxResponseCount());
    $filter_warning = 'CKEditor 5 only works with HTML-based text formats. The "A TYPE_MARKUP_LANGUAGE filter incompatible with CKEditor 5" (filter_incompatible) filter implies this text format is not HTML anymore.';
    // The presence of this validation error message confirms the AJAX callback
    // was invoked.
    $assert_session->pageTextContains($filter_warning);
    // Disable the incompatible filter. This should trigger another AJAX rebuild
    // which will include the removal of the validation error as the issue has
    // been corrected.
    $this->assertTrue($page->hasCheckedField($incompatible_filter_name));
    $page->uncheckField($incompatible_filter_name);
    $assert_session->assertWaitOnAjaxRequest();
    $this->assertSame(2, $this->getAjaxResponseCount());
    $assert_session->pageTextNotContains($filter_warning);
}

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