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\ProductAssociationTypeInterface; |
16
|
|
|
use Symfony\Component\HttpFoundation\Response; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Kamil Kokot <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
final class ProductAssociationTypeApiTest extends JsonApiTestCase |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @test |
25
|
|
|
*/ |
26
|
|
|
public function it_denies_creating_product_association_type_for_non_authenticated_user() |
27
|
|
|
{ |
28
|
|
|
$this->client->request('POST', '/api/v1/product-association-types/'); |
29
|
|
|
|
30
|
|
|
$response = $this->client->getResponse(); |
31
|
|
|
$this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @test |
36
|
|
|
*/ |
37
|
|
|
public function it_does_not_allow_to_create_product_association_type_without_specifying_required_data() |
38
|
|
|
{ |
39
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
40
|
|
|
|
41
|
|
|
$this->client->request('POST', '/api/v1/product-association-types/', [], [], [ |
42
|
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', |
43
|
|
|
'CONTENT_TYPE' => 'application/json', |
44
|
|
|
]); |
45
|
|
|
|
46
|
|
|
$response = $this->client->getResponse(); |
47
|
|
|
$this->assertResponse($response, 'product_association_type/create_validation_fail_response', Response::HTTP_BAD_REQUEST); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @test |
52
|
|
|
*/ |
53
|
|
|
public function it_allows_to_create_product_association_type() |
54
|
|
|
{ |
55
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
56
|
|
|
$this->loadFixturesFromFile('resources/locales.yml'); |
57
|
|
|
|
58
|
|
|
$data = |
59
|
|
|
<<<EOT |
60
|
|
|
{ |
61
|
|
|
"code": "cross_sell", |
62
|
|
|
"translations": { |
63
|
|
|
"en_US": { |
64
|
|
|
"name": "Cross sell" |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
EOT; |
69
|
|
|
|
70
|
|
|
$this->client->request('POST', '/api/v1/product-association-types/', [], [], [ |
71
|
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', |
72
|
|
|
'CONTENT_TYPE' => 'application/json', |
73
|
|
|
], $data); |
74
|
|
|
|
75
|
|
|
$response = $this->client->getResponse(); |
76
|
|
|
$this->assertResponse($response, 'product_association_type/create_response', Response::HTTP_CREATED); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @test |
81
|
|
|
*/ |
82
|
|
|
public function it_denies_getting_product_association_types_for_non_authenticated_user() |
83
|
|
|
{ |
84
|
|
|
$this->client->request('GET', '/api/v1/product-association-types/'); |
85
|
|
|
|
86
|
|
|
$response = $this->client->getResponse(); |
87
|
|
|
$this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @test |
92
|
|
|
*/ |
93
|
|
|
public function it_allows_to_get_product_association_types() |
94
|
|
|
{ |
95
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
96
|
|
|
$this->loadFixturesFromFile('resources/product_association_types.yml'); |
97
|
|
|
|
98
|
|
|
$this->client->request('GET', '/api/v1/product-association-types/', [], [], [ |
99
|
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', |
100
|
|
|
]); |
101
|
|
|
|
102
|
|
|
$response = $this->client->getResponse(); |
103
|
|
|
$this->assertResponse($response, 'product_association_type/index_response', Response::HTTP_OK); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @test |
108
|
|
|
*/ |
109
|
|
|
public function it_denies_getting_product_association_type_for_non_authenticated_user() |
110
|
|
|
{ |
111
|
|
|
$this->client->request('GET', '/api/v1/product-association-types/1'); |
112
|
|
|
|
113
|
|
|
$response = $this->client->getResponse(); |
114
|
|
|
$this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @test |
119
|
|
|
*/ |
120
|
|
|
public function it_returns_not_found_response_when_requesting_details_of_a_product_association_type_which_does_not_exist() |
121
|
|
|
{ |
122
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
123
|
|
|
|
124
|
|
|
$this->client->request('GET', '/api/v1/product-association-types/-1', [], [], [ |
125
|
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', |
126
|
|
|
'ACCEPT' => 'application/json', |
127
|
|
|
]); |
128
|
|
|
|
129
|
|
|
$response = $this->client->getResponse(); |
130
|
|
|
$this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @test |
135
|
|
|
*/ |
136
|
|
|
public function it_allows_to_get_product_association_type() |
137
|
|
|
{ |
138
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
139
|
|
|
$productAssociationTypes = $this->loadFixturesFromFile('resources/product_association_types.yml'); |
140
|
|
|
$productAssociationType = $productAssociationTypes['productAssociationType1']; |
141
|
|
|
|
142
|
|
|
$this->client->request('GET', $this->getAssociationTypeUrl($productAssociationType), [], [], [ |
143
|
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', |
144
|
|
|
'ACCEPT' => 'application/json', |
145
|
|
|
]); |
146
|
|
|
|
147
|
|
|
$response = $this->client->getResponse(); |
148
|
|
|
$this->assertResponse($response, 'product_association_type/show_response', Response::HTTP_OK); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @test |
153
|
|
|
*/ |
154
|
|
|
public function it_denies_updating_product_association_type_for_non_authenticated_user() |
155
|
|
|
{ |
156
|
|
|
$this->client->request('PUT', '/api/v1/product-association-types/1'); |
157
|
|
|
|
158
|
|
|
$response = $this->client->getResponse(); |
159
|
|
|
$this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @test |
164
|
|
|
*/ |
165
|
|
|
public function it_returns_not_found_response_when_trying_to_update_product_association_type_which_does_not_exist() |
166
|
|
|
{ |
167
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
168
|
|
|
|
169
|
|
|
$this->client->request('PUT', '/api/v1/product-association-types/-1', [], [], [ |
170
|
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', |
171
|
|
|
'ACCEPT' => 'application/json', |
172
|
|
|
]); |
173
|
|
|
|
174
|
|
|
$response = $this->client->getResponse(); |
175
|
|
|
$this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @test |
180
|
|
|
*/ |
181
|
|
|
public function it_does_not_allow_to_update_product_association_type_without_specifying_required_data() |
182
|
|
|
{ |
183
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
184
|
|
|
$this->loadFixturesFromFile('resources/locales.yml'); |
185
|
|
|
$productAssociationTypes = $this->loadFixturesFromFile('resources/product_association_types.yml'); |
186
|
|
|
$productAssociationType = $productAssociationTypes['productAssociationType1']; |
187
|
|
|
|
188
|
|
|
$this->client->request('PUT', $this->getAssociationTypeUrl($productAssociationType), [], [], [ |
189
|
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', |
190
|
|
|
'CONTENT_TYPE' => 'application/json', |
191
|
|
|
]); |
192
|
|
|
|
193
|
|
|
$response = $this->client->getResponse(); |
194
|
|
|
$this->assertResponse($response, 'product_association_type/update_validation_fail_response', Response::HTTP_BAD_REQUEST); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @test |
199
|
|
|
*/ |
200
|
|
|
public function it_allows_to_update_product_association_type() |
201
|
|
|
{ |
202
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
203
|
|
|
$this->loadFixturesFromFile('resources/locales.yml'); |
204
|
|
|
$productAssociationTypes = $this->loadFixturesFromFile('resources/product_association_types.yml'); |
205
|
|
|
$productAssociationType = $productAssociationTypes['productAssociationType1']; |
206
|
|
|
|
207
|
|
|
$data = |
208
|
|
|
<<<EOT |
209
|
|
|
{ |
210
|
|
|
"translations": { |
211
|
|
|
"en_US": { |
212
|
|
|
"name": "Cross sell (old)" |
213
|
|
|
}, |
214
|
|
|
"nl_NL": { |
215
|
|
|
"name": "Cross sell (old, nl_NL)" |
216
|
|
|
} |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
EOT; |
220
|
|
|
|
221
|
|
|
$this->client->request('PUT', $this->getAssociationTypeUrl($productAssociationType), [], [], [ |
222
|
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', |
223
|
|
|
'CONTENT_TYPE' => 'application/json', |
224
|
|
|
], $data); |
225
|
|
|
|
226
|
|
|
$response = $this->client->getResponse(); |
227
|
|
|
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @test |
232
|
|
|
*/ |
233
|
|
|
public function it_returns_not_found_response_when_trying_to_partially_update_product_association_type_which_does_not_exist() |
234
|
|
|
{ |
235
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
236
|
|
|
|
237
|
|
|
$this->client->request('PATCH', '/api/v1/product-association-types/-1', [], [], [ |
238
|
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', |
239
|
|
|
'ACCEPT' => 'application/json', |
240
|
|
|
]); |
241
|
|
|
|
242
|
|
|
$response = $this->client->getResponse(); |
243
|
|
|
$this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @test |
248
|
|
|
*/ |
249
|
|
|
public function it_allows_to_partially_update_product_association_type() |
250
|
|
|
{ |
251
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
252
|
|
|
$this->loadFixturesFromFile('resources/locales.yml'); |
253
|
|
|
$productAssociationTypes = $this->loadFixturesFromFile('resources/product_association_types.yml'); |
254
|
|
|
$productAssociationType = $productAssociationTypes['productAssociationType1']; |
255
|
|
|
|
256
|
|
|
$data = |
257
|
|
|
<<<EOT |
258
|
|
|
{ |
259
|
|
|
"translations": { |
260
|
|
|
"en_US": { |
261
|
|
|
"name": "Cross sell (old)" |
262
|
|
|
} |
263
|
|
|
} |
264
|
|
|
} |
265
|
|
|
EOT; |
266
|
|
|
|
267
|
|
|
$this->client->request('PATCH', $this->getAssociationTypeUrl($productAssociationType), [], [], [ |
268
|
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', |
269
|
|
|
'CONTENT_TYPE' => 'application/json', |
270
|
|
|
], $data); |
271
|
|
|
|
272
|
|
|
$response = $this->client->getResponse(); |
273
|
|
|
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* @test |
278
|
|
|
*/ |
279
|
|
|
public function it_returns_not_found_response_when_trying_to_delete_product_association_type_which_does_not_exist() |
280
|
|
|
{ |
281
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
282
|
|
|
|
283
|
|
|
$this->client->request('DELETE', '/api/v1/product-association-types/-1', [], [], [ |
284
|
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', |
285
|
|
|
'ACCEPT' => 'application/json', |
286
|
|
|
]); |
287
|
|
|
|
288
|
|
|
$response = $this->client->getResponse(); |
289
|
|
|
$this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* @test |
294
|
|
|
*/ |
295
|
|
|
public function it_allows_to_delete_product_association_type() |
296
|
|
|
{ |
297
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
298
|
|
|
$productAssociationTypes = $this->loadFixturesFromFile('resources/product_association_types.yml'); |
299
|
|
|
$productAssociationType = $productAssociationTypes['productAssociationType1']; |
300
|
|
|
|
301
|
|
|
$this->client->request('DELETE', $this->getAssociationTypeUrl($productAssociationType), [], [], [ |
302
|
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', |
303
|
|
|
'CONTENT_TYPE' => 'application/json', |
304
|
|
|
], []); |
305
|
|
|
|
306
|
|
|
$response = $this->client->getResponse(); |
307
|
|
|
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT); |
308
|
|
|
|
309
|
|
|
$this->client->request('GET', $this->getAssociationTypeUrl($productAssociationType), [], [], [ |
310
|
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', |
311
|
|
|
'ACCEPT' => 'application/json', |
312
|
|
|
]); |
313
|
|
|
|
314
|
|
|
$response = $this->client->getResponse(); |
315
|
|
|
$this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND); |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* @param ProductAssociationTypeInterface $productAssociationType |
320
|
|
|
* |
321
|
|
|
* @return string |
322
|
|
|
*/ |
323
|
|
|
private function getAssociationTypeUrl(ProductAssociationTypeInterface $productAssociationType) |
324
|
|
|
{ |
325
|
|
|
return 'api/v1/product-association-types/' . $productAssociationType->getCode(); |
326
|
|
|
} |
327
|
|
|
} |
328
|
|
|
|