Пример #1
0
 public function testRolePermissions()
 {
     $role = new Role();
     $role->setRoleId(0);
     $permission = new Permission();
     $permission->setName('view');
     $permission2 = new Permission();
     $permission2->setName('read');
     $role->addPermission($permission);
     $role->addPermission($permission2);
     //$result = new \ArrayObject([$permission, $permission2]);
     $result = [$permission, $permission2];
     $this->assertEquals($result, $role->getPermissions());
 }
Пример #2
0
 public function testAclCan()
 {
     $permission = new Permission();
     $permission->setName('view');
     $role = new Role(0);
     $role->addPermission($permission);
     $roles[] = $role;
     $user = new User();
     $user->setId(1);
     $resource = new Resource(Book::class, 'getUserId');
     $resources[] = $resource;
     $acl = new Acl($roles, $resources);
     $acl->setUser($user);
     $this->assertEquals(1, $acl->can('view'));
     $acl = new Acl($roles, $resources);
     $this->assertEquals(1, $acl->can('view', $user));
     $this->assertEquals(1, $acl->can('view'));
     $this->assertEquals(null, $acl->can('read'));
 }
Пример #3
0
 public function testPermissionName()
 {
     $permission = new Permission();
     $permission->setName('Jeff');
     $this->assertEquals('Jeff', $permission->getName());
 }