*/ class CountryApiTest extends JsonApiTestCase { /** * @var array */ private static $authorizedHeaderWithContentType = [ 'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', 'CONTENT_TYPE' => 'application/json', ]; /** * @var array */ private static $authorizedHeaderWithAccept = [ 'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', 'ACCEPT' => 'application/json', ]; public function testCreateCountryAccessDeniedResponse() { $this->client->request('POST', '/api/countries/'); $response = $this->client->getResponse(); $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED); } public function testCreateCountryValidationFailResponse() { $this->loadFixturesFromFile('authentication/api_administrator.yml'); $this->client->request('POST', '/api/countries/', [], [], static::$authorizedHeaderWithContentType); $response = $this->client->getResponse(); $this->assertResponse($response, 'country/create_validation_fail_response', Response::HTTP_BAD_REQUEST); } public function testCreateCountryResponse() { $this->loadFixturesFromFile('authentication/api_administrator.yml'); $data = <<client->request('POST', '/api/countries/', [], [], static::$authorizedHeaderWithContentType, $data); $response = $this->client->getResponse(); $this->assertResponse($response, 'country/create_response', Response::HTTP_CREATED); } public function testGetSCountryWhichDoesNotExistResponse() { $this->loadFixturesFromFile('authentication/api_administrator.yml'); $this->client->request('GET', '/api/countries/-1', [], [], static::$authorizedHeaderWithAccept); $response = $this->client->getResponse(); $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND); } public function testGetCountriesListResponse() { $this->loadFixturesFromFile('authentication/api_administrator.yml'); $this->loadFixturesFromFile('resources/countries.yml'); $this->client->request('GET', '/api/countries/', [], [], static::$authorizedHeaderWithAccept); $response = $this->client->getResponse(); $this->assertResponse($response, 'country/index_response', Response::HTTP_OK); } public function testGetCountryResponse() { $this->loadFixturesFromFile('authentication/api_administrator.yml'); $countries = $this->loadFixturesFromFile('resources/countries.yml'); $this->client->request('GET', '/api/countries/'.$countries['country_NL']->getId(), [], [], static::$authorizedHeaderWithAccept); $response = $this->client->getResponse(); $this->assertResponse($response, 'country/show_response', Response::HTTP_OK); } public function testGetCountryAccessDeniedResponse() { $this->loadFixturesFromFile('resources/countries.yml'); $this->client->request('GET', '/api/countries/1'); $response = $this->client->getResponse(); $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED); } public function testDeleteCountryWhichDoesNotExistResponse() { $this->loadFixturesFromFile('authentication/api_administrator.yml'); $this->client->request('DELETE', '/api/countries/-1', [], [], static::$authorizedHeaderWithAccept); $response = $this->client->getResponse(); $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND); } public function testDeleteCountryResponse() { $this->loadFixturesFromFile('authentication/api_administrator.yml'); $countries = $this->loadFixturesFromFile('resources/countries.yml'); $this->client->request('DELETE', '/api/countries/' . $countries['country_NL']->getId(), [], [], static::$authorizedHeaderWithContentType, []); $response = $this->client->getResponse(); $this->assertResponseCode($response, Response::HTTP_NO_CONTENT); $this->client->request('GET', '/api/countries/' . $countries['country_NL']->getId(), [], [], static::$authorizedHeaderWithAccept); $response = $this->client->getResponse(); $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND); } }