Issue #1146244 by Dean Reilly, fago: Add tests for ensuring node is fully saved when hook_node_insert() fires.
parent
bbfc566c7f
commit
f3434e569f
|
@ -156,4 +156,20 @@ class NodeSaveTest extends NodeTestBase {
|
|||
$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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue