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 29 - Tests for user.module.
Class
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)) {
$this->assertResponse(403);
$user_log = db_query_range('SELECT message FROM {watchdog} WHERE type = :type ORDER BY wid DESC', 0, 1, array(':type' => 'user'))->fetchField();
$user_flood_test_log = db_query_range('SELECT message FROM {watchdog} WHERE type = :type ORDER BY wid DESC', 0, 1, array(':type' => 'user_flood_test'))->fetchField();
if ($flood_trigger == 'user') {
$this->assertRaw(t('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'), '@count' => config_get('user.flood', 'flood_user_limit'))));
$this->assertEqual('Flood control blocked login attempt for %user from %ip.', $user_log, 'A watchdog message was logged for the login attempt blocked by flood control per user');
$this->assertEqual('hook_user_flood_control was passed username %username and IP %ip.', $user_flood_test_log, 'hook_user_flood_control was invoked by flood control per user');
}
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'))));
$this->assertEqual('Flood control blocked login attempt from %ip.', $user_log, 'A watchdog message was logged for the login attempt blocked by flood control per IP');
$this->assertEqual('hook_user_flood_control was passed IP %ip.', $user_flood_test_log, 'hook_user_flood_control was invoked by flood control per IP');
}
}
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 email 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.'));
}
}
}