function CKEditor5IntegrationTest::testDiscard
Tests that changes can be discarded.
File
-
core/
modules/ quickedit/ tests/ src/ FunctionalJavascript/ CKEditor5IntegrationTest.php, line 114
Class
- CKEditor5IntegrationTest
- Tests that Quick Edit can load CKEditor 5.
Namespace
Drupal\Tests\quickedit\FunctionalJavascriptCode
public function testDiscard() {
$page = $this->getSession()
->getPage();
$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',
]);
$assert_session = $this->assertSession();
// 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"]', ' I am not wanted here');
$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',
]);
$assert_session->pageTextContains('I am not wanted here');
// Click the 'Cancel' button.
$page->find('css', '.action-cancel.quickedit-button')
->press();
hold_test_response(TRUE);
// Click the 'Discard Changes' button.
$discard_changes_button = $page->findAll('css', '.ui-dialog-buttonset .button')[1];
$this->assertEquals('Discard changes', $discard_changes_button->getText());
$discard_changes_button->press();
$assert_session->pageTextNotContains('I am not wanted here');
hold_test_response(FALSE);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.