You are here

public function PasswordPolicyConstraintsTestCase::testDelayConstraint in Password Policy 7.2

Tests delay constraint.

File

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

Class

PasswordPolicyConstraintsTestCase
Test case to verify accuracy of each available policy constraint.

Code

public function testDelayConstraint() {
  $policy = $this
    ->createPolicy(array(
    'delay' => array(
      'delay' => '24 hours',
    ),
  ));
  $this
    ->assertFalse($this
    ->checkPolicy($policy, 'password', $this->account), 'Delay constraint fails with new password before delay window expires.', 'Constraint');
  $policy = $this
    ->createPolicy(array(
    'delay' => array(
      'delay' => '1 sec',
    ),
  ));
  sleep(2);
  $this
    ->assertTrue($this
    ->checkPolicy($policy, 'password', $this->account), 'Delay constraint passes with new password after delay window expires.', 'Constraint');
  $policy = $this
    ->createPolicy(array(
    'delay' => array(
      'delay' => '24 hours',
      'threshold' => 2,
    ),
  ));
  $this
    ->assertTrue($this
    ->checkPolicy($policy, 'password', $this->account), 'Delay constraint passes with new password before delay window expires but threshold is not reached.', 'Constraint');
  $this->account = $this
    ->updateUserPassword($this->account);
  $this
    ->assertFalse($this
    ->checkPolicy($policy, 'password', $this->account), 'Delay constraint fails with new password before delay window expires and threshold is reached.', 'Constraint');
}