public function UserPasswordResetTest::testUserResetPasswordUserFloodControl in Drupal 9
Same name and namespace in other branches
- 8 core/modules/user/tests/src/Functional/UserPasswordResetTest.php \Drupal\Tests\user\Functional\UserPasswordResetTest::testUserResetPasswordUserFloodControl()
Tests password reset flood control for one user.
File
- core/
modules/ user/ tests/ src/ Functional/ UserPasswordResetTest.php, line 393
Class
- UserPasswordResetTest
- Ensure that password reset methods work as expected.
Namespace
Drupal\Tests\user\FunctionalCode
public function testUserResetPasswordUserFloodControl() {
\Drupal::configFactory()
->getEditable('user.flood')
->set('user_limit', 3)
->save();
$edit = [
'name' => $this->account
->getAccountName(),
];
// Count email messages before to compare with after.
$before = count($this
->drupalGetMails([
'id' => 'user_password_reset',
]));
// Try 3 requests that should not trigger flood control.
for ($i = 0; $i < 3; $i++) {
$this
->drupalGet('user/password');
$this
->submitForm($edit, 'Submit');
$this
->assertValidPasswordReset($edit['name']);
}
// Ensure 3 emails were sent.
$this
->assertCount($before + 3, $this
->drupalGetMails([
'id' => 'user_password_reset',
]), '3 emails sent without triggering flood control.');
// The next request should trigger flood control.
$this
->drupalGet('user/password');
$this
->submitForm($edit, 'Submit');
// Ensure no further emails were sent.
$this
->assertCount($before + 3, $this
->drupalGetMails([
'id' => 'user_password_reset',
]), 'No further email was sent after triggering flood control.');
}