class NodeFormSaveChangedTimeTest
Same name and namespace in other branches
- 11.x core/modules/node/tests/src/Functional/NodeFormSaveChangedTimeTest.php \Drupal\Tests\node\Functional\NodeFormSaveChangedTimeTest
- 10 core/modules/node/tests/src/Functional/NodeFormSaveChangedTimeTest.php \Drupal\Tests\node\Functional\NodeFormSaveChangedTimeTest
- 8.9.x core/modules/node/tests/src/Functional/NodeFormSaveChangedTimeTest.php \Drupal\Tests\node\Functional\NodeFormSaveChangedTimeTest
Tests updating the changed time after API and FORM entity save.
@group node
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\node\Functional\NodeFormSaveChangedTimeTest extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of NodeFormSaveChangedTimeTest
File
-
core/
modules/ node/ tests/ src/ Functional/ NodeFormSaveChangedTimeTest.php, line 12
Namespace
Drupal\Tests\node\FunctionalView source
class NodeFormSaveChangedTimeTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'node',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* A user with permissions to create and edit articles.
*
* @var \Drupal\user\UserInterface
*/
protected $authorUser;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Create a node type.
$this->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$this->authorUser = $this->drupalCreateUser([
'access content',
'create article content',
'edit any article content',
], 'author');
$this->drupalLogin($this->authorUser);
// Create one node of the above node type .
$this->drupalCreateNode([
'type' => 'article',
]);
}
/**
* Tests the changed time after API and FORM save without changes.
*/
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.");
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.