Beispiel #1
0
 public function testRemoveUserRole()
 {
     $user = TestUser::create(['name' => 'user']);
     $role = Role::create(['name' => 'role']);
     $user->addRole($role);
     $user->removeRole($role);
     $this->assertFalse($user->roles->contains($role->getKey()));
     $this->assertFalse($role->users->contains($user->getKey()));
 }
 public function testUserPermissionComesBeforeRolePermission()
 {
     $user = TestUser::create(['name' => 'user']);
     $role = Role::create(['name' => 'role']);
     $perm = Permission::create(['name' => 'permission']);
     $user->addRole($role);
     $role->allowPermission($perm);
     $user->denyPermission($perm);
     $perm = $user->getPermission($perm);
     $this->assertNotNull($perm);
     $this->assertFalse($perm->allow);
 }
 public function testLocalAndGlobalPermissionAccess()
 {
     $res1 = TestResource::create(['name' => 'resource 1']);
     $res2 = TestResource::create(['name' => 'resource 2']);
     $role = Role::create(['name' => 'role']);
     $perm1 = Permission::create(['name' => 'permission 1']);
     $perm2 = Permission::create(['name' => 'permission 2']);
     TestResource::addGlobalPermissionTo('show', $perm1);
     $res2->addPermissionTo('show', $perm2);
     $role->allowPermission($perm1);
     $this->assertTrue($role->hasAccessTo('show', $res1));
     $this->assertFalse($role->hasAccessTo('show', $res2));
     $role->allowPermission($perm2);
     $this->assertTrue($role->hasAccessTo('show', $res2));
 }
Beispiel #4
0
 protected function createFakes()
 {
     return [TestUser::create(['name' => 'user']), Role::create(['name' => 'role']), Permission::create(['name' => 'permission']), TestResource::create(['name' => 'resource'])];
 }
 /**
  * @expectedException RuntimeException
  */
 public function testRolePermissionActionAttribute()
 {
     $role = Role::create(['name' => 'role']);
     $perm = Permission::create(['name' => 'permission']);
     $role->allowPermission($perm);
     $perm = $role->mergedPermissions()->first();
     $var = $perm->action;
 }