function NodeSaveTest::testNodeSaveOnInsert

Same name in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeSaveTest.php \Drupal\Tests\node\Functional\NodeSaveTest::testNodeSaveOnInsert()
  2. 10 core/modules/node/tests/src/Functional/NodeSaveTest.php \Drupal\Tests\node\Functional\NodeSaveTest::testNodeSaveOnInsert()
  3. 11.x 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.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.