Chris@14: drupalPlaceBlock('system_menu_block:account'); Chris@14: // Make test-page default. Chris@14: $this->config('system.site')->set('page.front', '/test-page')->save(); Chris@14: } Chris@14: Chris@14: /** Chris@14: * Tests the secondary menu. Chris@14: */ Chris@14: public function testSecondaryMenu() { Chris@14: // Create a regular user. Chris@14: $user = $this->drupalCreateUser([]); Chris@14: Chris@14: // Log in and get the homepage. Chris@14: $this->drupalLogin($user); Chris@14: $this->drupalGet(''); Chris@14: Chris@14: // For a logged-in user, expect the secondary menu to have links for "My Chris@14: // account" and "Log out". Chris@14: $link = $this->xpath('//ul[@class=:menu_class]/li/a[contains(@href, :href) and text()=:text]', [ Chris@14: ':menu_class' => 'menu', Chris@14: ':href' => 'user', Chris@14: ':text' => 'My account', Chris@14: ]); Chris@14: $this->assertEqual(count($link), 1, 'My account link is in secondary menu.'); Chris@14: Chris@14: $link = $this->xpath('//ul[@class=:menu_class]/li/a[contains(@href, :href) and text()=:text]', [ Chris@14: ':menu_class' => 'menu', Chris@14: ':href' => 'user/logout', Chris@14: ':text' => 'Log out', Chris@14: ]); Chris@14: $this->assertEqual(count($link), 1, 'Log out link is in secondary menu.'); Chris@14: Chris@14: // Log out and get the homepage. Chris@14: $this->drupalLogout(); Chris@14: $this->drupalGet(''); Chris@14: Chris@14: // For a logged-out user, expect the secondary menu to have a "Log in" link. Chris@14: $link = $this->xpath('//ul[@class=:menu_class]/li/a[contains(@href, :href) and text()=:text]', [ Chris@14: ':menu_class' => 'menu', Chris@14: ':href' => 'user/login', Chris@14: ':text' => 'Log in', Chris@14: ]); Chris@14: $this->assertEqual(count($link), 1, 'Log in link is in secondary menu.'); Chris@14: } Chris@14: Chris@14: /** Chris@14: * Tests disabling the 'My account' link. Chris@14: */ Chris@14: public function testDisabledAccountLink() { Chris@14: // Create an admin user and log in. Chris@14: $this->drupalLogin($this->drupalCreateUser(['access administration pages', 'administer menu'])); Chris@14: Chris@14: // Verify that the 'My account' link exists before we check for its Chris@14: // disappearance. Chris@14: $link = $this->xpath('//ul[@class=:menu_class]/li/a[contains(@href, :href) and text()=:text]', [ Chris@14: ':menu_class' => 'menu', Chris@14: ':href' => 'user', Chris@14: ':text' => 'My account', Chris@14: ]); Chris@14: $this->assertEqual(count($link), 1, 'My account link is in the secondary menu.'); Chris@14: Chris@14: // Verify that the 'My account' link is enabled. Do not assume the value of Chris@14: // auto-increment is 1. Use XPath to obtain input element id and name using Chris@14: // the consistent label text. Chris@14: $this->drupalGet('admin/structure/menu/manage/account'); Chris@14: $label = $this->xpath('//label[contains(.,:text)]/@for', [':text' => 'Enable My account menu link']); Chris@14: $this->assertFieldChecked($label[0]->getText(), "The 'My account' link is enabled by default."); Chris@14: Chris@14: // Disable the 'My account' link. Chris@14: $edit['links[menu_plugin_id:user.page][enabled]'] = FALSE; Chris@14: $this->drupalPostForm('admin/structure/menu/manage/account', $edit, t('Save')); Chris@14: Chris@14: // Get the homepage. Chris@14: $this->drupalGet(''); Chris@14: Chris@14: // Verify that the 'My account' link does not appear when disabled. Chris@14: $link = $this->xpath('//ul[@class=:menu_class]/li/a[contains(@href, :href) and text()=:text]', [ Chris@14: ':menu_class' => 'menu', Chris@14: ':href' => 'user', Chris@14: ':text' => 'My account', Chris@14: ]); Chris@14: $this->assertEqual(count($link), 0, 'My account link is not in the secondary menu.'); Chris@14: } Chris@14: Chris@14: /** Chris@14: * Tests page title is set correctly on user account tabs. Chris@14: */ Chris@14: public function testAccountPageTitles() { Chris@14: // Default page titles are suffixed with the site name - Drupal. Chris@14: $title_suffix = ' | Drupal'; Chris@14: Chris@14: $this->drupalGet('user'); Chris@14: $this->assertTitle('Log in' . $title_suffix, "Page title of /user is 'Log in'"); Chris@14: Chris@14: $this->drupalGet('user/login'); Chris@14: $this->assertTitle('Log in' . $title_suffix, "Page title of /user/login is 'Log in'"); Chris@14: Chris@14: $this->drupalGet('user/register'); Chris@14: $this->assertTitle('Create new account' . $title_suffix, "Page title of /user/register is 'Create new account' for anonymous users."); Chris@14: Chris@14: $this->drupalGet('user/password'); Chris@14: $this->assertTitle('Reset your password' . $title_suffix, "Page title of /user/register is 'Reset your password' for anonymous users."); Chris@14: Chris@14: // Check the page title for registered users is "My Account" in menus. Chris@14: $this->drupalLogin($this->drupalCreateUser()); Chris@14: // After login, the client is redirected to /user. Chris@14: $this->assertLink(t('My account'), 0, "Page title of /user is 'My Account' in menus for registered users"); Chris@14: $this->assertLinkByHref(\Drupal::urlGenerator()->generate('user.page'), 0); Chris@14: } Chris@14: Chris@14: }