You are here

public function NodeFormSaveChangedTimeTest::testChangedTimeAfterSaveWithoutChanges in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/node/tests/src/Functional/NodeFormSaveChangedTimeTest.php \Drupal\Tests\node\Functional\NodeFormSaveChangedTimeTest::testChangedTimeAfterSaveWithoutChanges()

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

File

core/modules/node/tests/src/Functional/NodeFormSaveChangedTimeTest.php, line 63

Class

NodeFormSaveChangedTimeTest
Tests updating the changed time after API and FORM entity save.

Namespace

Drupal\Tests\node\Functional

Code

public function testChangedTimeAfterSaveWithoutChanges() {
  $storage = $this->container
    ->get('entity_type.manager')
    ->getStorage('node');
  $storage
    ->resetCache([
    1,
  ]);
  $node = $storage
    ->load(1);
  $changed_timestamp = $node
    ->getChangedTime();
  $node
    ->save();
  $storage
    ->resetCache([
    1,
  ]);
  $node = $storage
    ->load(1);
  $this
    ->assertEquals($changed_timestamp, $node
    ->getChangedTime(), "The entity's changed time wasn't updated after API save without changes.");

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

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