@@ 24-59 (lines=36) @@ | ||
21 | 'permissions' => '', |
|
22 | ]; |
|
23 | ||
24 | public function testAttachSinglePermissionToRole_() |
|
25 | { |
|
26 | $this->getTestingAdmin(); |
|
27 | ||
28 | $roleA = Role::create([ |
|
29 | 'name' => 'role-A', |
|
30 | 'description' => 'AA', |
|
31 | 'display_name' => 'A', |
|
32 | ]); |
|
33 | ||
34 | $permissionA = Permission::create([ |
|
35 | 'name' => 'permission-A', |
|
36 | 'description' => 'AA', |
|
37 | 'display_name' => 'A', |
|
38 | ]); |
|
39 | ||
40 | $data = [ |
|
41 | 'role_name' => $roleA['name'], |
|
42 | 'permission_name' => $permissionA['name'], |
|
43 | ]; |
|
44 | ||
45 | // send the HTTP request |
|
46 | $response = $this->apiCall($this->endpoint, 'post', $data, true); |
|
47 | ||
48 | // assert response status is correct |
|
49 | $this->assertEquals('200', $response->getStatusCode()); |
|
50 | ||
51 | $responseObject = $this->getResponseObject($response); |
|
52 | ||
53 | $this->assertEquals($roleA['name'], $responseObject->data->name); |
|
54 | ||
55 | $this->seeInDatabase('role_has_permissions', [ |
|
56 | 'permission_id' => $permissionA->id, |
|
57 | 'role_id' => $roleA->id |
|
58 | ]); |
|
59 | } |
|
60 | ||
61 | public function testAttachMultiplePermissionToRole_() |
|
62 | { |
@@ 24-61 (lines=38) @@ | ||
21 | 'permissions' => '', |
|
22 | ]; |
|
23 | ||
24 | public function testDetachSinglePermissionFromRole_() |
|
25 | { |
|
26 | $this->getTestingAdmin(); |
|
27 | ||
28 | $permissionA = Permission::create([ |
|
29 | 'name' => 'permission-A', |
|
30 | 'description' => 'AA', |
|
31 | 'display_name' => 'A', |
|
32 | ]); |
|
33 | ||
34 | $roleA = Role::create([ |
|
35 | 'name' => 'role-A', |
|
36 | 'description' => 'AA', |
|
37 | 'display_name' => 'A', |
|
38 | ]); |
|
39 | ||
40 | $roleA->givePermissionTo($permissionA); |
|
41 | ||
42 | $data = [ |
|
43 | 'role_name' => $roleA['name'], |
|
44 | 'permission_name' => $permissionA['name'], |
|
45 | ]; |
|
46 | ||
47 | // send the HTTP request |
|
48 | $response = $this->apiCall($this->endpoint, 'post', $data, true); |
|
49 | ||
50 | // assert response status is correct |
|
51 | $this->assertEquals('200', $response->getStatusCode()); |
|
52 | ||
53 | $responseObject = $this->getResponseObject($response); |
|
54 | ||
55 | $this->assertEquals($roleA['name'], $responseObject->data->name); |
|
56 | ||
57 | $this->missingFromDatabase('role_has_permissions', [ |
|
58 | 'permission_id' => $permissionA->id, |
|
59 | 'role_id' => $roleA->id |
|
60 | ]); |
|
61 | } |
|
62 | ||
63 | public function testDetachMultiplePermissionFromRole_() |
|
64 | { |