You are here

protected function UserLoginTest::drupalLoginUsingEmail in farmOS 2.x

A helper function to login using an email.

Parameters

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

See also

drupalLogin()

drupalCreateUser()

1 call to UserLoginTest::drupalLoginUsingEmail()
UserLoginTest::testPerUserLoginFloodControl in modules/core/login/tests/src/Functional/UserLoginTest.php
Test the per-user login flood control.

File

modules/core/login/tests/src/Functional/UserLoginTest.php, line 181

Class

UserLoginTest
Test using an email in the UserLoginForm.

Namespace

Drupal\Tests\farm_login\Functional

Code

protected function drupalLoginUsingEmail(AccountInterface $account) {
  if ($this->loggedInUser) {
    $this
      ->drupalLogout();
  }
  $this
    ->drupalGet(Url::fromRoute('user.login'));
  $this
    ->submitForm([
    'name' => $account
      ->getEmail(),
    'pass' => $account->passRaw,
  ], $this
    ->t('Log in'));

  // @see ::drupalUserIsLoggedIn()
  $account->sessionId = $this
    ->getSession()
    ->getCookie(\Drupal::service('session_configuration')
    ->getOptions(\Drupal::request())['name']);
  $this
    ->assertTrue($this
    ->drupalUserIsLoggedIn($account), new FormattableMarkup('User %name successfully logged in.', [
    '%name' => $account
      ->getAccountName(),
  ]));
  $this->loggedInUser = $account;
  $this->container
    ->get('current_user')
    ->setAccount($account);
}