You are here

protected function ContentEntityAutosaveFormTestBase::doTestConcurrentEditing in Autosave Form 8

Tests concurrent editing.

1 call to ContentEntityAutosaveFormTestBase::doTestConcurrentEditing()
ContentEntityAutosaveFormTestBase::testAutosaveForms in tests/src/FunctionalJavascript/ContentEntity/ContentEntityAutosaveFormTestBase.php
Tests autosave.

File

tests/src/FunctionalJavascript/ContentEntity/ContentEntityAutosaveFormTestBase.php, line 177

Class

ContentEntityAutosaveFormTestBase
Base test class for testing autosave support for entity forms.

Namespace

Drupal\Tests\autosave_form\FunctionalJavascript\ContentEntity

Code

protected function doTestConcurrentEditing() {
  $entity = $this
    ->createTestEntity();

  // This test supports only entities implementing the entity changed
  // interface.
  if (!$entity instanceof EntityChangedInterface) {
    return;
  }

  // Make one change and assert that an autosave entry has been created for
  // it.
  $entity_form_edit_url = $entity
    ->toUrl('edit-form');
  $this
    ->drupalGet($entity_form_edit_url);
  $this
    ->assertTrue($this
    ->waitForAutosaveSubmits(1));
  $this
    ->makeEntityFormChange(1);
  $this
    ->assertTrue($this
    ->waitForAutosaveSubmits(2));
  $this
    ->assertTrue($this
    ->getCountAutosaveEntries($entity
    ->id()) > 0);
  $this
    ->assertAutosaveIsRunning(TRUE);

  // Meanwhile simulate saving by another user in the background.
  $entity
    ->setChangedTime($entity
    ->getChangedTime() + 1)
    ->save();

  // Ensure that after the entity is being saved in the background the
  // autosave submission is disabled by expecting maximum of one autosave
  // submission which will show the alert message on the page. If when the
  // following code is executed the autosave submission has not yet run then
  // there will be one autosave submission and afterwards autosave submission
  // should be disabled. If however when the following code is executed the
  // autosave submission has already run then autosave submission should have
  // been disabled already. In both cases we assert that we expect zero or
  // one autosave submission, but not more than one.
  $this
    ->assertFalse($this
    ->waitForAutosaveSubmits(2));
  $this
    ->assertAutosaveIsRunning(FALSE);
  $this
    ->assertEquals(0, $this
    ->getCountAutosaveEntries($entity
    ->id()));
  $message = $this
    ->config('autosave_form.messages')
    ->get('entity_saved_in_background_alert_message');
  $this
    ->assertSession()
    ->responseContains($message);
}