You are here

public function PasswordPolicyTestCase::testAlphanumericConstraint in Password Policy 7

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

Test alphanumeric constraint.

File

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

Class

PasswordPolicyTestCase
Tests of basic Password Policy constraints.

Code

public function testAlphanumericConstraint() {
  module_load_include('inc', 'password_policy', 'constraints/constraint_alphanumeric');
  $constraint = 2;
  $user = $this
    ->drupalCreateUser();
  $pass = '1$%';
  $result = password_policy_constraint_alphanumeric_validate($pass, $constraint, $user);
  $this
    ->assertFalse($result, 'One digit and no letter in the alphanumeric constraint with param 2');
  $pass = '1a#';
  $result = password_policy_constraint_alphanumeric_validate($pass, $constraint, $user);
  $this
    ->assertTrue($result, 'One digit and one letter in the alphanumeric constraint with param 2');
  $pass = '1ab';
  $result = password_policy_constraint_alphanumeric_validate($pass, $constraint, $user);
  $this
    ->assertTrue($result, 'One digit ant two letters in the alphanumeric constraint with param 2');
}