NodeSaveTestCase::testImport

7 node.test NodeSaveTestCase::testImport()
8 node.test NodeSaveTestCase::testImport()

Import test, to check if custom node ids are saved properly. Workflow:

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

File

modules/node/node.test, line 1158
Tests for node.module.

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' => 'article', 
    'nid' => $test_nid, 
    'is_new' => TRUE,
  );
  $node = node_submit((object) $node);

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

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

  $node_by_title = $this->drupalGetNodeByTitle($title);
  $this->assertTrue($node_by_title, t('Node load by node title.'));
}
Login or register to post comments