You are here

protected function ContentEntityAutosaveFormTestBase::doTestAutosaveStatesPurgingOnConfigEvent in Autosave Form 8

Tests that autosave states are purged on modifying a form related config.

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

File

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

Class

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

Namespace

Drupal\Tests\autosave_form\FunctionalJavascript\ContentEntity

Code

protected function doTestAutosaveStatesPurgingOnConfigEvent() {
  $entity = $this
    ->createTestEntity();
  $entity_id = $entity
    ->id();
  $entity_form_edit_url = $entity
    ->toUrl('edit-form');
  $create_autosave_state = function () use ($entity_form_edit_url, $entity_id) {
    $this
      ->drupalGet($entity_form_edit_url);

    // Wait for at least having two autosave submits being executed, make a
    // change wait for two more autosave submits and ensure an autosave state
    // has been created.
    $this
      ->assertTrue($this
      ->waitForAutosaveSubmits(2));
    $this
      ->makeEntityFormChange(1);
    $this
      ->assertTrue($this
      ->waitForAutosaveSubmits(2));
    $this
      ->assertEquals(1, $this
      ->getCountAutosaveEntries($entity_id));
  };

  // Make a non-significant modification on a form related config and ensure
  // that the autosave state hasn't been purged.
  $create_autosave_state();
  $field_config = FieldConfig::loadByName($this->entityType, $this->bundle, $this->unlimitedCardinalityField);
  $field_config
    ->setLabel('New Label Test AutosaveState Purge')
    ->save();
  $this
    ->assertEquals(1, $this
    ->getCountAutosaveEntries($entity_id));

  // Modify a form related config and ensure that the autosave state has been
  // purged.
  $field_storage = FieldStorageConfig::loadByName($this->entityType, $this->unlimitedCardinalityField);
  $field_storage
    ->setCardinality(10)
    ->save();
  $this
    ->assertEquals(0, $this
    ->getCountAutosaveEntries($entity_id));

  // Delete a form related config and ensure that the autosave state has been
  // purged.
  $create_autosave_state();
  $field_storage = FieldStorageConfig::loadByName($this->entityType, $this->unlimitedCardinalityField);
  $field_storage
    ->delete();
  $this
    ->assertEquals(0, $this
    ->getCountAutosaveEntries($entity_id));

  // Create a form related config and ensure that the autosave state has been
  // purged.
  $create_autosave_state();
  $this
    ->createMultipleTestField();
  $this
    ->assertEquals(0, $this
    ->getCountAutosaveEntries($entity_id));
}