コード例 #1
0
ファイル: MemoryTest.php プロジェクト: mattvb91/cphalcon
 /**
  * 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();
     });
 }
コード例 #2
0
ファイル: MemoryTest.php プロジェクト: phalcon/cphalcon
 /**
  * Tests adding wildcard rule second time
  *
  * @issue   2648
  *
  * @author  Wojciech Slawski <*****@*****.**>
  * @since   2016-10-01
  */
 public function testWildCardSecondTime()
 {
     $this->specify("Can't add acl rule to existing wildcard role", function () {
         $acl = new Memory();
         $acl->addRole(new Role("Guests"));
         $acl->addResource(new Resource('Post'), ['index', 'update', 'create']);
         $acl->allow('Guests', 'Post', 'create');
         $acl->allow('*', 'Post', 'index');
         $acl->allow('*', 'Post', 'update');
         expect($acl->isAllowed('Guests', 'Post', 'create'))->true();
         expect($acl->isAllowed('Guests', 'Post', 'index'))->true();
         expect($acl->isAllowed('Guests', 'Post', 'update'))->true();
     });
 }