You are here

public function MenuNodeAPITestCase::menuNodeAPIDeleteNode in Menu Node API 7

Helper function to delete a random node.

Parameters

$in_menu: Selects a node in the menu (or not).

2 calls to MenuNodeAPITestCase::menuNodeAPIDeleteNode()
MenuNodeAPIBasicTestCase::testMenuNodeAPI in tests/menu_node.test
Tests for basic internal module functions.
MenuNodeAPIHookTestCase::testMenuNodeAPIHooks in tests/menu_node.test
Run tests against the menu_node_test.module.

File

tests/menu_node.test, line 86
Simpletest for Menu Node API.

Class

MenuNodeAPITestCase
Utility test class that provides methods for other tests.

Code

public function menuNodeAPIDeleteNode($in_menu = TRUE) {
  $query = db_select('node', 'n')
    ->fields('n', array(
    'nid',
  ))
    ->range(0, 1);
  if ($in_menu) {
    $query
      ->join('menu_node', 'mn', 'n.nid = mn.nid');
  }
  else {
    $query
      ->join('menu_node', 'mn', 'n.nid = mn.nid AND mn.nid IS NULL');
  }
  $result = $query
    ->execute();
  foreach ($result as $data) {

    // Ensure we have a fresh copy of the node.
    // In normal, form-based Drupal, the cache clear handles this, but SimpleTest
    // runs our functions on a single callback.
    $node = node_load($data->nid, NULL, TRUE);
    node_delete($node->nid);
  }
}