You are here

public function QuickEditLoadingTest::testConcurrentEdit in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditLoadingTest.php \Drupal\Tests\quickedit\FunctionalJavascript\QuickEditLoadingTest::testConcurrentEdit()

Tests Quick Edit on a node that was concurrently edited on the full node form.

File

core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditLoadingTest.php, line 268

Class

QuickEditLoadingTest
Tests loading of in-place editing functionality and lazy loading of its in-place editors.

Namespace

Drupal\Tests\quickedit\FunctionalJavascript

Code

public function testConcurrentEdit() {
  $nid = $this->testNode
    ->id();
  $this
    ->drupalLogin($this->authorUser);

  // Open the edit page in the default session.
  $this
    ->drupalGet('node/' . $nid . '/edit');

  // Switch to a concurrent session and save a quick edit change.
  // We need to do some bookkeeping to keep track of the logged in user.
  $logged_in_user = $this->loggedInUser;
  $this->loggedInUser = FALSE;

  // Register a session to preform concurrent editing.
  $driver = $this
    ->getDefaultDriverInstance();
  $session = new Session($driver);
  $this->mink
    ->registerSession('concurrent', $session);
  $this->mink
    ->setDefaultSessionName('concurrent');
  $this
    ->initFrontPage();
  $this
    ->drupalLogin($this->editorUser);
  $this
    ->drupalGet('node/' . $nid);
  $assert = $this
    ->assertSession();
  $page = $this
    ->getSession()
    ->getPage();

  // Wait "Quick edit" button for node.
  $assert
    ->waitForElement('css', '[data-quickedit-entity-id="node/' . $nid . '"] .contextual .quickedit');

  // Click by "Quick edit".
  $this
    ->clickContextualLink('[data-quickedit-entity-id="node/' . $nid . '"]', 'Quick edit');

  // Switch to body field.
  $page
    ->find('css', '[data-quickedit-field-id="node/' . $nid . '/body/en/full"]')
    ->click();

  // Wait and update body field.
  $body_field_locator = '[name="body[0][value]"]';
  $body_text = 'Fine thanks.';
  $assert
    ->waitForElementVisible('css', $body_field_locator)
    ->setValue('<p>' . $body_text . '</p>');

  // Wait and click by "Save" button after body field was changed.
  $assert
    ->waitForElementVisible('css', '.quickedit-toolgroup.ops [type="submit"][aria-hidden="false"]')
    ->click();
  $assert
    ->waitForElementRemoved('css', $body_field_locator);

  // Ensure that the changes take effect.
  $assert
    ->responseMatches("|\\s*{$body_text}\\s*|");

  // Switch back to the default session.
  $this->mink
    ->setDefaultSessionName('default');
  $this->loggedInUser = $logged_in_user;

  // Ensure different save timestamps for field editing.
  sleep(2);
  $this
    ->submitForm([
    'body[0][value]' => '<p>Concurrent edit!</p>',
  ], 'Save');
  $this
    ->getSession()
    ->getPage()
    ->hasContent('The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved.');
}