You are here

public function PasswordPolicyTestCase::testUsernameConstraint in Password Policy 7

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

Test username constraint.

File

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

Class

PasswordPolicyTestCase
Tests of basic Password Policy constraints.

Code

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