function NodeSaveTest::testDeterminingChanges
Same name in other branches
- 9 core/modules/node/tests/src/Functional/NodeSaveTest.php \Drupal\Tests\node\Functional\NodeSaveTest::testDeterminingChanges()
- 10 core/modules/node/tests/src/Functional/NodeSaveTest.php \Drupal\Tests\node\Functional\NodeSaveTest::testDeterminingChanges()
- 11.x 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 147
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->assertEqual($node->label(), 'test_changes', '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->assertEqual($node->label(), 'updated_presave_update', 'Changes have been determined.');
// Test the static node load cache to be cleared.
$node = Node::load($node->id());
$this->assertEqual($node->label(), 'updated_presave', 'Static cache has been cleared.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.