You are here

function UserAccountLinksUnitTests::testSecondaryMenu in Drupal 7

Tests the secondary menu.

File

modules/user/user.test, line 1876
Tests for user.module.

Class

UserAccountLinksUnitTests
Tests user links in the secondary menu.

Code

function testSecondaryMenu() {

  // Create a regular user.
  $user = $this
    ->drupalCreateUser(array());

  // Log in and get the homepage.
  $this
    ->drupalLogin($user);
  $this
    ->drupalGet('<front>');

  // For a logged-in user, expect the secondary menu to have links for "My
  // account" and "Log out".
  $link = $this
    ->xpath('//ul[@id=:menu_id]/li/a[contains(@href, :href) and text()=:text]', array(
    ':menu_id' => 'secondary-menu-links',
    ':href' => 'user',
    ':text' => 'My account',
  ));
  $this
    ->assertEqual(count($link), 1, 'My account link is in secondary menu.');
  $link = $this
    ->xpath('//ul[@id=:menu_id]/li/a[contains(@href, :href) and text()=:text]', array(
    ':menu_id' => 'secondary-menu-links',
    ':href' => 'user/logout',
    ':text' => 'Log out',
  ));
  $this
    ->assertEqual(count($link), 1, 'Log out link is in secondary menu.');

  // Log out and get the homepage.
  $this
    ->drupalLogout();
  $this
    ->drupalGet('<front>');

  // For a logged-out user, expect no secondary links.
  $element = $this
    ->xpath('//ul[@id=:menu_id]', array(
    ':menu_id' => 'secondary-menu-links',
  ));
  $this
    ->assertEqual(count($element), 0, 'No secondary-menu for logged-out users.');
}