public function PasswordPolicyForcePasswordChangeTestCase::testSingleUser in Password Policy 7
Same name and namespace in other branches
- 6 tests/password_policy.test \PasswordPolicyForcePasswordChangeTestCase::testSingleUser()
Tests single user password change.
File
- tests/
password_policy.test, line 426 - Functional tests for Password policy module.
Class
- PasswordPolicyForcePasswordChangeTestCase
- Tests of forcing password changes.
Code
public function testSingleUser() {
$admin = $this
->drupalCreateUser(array(
'force password change',
'administer users',
));
$user = $this
->drupalCreateUser();
$this
->drupalLogin($admin);
$edit = array(
'force_password_change' => TRUE,
);
$this
->drupalPost("user/{$user->uid}/edit", $edit, t('Save'));
$this
->assertRaw(t('!user will be required to change their password the next time they log in.', array(
'!user' => $user->name,
)), 'User flagged for password change.');
$force_change = db_query('SELECT force_change FROM {password_policy_force_change} WHERE uid = :uid', array(
':uid' => $user->uid,
))
->fetchField();
$this
->assertTrue($force_change == 1, format_string('Force change flag set to %d for %s.', array(
'%d' => $force_change,
'%s' => $user->name,
)));
// Confirm admin can edit user account without changing password.
$edit = array(
'name' => $user->name,
'force_password_change' => TRUE,
);
$this
->drupalPost("user/{$user->uid}/edit", $edit, t('Save'));
$force_change = db_query('SELECT force_change FROM {password_policy_force_change} WHERE uid = :uid', array(
':uid' => $user->uid,
))
->fetchField();
$this
->assertTrue($force_change == 1, format_string('User force change flag set in database:%s.', array(
'%s' => $force_change,
)));
$this
->assertNoRaw(t('Your password has expired. You must change your password to proceed on the site.'), 'Admin can edit user account without changing password.');
$this
->drupalLogout();
// Verify user is forced to change password.
$this
->drupalLogin($user);
$this
->assertFieldByName('current_pass', NULL, 'User redirected correctly.');
$this
->assertRaw(t('Your password has expired. You must change your password to proceed on the site.'), 'User presented with error instructing them to change their password.');
// Attempt to change password.
$edit = array(
'current_pass' => $user->pass_raw,
'pass[pass1]' => 'random_string',
'pass[pass2]' => 'random_string',
);
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->assertRaw(t('The changes have been saved.'), 'Password change successful.');
// Verify user not prompted to change password a 2nd time.
$this
->drupalGet('node');
$this
->assertNoFieldByName('current_pass', NULL, 'User not forced to change password a 2nd time.');
$this
->drupalLogout();
}