mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-15 09:30:58 +00:00
302 lines
13 KiB
PHP
302 lines
13 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Sylius package.
|
|
*
|
|
* (c) Paweł Jędrzejewski
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Sylius\Bundle\CoreBundle\Tests\Controller;
|
|
|
|
use Lakion\ApiTestCase\JsonApiTestCase;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
/**
|
|
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
|
|
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
|
*/
|
|
class TaxCategoryApiTest extends JsonApiTestCase
|
|
{
|
|
public function testCreateTaxCategoryAccessDeniedResponse()
|
|
{
|
|
$this->client->request('POST', '/api/tax-categories/');
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
|
|
}
|
|
|
|
public function testCreateTaxCategoryValidationFailResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
|
|
$this->client->request('POST', '/api/tax-categories/', [], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
'CONTENT_TYPE' => 'application/json',
|
|
]);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'tax_category/create_validation_fail_response', Response::HTTP_BAD_REQUEST);
|
|
}
|
|
|
|
public function testCreateTaxCategoryResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
|
|
$data =
|
|
<<<EOT
|
|
{
|
|
"code": "clothing",
|
|
"name": "Clothing",
|
|
"description": "All items classified as clothing."
|
|
}
|
|
EOT;
|
|
|
|
$this->client->request('POST', '/api/tax-categories/', [], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
'CONTENT_TYPE' => 'application/json',
|
|
], $data);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'tax_category/create_response', Response::HTTP_CREATED);
|
|
}
|
|
|
|
public function testGetTaxCategoriesListAccessDeniedResponse()
|
|
{
|
|
$this->client->request('GET', '/api/tax-categories/');
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
|
|
}
|
|
|
|
public function testGetTaxCategoriesListResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
$this->loadFixturesFromFile('resources/tax_categories.yml');
|
|
|
|
$this->client->request('GET', '/api/tax-categories/', [], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
]);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'tax_category/index_response', Response::HTTP_OK);
|
|
}
|
|
|
|
public function testGetTaxCategoriesSortedListResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
$this->loadFixturesFromFile('resources/tax_categories.yml');
|
|
|
|
$this->client->request('GET', '/api/tax-categories/', ['sorting' => ['name' => 'asc']], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
]);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'tax_category/sorted_index_response', Response::HTTP_OK);
|
|
}
|
|
|
|
public function testGetTaxCategoriesFilteredListByNameResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
$this->loadFixturesFromFile('resources/tax_categories_for_filtering.yml');
|
|
|
|
$this->client->request('GET', '/api/tax-categories/', ['criteria' => ['name' => 'clothing']], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
]);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'tax_category/filtered_by_name_index_response', Response::HTTP_OK);
|
|
}
|
|
|
|
public function testGetTaxCategoriesFilteredListByCodeResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
$this->loadFixturesFromFile('resources/tax_categories_for_filtering.yml');
|
|
|
|
$this->client->request('GET', '/api/tax-categories/', ['criteria' => ['code' => 'TC1']], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
]);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'tax_category/filtered_by_code_index_response', Response::HTTP_OK);
|
|
}
|
|
|
|
public function testGetTaxCategoryAccessDeniedResponse()
|
|
{
|
|
$this->client->request('GET', '/api/tax-categories/1');
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
|
|
}
|
|
|
|
public function testGetTaxCategoryWhichDoesNotExistResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
|
|
$this->client->request('GET', '/api/tax-categories/-1', [], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
'ACCEPT' => 'application/json',
|
|
]);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
|
|
}
|
|
|
|
public function testGetTaxCategoryResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
$taxCategories = $this->loadFixturesFromFile('resources/tax_categories.yml');
|
|
|
|
$this->client->request('GET', '/api/tax-categories/'.$taxCategories['tax_category_1']->getId(), [], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
'ACCEPT' => 'application/json',
|
|
]);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'tax_category/show_response', Response::HTTP_OK);
|
|
}
|
|
|
|
public function testFullUpdateTaxCategoryAccessDeniedResponse()
|
|
{
|
|
$this->client->request('PUT', '/api/tax-categories/1');
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
|
|
}
|
|
|
|
public function testFullUpdateTaxCategoryWhichDoesNotExistResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
|
|
$this->client->request('PUT', '/api/tax-categories/-1', [], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
'ACCEPT' => 'application/json',
|
|
]);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
|
|
}
|
|
|
|
public function testFullUpdateTaxCategoryValidationFailResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
$taxCategories = $this->loadFixturesFromFile('resources/tax_categories.yml');
|
|
|
|
$this->client->request('PUT', '/api/tax-categories/'.$taxCategories['tax_category_1']->getId(), [], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
'CONTENT_TYPE' => 'application/json',
|
|
]);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'tax_category/update_validation_fail_response', Response::HTTP_BAD_REQUEST);
|
|
}
|
|
|
|
public function testFullUpdateTaxCategoryResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
$taxCategories = $this->loadFixturesFromFile('resources/tax_categories.yml');
|
|
|
|
$data =
|
|
<<<EOT
|
|
{
|
|
"name": "Clothing & Accessories",
|
|
"description": "All items classified as clothing with accessories."
|
|
}
|
|
EOT;
|
|
|
|
$this->client->request('PUT', '/api/tax-categories/'.$taxCategories['tax_category_1']->getId(), [], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
'CONTENT_TYPE' => 'application/json',
|
|
], $data);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
|
|
|
|
$this->client->request('GET', '/api/tax-categories/'.$taxCategories['tax_category_1']->getId(), [], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
'ACCEPT' => 'application/json',
|
|
]);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'tax_category/update_response', Response::HTTP_OK);
|
|
}
|
|
|
|
public function testPartialUpdateTaxCategoryWhichDoesNotExistResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
|
|
$this->client->request('PATCH', '/api/tax-categories/-1', [], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
'ACCEPT' => 'application/json',
|
|
]);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
|
|
}
|
|
|
|
public function testPartialUpdateTaxCategoryResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
$taxCategories = $this->loadFixturesFromFile('resources/tax_categories.yml');
|
|
|
|
$data =
|
|
<<<EOT
|
|
{
|
|
"name": "Clothing & Accessories"
|
|
}
|
|
EOT;
|
|
|
|
$this->client->request('PATCH', '/api/tax-categories/'.$taxCategories['tax_category_1']->getId(), [], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
'CONTENT_TYPE' => 'application/json',
|
|
], $data);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
|
|
|
|
$this->client->request('GET', '/api/tax-categories/'.$taxCategories['tax_category_1']->getId(), [], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
'ACCEPT' => 'application/json',
|
|
]);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'tax_category/partial_update_response', Response::HTTP_OK);
|
|
}
|
|
|
|
public function testDeleteTaxCategoryWhichDoesNotExistResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
|
|
$this->client->request('DELETE', '/api/tax-categories/-1', [], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
'ACCEPT' => 'application/json',
|
|
]);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
|
|
}
|
|
|
|
public function testDeleteTaxCategoryResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
$taxCategories = $this->loadFixturesFromFile('resources/tax_categories.yml');
|
|
|
|
$this->client->request('DELETE', '/api/tax-categories/'.$taxCategories['tax_category_1']->getId(), [], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
'CONTENT_TYPE' => 'application/json',
|
|
], []);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
|
|
|
|
$this->client->request('GET', '/api/tax-categories/'.$taxCategories['tax_category_1']->getId(), [], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
'ACCEPT' => 'application/json',
|
|
]);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
|
|
}
|
|
}
|