function NodeSaveTest::testDeterminingChanges

Tests node presave and static node load cache.

This test determines changes in hook_node_presave() and verifies that the static node load cache is cleared upon save.

File

drupal/core/modules/node/lib/Drupal/node/Tests/NodeSaveTest.php, line 136
Definition of Drupal\node\Tests\NodeSaveTest.

Class

NodeSaveTest
Tests node save related functionality, including import-save.

Namespace

Drupal\node\Tests

Code

function testDeterminingChanges() {

  // Initial creation.
  $node = entity_create('node', array(
    'uid' => $this->web_user->uid,
    '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->nid);
  $this
    ->assertEqual($node
    ->label(), 'updated_presave', 'Static cache has been cleared.');
}