Esempio n. 1
0
 /**
  * Tests function in Acl Allow Method without arguments
  *
  * @issue   12094
  *
  * @author  Wojciech Slawski <*****@*****.**>
  * @since   2016-06-05
  *
  * @expectedException           PHPUnit_Framework_Exception
  * @expectedExceptionMessage You didn't provide any parameters when check Guests can update Post. We will use default action when no arguments.
  */
 public function testAclAllowFunctionNoArgumentsWithWarning()
 {
     $this->specify('The function in allow should be called and isAllowed should return correct values when using function in allow method', function () {
         require_once PATH_DATA . 'acl/TestResourceAware.php';
         require_once PATH_DATA . 'acl/TestRoleAware.php';
         $acl = new Memory();
         $acl->setDefaultAction(Acl::ALLOW);
         $acl->setNoArgumentsDefaultAction(Acl::DENY);
         $acl->addRole('Guests');
         $acl->addRole('Members', 'Guests');
         $acl->addRole('Admins', 'Members');
         $acl->addResource('Post', array('update'));
         $guest = new \TestRoleAware(1, 'Guests');
         $member = new \TestRoleAware(2, 'Members');
         $anotherMember = new \TestRoleAware(3, 'Members');
         $admin = new \TestRoleAware(4, 'Admins');
         $model = new \TestResourceAware(2, 'Post');
         $acl->allow('Guests', 'Post', 'update', function ($parameter) {
             return $parameter % 2 == 0;
         });
         $acl->allow('Members', 'Post', 'update', function ($parameter) {
             return $parameter % 2 == 0;
         });
         $acl->allow('Admins', 'Post', 'update');
         expect($acl->isAllowed($guest, $model, 'update'))->false();
         expect($acl->isAllowed($member, $model, 'update'))->false();
         expect($acl->isAllowed($anotherMember, $model, 'update'))->false();
         expect($acl->isAllowed($admin, $model, 'update'))->true();
     });
 }
Esempio n. 2
0
 /**
  * Tests function in Acl Allow Method without arguments
  *
  * @issue   12094
  *
  * @author  Wojciech Slawski <*****@*****.**>
  * @since   2016-06-05
  */
 public function testAclAllowFunctionNoArgumentsWithWarning()
 {
     $this->specify('The function in allow should be called and isAllowed should return correct values when using function in allow method', function () {
         require_once PATH_DATA . 'acl/TestResourceAware.php';
         require_once PATH_DATA . 'acl/TestRoleAware.php';
         $acl = new Memory();
         $acl->setDefaultAction(Acl::ALLOW);
         $acl->setNoArgumentsDefaultAction(Acl::DENY);
         $acl->addRole('Guests');
         $acl->addRole('Members', 'Guests');
         $acl->addRole('Admins', 'Members');
         $acl->addResource('Post', ['update']);
         $guest = new \TestRoleAware(1, 'Guests');
         $member = new \TestRoleAware(2, 'Members');
         $anotherMember = new \TestRoleAware(3, 'Members');
         $admin = new \TestRoleAware(4, 'Admins');
         $model = new \TestResourceAware(2, 'Post');
         $acl->allow('Guests', 'Post', 'update', function ($parameter) {
             return $parameter % 2 == 0;
         });
         $acl->allow('Members', 'Post', 'update', function ($parameter) {
             return $parameter % 2 == 0;
         });
         $acl->allow('Admins', 'Post', 'update');
         expect($acl->isAllowed($guest, $model, 'update'))->false();
         expect($acl->isAllowed($member, $model, 'update'))->false();
         expect($acl->isAllowed($anotherMember, $model, 'update'))->false();
         expect($acl->isAllowed($admin, $model, 'update'))->true();
     }, ['throws' => [PHPUnit_Framework_Exception::class, "You didn't provide any parameters when check Guests can update Post. We will use default action when no arguments."]]);
 }