예제 #1
0
파일: RoleTest.php 프로젝트: znck/trust
 public function test_it_has_relations()
 {
     $role = Role::create(['name' => 'Foo', 'slug' => 'foo']);
     $this->assertTrue($role->users instanceof Collection);
     $this->assertTrue($role->users() instanceof BelongsToMany);
     $this->assertTrue($role->permissions instanceof Collection);
     $this->assertTrue($role->permissions() instanceof BelongsToMany);
 }
예제 #2
0
 public function test_it_can_check_permission_through_role()
 {
     $user = $this->createUser();
     $this->assertFalse($user->hasPermissionTo('create-post'));
     $permission = Permission::create(['name' => 'Create post', 'slug' => 'create-post']);
     $role = Role::create(['name' => 'Author', 'slug' => 'author']);
     $role->permissions()->attach($permission);
     $user->roles()->attach($role);
     $user->refreshPermissions();
     $this->assertTrue($user->hasPermissionTo('create-post'), 'user cannot create post');
 }
예제 #3
0
 /**
  * @param string $slug
  *
  * @return Role
  */
 protected function findRole(string $slug)
 {
     return Role::where('slug', $slug)->first();
 }