function NodeSaveTest::testDeterminingChanges

Same name and namespace in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeSaveTest.php \Drupal\Tests\node\Functional\NodeSaveTest::testDeterminingChanges()
  2. 8.9.x core/modules/node/tests/src/Functional/NodeSaveTest.php \Drupal\Tests\node\Functional\NodeSaveTest::testDeterminingChanges()
  3. 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 151

Class

NodeSaveTest
Tests $node->save() for saving content.

Namespace

Drupal\Tests\node\Functional

Code

public function testDeterminingChanges() : void {
  // 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.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.