You are here

public function UserAccountLinksTest::testSecondaryMenu in Drupal 10

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

  // 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);
}