1 node.test NodeLoadHooksTestCase::testHookNodeLoad()

Tests that hook_node_load() is invoked correctly.

File

core/modules/node/tests/node.test, line 122
Tests for node.module.

Class

NodeLoadHooksTestCase
Tests for the hooks invoked during node_load().

Code

function testHookNodeLoad() {
  // Create some sample posts and pages.
  $node1 = $this->backdropCreateNode(array('type' => 'post', 'status' => NODE_PUBLISHED));
  $node2 = $this->backdropCreateNode(array('type' => 'post', 'status' => NODE_PUBLISHED));
  $node3 = $this->backdropCreateNode(array('type' => 'post', 'status' => NODE_NOT_PUBLISHED));
  $node4 = $this->backdropCreateNode(array('type' => 'page', 'status' => NODE_NOT_PUBLISHED));

  // Check that when a set of nodes that only contains posts is loaded,
  // the properties added to the node by node_test_node_load() correctly
  // reflect the expected values.
  $nodes = node_load_multiple(array(), array('status' => NODE_PUBLISHED));
  $loaded_node = end($nodes);
  $this->assertEqual($loaded_node->node_test_loaded_nids, array($node1->nid, $node2->nid), 'hook_node_load() received the correct list of node IDs the first time it was called.');
  $this->assertEqual($loaded_node->node_test_loaded_types, array('post'), 'hook_node_load() received the correct list of node types the first time it was called.');

  // Now, as part of the same page request, load a set of nodes that contain
  // both posts and pages, and make sure the parameters passed to
  // node_test_node_load() are correctly updated.
  $nodes = node_load_multiple(array(), array('status' => NODE_NOT_PUBLISHED));
  $loaded_node = end($nodes);
  $this->assertEqual($loaded_node->node_test_loaded_nids, array($node3->nid, $node4->nid), 'hook_node_load() received the correct list of node IDs the second time it was called.');
  $this->assertEqual($loaded_node->node_test_loaded_types, array('page', 'post'), 'hook_node_load() received the correct list of node types the second time it was called.');
}