You are here

public function PasswordPolicyConditionsTestCase::testMultipleConditions in Password Policy 7.2

Tests using multiple conditions.

The policy should be applied if all conditions pass. That is, a Boolean AND is performed on the conditions.

File

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

Class

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

Code

public function testMultipleConditions() {

  // Create policy with two conditions.
  $rid = $this
    ->drupalCreateRole(array());
  $config = array(
    'role' => array(
      'roles' => array(
        $rid => 1,
      ),
    ),
    'authmap' => array(
      'authmodules' => array(
        'auth_module_one' => 'auth_module_one',
      ),
    ),
  );
  $policy = $this
    ->createPolicy($config);

  // Test condition #1 fail and condition #2 pass.
  $this
    ->assertFalse($this
    ->matchPolicy($policy), 'Role condition fails and authmap condition passes: Policy does not match.', 'Condition');

  // Test condition #1 pass and condition #2 pass.
  $this->account->roles[$rid] = 'test role';
  $this
    ->assertTrue($this
    ->matchPolicy($policy), 'Role condition passes and authmap condition passes: Policy matches.', 'Condition');

  // Test condition #1 pass and condition #2 fail.
  $authmaps = array(
    'authname_auth_module_one' => $this->account->name,
  );
  user_set_authmaps($this->account, $authmaps);
  $this
    ->assertFalse($this
    ->matchPolicy($policy), 'Role condition passes and authmap condition fails: Policy does not match.', 'Condition');

  // Test condition #1 fail and condition #2 fail.
  unset($this->account->roles[$rid]);
  $this
    ->assertFalse($this
    ->matchPolicy($policy), 'Role condition fails and authmap condition fails: Policy does not match.', 'Condition');
}