3 namespace Drupal\Tests\node\Functional;
5 use Drupal\Tests\BrowserTestBase;
8 * Tests updating the changed time after API and FORM entity save.
12 class NodeFormSaveChangedTimeTest extends BrowserTestBase {
19 public static $modules = [
24 * An user with permissions to create and edit articles.
26 * @var \Drupal\user\UserInterface
28 protected $authorUser;
33 protected function setUp() {
36 // Create a node type.
37 $this->drupalCreateContentType([
42 $this->authorUser = $this->drupalCreateUser(['access content', 'create article content', 'edit any article content'], 'author');
43 $this->drupalLogin($this->authorUser);
45 // Create one node of the above node type .
46 $this->drupalCreateNode([
52 * Test the changed time after API and FORM save without changes.
54 public function testChangedTimeAfterSaveWithoutChanges() {
55 $storage = $this->container->get('entity_type.manager')->getStorage('node');
56 $storage->resetCache([1]);
57 $node = $storage->load(1);
58 $changed_timestamp = $node->getChangedTime();
60 $storage->resetCache([1]);
61 $node = $storage->load(1);
62 $this->assertEqual($changed_timestamp, $node->getChangedTime(), "The entity's changed time wasn't updated after API save without changes.");
64 // Ensure different save timestamps.
67 // Save the node on the regular node edit form.
68 $this->drupalPostForm('node/1/edit', [], t('Save'));
70 $storage->resetCache([1]);
71 $node = $storage->load(1);
72 $this->assertNotEqual($changed_timestamp, $node->getChangedTime(), "The entity's changed time was updated after form save without changes.");