You are here

public function MenuNodeAPITestCase::menuNodeAPICreateNodes in Menu Node API 7

Helper function to create menu items from nodes.

Parameters

$count: The number of nodes to create.

$items: The number of menu items to create from those nodes.

2 calls to MenuNodeAPITestCase::menuNodeAPICreateNodes()
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 27
Simpletest for Menu Node API.

Class

MenuNodeAPITestCase
Utility test class that provides methods for other tests.

Code

public function menuNodeAPICreateNodes($count = 10, $items = 3) {

  // Create some nodes.
  for ($i = 0; $i < $count; $i++) {
    $settings = array(
      'type' => 'page',
      'title' => $this
        ->randomName(32),
      'body' => array(
        LANGUAGE_NONE => array(
          array(
            $this
              ->randomName(64),
          ),
        ),
      ),
    );
    $this
      ->drupalCreateNode($settings);
  }

  // Assign some of the nodes to the menu.
  $result = db_select('node', 'n')
    ->fields('n', array(
    'nid',
  ))
    ->range(0, $items)
    ->execute();
  foreach ($result as $data) {
    $node = node_load($data->nid);
    $item = array(
      'menu_name' => 'navigation',
      'link_path' => "node/{$node->nid}",
      'link_title' => $node->title,
      'description' => '',
      'enabled' => 1,
      'expanded' => 0,
      'parent' => 'navigation' . ':' . 0,
      'weight' => '0',
    );
    menu_link_save($item);
  }
}