function AdminUiTest::testMessagesDoNotAccumulate

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

Ensure CKEditor 5 admin UI's real-time validation errors do not accumulate.

File

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

Class

AdminUiTest
Tests for CKEditor 5 in the admin UI.

Namespace

Drupal\Tests\ckeditor5\FunctionalJavascript

Code

public function testMessagesDoNotAccumulate() : void {
    $page = $this->getSession()
        ->getPage();
    $assert_session = $this->assertSession();
    $this->addNewTextFormat($page, $assert_session);
    $this->drupalGet('admin/config/content/formats/manage/ckeditor5');
    // Add the source editing plugin to the CKEditor 5 toolbar.
    $this->assertNotEmpty($assert_session->waitForElement('css', '.ckeditor5-toolbar-item-sourceEditing'));
    $this->triggerKeyUp('.ckeditor5-toolbar-item-sourceEditing', 'ArrowDown');
    $assert_session->assertWaitOnAjaxRequest();
    $find_validation_error_messages = function () use ($page) : array {
        return $page->findAll('css', '[role=alert]:contains("The following tag(s) are already supported by enabled plugins and should not be added to the Source Editing "Manually editable HTML tags" field: Bold (<strong>).")');
    };
    // No validation errors when we start.
    $this->assertCount(0, $find_validation_error_messages());
    // Configure Source Editing to allow editing `<strong>` to trigger
    // validation error.
    $assert_session->waitForText('Source editing');
    $page->find('css', '[href^="#edit-editor-settings-plugins-ckeditor5-sourceediting"]')
        ->click();
    $assert_session->assertWaitOnAjaxRequest();
    $assert_session->waitForText('Manually editable HTML tags');
    $source_edit_tags_field = $assert_session->fieldExists('editor[settings][plugins][ckeditor5_sourceEditing][allowed_tags]');
    $source_edit_tags_field->setValue('<strong>');
    $assert_session->assertWaitOnAjaxRequest();
    $this->assertCount(1, $find_validation_error_messages());
    // Revert Source Editing it: validation messages should be gone.
    $source_edit_tags_field->setValue('');
    $assert_session->assertWaitOnAjaxRequest();
    $this->assertCount(0, $find_validation_error_messages());
    // Add `<strong>` again: validation messages should be back.
    $source_edit_tags_field->setValue('<strong>');
    $assert_session->assertWaitOnAjaxRequest();
    $this->assertCount(1, $find_validation_error_messages());
}

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