function CKEditor5IntegrationTest::testArticleNode
Tests if an article node can be in-place edited with Quick Edit.
File
-
core/
modules/ quickedit/ tests/ src/ FunctionalJavascript/ CKEditor5IntegrationTest.php, line 195
Class
- CKEditor5IntegrationTest
- Tests that Quick Edit can load CKEditor 5.
Namespace
Drupal\Tests\quickedit\FunctionalJavascriptCode
public function testArticleNode() {
$assert_session = $this->assertSession();
$node = $this->drupalCreateNode([
'type' => 'article',
'title' => t('My Test Node'),
'body' => [
'value' => '<p>Hello world!</p><p>I do not know what to say…</p><p>I wish I were eloquent.</p>',
'format' => 'some_format',
],
]);
$this->drupalGet('node/' . $node->id());
// Initial state.
$this->awaitQuickEditForEntity('node', 1);
$this->assertEntityInstanceStates([
'node/1[0]' => 'closed',
]);
$this->assertEntityInstanceFieldStates('node', 1, 0, [
'node/1/title/en/full' => 'inactive',
'node/1/body/en/full' => 'inactive',
]);
// Start in-place editing of the article node.
$this->startQuickEditViaToolbar('node', 1, 0);
$this->assertEntityInstanceStates([
'node/1[0]' => 'opened',
]);
$this->assertQuickEditEntityToolbar((string) $node->label(), NULL);
$this->assertEntityInstanceFieldStates('node', 1, 0, [
'node/1/title/en/full' => 'candidate',
'node/1/body/en/full' => 'candidate',
]);
// Confirm that the JavaScript that generates IE11 warnings loads.
$assert_session->elementExists('css', 'script[src*="ckeditor5/js/ie11.user.warnings.js"]');
// Click the body field.
hold_test_response(TRUE);
$this->click('[data-quickedit-field-id="node/1/body/en/full"]');
$assert_session->waitForElement('css', '.quickedit-toolbar-field div[id*="body"]');
$this->assertQuickEditEntityToolbar((string) $node->label(), 'Body');
$this->assertEntityInstanceFieldStates('node', 1, 0, [
'node/1/title/en/full' => 'candidate',
'node/1/body/en/full' => 'active',
]);
hold_test_response(FALSE);
$this->assertEntityInstanceFieldMarkup([
'node/1/body/en/full' => '.ck-editor__editable_inline',
]);
$this->assertSession()
->elementExists('css', '#quickedit-entity-toolbar .quickedit-toolgroup.wysiwyg-main .ck-toolbar[role="toolbar"] .ck-toolbar__items > .ck-button[type="button"]');
// Click the body field.
$this->click('[data-quickedit-field-id="node/1/body/en/full"]');
$assert_session->waitForElement('css', '.quickedit-toolbar-field div[id*="body"]');
$this->typeInPlainTextEditor('[data-quickedit-field-id="node/1/body/en/full"]', ' Added text with CKEditor 5');
$assert_session->waitForElement('css', '.quickedit-toolbar-field div[id*="body"].quickedit-changed');
$this->assertEntityInstanceFieldStates('node', 1, 0, [
'node/1/title/en/full' => 'candidate',
'node/1/body/en/full' => 'changed',
]);
// Click 'Save'.
hold_test_response(TRUE);
$this->saveQuickEdit();
$this->assertEntityInstanceStates([
'node/1[0]' => 'committing',
]);
$this->assertEntityInstanceFieldStates('node', 1, 0, [
'node/1/title/en/full' => 'candidate',
'node/1/body/en/full' => 'saving',
]);
$this->assertEntityInstanceFieldMarkup([
'node/1/body/en/full' => '.quickedit-changed',
]);
hold_test_response(FALSE);
$this->assertJsCondition("Drupal.quickedit.collections.entities.get('node/1[0]').get('state') === 'closed'");
$this->assertEntityInstanceStates([
'node/1[0]' => 'closed',
]);
// Get the load again and ensure the values are the expected values.
$this->drupalGet('node/' . $node->id());
$this->assertSession()
->pageTextContains('I wish I were eloquent.');
$this->assertSession()
->pageTextContains('Added text with CKEditor 5');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.