You are here

function UserAccountLinksUnitTests::testDisabledAccountLink in Drupal 7

Tests disabling the 'My account' link.

File

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

Class

UserAccountLinksUnitTests
Tests user links in the secondary menu.

Code

function testDisabledAccountLink() {

  // Create an admin user and log in.
  $this
    ->drupalLogin($this
    ->drupalCreateUser(array(
    'access administration pages',
    'administer menu',
  )));

  // Verify that the 'My account' link is enabled.
  $this
    ->drupalGet('admin/structure/menu/manage/user-menu');
  $label = $this
    ->xpath('//label[contains(.,:text)]/@for', array(
    ':text' => 'Enable My account menu link',
  ));
  $this
    ->assertFieldChecked((string) $label[0], "The 'My account' link is enabled by default.");

  // Disable the 'My account' link.
  $input = $this
    ->xpath('//input[@id=:field_id]/@name', array(
    ':field_id' => (string) $label[0],
  ));
  $edit = array(
    (string) $input[0] => FALSE,
  );
  $this
    ->drupalPost('admin/structure/menu/manage/user-menu', $edit, t('Save configuration'));

  // Get the homepage.
  $this
    ->drupalGet('<front>');

  // Verify that the 'My account' link does not appear when disabled.
  $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), 0, 'My account link is not in the secondary menu.');
}