You are here

multiple_node_menu.test in Multiple Node Menu 7

Tests for Multiple Node Menu module.

File

multiple_node_menu.test
View source
<?php

/**
 * @file
 * Tests for Multiple Node Menu module.
 */
class MultipleNodeMenuTestCase extends DrupalWebTestCase {
  protected $admin_user;
  public static function getInfo() {
    return array(
      'name' => 'Multiple Node Menu',
      'description' => 'Test adding, editing and deleting multiple menu links attachd to nodes.',
      'group' => 'Multiple Node Menu',
    );
  }
  function setUp() {
    parent::setUp('menu', 'multiple_node_menu');
    $this->admin_user = $this
      ->drupalCreateUser(array(
      'access administration pages',
      'administer content types',
      'administer menu',
      'create page content',
      'edit any page content',
      'delete any page content',
    ));
    $this
      ->drupalLogin($this->admin_user);
  }

  /**
   * Test creating, editing, deleting menu links via node form widget.
   */
  function testNodeFormWidget() {

    // Enable Navigation menu as available menu.
    $edit = array(
      'menu_options[navigation]' => 1,
    );
    $this
      ->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));

    // Change default parent item to Navigation menu, so we can assert more
    // easily.
    $edit = array(
      'menu_parent' => 'navigation:0',
    );
    $this
      ->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));

    // Create a node.
    $node_title = $this
      ->randomName();
    $edit = array(
      'title' => $node_title,
      'body[' . LANGUAGE_NONE . '][0][value]' => $this
        ->randomString(),
      'multiple_node_menu[enabled]' => TRUE,
      'multiple_node_menu[add_link][link_title]' => $node_title,
      'multiple_node_menu[add_link][weight]' => 5,
    );
    $this
      ->drupalPost('node/add/page', $edit, t('Save'));
    $node = $this
      ->drupalGetNodeByTitle($node_title);

    // Assert that the link exists.
    $this
      ->drupalGet('');
    $this
      ->assertLink($node_title, 0, t('Menu link is present.'));

    // Check if weight was set correctly.
    $this
      ->drupalGet('node/' . $node->nid . '/edit');
    $this
      ->assertOptionSelected('edit-multiple-node-menu-current-links-0-weight', 5, t('Menu weight correct in edit form'));

    // Add another item via Ajax.
    $new_link_title = $this
      ->randomName();
    $edit = array(
      'multiple_node_menu[add_link][link_title]' => $new_link_title,
      'multiple_node_menu[add_link][weight]' => -5,
    );
    $this
      ->drupalPostAjax(NULL, $edit, array(
      'op' => t('Add new menu link'),
    ));
    $this
      ->drupalPost(NULL, array(), t('Save'));

    // Assert that the new link exists.
    $this
      ->drupalGet('');
    $this
      ->assertLink($new_link_title, 0, t('Menu link is present.'));

    // Disable first menu item.
    $edit = array(
      'multiple_node_menu[current_links][0][enabled]' => FALSE,
    );
    $this
      ->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));

    // Assert that the first link has been hidden.
    $this
      ->drupalGet('');
    $this
      ->assertNoLink($node_title, t('Menu link was disabled.'));

    // Edit the node and remove the menu link.
    $this
      ->drupalGet('node/' . $node->nid . '/edit');
    $this
      ->drupalPostAjax(NULL, array(), array(
      'remove_1' => t('Delete'),
    ));
    $this
      ->drupalPost(NULL, array(), t('Save'));

    // Assert that there are no links to display for the node.
    $this
      ->drupalGet('');
    $this
      ->assertNoLink($node_title, t('No enabled menu links.'));
    $this
      ->assertNoLink($new_link_title, t('No enabled menu links.'));

    // Edit the node and re-enable the menu link.
    $edit = array(
      'multiple_node_menu[enabled]' => TRUE,
      'multiple_node_menu[current_links][0][enabled]' => TRUE,
    );
    $this
      ->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));

    // Assert that the link exists.
    $this
      ->drupalGet('');
    $this
      ->assertLink($node_title, 0, t('Menu link is present.'));

    // Test disabling menu links when the 'Provide menu link' checkbox is
    // unchecked.
    $edit = array(
      'multiple_node_menu[enabled]' => FALSE,
    );
    $this
      ->drupalGet('');
    $this
      ->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));

    // Assert that there are no links to display for the node.
    $this
      ->drupalGet('');
    $this
      ->assertNoLink($node_title, t('No enabled menu links.'));
  }

}

Classes

Namesort descending Description
MultipleNodeMenuTestCase @file Tests for Multiple Node Menu module.