function CKEditor5ReadOnlyModeTest::testReadOnlyMode

Same name in other branches
  1. 11.x core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5ReadOnlyModeTest.php \Drupal\Tests\ckeditor5\FunctionalJavascript\CKEditor5ReadOnlyModeTest::testReadOnlyMode()

Test that disabling a CKEditor 5 field results in an uneditable editor.

File

core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5ReadOnlyModeTest.php, line 55

Class

CKEditor5ReadOnlyModeTest
Tests read-only mode for CKEditor 5.

Namespace

Drupal\Tests\ckeditor5\FunctionalJavascript

Code

public function testReadOnlyMode() : void {
    $page = $this->getSession()
        ->getPage();
    $assert_session = $this->assertSession();
    $this->addNewTextFormat();
    // Check that both CKEditor 5 fields are editable.
    $this->drupalGet('node/add');
    $assert_session->elementAttributeContains('css', '.field--name-body .ck-editor .ck-content', 'contenteditable', 'true');
    $assert_session->elementAttributeContains('css', '.field--name-field-second-ckeditor5-field .ck-editor .ck-content', 'contenteditable', 'true');
    $this->container
        ->get('state')
        ->set('ckeditor5_read_only_mode_body_enabled', TRUE);
    // Check that the first body field is no longer editable.
    $this->drupalGet('node/add');
    $assert_session->elementAttributeContains('css', '.field--name-body .ck-editor .ck-content', 'contenteditable', 'false');
    $assert_session->elementAttributeContains('css', '.field--name-field-second-ckeditor5-field .ck-editor .ck-content', 'contenteditable', 'true');
    $this->container
        ->get('state')
        ->set('ckeditor5_read_only_mode_second_ckeditor5_field_enabled', TRUE);
    // Both fields are disabled, check that both fields are no longer editable.
    $this->drupalGet('node/add');
    $assert_session->elementAttributeContains('css', '.field--name-body .ck-editor .ck-content', 'contenteditable', 'false');
    $assert_session->elementAttributeContains('css', '.field--name-field-second-ckeditor5-field .ck-editor .ck-content', 'contenteditable', 'false');
}

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