You are here

function NodeSaveTestCase::testDeterminingChanges in Drupal 7

Tests determing changes in hook_node_presave() and verifies the static node load cache is cleared upon save.

File

modules/node/node.test, line 1413
Tests for node.module.

Class

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

Code

function testDeterminingChanges() {

  // Initial creation.
  $node = (object) array(
    'uid' => $this->web_user->uid,
    'type' => 'article',
    'title' => 'test_changes',
  );
  node_save($node);

  // Update the node without applying changes.
  node_save($node);
  $this
    ->assertEqual($node->title, 'test_changes', 'No changes have been determined.');

  // Apply changes.
  $node->title = 'updated';
  node_save($node);

  // The hook implementations node_test_node_presave() and
  // node_test_node_update() determine changes and change the title.
  $this
    ->assertEqual($node->title, 'updated_presave_update', 'Changes have been determined.');

  // Test the static node load cache to be cleared.
  $node = node_load($node->nid);
  $this
    ->assertEqual($node->title, 'updated_presave', 'Static cache has been cleared.');
}