You are here

public function UserPasswordResetTest::testUserResetPasswordUserFloodControl in Drupal 8

Same name and namespace in other branches
  1. 9 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 294

Class

UserPasswordResetTest
Ensure that password reset methods work as expected.

Namespace

Drupal\Tests\user\Functional

Code

public function testUserResetPasswordUserFloodControl() {
  \Drupal::configFactory()
    ->getEditable('user.flood')
    ->set('user_limit', 3)
    ->save();
  $edit = [
    'name' => $this->account
      ->getAccountName(),
  ];

  // Try 3 requests that should not trigger flood control.
  for ($i = 0; $i < 3; $i++) {
    $this
      ->drupalGet('user/password');
    $this
      ->drupalPostForm(NULL, $edit, t('Submit'));
    $this
      ->assertValidPasswordReset($edit['name']);
    $this
      ->assertNoPasswordUserFlood();
  }

  // The next request should trigger flood control.
  $this
    ->drupalGet('user/password');
  $this
    ->drupalPostForm(NULL, $edit, t('Submit'));
  $this
    ->assertPasswordUserFlood();
}