You are here

public function UserAccountLinksTest::testDisabledAccountLink in Drupal 9

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

Tests disabling the 'My account' link.

File

core/modules/user/tests/src/Functional/UserAccountLinksTest.php, line 63

Class

UserAccountLinksTest
Tests user-account links.

Namespace

Drupal\Tests\user\Functional

Code

public function testDisabledAccountLink() {

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

  // Verify that the 'My account' link exists before we check for its
  // disappearance.
  $this
    ->assertSession()
    ->elementsCount('xpath', '//ul[@class="menu"]/li/a[contains(@href, "user") and text()="My account"]', 1);

  // 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', [
    ':text' => 'Enable My account menu link',
  ]);
  $this
    ->assertSession()
    ->checkboxChecked($label[0]
    ->getText());

  // Disable the 'My account' link.
  $edit['links[menu_plugin_id:user.page][enabled]'] = FALSE;
  $this
    ->drupalGet('admin/structure/menu/manage/account');
  $this
    ->submitForm($edit, 'Save');

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

  // Verify that the 'My account' link does not appear when disabled.
  $this
    ->assertSession()
    ->elementNotExists('xpath', '//ul[@class="menu"]/li/a[contains(@href, "user") and text()="My account"]');
}