UserRoleTest.php
5.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
use Tests\BrowserKitTestCase;
/**
* Class UserRoleTest.
*/
class UserRoleTest extends BrowserKitTestCase
{
public function testAttachRoleToUserById()
{
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->user->attachRole($this->adminRole->id);
$this->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
}
public function testAttachRoleToUserByObject()
{
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->user->attachRole($this->adminRole);
$this->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
}
public function testDetachRoleByIdFromUser()
{
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->user->attachRole($this->adminRole->id);
$this->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->user->detachRole($this->adminRole->id);
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
}
public function testDetachRoleByObjectFromUser()
{
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->user->attachRole($this->adminRole);
$this->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->user->detachRole($this->adminRole);
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
}
public function testAttachRolesByIdToUser()
{
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->executiveRole->id]);
$this->user->attachRoles([$this->adminRole->id, $this->executiveRole->id]);
$this->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->executiveRole->id]);
}
public function testAttachRolesByObjectToUser()
{
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->executiveRole->id]);
$this->user->attachRoles([$this->adminRole, $this->executiveRole]);
$this->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->executiveRole->id]);
}
public function testDetachRolesByIdFromUser()
{
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->executiveRole->id]);
$this->user->attachRoles([$this->adminRole->id, $this->executiveRole->id]);
$this->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->executiveRole->id]);
$this->user->detachRoles([$this->adminRole->id, $this->executiveRole->id]);
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->executiveRole->id]);
}
public function testDetachRolesByObjectFromUser()
{
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->executiveRole->id]);
$this->user->attachRoles([$this->adminRole, $this->executiveRole]);
$this->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->executiveRole->id]);
$this->user->detachRoles([$this->adminRole, $this->executiveRole]);
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->executiveRole->id]);
}
}