public function UserAccountLinksTest::testSecondaryMenu in Drupal 9
Same name and namespace in other branches
- 8 core/modules/user/tests/src/Functional/UserAccountLinksTest.php \Drupal\Tests\user\Functional\UserAccountLinksTest::testSecondaryMenu()
Tests the secondary menu.
File
- core/
modules/ user/ tests/ src/ Functional/ UserAccountLinksTest.php, line 39
Class
- UserAccountLinksTest
- Tests user-account links.
Namespace
Drupal\Tests\user\FunctionalCode
public function testSecondaryMenu() {
// Create a regular user.
$user = $this
->drupalCreateUser([]);
// 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".
$this
->assertSession()
->elementsCount('xpath', '//ul[@class="menu"]/li/a[contains(@href, "user") and text()="My account"]', 1);
$this
->assertSession()
->elementsCount('xpath', '//ul[@class="menu"]/li/a[contains(@href, "user/logout") and text()="Log out"]', 1);
// Log out and get the homepage.
$this
->drupalLogout();
$this
->drupalGet('<front>');
// For a logged-out user, expect the secondary menu to have a "Log in" link.
$this
->assertSession()
->elementsCount('xpath', '//ul[@class="menu"]/li/a[contains(@href, "user/login") and text()="Log in"]', 1);
}