Ejemplo n.º 1
0
 /**
  * Tests function in Acl Allow Method
  *
  * @issue   11235
  *
  * @author  Wojciech Slawski <*****@*****.**>
  * @since   2015-12-16
  */
 public function testAclAllowFunction()
 {
     $this->specify('The function in allow should be called and isAllowed should return correct values when using function in allow method', function () {
         $acl = new PhTAclMem();
         $acl->setDefaultAction(PhAcl::DENY);
         $acl->addRole('Guests');
         $acl->addRole('Members', 'Guests');
         $acl->addRole('Admins', 'Members');
         $acl->addResource('Post', array('update'));
         $guest = new TestRoleable(1, 'Guests');
         $member = new TestRoleable(2, 'Members');
         $anotherMember = new TestRoleable(3, 'Members');
         $admin = new TestRoleable(4, 'Admins');
         $model = new TestResourceable(2, 'Post');
         $acl->deny('Guests', 'Post', 'update');
         $acl->allow('Members', 'Post', 'update', function (TestRoleable $user, TestResourceable $model) {
             return $user->getId() == $model->getUser();
         });
         $acl->allow('Admins', 'Post', 'update');
         $actual = (bool) $acl->isAllowed($guest, $model, 'update');
         expect($actual)->false();
         $actual = (bool) $acl->isAllowed($member, $model, 'update');
         expect($actual)->true();
         $actual = (bool) $acl->isAllowed($anotherMember, $model, 'update');
         expect($actual)->false();
         $actual = (bool) $acl->isAllowed($admin, $model, 'update');
         expect($actual)->true();
     });
 }
Ejemplo n.º 2
0
 /**
  * Tests negation of inherited roles
  *
  * @issue   65
  *
  * @author  Nikolaos Dimopoulos <*****@*****.**>
  * @since   2014-10-04
  */
 public function testAclNegationOfInheritedRoles()
 {
     $this->specify('Negation of inherited roles does not return the correct result', function () {
         $acl = new PhTAclMem();
         $acl->setDefaultAction(PhAcl::DENY);
         $acl->addRole('Guests');
         $acl->addRole('Members', 'Guests');
         $acl->addResource('Login', array('index'));
         $acl->allow('Guests', 'Login', 'index');
         $acl->deny('Members', 'Login', 'index');
         $actual = (bool) $acl->isAllowed('Members', 'Login', 'index');
         expect($actual)->false();
     });
 }