public function UserAccountLinksTest::testSecondaryMenu in Drupal 8
Same name and namespace in other branches
- 9 core/modules/user/tests/src/Functional/UserAccountLinksTest.php \Drupal\Tests\user\Functional\UserAccountLinksTest::testSecondaryMenu()
- 10 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".
$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.');
}