You are here

public function PasswordPolicyConditionsTestCase::testAuthmapCondition in Password Policy 7.2

Tests authmap condition.

File

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

Class

PasswordPolicyConditionsTestCase
Test case to verify accuracy of each available policy condition.

Code

public function testAuthmapCondition() {
  $config = array(
    'authmap' => array(
      'authmodules' => array(
        'auth_module_one' => 'auth_module_one',
      ),
    ),
  );
  $policy = $this
    ->createPolicy($config);
  $this
    ->assertTrue($this
    ->matchPolicy($policy, drupal_anonymous_user()), 'Authmap condition passes for anonymous user.', 'Condition');
  $this
    ->assertTrue($this
    ->matchPolicy($policy), 'Authmap condition passes with account not mapped to external authentication module.', 'Condition');

  // Add authmap to user so that the condition does not match.
  $authmaps = array(
    'authname_auth_module_one' => $this->account->name,
  );
  user_set_authmaps($this->account, $authmaps);
  $this
    ->assertFalse($this
    ->matchPolicy($policy), 'Authmap condition fails with account mapped to excluded external authentication module.', 'Condition');

  // Exclude a different authentication module to match the condition.
  $config = array(
    'authmap' => array(
      'authmodules' => array(
        'auth_module_two' => 'auth_module_two',
      ),
    ),
  );
  $policy = $this
    ->createPolicy($config);
  $this
    ->assertTrue($this
    ->matchPolicy($policy), 'Authmap condition passes with account mapped to included external authentication module.', 'Condition');
}