public function UserLoginTest::assertFailedLogin in Drupal 8
Same name and namespace in other branches
- 9 core/modules/user/tests/src/Functional/UserLoginTest.php \Drupal\Tests\user\Functional\UserLoginTest::assertFailedLogin()
Make an unsuccessful login attempt.
Parameters
\Drupal\user\Entity\User $account: A user object with name and passRaw attributes for the login attempt.
mixed $flood_trigger: (optional) Whether or not to expect that the flood control mechanism will be triggered. Defaults to NULL.
- Set to 'user' to expect a 'too many failed logins error.
- Set to any value to expect an error for too many failed logins per IP
.
- Set to NULL to expect a failed login.
2 calls to UserLoginTest::assertFailedLogin()
- UserLoginTest::testGlobalLoginFloodControl in core/
modules/ user/ tests/ src/ Functional/ UserLoginTest.php - Test the global login flood control.
- UserLoginTest::testPerUserLoginFloodControl in core/
modules/ user/ tests/ src/ Functional/ UserLoginTest.php - Test the per-user login flood control.
File
- core/
modules/ user/ tests/ src/ Functional/ UserLoginTest.php, line 163
Class
- UserLoginTest
- Ensure that login works as expected.
Namespace
Drupal\Tests\user\FunctionalCode
public function assertFailedLogin($account, $flood_trigger = NULL) {
$edit = [
'name' => $account
->getAccountName(),
'pass' => $account->passRaw,
];
$this
->drupalPostForm('user/login', $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(\Drupal::translation()
->formatPlural($this
->config('user.flood')
->get('user_limit'), '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>.', '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>.', [
':url' => Url::fromRoute('user.pass')
->toString(),
]));
}
else {
// No uid, so the limit is IP-based.
$this
->assertRaw(t('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>.', [
':url' => Url::fromRoute('user.pass')
->toString(),
]));
}
}
else {
$this
->assertText(t('Unrecognized username or password. Forgot your password?'));
}
}