You are here

function PasswordPolicyTestCase::testDigitPlacementConstraint in Password Policy 6

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

File

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

Class

PasswordPolicyTestCase
@file Unit tests for Password policy module.

Code

function testDigitPlacementConstraint() {
  module_load_include('inc', 'password_policy', 'constraints/constraint_digit_placement');
  $constraint = 0;
  $uid = 0;
  $pass = 'ILove2Password';
  $result = password_policy_constraint_digit_placement_validate($pass, $constraint, $uid);
  $this
    ->assertTrue($result, 'One numeric character in the digit placement constraint with param 0');
  $pass = 'ILovePassword2';
  $result = password_policy_constraint_digit_placement_validate($pass, $constraint, $uid);
  $this
    ->assertTrue($result, 'One numeric character in the digit placement constraint with param 0');
  $constraint = 1;
  $pass = 'ILove2Password';
  $result = password_policy_constraint_digit_placement_validate($pass, $constraint, $uid);
  $this
    ->assertTrue($result, 'One numeric character in the digit placement constraint with param 1');
  $pass = 'ILovePassword2';
  $result = password_policy_constraint_digit_placement_validate($pass, $constraint, $uid);
  $this
    ->assertTrue($result, 'One numeric character in the digit placement constraint with param 1');
  $constraint = 2;
  $pass = 'ILove2Password';
  $result = password_policy_constraint_digit_placement_validate($pass, $constraint, $uid);
  $this
    ->assertTrue($result, 'One numeric character in the digit placement constraint with param 2');
  $pass = 'ILovePassword2';
  $result = password_policy_constraint_digit_placement_validate($pass, $constraint, $uid);
  $this
    ->assertFalse($result, 'One numeric character in the digit placement constraint with param 2');
  $pass = '1LovePassword';
  $result = password_policy_constraint_digit_placement_validate($pass, $constraint, $uid);
  $this
    ->assertFalse($result, 'One numeric character in the digit placement constraint with param 2');
  $pass = '1LovePassword2';
  $result = password_policy_constraint_digit_placement_validate($pass, $constraint, $uid);
  $this
    ->assertTrue($result, 'One numeric character in the digit placement constraint with param 2');
  $pass = 'ILove2Password3';
  $result = password_policy_constraint_digit_placement_validate($pass, $constraint, $uid);
  $this
    ->assertTrue($result, 'One numeric character in the digit placement constraint with param 2');
}