public function PasswordPolicyForcePasswordChangeTestCase::testSingleUser in Password Policy 6
Same name and namespace in other branches
- 7 tests/password_policy.test \PasswordPolicyForcePasswordChangeTestCase::testSingleUser()
File
- tests/
password_policy.test, line 318 - Unit tests for Password policy module.
Class
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,
)), t('User flagged for password change.'));
$force_change = db_result(db_query('SELECT force_change FROM {password_policy_force_change} WHERE uid=%d', $user->uid));
$this
->assertTrue($force_change == 1, t('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,
'mail' => $user->mail,
'force_password_change' => TRUE,
);
$this
->drupalPost("user/{$user->uid}/edit", $edit, t('Save'));
$force_change = db_result(db_query('SELECT force_change FROM {password_policy_force_change} WHERE uid=%d', $user->uid));
$this
->assertTrue($force_change == 1, t('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.'), t('Admin can edit user account without changing password.'));
$this
->drupalLogout();
// verify user is forced to change password
$this
->drupalLogin($user);
$this
->assertFieldByName('mail', '', t('User redirected correctly.'));
// marginal
$this
->assertRaw(t('Your password has expired. You must change your password to proceed on the site.'), t('User presented with error instructing them to change their password.'));
// attempt to change password
$edit = array(
'mail' => $user->mail,
'pass[pass1]' => 'random_string',
'pass[pass2]' => 'random_string',
);
$this
->drupalPost("user/{$user->uid}/edit", $edit, t('Save'));
$this
->assertRaw(t('The changes have been saved.'), t('Password change successful.'));
// verify user not prompted to change password a 2nd time
$this
->drupalGet('node');
$this
->assertNoFieldByName('mail', '', t('User not forced to change password a 2nd time.'));
$this
->drupalLogout();
}