You are here

public function NodeSaveTest::testNodeSaveOnInsert in Drupal 9

Same name and namespace in other branches
  1. 8 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 183

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
    ->assertEquals('Node ' . $node
    ->id(), $node
    ->getTitle(), 'Node saved on node insert.');
}