1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sylius\Tests\Controller; |
13
|
|
|
|
14
|
|
|
use Lakion\ApiTestCase\JsonApiTestCase; |
15
|
|
|
use Sylius\Component\Product\Model\ProductAttributeInterface; |
16
|
|
|
use Symfony\Component\HttpFoundation\Response; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Anna Walasek <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
final class ProductAttributeApiTest extends JsonApiTestCase |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
private static $authorizedHeaderWithAccept = [ |
27
|
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', |
28
|
|
|
'ACCEPT' => 'application/json', |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @test |
33
|
|
|
*/ |
34
|
|
|
public function it_does_not_allow_to_show_product_attributes_list_when_access_is_denied() |
35
|
|
|
{ |
36
|
|
|
$this->loadFixturesFromFile('resources/product_attributes.yml'); |
37
|
|
|
|
38
|
|
|
$this->client->request('GET', '/api/v1/product-attributes/'); |
39
|
|
|
|
40
|
|
|
$response = $this->client->getResponse(); |
41
|
|
|
$this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @test |
46
|
|
|
*/ |
47
|
|
|
public function it_allows_indexing_product_attributes() |
48
|
|
|
{ |
49
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
50
|
|
|
$this->loadFixturesFromFile('resources/product_attributes.yml'); |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
$this->client->request('GET', '/api/v1/product-attributes/', [], [], static::$authorizedHeaderWithAccept); |
|
|
|
|
54
|
|
|
|
55
|
|
|
$response = $this->client->getResponse(); |
56
|
|
|
$this->assertResponse($response, 'product_attribute/index_response', Response::HTTP_OK); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @test |
61
|
|
|
*/ |
62
|
|
|
public function it_does_not_allow_to_show_product_attribute_when_it_does_not_exist() |
63
|
|
|
{ |
64
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
65
|
|
|
|
66
|
|
|
$this->client->request('GET', '/api/v1/product-attributes/-1', [], [], static::$authorizedHeaderWithAccept); |
|
|
|
|
67
|
|
|
|
68
|
|
|
$response = $this->client->getResponse(); |
69
|
|
|
$this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @test |
74
|
|
|
*/ |
75
|
|
|
public function it_allows_showing_product_attribute() |
76
|
|
|
{ |
77
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
78
|
|
|
$productAttributes = $this->loadFixturesFromFile('resources/product_attributes.yml'); |
79
|
|
|
$productAttribute = $productAttributes['productAttribute1']; |
80
|
|
|
|
81
|
|
|
$this->client->request('GET', $this->getProductAttributeUrl($productAttribute), [], [], static::$authorizedHeaderWithAccept); |
|
|
|
|
82
|
|
|
|
83
|
|
|
$response = $this->client->getResponse(); |
84
|
|
|
$this->assertResponse($response, 'product_attribute/show_response', Response::HTTP_OK); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param ProductAttributeInterface $productAttribute |
89
|
|
|
* |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
private function getProductAttributeUrl(ProductAttributeInterface $productAttribute) |
93
|
|
|
{ |
94
|
|
|
return '/api/v1/product-attributes/' . $productAttribute->getCode(); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
Late static binding only has effect in subclasses. A
final
class cannot be extended anymore so late static binding cannot occurr. Consider replacingstatic::
withself::
.To learn more about late static binding, please refer to the PHP core documentation.