1 backdrop_web_test_case.php protected BackdropWebTestCase::backdropLogin($account, $by_email = FALSE)

Log in a user with the internal 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 global $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 backdropCreateUser()), e.g. to log in the same user again, then it must be re-assigned manually. For example:

  // Create a user.
  $account = $this->backdropCreateUser(array());
  // Load real user object.
  $pass_raw = $account->pass_raw;
  $account = user_load($account->uid);
  $account->pass_raw = $pass_raw;


$account: User object representing the user to log in.

$by_email: Whether to use email for login instead of username.

See also



core/modules/simpletest/backdrop_web_test_case.php, line 1443


Test case for typical Backdrop tests.


protected function backdropLogin($account, $by_email = FALSE) {
  global $user;
  if ($this->loggedInUser) {
  // Sometimes $this->loggedInUser is FALSE even when user is logged in.
  elseif ($user->uid) {

  $edit = array(
    'name' => $by_email ? $account->mail : $account->name,
    'pass' => $account->pass_raw
  $this->backdropPost('user/login', $edit, t('Log in'));

  // Check for the logged-in class.
  $result = $this->xpath('/html/body[contains(@class, "logged-in")]');
  $pass = $this->assertEqual(count($result), 1, t('User %name successfully logged in.', array('%name' => $account->name)), t('User login'));

  if ($pass) {
    $this->loggedInUser = $account;