function PasswordStrengthTestCase::changePassword in Password Strength 6.2
Same name and namespace in other branches
- 7 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 68 - Tests for password strength module.
Class
- PasswordStrengthTestCase
- Tests the functionality of the 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]'] = 'foo';
$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';
// The current password doesn't apply in Drupal 6.
//$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'))));
// The current password doesn't apply in Drupal 6.
//$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;
// The current password doesn't apply in Drupal 6.
//$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.
// The current password doesn't apply in Drupal 6.
//$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();
}
}