NodeFormSaveChangedTimeTest.php in Drupal 9
File
core/modules/node/tests/src/Functional/NodeFormSaveChangedTimeTest.php
View source
<?php
namespace Drupal\Tests\node\Functional;
use Drupal\Tests\BrowserTestBase;
class NodeFormSaveChangedTimeTest extends BrowserTestBase {
protected static $modules = [
'node',
];
protected $defaultTheme = 'stark';
protected $authorUser;
protected function setUp() : void {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$this->authorUser = $this
->drupalCreateUser([
'access content',
'create article content',
'edit any article content',
], 'author');
$this
->drupalLogin($this->authorUser);
$this
->drupalCreateNode([
'type' => 'article',
]);
}
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.");
sleep(1);
$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.");
}
}