You are here

protected function AutosaveFormTestBase::waitForAutosaveSubmits in Autosave Form 8

Waits until a specific count of autosave submits have been triggered.

Parameters

$count: The count of the autosave submits to wait for.

Return value

bool TRUE, if the autosave submits have occurred, FALSE otherwise.

6 calls to AutosaveFormTestBase::waitForAutosaveSubmits()
ContentEntityAutosaveFormTestBase::doTestAutosaveAfterFormValidationFail in tests/src/FunctionalJavascript/ContentEntity/ContentEntityAutosaveFormTestBase.php
Tests the autosave message not being shown on reload after validation fail.
ContentEntityAutosaveFormTestBase::doTestAutosaveFormExistingEntity in tests/src/FunctionalJavascript/ContentEntity/ContentEntityAutosaveFormTestBase.php
Tests the autosave support on entity forms.
ContentEntityAutosaveFormTestBase::doTestAutosaveStatesPurgingOnConfigEvent in tests/src/FunctionalJavascript/ContentEntity/ContentEntityAutosaveFormTestBase.php
Tests that autosave states are purged on modifying a form related config.
ContentEntityAutosaveFormTestBase::doTestConcurrentEditing in tests/src/FunctionalJavascript/ContentEntity/ContentEntityAutosaveFormTestBase.php
Tests concurrent editing.
ContentEntityAutosaveFormTestBase::doTestSavingRestoredEntityForm in tests/src/FunctionalJavascript/ContentEntity/ContentEntityAutosaveFormTestBase.php
Tests saving an entity form restored from an autosaved state.

... See full list

File

tests/src/FunctionalJavascript/AutosaveFormTestBase.php, line 143

Class

AutosaveFormTestBase
Basic functionality for autosave form tests.

Namespace

Drupal\Tests\autosave_form\FunctionalJavascript

Code

protected function waitForAutosaveSubmits($count) {

  /** @var \Drupal\Core\State\StateInterface $state */
  $state = \Drupal::state();
  $state
    ->resetCache();
  $start_count = $state
    ->get('autosave_submit_count', 0);

  // Define a timeout for the autosave submissions by multiplying the .
  $system_slowness_factor = 5;
  $timeout = $this->interval / 1000 * $system_slowness_factor * $count;
  $deadline_time = time() + $timeout;
  while (TRUE) {
    $state
      ->resetCache();
    $current_count = $state
      ->get('autosave_submit_count', 0);
    if ($current_count >= $start_count + $count) {
      return TRUE;
    }
    if (time() >= $deadline_time) {
      return FALSE;
    }

    // sleep for 0.1 second.
    usleep(100000);
  }
}