Commit f3434e56 authored by webchick's avatar webchick

Issue #1146244 by Dean Reilly, fago: Add tests for ensuring node is fully...

Issue #1146244 by Dean Reilly, fago: Add tests for ensuring node is fully saved when hook_node_insert() fires.
parent bbfc566c
......@@ -156,4 +156,20 @@ function testDeterminingChanges() {
$node = node_load($node->nid);
$this->assertEqual($node->label(), 'updated_presave', 'Static cache has been cleared.');
}
/**
* Tests saving a node on node insert.
*
* This test ensures that a node has been fully saved when hook_node_insert()
* is invoked, so that the node can be saved again in a hook implementation
* without errors.
*
* @see node_test_node_insert()
*/
function testNodeSaveOnInsert() {
// node_test_node_insert() tiggers a save on insert if the title equals
// 'new'.
$node = $this->drupalCreateNode(array('title' => 'new'));
$this->assertEqual($node->title, 'Node ' . $node->nid, 'Node saved on node insert.');
}
}
......@@ -161,3 +161,18 @@ function node_test_entity_view_mode_alter(&$view_mode, Drupal\Core\Entity\Entity
$view_mode = $change_view_mode;
}
}
/**
* Implements hook_node_insert().
*
* This tests saving a node on node insert.
*
* @see \Drupal\node\Tests\NodeSaveTest::testNodeSaveOnInsert()
*/
function node_test_node_insert(Node $node) {
// Set the node title to the node ID and save.
if ($node->title == 'new') {
$node->title = 'Node '. $node->nid;
node_save($node);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment