function PasswordStrengthTestCase::changePassword in Password Strength 7
Same name and namespace in other branches
- 6.2 tests/password_strength.test \PasswordStrengthTestCase::changePassword()
Tests a user account password change.
Parameters
stdClass $account: Drupal user account for additional contexts.
string $new_pass: Plain-text password to be used as new password.
boolean $too_weak: Optional Whether the password is too weak and the change should fail.
1 call to PasswordStrengthTestCase::changePassword()
- PasswordStrengthTestCase::testChangePassword in tests/
password_strength.test - Tests various levels of minimum scores when changing a user account password.
File
- tests/
password_strength.test, line 66 - Tests for password strength module.
Class
- PasswordStrengthTestCase
- @file Tests for password strength module.
Code
function changePassword($account, $new_pass, $too_weak = FALSE) {
$this
->drupalLogin($account);
// Check that filling out a single password field does not validate.
$edit = array();
$edit['pass[pass1]'] = '';
$edit['pass[pass2]'] = $new_pass;
$this
->drupalPost("user/{$account->uid}/edit", $edit, t('Save'));
$this
->assertText(t("The specified passwords do not match."), 'Typing mismatched passwords displays an error message.');
$edit['pass[pass1]'] = $new_pass;
$edit['pass[pass2]'] = '';
$this
->drupalPost("user/{$account->uid}/edit", $edit, t('Save'));
$this
->assertText(t("The specified passwords do not match."), 'Typing mismatched passwords displays an error message.');
// Test that the error message appears when attempting to change the mail or
// pass without the current password.
$edit = array();
$edit['mail'] = $this
->randomName() . '@new.example.com';
$this
->drupalPost("user/{$account->uid}/edit", $edit, t('Save'));
$this
->assertRaw(t("Your current password is missing or incorrect; it's required to change the %name.", array(
'%name' => t('E-mail address'),
)));
$edit['current_pass'] = $account->pass_raw;
$this
->drupalPost("user/{$account->uid}/edit", $edit, t('Save'));
$this
->assertRaw(t("The changes have been saved."));
// Test that the user must enter current password before changing passwords.
$edit = array();
$edit['pass[pass1]'] = $new_pass;
$edit['pass[pass2]'] = $new_pass;
$this
->drupalPost("user/{$account->uid}/edit", $edit, t('Save'));
$this
->assertRaw(t("Your current password is missing or incorrect; it's required to change the %name.", array(
'%name' => t('Password'),
)));
// Try again with the current password.
$edit['current_pass'] = $account->pass_raw;
$this
->drupalPost("user/{$account->uid}/edit", $edit, t('Save'));
if ($too_weak) {
$this
->assertRaw(t("Password does not meet required strength."));
}
else {
$this
->assertRaw(t("The changes have been saved."));
// Make sure the user can log in with their new password.
$this
->drupalLogout();
$account->pass_raw = $new_pass;
$this
->drupalLogin($account);
$this
->drupalLogout();
}
}