Issue #1146244 by Dean Reilly, fago: Add tests for ensuring node is fully saved when hook_node_insert() fires.

8.0.x
webchick 2012-10-23 19:37:55 -07:00
parent bbfc566c7f
commit f3434e569f
2 changed files with 31 additions and 0 deletions

View File

@ -156,4 +156,20 @@ class NodeSaveTest extends NodeTestBase {
$node = node_load($node->nid); $node = node_load($node->nid);
$this->assertEqual($node->label(), 'updated_presave', 'Static cache has been cleared.'); $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.');
}
} }

View File

@ -161,3 +161,18 @@ function node_test_entity_view_mode_alter(&$view_mode, Drupal\Core\Entity\Entity
$view_mode = $change_view_mode; $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);
}
}