public static function getInstance() { if (null == self::$instance) { self::$instance = new Policy(); } return self::$instance; }
/** * 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); }
/** * Test that a false is returned when the user is not allowed * by the policy */ public function testAllowsSubjectInvalid() { $policy = Policy::instance()->hasUsername('notrightuser'); $policySet = PolicySet::instance()->add('policy1', $policy); $subject = new Subject((object) ['username' => 'ccornutt']); $en = new Enforcer($policySet); $this->assertFalse($en->allows('policy1', $subject)); }
/** * Test the creation of a new Policy object with the instance method */ public function testCreateNewInstance() { $policy = Policy::instance(); $this->assertInstanceOf('\\Psecio\\PropAuth\\Policy', $policy); }