You are here

public function CKEditor5IntegrationTest::testArticleNode in Drupal 10

Tests if an article node can be in-place edited with Quick Edit.

File

core/modules/quickedit/tests/src/FunctionalJavascript/CKEditor5IntegrationTest.php, line 194

Class

CKEditor5IntegrationTest
Tests that Quick Edit can load CKEditor 5.

Namespace

Drupal\Tests\quickedit\FunctionalJavascript

Code

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',
  ]);

  // 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');
}