public function testAddResourceWithSameName()
 {
     $site = new ResourceAggregate();
     $resource1 = new Resource('One');
     $resource2 = new Resource('One');
     $site->addResource($resource1);
     $site->addResource($resource2);
     $this->assertEquals(1, count($site->getResources()));
     $this->assertSame($resource1, $site->getResource('One'));
 }
Beispiel #2
0
 public function testSetAggregates()
 {
     $acl = new Acl();
     $u = new Role('U');
     $r = new Resource('R');
     $roleAgr = new RoleAggregate();
     $roleAgr->addRole($u);
     $resourceAgr = new ResourceAggregate();
     $resourceAgr->addResource($r);
     $self = $this;
     $rule = new Rule('View');
     $acl->addRule($u, $r, $rule, function (RuleResult $r) use($roleAgr, $resourceAgr, $self) {
         $self->assertSame($roleAgr, $r->getRoleAggregate());
         $self->assertSame($resourceAgr, $r->getResourceAggregate());
         return true;
     });
     $this->assertTrue($acl->isAllowed($roleAgr, $resourceAgr, 'View'));
     $rule->setAction(function (RuleResult $r) use($self) {
         $self->assertNull($r->getRoleAggregate());
         $self->assertNull($r->getResourceAggregate());
         return true;
     });
     $this->assertTrue($acl->isAllowed('U', 'R', 'View'));
 }