You are here

public function PasswordPolicyForcePasswordChangeTestCase::testUnforceChange in Password Policy 7

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

Tests unforcing a password change.

File

tests/password_policy.test, line 551
Functional tests for Password policy module.

Class

PasswordPolicyForcePasswordChangeTestCase
Tests of forcing password changes.

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,
  )), '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_query('SELECT force_change FROM {password_policy_force_change} WHERE uid = :uid', array(
    ':uid' => $user->uid,
  ))
    ->fetchField();
  $this
    ->assertTrue($force_change == 0, format_string('Force change flag set to %d for %s.', array(
    '%d' => $force_change,
    '%s' => $user->name,
  )));
}