protected function ContentEntityAutosaveFormTestBase::doTestAutosaveFormExistingEntity in Autosave Form 8
Tests the autosave support on entity forms.
1 call to ContentEntityAutosaveFormTestBase::doTestAutosaveFormExistingEntity()
- ContentEntityAutosaveFormTestBase::testAutosaveForms in tests/
src/ FunctionalJavascript/ ContentEntity/ ContentEntityAutosaveFormTestBase.php - Tests autosave.
File
- tests/
src/ FunctionalJavascript/ ContentEntity/ ContentEntityAutosaveFormTestBase.php, line 117
Class
- ContentEntityAutosaveFormTestBase
- Base test class for testing autosave support for entity forms.
Namespace
Drupal\Tests\autosave_form\FunctionalJavascript\ContentEntityCode
protected function doTestAutosaveFormExistingEntity() {
$entity = $this
->createTestEntity();
$entity_id = $entity
->id();
$entity_form_edit_url = $entity
->toUrl('edit-form');
$this
->drupalGet($entity_form_edit_url);
$this
->assertAutosaveFormLibraryLoaded(TRUE);
$this
->assertOriginalEntityTitleAsPageTitle();
// Wait for at least having two autosave submits being executed and assert
// that with no changes there will be no autosave states created.
$this
->assertTrue($this
->waitForAutosaveSubmits(2));
$this
->assertEquals(0, $this
->getCountAutosaveEntries($entity_id));
$latest_autosave_timestamp_per_change = $this
->makeAllEntityFormChanges($entity_id);
// Test the autosave restore of each change.
for ($change_id = $this->testAutosaveFormExistingEntityChangesCount; $change_id > 0; $change_id--) {
// Reload page otherwise new auto saves will be done and time checks get incorrect
$this
->drupalGet($entity_form_edit_url);
if (($last_autosave_timestamp = $this
->getLastAutosaveTimestamp($entity_id)) && $last_autosave_timestamp > $latest_autosave_timestamp_per_change[$change_id]) {
$delete_timestamps = range($latest_autosave_timestamp_per_change[$change_id] + 1, $last_autosave_timestamp);
$this
->deleteAutosavedStates($delete_timestamps);
}
$this
->reloadPageAndRestore($entity_form_edit_url, $this
->getLastAutosaveTimestamp($entity_id));
$this
->assertCorrectlyRestoredEntityFormState($change_id);
}
}