Exemple #1
0
 /**
  * Test the evaluation of all policies when no policy name is given
  */
 public function testAllPolicyEvaluateAllAny()
 {
     $set = PolicySet::instance()->add('policy1', Policy::instance()->hasUsername('ccornutt'));
     $user = (object) ['username' => 'ccornutt'];
     $subject = new Subject($user);
     $subject->setAuth(true);
     $context = new Context(['policies' => $set]);
     $gateway = new Gateway($subject, $context);
     // Evaluate the result of the policy above, true because they're:
     //  1. set correctly, 2. policy passes
     $result = $gateway->evaluate();
     $this->assertTrue($result);
 }
Exemple #2
0
 /**
  * Test that an exception is thrown when teh policy name isn't found
  *
  * @expectedException \InvalidArgumentException
  */
 public function testPolicyNameNotFoundAllows()
 {
     $policySet = PolicySet::instance();
     $subject = new Subject((object) ['username' => 'ccornutt']);
     $en = new Enforcer($policySet);
     $en->allows('policy1', $subject);
 }