function AdminUiTest::testSettingsOnlyFireAjaxWithCkeditor5

Same name and namespace in other branches
  1. 9 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 29

Class

AdminUiTest
Tests for CKEditor 5 in the admin UI.

Namespace

Drupal\Tests\ckeditor5\FunctionalJavascript

Code

public function testSettingsOnlyFireAjaxWithCkeditor5() : void {
  $page = $this->getSession()
    ->getPage();
  $assert_session = $this->assertSession();
  $this->addNewTextFormat();
  $this->addNewTextFormat('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->assertNoAjaxRequestTriggered();
  $page->checkField('filters[media_embed][status]');
  $assert_session->assertExpectedAjaxRequest(1);
  // 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->assertNoAjaxRequestTriggered();
  // 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');
  $this->assertFalse($assert_session->elementExists('css', '#edit-name-machine-name-suffix')
    ->isVisible());
  $name_field = $page->findField('name');
  $name_field->setValue('trigger validator');
  $this->assertTrue($assert_session->elementExists('css', '#edit-name-machine-name-suffix')
    ->isVisible());
  // 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->assertNoAjaxRequestTriggered();
  $page->selectFieldOption('editor[editor]', 'ckeditor5');
  $assert_session->assertExpectedAjaxRequest(1);
  $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->assertExpectedAjaxRequest(2);
  $assert_session->pageTextNotContains($filter_warning);
}

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