You are here

public function ContentTranslationUITestBase::doTestChangedTimeAfterSaveWithoutChanges in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase::doTestChangedTimeAfterSaveWithoutChanges()

Tests the changed time after API and FORM save without changes.

1 call to ContentTranslationUITestBase::doTestChangedTimeAfterSaveWithoutChanges()
ContentTranslationUITestBase::testTranslationUI in core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php
Tests the basic translation UI.

File

core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php, line 604

Class

ContentTranslationUITestBase
Tests the Content Translation UI.

Namespace

Drupal\Tests\content_translation\Functional

Code

public function doTestChangedTimeAfterSaveWithoutChanges() {
  $storage = $this->container
    ->get('entity_type.manager')
    ->getStorage($this->entityTypeId);
  $storage
    ->resetCache([
    $this->entityId,
  ]);
  $entity = $storage
    ->load($this->entityId);

  // Test only entities, which implement the EntityChangedInterface.
  if ($entity instanceof EntityChangedInterface) {
    $changed_timestamp = $entity
      ->getChangedTime();
    $entity
      ->save();
    $storage = $this->container
      ->get('entity_type.manager')
      ->getStorage($this->entityTypeId);
    $storage
      ->resetCache([
      $this->entityId,
    ]);
    $entity = $storage
      ->load($this->entityId);
    $this
      ->assertEquals($changed_timestamp, $entity
      ->getChangedTime(), 'The entity\'s changed time wasn\'t updated after API save without changes.');

    // Ensure different save timestamps.
    sleep(1);

    // Save the entity on the regular edit form.
    $language = $entity
      ->language();
    $edit_path = $entity
      ->toUrl('edit-form', [
      'language' => $language,
    ]);
    $this
      ->drupalGet($edit_path);
    $this
      ->submitForm([], $this
      ->getFormSubmitAction($entity, $language
      ->getId()));
    $storage
      ->resetCache([
      $this->entityId,
    ]);
    $entity = $storage
      ->load($this->entityId);
    $this
      ->assertNotEquals($changed_timestamp, $entity
      ->getChangedTime(), 'The entity\'s changed time was updated after form save without changes.');
  }
}