Example #1
0
 /**
  * Events Manager Interaction
  */
 public function testEventsManagerInteraction()
 {
     $events = new Phalcon\Events\Manager();
     $self = $this;
     $events->attach('acl:beforeCheckAccess', function ($event, $component, $object) use($self) {
         $self->assertEquals($component->getActiveRole(), 'Role');
         $self->assertEquals($component->getActiveResource(), 'Resource');
         $self->assertEquals($component->getActiveAccess(), 'index');
         return false;
     });
     $acl = new Phalcon\Acl\Adapter\Memory();
     $acl->setDefaultAction(Phalcon\Acl::DENY);
     $this->assertEquals($acl->getDefaultAction(), Phalcon\Acl::DENY);
     $acl->setEventsManager($events);
     $this->assertEquals($acl->getEventsManager(), $events);
     $resource = new Phalcon\Acl\Resource('Resource');
     $role = new Phalcon\Acl\Role('Role');
     $acl->addResource($resource, array('index'));
     $acl->addRole($role);
     $acl->allow('Role', 'Resource', 'index');
     $this->assertEquals($acl->getResources(), array($resource));
     $this->assertEquals($acl->getRoles(), array($role));
     $this->assertEquals($acl->isAllowed('Role', 'Resource', 'index'), false);
 }