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. 10 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() {
    // 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".
    $link = $this->xpath('//ul[@class=:menu_class]/li/a[contains(@href, :href) and text()=:text]', [
        ':menu_class' => 'menu',
        ':href' => 'user',
        ':text' => 'My account',
    ]);
    $this->assertCount(1, $link, 'My account link is in secondary menu.');
    $link = $this->xpath('//ul[@class=:menu_class]/li/a[contains(@href, :href) and text()=:text]', [
        ':menu_class' => 'menu',
        ':href' => 'user/logout',
        ':text' => 'Log out',
    ]);
    $this->assertCount(1, $link, 'Log out link is in secondary menu.');
    // 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.
    $link = $this->xpath('//ul[@class=:menu_class]/li/a[contains(@href, :href) and text()=:text]', [
        ':menu_class' => 'menu',
        ':href' => 'user/login',
        ':text' => 'Log in',
    ]);
    $this->assertCount(1, $link, 'Log in link is in secondary menu.');
}

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