You are here

function UserAccountLinksTest::testDisabledAccountLink in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/user/src/Tests/UserAccountLinksTest.php \Drupal\user\Tests\UserAccountLinksTest::testDisabledAccountLink()

Tests disabling the 'My account' link.

File

core/modules/user/src/Tests/UserAccountLinksTest.php, line 79
Contains \Drupal\user\Tests\UserAccountLinksTest.

Class

UserAccountLinksTest
Tests user-account links.

Namespace

Drupal\user\Tests

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 exists before we check for its
  // disappearance.
  $link = $this
    ->xpath('//ul[@class=:menu_class]/li/a[contains(@href, :href) and text()=:text]', array(
    ':menu_class' => 'menu',
    ':href' => 'user',
    ':text' => 'My account',
  ));
  $this
    ->assertEqual(count($link), 1, 'My account link is in the secondary menu.');

  // Verify that the 'My account' link is enabled. Do not assume the value of
  // auto-increment is 1. Use XPath to obtain input element id and name using
  // the consistent label text.
  $this
    ->drupalGet('admin/structure/menu/manage/account');
  $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.
  $edit['links[menu_plugin_id:user.page][enabled]'] = FALSE;
  $this
    ->drupalPostForm('admin/structure/menu/manage/account', $edit, t('Save'));

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

  // Verify that the 'My account' link does not appear when disabled.
  $link = $this
    ->xpath('//ul[@class=:menu_class]/li/a[contains(@href, :href) and text()=:text]', array(
    ':menu_class' => 'menu',
    ':href' => 'user',
    ':text' => 'My account',
  ));
  $this
    ->assertEqual(count($link), 0, 'My account link is not in the secondary menu.');
}