You are here

protected function AutosaveFormTestBase::assertAutosaveResumeDiscardMessageIsShown in Autosave Form 8

Asserts whether the autosave resume/discard message is shown or not.

Parameters

bool $excepted: The expectation whether the message should be shown or not.

$last_autosave_timestamp: The autosave state timestamp contained in the message.

int $timeout: (Optional) Timeout in seconds, defaults to 10.

Throws

ResponseTextException

2 calls to AutosaveFormTestBase::assertAutosaveResumeDiscardMessageIsShown()
AutosaveFormTestBase::reloadPageAndRestore in tests/src/FunctionalJavascript/AutosaveFormTestBase.php
Loads the page and submits the autosave restore.
ContentEntityAutosaveFormTestBase::doTestAutosaveAfterFormValidationFail in tests/src/FunctionalJavascript/ContentEntity/ContentEntityAutosaveFormTestBase.php
Tests the autosave message not being shown on reload after validation fail.

File

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

Class

AutosaveFormTestBase
Basic functionality for autosave form tests.

Namespace

Drupal\Tests\autosave_form\FunctionalJavascript

Code

protected function assertAutosaveResumeDiscardMessageIsShown($excepted, $last_autosave_timestamp, $timeout = 30) {
  $date = \Drupal::service('date.formatter')
    ->format((int) $last_autosave_timestamp, 'custom', 'M d, Y H:i');
  $message = (string) t('A version of this page you were editing at @date was saved as a draft. Do you want to resume editing or discard it?', [
    '@date' => $date,
  ]);
  if ($excepted) {
    while ($timeout > 0) {
      $timeout--;
      try {
        $this
          ->assertSession()
          ->pageTextContains($message);
        break;
      } catch (ResponseTextException $e) {
        if ($timeout <= 0) {
          throw $e;
        }
      }
      if ($timeout > 0) {
        sleep(1);
      }
    }
  }
  else {
    sleep($timeout);
    $this
      ->assertSession()
      ->pageTextNotContains($message);
  }
}