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