1 user.test UserLoginTestBase::assertFailedLogin($account, $by_email = FALSE, $incorrect_pass = FALSE, $flood_trigger = NULL)

Make an unsuccessful login attempt.

Parameters

User $account: A user object with name and pass_raw attributes for the login attempt.

bool $by_email: Fail with an incorrect email instead of username.

$incorrect_pass: Fail because of an incorrect password.

$flood_trigger: Whether or not to expect that the flood control mechanism will be triggered..

File

core/modules/user/tests/user.test, line 25
Tests for user.module.

Class

UserLoginTestBase

Code

function assertFailedLogin($account, $by_email = FALSE, $incorrect_pass = FALSE, $flood_trigger = NULL) {
  if ($this->loggedInUser) {
    $this->backdropLogout();
  }
  $edit = array(
    'name' => $by_email ? $account->mail : $account->name,
    'pass' => $account->pass_raw,
  );
  $this->backdropPost('user', $edit, t('Log in'));
  $this->assertNoFieldByXPath("//input[@name='pass' and @value!='']", NULL, 'Password value attribute is blank.');
  if (isset($flood_trigger)) {
    if ($flood_trigger == 'user') {
      $this->assertRaw(format_plural(config_get('user.flood', 'flood_user_limit'), 'Sorry, there has been more than one failed login attempt for this account. It is temporarily blocked. Try again later or <a href="@url">request a new password</a>.', 'Sorry, there have been more than @count failed login attempts for this account. It is temporarily blocked. Try again later or <a href="@url">request a new password</a>.', array('@url' => url('user/password'))));
    }
    else {
      // No uid, so the limit is IP-based.
      $this->assertRaw(t('Sorry, too many failed login attempts from your IP address. This IP address is temporarily blocked. Try again later or <a href="@url">request a new password</a>.', array('@url' => url('user/password'))));
    }
  }
  elseif ($incorrect_pass) {
    $this->assertRaw(t('Sorry, incorrect password. <a href="@password">Have you forgotten your password?</a>', array('@password' => url('user/password', array('query' => array('name' => $edit['name']))))));
  }
  else {
    $login_method = config_get('system.core', 'user_login_method');
    switch ($login_method) {
      case USER_LOGIN_EMAIL_ONLY:
        if (!$by_email) {
          $this->assertRaw(t('The e-mail address %email is not valid.', array('%email' => $account->name)));
        }
        else {
          $this->assertRaw(t('Sorry, no account with that email address found.'));
        }
        break;
      case USER_LOGIN_USERNAME_OR_EMAIL:
        if (!$by_email) {
          $this->assertRaw(t('Sorry, unrecognized username.'));
        }
        else {
          $this->assertRaw(t('Sorry, no account with that email address found.'));
        }
        break;
      case USER_LOGIN_USERNAME_ONLY:
      default:
        $this->assertRaw(t('Sorry, unrecognized username.'));
    }
  }
}