Exemplo n.º 1
0
 public function testResultWithNullAction()
 {
     $collection = new RuleResultCollection();
     $rule = new Rule('Test');
     $rule->setAction(null);
     $result = new RuleResult($rule, 0, 'testNeedRole', 'testNeedResource');
     $rule2 = new Rule('Test2');
     $rule2->setAction(true);
     $result2 = new RuleResult($rule2, 0, 'testNeedRole', 'testNeedResource');
     $collection->add($result);
     $this->assertFalse($collection->get());
     $collection->add($result2);
     $this->assertTrue($collection->get());
 }
Exemplo n.º 2
0
 public function testActionCallable()
 {
     $rule = new Rule('Rule');
     $ruleResult = new RuleResult($rule, 0, 'testNeedRoleName', 'testNeedResourceName');
     $self = $this;
     $isCalled = false;
     $rule->setAction(function (RuleResult $r) use(&$isCalled, $self) {
         $isCalled = true;
         $self->assertEquals('testNeedRoleName', $r->getNeedRoleName());
         $self->assertEquals('testNeedResourceName', $r->getNeedResourceName());
         $self->assertEquals(0, $r->getPriority());
         return true;
     });
     $this->assertTrue($rule->getAction($ruleResult));
     $this->assertTrue($isCalled);
 }
Exemplo n.º 3
0
 public function testRuleResult()
 {
     $roleAggregate = $this->getMock('SimpleAcl\\Role\\RoleAggregateInterface');
     $resourceAggregate = $this->getMock('SimpleAcl\\Resource\\ResourceAggregateInterface');
     $rule = new Rule('Test');
     $rule->setRoleAggregate($roleAggregate);
     $rule->setResourceAggregate($resourceAggregate);
     $rule->setAction(true);
     $result = new RuleResult($rule, 0, 'testNeedRole', 'testNeedResource');
     $this->assertSame($rule, $result->getRule());
     $this->assertEquals('testNeedRole', $result->getNeedRoleName());
     $this->assertEquals('testNeedResource', $result->getNeedResourceName());
     $this->assertEquals(0, $result->getPriority());
     $this->assertEquals($rule->getAction($result), $result->getAction());
     $result->setPriority(10);
     $this->assertEquals(10, $result->getPriority());
     $this->assertSame($roleAggregate, $result->getRoleAggregate());
     $this->assertSame($resourceAggregate, $result->getResourceAggregate());
     $this->assertNotEmpty($result->getId());
 }
Exemplo n.º 4
0
 public function testRuleOrResourceNull()
 {
     $acl = new Acl();
     $rule = new Rule('View');
     $rule->setAction(false);
     $u = new Role('U');
     $r = new Resource('R');
     $acl->addRule(null, $r, $rule, true);
     $this->assertTrue($acl->isAllowed('Any', 'R', 'View'));
     $this->assertFalse($acl->isAllowed('Any', 'R1', 'View'));
     $this->assertNull($rule->getRole());
     $this->assertSame($r, $rule->getResource());
     $acl->addRule($u, null, $rule, true);
     $this->assertTrue($acl->isAllowed('U', 'Any', 'View'));
     $this->assertFalse($acl->isAllowed('U1', 'Any', 'View'));
     $this->assertNull($rule->getResource());
     $this->assertSame($u, $rule->getRole());
 }