You are here

public function UsernameEnumerationPreventionTestCase::testPasswordResetEnum in Username Enumeration Prevention 7

Submit the password reset form and check for resulting messaging.

File

tests/simpletest/username_enumeration_prevention.test, line 34
Test case for enumerating password reset form.

Class

UsernameEnumerationPreventionTestCase
The UsernameEnumerationPreventionTestCase tests functionality of this module.

Code

public function testPasswordResetEnum() {

  // Add some fake users.
  $users = [
    'foo',
    'bar',
    'baz',
  ];

  // Create some real users.
  for ($i = 0; $i < 5; $i++) {
    $user = $this
      ->drupalCreateUser();
    $users[] = $user->name;
  }
  foreach ($users as $username) {

    // Submit the password reset form.
    $edit = [
      'name' => $username,
    ];
    $this
      ->drupalPost('user/password', $edit, t('E-mail new password'));

    // Confirm the message returns the same text for all cases.
    $this
      ->assertText(t('Further instructions have been sent to your e-mail address.'), t('Password reset instructions mailed message displayed for %name.', [
      '%name' => $username,
    ]));
    $this
      ->assertNoText(t('Sorry, %name is not recognized as a user name or an e-mail address.', [
      '%name' => $username,
    ]), 'Unrecognized username message not displayed.');
  }
}