You are here

public function NodeSaveTest::testNodeSaveOnInsert in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeSaveTest.php \Drupal\Tests\node\Functional\NodeSaveTest::testNodeSaveOnInsert()

Tests saving a node on node insert.

This test ensures that a node has been fully saved when hook_ENTITY_TYPE_insert() is invoked, so that the node can be saved again in a hook implementation without errors.

See also

node_test_node_insert()

File

core/modules/node/tests/src/Functional/NodeSaveTest.php, line 182

Class

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

Namespace

Drupal\Tests\node\Functional

Code

public function testNodeSaveOnInsert() {

  // node_test_node_insert() triggers a save on insert if the title equals
  // 'new'.
  $node = $this
    ->drupalCreateNode([
    'title' => 'new',
  ]);
  $this
    ->assertEqual($node
    ->getTitle(), 'Node ' . $node
    ->id(), 'Node saved on node insert.');
}