You are here

protected function ContentEntityAutosaveFormTestBase::assertCorrectlyRestoredEntityFormState in Autosave Form 8

Tests the restored autosave state by the change ID.

Parameters

$change_id: The change ID for which to test the restored autosaved state.

See also

::makeEntityFormChange().

1 call to ContentEntityAutosaveFormTestBase::assertCorrectlyRestoredEntityFormState()
ContentEntityAutosaveFormTestBase::doTestAutosaveFormExistingEntity in tests/src/FunctionalJavascript/ContentEntity/ContentEntityAutosaveFormTestBase.php
Tests the autosave support on entity forms.

File

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

Class

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

Namespace

Drupal\Tests\autosave_form\FunctionalJavascript\ContentEntity

Code

protected function assertCorrectlyRestoredEntityFormState($change_id) {
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->logHtmlOutput(__FUNCTION__ . ' before restore of change ' . $change_id);
  switch ($change_id) {
    case 5:
      $test_field_delta_0 = $page
        ->findField($this->requiredField . '[0][value]');
      $this
        ->assertNotEmpty($test_field_delta_0);
      $this
        ->assertEquals('required test field', $test_field_delta_0
        ->getValue());
    case 4:
      $test_field_delta_1 = $page
        ->findField($this->unlimitedCardinalityField . '[1][value]');
      $this
        ->assertNotEmpty($test_field_delta_1);
      $this
        ->assertEquals('delta 1', $test_field_delta_1
        ->getValue());
    case 3:

      // Not applying because of case 4.
      if ($change_id == 3) {
        $test_field_delta_1 = $page
          ->findField($this->unlimitedCardinalityField . '[1][value]');
        $this
          ->assertNotEmpty($test_field_delta_1);
        $this
          ->assertEquals('', $test_field_delta_1
          ->getValue());
      }
    case 2:
      $test_field_delta_0 = $page
        ->findField($this->unlimitedCardinalityField . '[0][value]');
      $this
        ->assertNotEmpty($test_field_delta_0);
      $this
        ->assertEquals('delta 0', $test_field_delta_0
        ->getValue());
    case 1:
      $this
        ->assertOriginalEntityTitleAsPageTitle();
      $entity_type = \Drupal::entityTypeManager()
        ->getDefinition($this->entityType);
      $this
        ->assertEquals($this->changedEntityTitle, $page
        ->findField($entity_type
        ->getKey('label') . '[0][value]')
        ->getValue());
      break;
  }
  $this
    ->logHtmlOutput(__FUNCTION__ . ' after restore of change ' . $change_id);
}