You are here

protected function SoftLengthLimitJavascriptTest::drupalLogin in Soft Length Limit 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()

2 calls to SoftLengthLimitJavascriptTest::drupalLogin()
SoftLengthLimitJavascriptTest::testSoftLengthLimitWithoutStyleSelect in tests/src/FunctionalJavascript/SoftLengthLimitJavascriptTest.php
Tests that the soft length limit widget works.
SoftLengthLimitJavascriptTest::testSoftLengthLimitWithStyleSelect in tests/src/FunctionalJavascript/SoftLengthLimitJavascriptTest.php
Tests that the soft length limit widget works.

File

tests/src/FunctionalJavascript/SoftLengthLimitJavascriptTest.php, line 76

Class

SoftLengthLimitJavascriptTest
Tests soft length limit JavaScript behavior for text fields.

Namespace

Drupal\Tests\soft_length_limit\FunctionalJavascript

Code

protected function drupalLogin(AccountInterface $account) {

  // This is a clone of the UiHelperTrait::drupalLogin() method,
  // which seems to make the test fail no matter what, when asserting the
  // user session.
  if ($this->loggedInUser) {
    $this
      ->drupalLogout();
  }
  $this
    ->drupalGet('user/login');
  $this
    ->submitForm([
    'name' => $account
      ->getAccountName(),
    'pass' => $account->passRaw,
  ], t('Log in'));

  // @see ::drupalUserIsLoggedIn()
  $account->sessionId = $this
    ->getSession()
    ->getCookie(\Drupal::service('session_configuration')
    ->getOptions(\Drupal::request())['name']);
  $this->loggedInUser = $account;
  $this->container
    ->get('current_user')
    ->setAccount($account);
}