You are here

function og_menu_singleMenuItemNodeCreateTest::testMenuLinkCreated in OG Menu Single 7

Test skipping OgBehaviorHandler.

File

tests/og_menu_singleBase.test, line 41
Provides a base unit test class.

Class

og_menu_singleMenuItemNodeCreateTest

Code

function testMenuLinkCreated() {
  $user1 = $this
    ->drupalCreateUser(array(
    'administer group',
    'access content',
    'create post content',
    'administer menu',
  ));

  // Create group nodes.
  $settings = array(
    'type' => 'group',
    'uid' => $user1->uid,
  );
  $posts = array();
  $group1 = $this
    ->drupalCreateNode($settings);
  $this
    ->drupalLogin($user1);
  $group1_mlid = og_menu_single_get_link_mlid('node', $group1->nid);
  $posts[0] = $this
    ->createPostInGroup($group1, $user1, 'post');
  $this
    ->drupalGet("node/" . $posts[0]->nid . "/edit");
  $this
    ->assertOption('edit-menu-parent', OG_MENU_SINGLE_MENU_NAME . ':' . $group1_mlid, t('Option to add to group menu exists'));
  $posts[1] = $this
    ->createPostInGroup($group1, $user1, 'post_no_menu');
  $this
    ->drupalGet("node/" . $posts[1]->nid . "/edit");
  $this
    ->assertOption('edit-menu-parent', OG_MENU_SINGLE_MENU_NAME . ':' . $group1_mlid, t('Option to add to group menu exists when no regular menus enabled'));

  // Add both posts to menu.
  foreach ($posts as $key => $post) {
    $this
      ->addPostToMenu($post, $group1_mlid);
    $posts[$key]->mlid = og_menu_single_get_link_mlid('node', $posts[$key]->nid);
  }

  // Check that a new post in group has both menu links.
  $posts[2] = $this
    ->createPostInGroup($group1, $user1, 'post');
  $this
    ->drupalGet("node/" . $posts[2]->nid . "/edit");
  $this
    ->assertOption('edit-menu-parent', OG_MENU_SINGLE_MENU_NAME . ':' . $posts[0]->mlid, t('Menu link appears for post'));
  $this
    ->assertOption('edit-menu-parent', OG_MENU_SINGLE_MENU_NAME . ':' . $posts[1]->mlid, t('Menu link appears for post'));

  // Add posts below each menu
  for ($i = 0; $i < 2; $i++) {
    $posts[$i]->children_posts = array();
    for ($j = 0; $j < 2; $j++) {
      $posts[$i]->children_posts[$j] = $this
        ->createPostInGroup($group1, $user1, 'post');
      $this
        ->addPostToMenu($posts[$i]->children_posts[$j], $posts[$i]->mlid);
    }
    $this
      ->drupalGet("node/" . $posts[2]->nid . "/edit");
    $options = $this
      ->gatherMenuOptions();
    foreach ($posts[$i]->children_posts as $child_post) {
      $child_mlid = og_menu_single_get_link_mlid('node', $child_post->nid);
      $this
        ->assertOption('edit-menu-parent', OG_MENU_SINGLE_MENU_NAME . ':' . $child_mlid, t('Menu link appears for post as child'), '---- ' . check_plain($child_post->title));
      $this
        ->assertTrue(!empty($options[$posts[$i]->mlid][$child_mlid]), t('Child option has correct parent'));
    }
  }
  $settings = array(
    'type' => 'group',
    'uid' => $user1->uid,
  );
  $group2 = $this
    ->drupalCreateNode($settings);
  $group2_posts = array();
  $group2_mlid = og_menu_single_get_link_mlid('node', $group2->nid);
  $group2_posts[0] = $this
    ->createPostInGroup($group2, $user1, 'post');
  $this
    ->drupalGet("node/" . $group2_posts[0]->nid . "/edit");
  $this
    ->assertOption('edit-menu-parent', OG_MENU_SINGLE_MENU_NAME . ':' . $group2_mlid, t('Option to add to group menu exists'));
  $this
    ->assertNoOption('edit-menu-parent', OG_MENU_SINGLE_MENU_NAME . ':' . $group1_mlid, t('Option to add to a different group does not exist'));
}