You are here

function NodeSaveTest::testDeterminingChanges in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/node/src/Tests/NodeSaveTest.php \Drupal\node\Tests\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/src/Tests/NodeSaveTest.php, line 145
Contains \Drupal\node\Tests\NodeSaveTest.

Class

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

Namespace

Drupal\node\Tests

Code

function testDeterminingChanges() {

  // Initial creation.
  $node = entity_create('node', array(
    '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.');
}