You are here

public function PasswordPolicyExpirationTestCase::testUnblockingReblockedAccount in Password Policy 7

Tests unblocking a "reblocked" account.

By "reblocked" account we mean one that was blocked due to password expiration, unblocked, then blocked again due to the password not being changed within 24 hours.

File

tests/password_policy_expiration.test, line 246
Tests for Password policy module expiration functionality.

Class

PasswordPolicyExpirationTestCase
Tests of password expiration.

Code

public function testUnblockingReblockedAccount() {

  // Create role to which the expiration policy will apply.
  $expiration_rid = $this
    ->drupalCreateRole(array());

  // Add user covered by expiration policy.
  $account = $this
    ->drupalCreateUser();
  user_multiple_role_edit(array(
    $account->uid,
  ), 'add_role', $expiration_rid);

  // Set an expiration policy.
  $expiration_days = 7;
  $this
    ->setExpirationPolicy($expiration_days, $expiration_rid);

  // Allow the password to expire.
  $seven_days_one_second = 60 * 60 * 24 * 7 + 1;
  _password_policy_advance_test_clock($seven_days_one_second);
  $this
    ->cronRun();

  // Log in as policy making user to unblock the test user.
  $this
    ->drupalLogin($this->policyMaker);
  $this
    ->drupalPost('admin/people/expired/unblock/' . $account->uid, array(), t('Unblock user'));
  $this
    ->assertText(t('The user !name has been unblocked.', array(
    '!name' => $account->name,
  )), 'Account account has been unblocked.');
  $this
    ->drupalGet('admin/people/expired');
  $this
    ->assertNoText('unblock', 'Account not marked as blocked on Expired Accounts tab.');
  $this
    ->drupalLogout();

  // Wait over one day so account is reblocked.
  $one_day_one_second = 60 * 60 * 24 + 1;
  _password_policy_advance_test_clock($one_day_one_second);
  $this
    ->cronRun();

  // Attempt to log in. User should be blocked.
  $edit = array(
    'name' => $account->name,
    'pass' => $account->pass_raw,
  );
  $this
    ->drupalPost('user/login', $edit, t('Log in'));
  $this
    ->assertText(t('The username !name has not been activated or is blocked.', array(
    '!name' => $account->name,
  )), 'Account blocked from logging in.');

  // Log in as policy making user to unblock the test user.
  $this
    ->drupalLogin($this->policyMaker);
  $this
    ->drupalPost('admin/people/expired/unblock/' . $account->uid, array(), t('Unblock user'));
  $this
    ->assertText(t('The user !name has been unblocked.', array(
    '!name' => $account->name,
  )), 'Account account has been unblocked.');
  $this
    ->drupalGet('admin/people/expired');
  $this
    ->assertNoText('unblock', 'Account not marked as blocked on Expired Accounts tab.');
  $this
    ->drupalLogout();

  // Attempt to log in. User should not be blocked.
  $edit = array(
    'name' => $account->name,
    'pass' => $account->pass_raw,
  );
  $this
    ->drupalPost('user/login', $edit, t('Log in'));
  $this
    ->assertNoText(t('The username !name has not been activated or is blocked.', array(
    '!name' => $account->name,
  )), 'Account not blocked from logging in.');
  $this
    ->drupalLogout();
}