You are here

public function PasswordPolicyForcePasswordChangeTestCase::testUnforceChange in Password Policy 6

Same name and namespace in other branches
  1. 7 tests/password_policy.test \PasswordPolicyForcePasswordChangeTestCase::testUnforceChange()

Test unforcing a password change.

File

tests/password_policy.test, line 438
Unit tests for Password policy module.

Class

PasswordPolicyForcePasswordChangeTestCase

Code

public function testUnforceChange() {
  $admin = $this
    ->drupalCreateUser(array(
    'force password change',
    'administer users',
  ));
  $user = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($admin);

  // Force a password change.
  $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.'));

  // Unforce the password change.
  $edit = array(
    'force_password_change' => FALSE,
  );
  $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 == 0, t('Force change flag set to %d for %s.', array(
    '%d' => $force_change,
    '%s' => $user->name,
  )));
}