1.20.x node.test NodeSaveTestCase::testImport()

Checks whether custom node IDs are saved properly during an import operation.

Workflow:

  • first create a piece of content
  • save the content
  • check if node exists

File

modules/node/tests/node.test, line 1622
Tests for node.module.

Class

NodeSaveTestCase
Tests node save related functionality, including import-save.

Code

function testImport() {
  // Node ID must be a number that is not in the database.
  $max_nid = db_query('SELECT MAX(nid) FROM {node}')->fetchField();
  $test_nid = $max_nid + mt_rand(1000, 1000000);
  $title = $this->randomName(8);
  $node = array(
    'title' => $title,
    'body' => array(LANGUAGE_NONE => array(array('value' => $this->randomName(32)))),
    'uid' => $this->web_user->uid,
    'type' => 'post',
    'nid' => $test_nid,
    'is_new' => TRUE,
  );
  $node = node_submit(entity_create('node', $node));

  // Verify that node_submit did not overwrite the user ID.
  $this->assertEqual($node->uid, $this->web_user->uid, 'Function node_submit() preserves user ID');

  $node->save();
  // Test the import.
  $node_by_nid = node_load($test_nid);
  $this->assertTrue($node_by_nid, 'Node load by node ID.');

  $node_by_title = $this->backdropGetNodeByTitle($title);
  $this->assertTrue($node_by_title, 'Node load by node title.');
}