function UserAccountLinksTest::testDisabledAccountLink
Same name in other branches
- 8.9.x core/modules/user/tests/src/Functional/UserAccountLinksTest.php \Drupal\Tests\user\Functional\UserAccountLinksTest::testDisabledAccountLink()
- 10 core/modules/user/tests/src/Functional/UserAccountLinksTest.php \Drupal\Tests\user\Functional\UserAccountLinksTest::testDisabledAccountLink()
- 11.x 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\FunctionalCode
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', '//nav[@id="block-user-account-links-test-system-menu-block-account"]/ul/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', '//nav[@id="block-user-account-links-test-system-menu-block-account"]/ul/li/a[contains(@href, "user") and text()="My account"]');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.