| @@ 13-39 (lines=27) @@ | ||
| 10 | * |
|
| 11 | * @author Mahmoud Zalt <[email protected]> |
|
| 12 | */ |
|
| 13 | class ListPermissionsTest extends TestCase |
|
| 14 | { |
|
| 15 | ||
| 16 | protected $endpoint = '/permissions'; |
|
| 17 | ||
| 18 | protected $access = [ |
|
| 19 | 'roles' => 'admin', |
|
| 20 | 'permissions' => '', |
|
| 21 | ]; |
|
| 22 | ||
| 23 | public function testListAllPermissions_() |
|
| 24 | { |
|
| 25 | $this->getTestingAdmin(); |
|
| 26 | ||
| 27 | // send the HTTP request |
|
| 28 | $response = $this->apiCall($this->endpoint, 'get'); |
|
| 29 | ||
| 30 | // assert response status is correct |
|
| 31 | $this->assertEquals('200', $response->getStatusCode()); |
|
| 32 | ||
| 33 | // convert JSON response string to Object |
|
| 34 | $responseObject = $this->getResponseObject($response); |
|
| 35 | ||
| 36 | $this->assertTrue(count($responseObject->data) > 0); |
|
| 37 | } |
|
| 38 | ||
| 39 | } |
|
| 40 | ||
| @@ 13-39 (lines=27) @@ | ||
| 10 | * |
|
| 11 | * @author Mahmoud Zalt <[email protected]> |
|
| 12 | */ |
|
| 13 | class ListRolesTest extends TestCase |
|
| 14 | { |
|
| 15 | ||
| 16 | protected $endpoint = '/roles'; |
|
| 17 | ||
| 18 | protected $access = [ |
|
| 19 | 'roles' => 'admin', |
|
| 20 | 'permissions' => '', |
|
| 21 | ]; |
|
| 22 | ||
| 23 | public function testListAllRoles_() |
|
| 24 | { |
|
| 25 | $this->getTestingAdmin(); |
|
| 26 | ||
| 27 | // send the HTTP request |
|
| 28 | $response = $this->apiCall($this->endpoint, 'get'); |
|
| 29 | ||
| 30 | // assert response status is correct |
|
| 31 | $this->assertEquals('200', $response->getStatusCode()); |
|
| 32 | ||
| 33 | // convert JSON response string to Object |
|
| 34 | $responseObject = $this->getResponseObject($response); |
|
| 35 | ||
| 36 | $this->assertTrue(count($responseObject->data) > 0); |
|
| 37 | } |
|
| 38 | ||
| 39 | } |
|
| 40 | ||
| @@ 12-39 (lines=28) @@ | ||
| 9 | * |
|
| 10 | * @author Mahmoud Zalt <[email protected]> |
|
| 11 | */ |
|
| 12 | class ListAllCountriesTest extends TestCase |
|
| 13 | { |
|
| 14 | ||
| 15 | protected $endpoint = '/countries'; |
|
| 16 | ||
| 17 | protected $access = [ |
|
| 18 | 'roles' => '', |
|
| 19 | 'permissions' => '', |
|
| 20 | ]; |
|
| 21 | ||
| 22 | public function testListAllCountries_() |
|
| 23 | { |
|
| 24 | $this->getTestingUser(); |
|
| 25 | ||
| 26 | // send the HTTP request |
|
| 27 | $response = $this->apiCall($this->endpoint, 'get'); |
|
| 28 | ||
| 29 | // assert response status is correct |
|
| 30 | $this->assertEquals($response->getStatusCode(), '200'); |
|
| 31 | ||
| 32 | // convert JSON response string to object |
|
| 33 | $responseObject = $this->getResponseObject($response); |
|
| 34 | ||
| 35 | // assert the returned data size is correct |
|
| 36 | $this->assertCount(249, $responseObject->data); |
|
| 37 | } |
|
| 38 | ||
| 39 | } |
|
| 40 | ||
| @@ 13-62 (lines=50) @@ | ||
| 10 | * |
|
| 11 | * @author Mahmoud Zalt <[email protected]> |
|
| 12 | */ |
|
| 13 | class ListAllUsersTest extends TestCase |
|
| 14 | { |
|
| 15 | ||
| 16 | protected $endpoint = '/users'; |
|
| 17 | ||
| 18 | protected $access = [ |
|
| 19 | 'roles' => 'admin', |
|
| 20 | 'permissions' => 'list-users', |
|
| 21 | ]; |
|
| 22 | ||
| 23 | public function testListAllUsersByAdmin_() |
|
| 24 | { |
|
| 25 | $this->getTestingAdmin(); |
|
| 26 | ||
| 27 | // create some non-admin users |
|
| 28 | factory(User::class, 4)->create(); |
|
| 29 | ||
| 30 | // send the HTTP request |
|
| 31 | $response = $this->apiCall($this->endpoint, 'get'); |
|
| 32 | ||
| 33 | // assert response status is correct |
|
| 34 | $this->assertEquals('200', $response->getStatusCode()); |
|
| 35 | ||
| 36 | // convert JSON response string to Object |
|
| 37 | $responseObject = $this->getResponseObject($response); |
|
| 38 | ||
| 39 | // assert the returned data size is correct |
|
| 40 | $this->assertCount(6, |
|
| 41 | $responseObject->data); // 6 = 4 (fake in this test) + 1 (that is logged in) + 1 (seeded super admin) |
|
| 42 | } |
|
| 43 | ||
| 44 | // TODO: uncomment this. was temporally commented out after upgrading from L5.3 to L5.4 |
|
| 45 | // because the error handler is not capturing the authorization error and transforming it to 403 |
|
| 46 | ||
| 47 | // public function testListAllUsersByNonAdmin_() |
|
| 48 | // { |
|
| 49 | // // by default permission is set, so we need to revoke it manually |
|
| 50 | // $this->getTestingUserWithoutPermissions(); |
|
| 51 | // |
|
| 52 | // // create some fake users |
|
| 53 | // factory(User::class, 4)->create(); |
|
| 54 | // |
|
| 55 | // // send the HTTP request |
|
| 56 | // $response = $this->apiCall($this->endpoint, 'get'); |
|
| 57 | // |
|
| 58 | // // assert response status is correct |
|
| 59 | // $this->assertEquals('403', $response->getStatusCode()); |
|
| 60 | // } |
|
| 61 | ||
| 62 | } |
|
| 63 | ||
| @@ 13-41 (lines=29) @@ | ||
| 10 | * |
|
| 11 | * @author Mahmoud Zalt <[email protected]> |
|
| 12 | */ |
|
| 13 | class DeleteRoleTest extends TestCase |
|
| 14 | { |
|
| 15 | ||
| 16 | protected $endpoint = '/roles/{id}'; |
|
| 17 | ||
| 18 | protected $access = [ |
|
| 19 | 'roles' => 'admin', |
|
| 20 | 'permissions' => '', |
|
| 21 | ]; |
|
| 22 | ||
| 23 | public function testDeleteExistingRole_() |
|
| 24 | { |
|
| 25 | $this->getTestingAdmin(); |
|
| 26 | ||
| 27 | $role = factory(Role::class)->create(); |
|
| 28 | ||
| 29 | // send the HTTP request |
|
| 30 | $response = $this->apiCall($this->injectEndpointId($this->endpoint, $role->id), 'delete'); |
|
| 31 | ||
| 32 | // assert response status is correct |
|
| 33 | $this->assertEquals('202', $response->getStatusCode()); |
|
| 34 | ||
| 35 | // assert the returned message is correct |
|
| 36 | $this->assertResponseContainKeyValue([ |
|
| 37 | 'message' => 'Role (' . $role->id . ') Deleted Successfully.', |
|
| 38 | ], $response); |
|
| 39 | } |
|
| 40 | ||
| 41 | } |
|
| 42 | ||