You are here

public function UserAccountLinksTest::testAccountPageTitles in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/user/tests/src/Functional/UserAccountLinksTest.php \Drupal\Tests\user\Functional\UserAccountLinksTest::testAccountPageTitles()

Tests page title is set correctly on user account tabs.

File

core/modules/user/tests/src/Functional/UserAccountLinksTest.php, line 96

Class

UserAccountLinksTest
Tests user-account links.

Namespace

Drupal\Tests\user\Functional

Code

public function testAccountPageTitles() {

  // Default page titles are suffixed with the site name - Drupal.
  $title_suffix = ' | Drupal';
  $this
    ->drupalGet('user');
  $this
    ->assertSession()
    ->titleEquals('Log in' . $title_suffix);
  $this
    ->drupalGet('user/login');
  $this
    ->assertSession()
    ->titleEquals('Log in' . $title_suffix);
  $this
    ->drupalGet('user/register');
  $this
    ->assertSession()
    ->titleEquals('Create new account' . $title_suffix);
  $this
    ->drupalGet('user/password');
  $this
    ->assertSession()
    ->titleEquals('Reset your password' . $title_suffix);

  // Check the page title for registered users is "My Account" in menus.
  $this
    ->drupalLogin($this
    ->drupalCreateUser());

  // After login, the client is redirected to /user.
  $this
    ->assertSession()
    ->linkExists('My account', 0, "Page title of /user is 'My Account' in menus for registered users");
  $this
    ->assertSession()
    ->linkByHrefExists(\Drupal::urlGenerator()
    ->generate('user.page'), 0);
}