You are here

protected function EmailRegistrationLoginTest::drupalLogin in Email Registration 8

Logs in a user using the Mink controlled browser.

If a user is already logged in, then the current user is logged out before logging in the specified user.

Please note that neither the current user nor the passed-in user object is populated with data of the logged in user. If you need full access to the user object after logging in, it must be updated manually. If you also need access to the plain-text password of the user (set by drupalCreateUser()), e.g. to log in the same user again, then it must be re-assigned manually. For example:

// Create a user.
$account = $this
  ->drupalCreateUser(array());
$this
  ->drupalLogin($account);

// Load real user object.
$pass_raw = $account->passRaw;
$account = User::load($account
  ->id());
$account->passRaw = $pass_raw;

Parameters

\Drupal\Core\Session\AccountInterface $account: User object representing the user to log in.

Overrides UiHelperTrait::drupalLogin

See also

drupalCreateUser()

File

tests/src/Functional/Plugin/Commerce/CheckoutPane/EmailRegistrationLoginTest.php, line 249

Class

EmailRegistrationLoginTest
Tests the login checkout pane.

Namespace

Drupal\Tests\email_registration\Functional\Plugin\Commerce\CheckoutPane

Code

protected function drupalLogin(AccountInterface $account) {
  if ($this->loggedInUser) {
    $this
      ->drupalLogout();
  }
  $this
    ->drupalGet('user/login');
  $this
    ->submitForm([
    'mail' => $account
      ->getEmail(),
    'pass' => $account->passRaw,
  ], t('Log in'));
  $this
    ->assertLoggedIn($account);
}