public function NodeSaveTest::testDeterminingChanges in Drupal 9
Same name and namespace in other branches
- 8 core/modules/node/tests/src/Functional/NodeSaveTest.php \Drupal\Tests\node\Functional\NodeSaveTest::testDeterminingChanges()
Tests node presave and static node load cache.
This test determines changes in hook_ENTITY_TYPE_presave() and verifies that the static node load cache is cleared upon save.
File
- core/
modules/ node/ tests/ src/ Functional/ NodeSaveTest.php, line 148
Class
- NodeSaveTest
- Tests $node->save() for saving content.
Namespace
Drupal\Tests\node\FunctionalCode
public function testDeterminingChanges() {
// Initial creation.
$node = Node::create([
'uid' => $this->webUser
->id(),
'type' => 'article',
'title' => 'test_changes',
]);
$node
->save();
// Update the node without applying changes.
$node
->save();
$this
->assertEquals('test_changes', $node
->label(), 'No changes have been determined.');
// Apply changes.
$node->title = 'updated';
$node
->save();
// The hook implementations node_test_node_presave() and
// node_test_node_update() determine changes and change the title.
$this
->assertEquals('updated_presave_update', $node
->label(), 'Changes have been determined.');
// Test the static node load cache to be cleared.
$node = Node::load($node
->id());
$this
->assertEquals('updated_presave', $node
->label(), 'Static cache has been cleared.');
}