function FieldTest::testFieldWithCkeditor

Same name in other branches
  1. 8.9.x core/modules/quickedit/tests/src/FunctionalJavascript/FieldTest.php \Drupal\Tests\quickedit\FunctionalJavascript\FieldTest::testFieldWithCkeditor()

Tests that quickeditor works correctly for field with CKEditor.

File

core/modules/quickedit/tests/src/FunctionalJavascript/FieldTest.php, line 76

Class

FieldTest
Tests quickedit.

Namespace

Drupal\Tests\quickedit\FunctionalJavascript

Code

public function testFieldWithCkeditor() {
    $body_value = '<p>Dare to be wise</p>';
    $node = Node::create([
        'type' => 'page',
        'title' => 'Page node',
        'body' => [
            [
                'value' => $body_value,
                'format' => 'filtered_html',
            ],
        ],
    ]);
    $node->save();
    $page = $this->getSession()
        ->getPage();
    $assert = $this->assertSession();
    $this->drupalGet('node/' . $node->id());
    // Wait "Quick edit" button for node.
    $this->assertSession()
        ->waitForElement('css', '[data-quickedit-entity-id="node/' . $node->id() . '"] .contextual .quickedit');
    // Click by "Quick edit".
    $this->clickContextualLink('[data-quickedit-entity-id="node/' . $node->id() . '"]', 'Quick edit');
    // Switch to body field.
    $page->find('css', '[data-quickedit-field-id="node/' . $node->id() . '/body/en/full"]')
        ->click();
    // Wait and click by "Blockquote" button from editor for body field.
    $this->assertSession()
        ->waitForElementVisible('css', '.cke_button.cke_button__blockquote')
        ->click();
    // Wait and click by "Save" button after body field was changed.
    $this->assertSession()
        ->waitForElementVisible('css', '.quickedit-toolgroup.ops [type="submit"][aria-hidden="false"]')
        ->click();
    // Wait until the save occurs and the editor UI disappears.
    $this->assertSession()
        ->assertNoElementAfterWait('css', '.cke_button.cke_button__blockquote');
    // Ensure that the changes take effect.
    $assert->responseMatches("|<blockquote>\\s*{$body_value}\\s*</blockquote>|");
}

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