You are here

function PasswordPolicyTestCase::testUsernameConstraint in Password Policy 6

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

File

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

Class

PasswordPolicyTestCase
@file Unit tests for Password policy module.

Code

function testUsernameConstraint() {
  module_load_include('inc', 'password_policy', 'constraints/constraint_username');
  $constraint = 2;
  $user = $this
    ->drupalCreateUser();
  $name = $this
    ->randomName();
  $result = password_policy_constraint_username_validate($name, $constraint, $user->uid);
  $this
    ->assertTrue($result, 'Random string in the username constraint');
  $result = password_policy_constraint_username_validate($user->name, $constraint, $user->uid);
  $this
    ->assertFalse($result, 'Username in the username constraint');
  $result = password_policy_constraint_username_validate('foo' . $user->name . 'bar', $constraint, $user->uid);
  $this
    ->assertFalse($result, 'String containing username in the username constraint');
}