function UserAccountLinksTest::testSecondaryMenu

Same name in other branches
  1. 9 core/modules/user/tests/src/Functional/UserAccountLinksTest.php \Drupal\Tests\user\Functional\UserAccountLinksTest::testSecondaryMenu()
  2. 8.9.x core/modules/user/tests/src/Functional/UserAccountLinksTest.php \Drupal\Tests\user\Functional\UserAccountLinksTest::testSecondaryMenu()
  3. 11.x 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\Functional

Code

public function testSecondaryMenu() : void {
    // 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', '//nav[@id="block-user-account-links-test-system-menu-block-account"]/ul/li/a[contains(@href, "user") and text()="My account"]', 1);
    $this->assertSession()
        ->elementsCount('xpath', '//nav[@id="block-user-account-links-test-system-menu-block-account"]/ul/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', '//nav[@id="block-user-account-links-test-system-menu-block-account"]/ul/li/a[contains(@href, "user/login") and text()="Log in"]', 1);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.