class AdminMenuCustomizedTestCase

  1. nittany7 modules/contrib/admin_menu/tests/admin_menu.test AdminMenuCustomizedTestCase
  2. cis7 modules/contrib/admin_menu/tests/admin_menu.test AdminMenuCustomizedTestCase
  3. mooc7 modules/contrib/admin_menu/tests/admin_menu.test AdminMenuCustomizedTestCase

Tests customized menu links.

Hierarchy

Expanded class hierarchy of AdminMenuCustomizedTestCase

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
AdminMenuCustomizedTestCase::getInfo public static function
AdminMenuCustomizedTestCase::queryMlidByPath protected function Returns the menu link ID for a given link path in the management menu.
AdminMenuCustomizedTestCase::setUp function Overrides AdminMenuWebTestCase::setUp
AdminMenuCustomizedTestCase::testCustomDisabled function Test disabled custom links.
AdminMenuCustomizedTestCase::testCustomExternal function Tests external links.
AdminMenuWebTestCase::$basePermissions protected property
AdminMenuWebTestCase::$profile protected property
AdminMenuWebTestCase::assertElementByXPath protected function Check that an element exists in HTML markup.
AdminMenuWebTestCase::assertLinkTrailByTitle protected function Asserts that links appear in the menu in a specified trail.
AdminMenuWebTestCase::assertNoElementByXPath protected function Check that an element does not exist in HTML markup.
AdminMenuWebTestCase::assertNoLinkTrailByTitle protected function Asserts that no link appears in the menu for a specified trail.

File

modules/contrib/admin_menu/tests/admin_menu.test, line 428
Tests for the Administration menu module.

View source
class AdminMenuCustomizedTestCase extends AdminMenuWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Customized links',
      'description' => 'Tests customized menu links.',
      'group' => 'Administration menu',
    );
  }

  function setUp() {
    parent::setUp(array('menu'));

    $this->admin_user = $this->drupalCreateUser($this->basePermissions + array(
      'administer menu',
    ));
    $this->drupalLogin($this->admin_user);
  }

  /**
   * Test disabled custom links.
   */
  function testCustomDisabled() {
    $type = $this->drupalCreateContentType();
    $node = $this->drupalCreateNode(array('type' => $type->type));
    $text = $this->randomName();
    $xpath = $this->buildXPathQuery('//div[@id=:id]//a[contains(text(), :text)]', array(
      ':id' => 'admin-menu',
      ':text' => $text,
    ));

    // Verify that the link does not appear in the menu.
    $this->drupalGet('node');
    $elements = $this->xpath($xpath);
    $this->assertFalse($elements, 'Custom link not found.');

    // Add a custom link to the node to the menu.
    $edit = array(
      'link_path' => 'node/' . $node->nid,
      'link_title' => $text,
      'parent' => 'management:' . $this->queryMlidByPath('admin'),
    );
    $this->drupalPost('admin/structure/menu/manage/management/add', $edit, t('Save'));

    // Verify that the link appears in the menu.
    $this->drupalGet('node');
    $elements = $this->xpath($xpath);
    $this->assertTrue($elements, 'Custom link found.');

    // Disable the link.
    $edit = array(
      'enabled' => FALSE,
    );
    $this->drupalPost('admin/structure/menu/item/' . $this->queryMlidByPath('node/' . $node->nid) . '/edit', $edit, t('Save'));

    // Verify that the disabled link does not appear in the menu.
    $this->drupalGet('node');
    $elements = $this->xpath($xpath);
    $this->assertFalse($elements, 'Disabled custom link not found.');
  }

  /**
   * Tests external links.
   */
  function testCustomExternal() {
    // Add a custom link to the node to the menu.
    $edit = array(
      'link_path' => 'http://example.com',
      'link_title' => 'Example',
      'parent' => 'management:' . $this->queryMlidByPath('admin'),
    );
    $this->drupalPost('admin/structure/menu/manage/management/add', $edit, t('Save'));

    // Verify that the link appears in the menu.
    $this->drupalGet('');
    $elements = $this->xpath('//div[@id=:id]//a[@href=:href and contains(text(), :text)]', array(
      ':id' => 'admin-menu',
      ':href' => $edit['link_path'],
      ':text' => $edit['link_title'],
    ));
    $this->assertTrue($elements, 'External link found.');
  }

  /**
   * Returns the menu link ID for a given link path in the management menu.
   */
  protected function queryMlidByPath($path) {
    return db_query('SELECT mlid FROM {menu_links} WHERE menu_name = :menu AND link_path = :path', array(
      ':menu' => 'management',
      ':path' => $path,
    ))->fetchField();
  }
}