mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-15 09:30:58 +00:00
263 lines
11 KiB
PHP
263 lines
11 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>
|
|
*/
|
|
class ShippingCategoryApiTest extends JsonApiTestCase
|
|
{
|
|
public function testCreateShippingCategoryAccessDeniedResponse()
|
|
{
|
|
$this->client->request('POST', '/api/shipping-categories/');
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
|
|
}
|
|
|
|
public function testCreateShippingCategoryValidationFailResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
|
|
$this->client->request('POST', '/api/shipping-categories/', [], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
'CONTENT_TYPE' => 'application/json',
|
|
]);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'shipping_category/create_validation_fail_response', Response::HTTP_BAD_REQUEST);
|
|
}
|
|
|
|
public function testCreateShippingCategoryResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
|
|
$data =
|
|
<<<EOT
|
|
{
|
|
"code": "reg",
|
|
"name": "Regular",
|
|
"description": "Regular weight items"
|
|
}
|
|
EOT;
|
|
|
|
$this->client->request('POST', '/api/shipping-categories/', [], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
'CONTENT_TYPE' => 'application/json',
|
|
], $data);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'shipping_category/create_response', Response::HTTP_CREATED);
|
|
}
|
|
|
|
public function testGetShippingCategoriesListAccessDeniedResponse()
|
|
{
|
|
$this->client->request('GET', '/api/shipping-categories/');
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
|
|
}
|
|
|
|
public function testGetShippingCategoriesListResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
$this->loadFixturesFromFile('resources/shipping_categories.yml');
|
|
|
|
$this->client->request('GET', '/api/shipping-categories/', [], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
]);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'shipping_category/index_response', Response::HTTP_OK);
|
|
}
|
|
|
|
public function testGetShippingCategoryAccessDeniedResponse()
|
|
{
|
|
$this->client->request('GET', '/api/shipping-categories/1');
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
|
|
}
|
|
|
|
public function testGetShippingCategoryWhichDoesNotExistResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
|
|
$this->client->request('GET', '/api/shipping-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 testGetShippingCategoryResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
$shippingCategories = $this->loadFixturesFromFile('resources/shipping_categories.yml');
|
|
|
|
$this->client->request('GET', '/api/shipping-categories/'.$shippingCategories['shipping_category_1']->getId(), [], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
'ACCEPT' => 'application/json',
|
|
]);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'shipping_category/show_response', Response::HTTP_OK);
|
|
}
|
|
|
|
public function testFullUpdateShippingCategoryAccessDeniedResponse()
|
|
{
|
|
$this->client->request('PUT', '/api/shipping-categories/1');
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
|
|
}
|
|
|
|
public function testFullUpdateShippingCategoryWhichDoesNotExistResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
|
|
$this->client->request('PUT', '/api/shipping-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 testFullUpdateShippingCategoryValidationFailResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
$shippingCategories = $this->loadFixturesFromFile('resources/shipping_categories.yml');
|
|
|
|
$this->client->request('PUT', '/api/shipping-categories/'.$shippingCategories['shipping_category_1']->getId(), [], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
'CONTENT_TYPE' => 'application/json',
|
|
]);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'shipping_category/update_validation_fail_response', Response::HTTP_BAD_REQUEST);
|
|
}
|
|
|
|
public function testFullUpdateShippingCategoryResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
$shippingCategories = $this->loadFixturesFromFile('resources/shipping_categories.yml');
|
|
|
|
$data =
|
|
<<<EOT
|
|
{
|
|
"name": "Light",
|
|
"description": "Light weight items"
|
|
}
|
|
EOT;
|
|
|
|
$this->client->request('PUT', '/api/shipping-categories/'.$shippingCategories['shipping_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/shipping-categories/'.$shippingCategories['shipping_category_1']->getId(), [], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
'ACCEPT' => 'application/json',
|
|
]);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'shipping_category/update_response', Response::HTTP_OK);
|
|
}
|
|
|
|
public function testPartialUpdateShippingCategoryWhichDoesNotExistResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
|
|
$this->client->request('PATCH', '/api/shipping-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 testPartialUpdateShippingCategoryResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
$shippingCategories = $this->loadFixturesFromFile('resources/shipping_categories.yml');
|
|
|
|
$data =
|
|
<<<EOT
|
|
{
|
|
"name": "Light",
|
|
"description": "Light weight items"
|
|
}
|
|
EOT;
|
|
|
|
$this->client->request('PATCH', '/api/shipping-categories/'.$shippingCategories['shipping_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/shipping-categories/'.$shippingCategories['shipping_category_1']->getId(), [], [], [
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
|
'ACCEPT' => 'application/json',
|
|
]);
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertResponse($response, 'shipping_category/update_response', Response::HTTP_OK);
|
|
}
|
|
|
|
public function testDeleteShippingCategoryWhichDoesNotExistResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
|
|
$this->client->request('DELETE', '/api/shipping-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 testDeleteShippingCategoryResponse()
|
|
{
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
|
$shippingCategories = $this->loadFixturesFromFile('resources/shipping_categories.yml');
|
|
|
|
$this->client->request('DELETE', '/api/shipping-categories/'.$shippingCategories['shipping_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/shipping-categories/'.$shippingCategories['shipping_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);
|
|
}
|
|
}
|