Completed
Push — allow-no-default-tax-zone-in-c... ( 67cea0 )
by Kamil
06:23
created

CartApiTest::it_allows_to_delete_cart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
declare(strict_types=1);
13
14
namespace Sylius\Tests\Controller;
15
16
use Lakion\ApiTestCase\JsonApiTestCase;
17
use Sylius\Component\Core\Model\OrderInterface;
18
use Sylius\Component\Order\Model\OrderItemInterface;
19
use Symfony\Component\HttpFoundation\Response;
20
21
final class CartApiTest extends JsonApiTestCase
22
{
23
    /** @var array */
24
    private static $authorizedHeaderWithContentType = [
25
        'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
26
        'CONTENT_TYPE' => 'application/json',
27
    ];
28
29
    /** @var array */
30
    private static $authorizedHeaderWithAccept = [
31
        'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
32
        'ACCEPT' => 'application/json',
33
    ];
34
35
    /**
36
     * @test
37
     */
38
    public function it_denies_getting_an_cart_for_non_authenticated_user()
39
    {
40
        $this->client->request('GET', $this->getCartApiUrl('-1'));
41
42
        $response = $this->client->getResponse();
43
        $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
44
    }
45
46
    /**
47
     * @test
48
     */
49
    public function it_returns_not_found_response_when_requesting_details_of_an_cart_which_does_not_exist()
50
    {
51
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
52
53
        $this->client->request('GET', $this->getCartApiUrl('-1'), [], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
54
55
        $response = $this->client->getResponse();
56
        $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
57
    }
58
59
    /**
60
     * @test
61
     */
62
    public function it_allows_to_get_cart()
63
    {
64
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
65
        $cartData = $this->loadFixturesFromFile('resources/cart.yml');
66
67
        /** @var OrderInterface $cart */
68
        $cart = $cartData['order_001'];
69
70
        $this->client->request('GET', $this->getCartApiUrl((string) $cart->getId()), [], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
71
72
        $response = $this->client->getResponse();
73
        $this->assertResponse($response, 'cart/show_response', Response::HTTP_OK);
74
    }
75
76
    /**
77
     * @test
78
     */
79
    public function it_does_not_show_orders_in_state_other_than_cart()
80
    {
81
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
82
        $orderData = $this->loadFixturesFromFile('resources/order.yml');
83
84
        /** @var OrderInterface $cart */
85
        $cart = $orderData['order_001'];
86
87
        $this->client->request('GET', $this->getCartApiUrl((string) $cart->getId()), [], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
88
89
        $response = $this->client->getResponse();
90
        $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
91
    }
92
93
    /**
94
     * @test
95
     */
96
    public function it_denies_creating_cart_for_non_authenticated_user()
97
    {
98
        $this->client->request('POST', $this->getCartApiUrl());
99
100
        $response = $this->client->getResponse();
101
        $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
102
    }
103
104
    /**
105
     * @test
106
     */
107
    public function it_does_not_allow_to_create_cart_without_specifying_required_data()
108
    {
109
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
110
111
        $this->client->request('POST', $this->getCartApiUrl(), [], [], static::$authorizedHeaderWithContentType);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
112
113
        $response = $this->client->getResponse();
114
        $this->assertResponse($response, 'cart/create_validation_fail_response', Response::HTTP_BAD_REQUEST);
115
    }
116
117
    /**
118
     * @test
119
     */
120
    public function it_allows_to_create_cart()
121
    {
122
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
123
        $this->loadFixturesFromFile('resources/cart.yml');
124
125
        $data =
126
<<<EOT
127
        {
128
            "customer": "[email protected]",
129
            "channel": "WEB",
130
            "localeCode": "en_US"
131
        }
132
EOT;
133
134
        $this->client->request('POST', $this->getCartApiUrl(), [], [], static::$authorizedHeaderWithContentType, $data);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
135
136
        $response = $this->client->getResponse();
137
138
        $this->assertResponse($response, 'cart/show_response', Response::HTTP_CREATED);
139
    }
140
141
    /**
142
     * @test
143
     */
144
    public function it_denies_getting_carts_for_non_authenticated_user()
145
    {
146
        $this->client->request('GET', $this->getCartApiUrl());
147
148
        $response = $this->client->getResponse();
149
        $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
150
    }
151
152
    /**
153
     * @test
154
     */
155
    public function it_allows_to_get_carts_list()
156
    {
157
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
158
        $this->loadFixturesFromFile('resources/cart.yml');
159
160
        $this->client->request('GET', $this->getCartApiUrl(), [], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
161
162
        $response = $this->client->getResponse();
163
        $this->assertResponse($response, 'cart/index_response', Response::HTTP_OK);
164
    }
165
166
    /**
167
     * @test
168
     */
169
    public function it_does_not_allow_to_list_carts_in_state_different_than_cart()
170
    {
171
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
172
        $this->loadFixturesFromFile('resources/order.yml');
173
174
        $this->client->request('GET', $this->getCartApiUrl(), [], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
175
176
        $response = $this->client->getResponse();
177
        $this->assertResponse($response, 'cart/empty_index_response', Response::HTTP_OK);
178
    }
179
180
    /**
181
     * @test
182
     */
183
    public function it_denies_carts_deletion_for_non_authenticated_user()
184
    {
185
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
186
        $carts = $this->loadFixturesFromFile('resources/cart.yml');
187
        /** @var OrderInterface $cart */
188
        $cart = $carts['order_001'];
189
190
        $this->client->request('DELETE', $this->getCartApiUrl((string) $cart->getId()));
191
192
        $response = $this->client->getResponse();
193
        $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
194
    }
195
196
    /**
197
     * @test
198
     */
199
    public function it_returns_not_found_response_when_trying_to_delete_cart_which_does_not_exist()
200
    {
201
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
202
203
        $this->client->request('DELETE', $this->getCartApiUrl('-1'), [], [], static::$authorizedHeaderWithContentType);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
204
205
        $response = $this->client->getResponse();
206
        $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
207
    }
208
209
    /**
210
     * @test
211
     */
212
    public function it_allows_to_delete_cart()
213
    {
214
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
215
        $carts = $this->loadFixturesFromFile('resources/cart.yml');
216
217
        /** @var OrderInterface $cart */
218
        $cart = $carts['order_001'];
219
220
        $this->client->request('DELETE', $this->getCartApiUrl((string) $cart->getId()), [], [], static::$authorizedHeaderWithContentType);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
221
222
        $response = $this->client->getResponse();
223
        $this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
224
225
        $this->client->request('GET', $this->getCartApiUrl((string) $cart->getId()), [], [], static::$authorizedHeaderWithContentType);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
226
227
        $response = $this->client->getResponse();
228
        $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
229
    }
230
231
    /**
232
     * @test
233
     */
234
    public function it_does_not_allow_to_delete_orders_in_state_different_than_cart()
235
    {
236
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
237
        $orders = $this->loadFixturesFromFile('resources/order.yml');
238
239
        /** @var OrderItemInterface $order */
240
        $order = $orders['order_001'];
241
242
        $this->client->request('DELETE', $this->getCartApiUrl((string) $order->getId()), [], [], static::$authorizedHeaderWithContentType);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
243
244
        $response = $this->client->getResponse();
245
        $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
246
    }
247
248
    /**
249
     * @test
250
     */
251
    public function it_denies_adding_a_product_to_cart_for_non_authenticated_user()
252
    {
253
        $this->client->request('POST', $this->getCartApiUrl('1/items/'));
254
255
        $response = $this->client->getResponse();
256
        $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
257
    }
258
259
    /**
260
     * @test
261
     */
262
    public function it_does_not_allow_to_add_item_to_cart_without_providing_required_fields()
263
    {
264
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
265
        $carts = $this->loadFixturesFromFile('resources/cart.yml');
266
267
        /** @var OrderInterface $cart */
268
        $cart = $carts['order_001'];
269
270
        $this->client->request('POST', $this->getCartItemListUrl($cart), [], [], static::$authorizedHeaderWithContentType);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
271
272
        $response = $this->client->getResponse();
273
        $this->assertResponse($response, 'cart/add_to_cart_validation_fail_response', Response::HTTP_BAD_REQUEST);
274
    }
275
276
    /**
277
     * @test
278
     */
279
    public function it_adds_an_item_to_the_cart()
280
    {
281
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
282
        $carts = $this->loadFixturesFromFile('resources/cart.yml');
283
284
        /** @var OrderInterface $cart */
285
        $cart = $carts['order_001'];
286
287
        $data =
288
<<<EOT
289
        {
290
            "variant": "MUG_SW",
291
            "quantity": 1
292
        }
293
EOT;
294
        $this->client->request('POST', $this->getCartItemListUrl($cart), [], [], static::$authorizedHeaderWithContentType, $data);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
295
296
        $response = $this->client->getResponse();
297
        $this->assertResponse($response, 'cart/add_to_cart_response', Response::HTTP_CREATED);
298
    }
299
300
    /**
301
     * @test
302
     */
303
    public function it_does_not_allow_to_add_item_with_negative_quantity()
304
    {
305
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
306
        $carts = $this->loadFixturesFromFile('resources/cart.yml');
307
308
        /** @var OrderInterface $cart */
309
        $cart = $carts['order_001'];
310
311
        $data =
312
<<<EOT
313
        {
314
            "variant": "MUG_SW",
315
            "quantity": -1
316
        }
317
EOT;
318
        $this->client->request('POST', $this->getCartItemListUrl($cart), [], [], static::$authorizedHeaderWithContentType, $data);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
319
320
        $response = $this->client->getResponse();
321
        $this->assertResponse($response, 'cart/add_to_cart_quantity_validation_fail_response', Response::HTTP_BAD_REQUEST);
322
    }
323
324
    /**
325
     * @test
326
     */
327
    public function it_adds_an_item_to_the_cart_with_quantity_bigger_than_one()
328
    {
329
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
330
        $carts = $this->loadFixturesFromFile('resources/cart.yml');
331
332
        /** @var OrderInterface $cart */
333
        $cart = $carts['order_001'];
334
335
        $data =
336
<<<EOT
337
        {
338
            "variant": "MUG_SW",
339
            "quantity": 3
340
        }
341
EOT;
342
        $this->client->request('POST', $this->getCartItemListUrl($cart), [], [], static::$authorizedHeaderWithContentType, $data);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
343
344
        $response = $this->client->getResponse();
345
        $this->assertResponse($response, 'cart/add_to_cart_with_bigger_quantity_response', Response::HTTP_CREATED);
346
    }
347
348
    /**
349
     * @test
350
     */
351
    public function it_adds_an_item_with_tracked_variant_to_the_cart()
352
    {
353
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
354
        $carts = $this->loadFixturesFromFile('resources/cart.yml');
355
356
        /** @var OrderInterface $cart */
357
        $cart = $carts['order_001'];
358
359
        $data =
360
<<<EOT
361
        {
362
            "variant": "HARD_AVAILABLE_MUG",
363
            "quantity": 1
364
        }
365
EOT;
366
        $this->client->request('POST', $this->getCartItemListUrl($cart), [], [], static::$authorizedHeaderWithContentType, $data);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
367
368
        $response = $this->client->getResponse();
369
        $this->assertResponse($response, 'cart/add_to_cart_hard_available_item_response', Response::HTTP_CREATED);
370
    }
371
372
    /**
373
     * @test
374
     */
375
    public function it_checks_if_requested_variant_is_available()
376
    {
377
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
378
        $carts = $this->loadFixturesFromFile('resources/cart.yml');
379
380
        /** @var OrderInterface $cart */
381
        $cart = $carts['order_001'];
382
383
        $data =
384
<<<EOT
385
        {
386
            "variant": "HARD_AVAILABLE_MUG",
387
            "quantity": 3
388
        }
389
EOT;
390
        $this->client->request('POST', $this->getCartItemListUrl($cart), [], [], static::$authorizedHeaderWithContentType, $data);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
391
392
        $response = $this->client->getResponse();
393
        $this->assertResponse($response, 'cart/add_to_cart_hard_available_item_validation_error_response', Response::HTTP_BAD_REQUEST);
394
    }
395
396
    /**
397
     * @test
398
     */
399
    public function it_denies_updating_a_cart_item_quantity_for_non_authenticated_user()
400
    {
401
        $this->client->request('PUT', $this->getCartApiUrl('1/items/1'));
402
403
        $response = $this->client->getResponse();
404
        $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
405
    }
406
407
    /**
408
     * @test
409
     */
410
    public function it_does_not_allow_to_update_items_variant()
411
    {
412
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
413
        $cartWithItems = $this->loadFixturesFromFile('resources/cart_with_items.yml');
414
415
        /** @var OrderInterface $cart */
416
        $cart = $cartWithItems['cart_with_items'];
417
        /** @var OrderItemInterface $cartItem */
418
        $cartItem = $cartWithItems['sw_mug_item'];
419
420
        $data =
421
<<<EOT
422
        {
423
            "variant": "MUG_SW"
424
        }
425
EOT;
426
427
        $this->client->request('PUT', $this->getCartItemUrl($cart, $cartItem), [], [], static::$authorizedHeaderWithContentType, $data);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
428
429
        $response = $this->client->getResponse();
430
        $this->assertResponse($response, 'cart/update_cart_item_validation_fail_response', Response::HTTP_BAD_REQUEST);
431
    }
432
433
    /**
434
     * @test
435
     */
436
    public function it_updates_item_quantity()
437
    {
438
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
439
        $cartWithItems = $this->loadFixturesFromFile('resources/cart_with_items.yml');
440
441
        /** @var OrderInterface $cart */
442
        $cart = $cartWithItems['cart_with_items'];
443
        /** @var OrderItemInterface $cartItem */
444
        $cartItem = $cartWithItems['sw_mug_item'];
445
446
        $data =
447
<<<EOT
448
        {
449
            "quantity": 3
450
        }
451
EOT;
452
        $this->client->request('PUT', $this->getCartItemUrl($cart, $cartItem), [], [], static::$authorizedHeaderWithContentType, $data);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
453
454
        $response = $this->client->getResponse();
455
        $this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
456
457
        $this->client->request('GET', $this->getCartApiUrl((string) $cart->getId()), [], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
458
459
        $response = $this->client->getResponse();
460
        $this->assertResponse($response, 'cart/increase_quantity_response', Response::HTTP_OK);
461
    }
462
463
    /**
464
     * @test
465
     */
466
    public function it_checks_if_requested_variant_is_available_during_quantity_update()
467
    {
468
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
469
        $cartWithItems = $this->loadFixturesFromFile('resources/cart_with_items.yml');
470
471
        /** @var OrderInterface $cart */
472
        $cart = $cartWithItems['cart_with_items'];
473
        /** @var OrderItemInterface $cartItem */
474
        $cartItem = $cartWithItems['hard_available_mug_item'];
475
476
        $data =
477
<<<EOT
478
        {
479
            "quantity": 3
480
        }
481
EOT;
482
        $this->client->request('PUT', $this->getCartItemUrl($cart, $cartItem), [], [], static::$authorizedHeaderWithContentType, $data);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
483
484
        $response = $this->client->getResponse();
485
        $this->assertResponse($response, 'cart/update_hard_available_cart_item_validation_error_response', Response::HTTP_BAD_REQUEST);
486
    }
487
488
    /**
489
     * @test
490
     */
491
    public function it_denies_carts_item_deletion_for_non_authenticated_user()
492
    {
493
        $this->client->request('DELETE', $this->getCartApiUrl('-1/items/-1'));
494
495
        $response = $this->client->getResponse();
496
        $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
497
    }
498
499
    /**
500
     * @test
501
     */
502
    public function it_returns_not_found_response_when_trying_to_delete_cart_item_which_does_not_exist()
503
    {
504
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
505
        $cartWithItems = $this->loadFixturesFromFile('resources/cart_with_items.yml');
506
507
        /** @var OrderInterface $cart */
508
        $cart = $cartWithItems['cart_with_items'];
509
        $url = sprintf($this->getCartApiUrl('%s/items/-1'), $cart->getId());
510
511
        $this->client->request('DELETE', $url, [], [], static::$authorizedHeaderWithContentType);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
512
513
        $response = $this->client->getResponse();
514
        $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
515
    }
516
517
    /**
518
     * @test
519
     */
520
    public function it_allows_to_delete_cart_item()
521
    {
522
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
523
        $cartWithItems = $this->loadFixturesFromFile('resources/cart_with_items.yml');
524
525
        /** @var OrderInterface $cart */
526
        $cart = $cartWithItems['cart_with_items'];
527
        /** @var OrderItemInterface $cartItem */
528
        $cartItem = $cartWithItems['hard_available_mug_item'];
529
530
        $this->client->request('DELETE', $this->getCartItemUrl($cart, $cartItem), [], [], static::$authorizedHeaderWithContentType);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
531
532
        $response = $this->client->getResponse();
533
        $this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
534
    }
535
536
    /**
537
     * @test
538
     */
539
    public function it_resets_totals_if_cart_item_was_removed()
540
    {
541
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
542
        $cartWithItems = $this->loadFixturesFromFile('resources/cart_with_items.yml');
543
544
        /** @var OrderInterface $cart */
545
        $cart = $cartWithItems['cart_with_items'];
546
        /** @var OrderItemInterface $cartItem */
547
        $cartItem = $cartWithItems['hard_available_mug_item'];
548
549
        $this->client->request('DELETE', $this->getCartItemUrl($cart, $cartItem), [], [], static::$authorizedHeaderWithContentType);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
550
551
        $response = $this->client->getResponse();
552
        $this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
553
554
        $this->client->request('GET', $this->getCartApiUrl((string) $cart->getId()), [], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\CartApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
555
556
        $response = $this->client->getResponse();
557
        $this->assertResponse($response, 'cart/recalculated_items_total_response', Response::HTTP_OK);
558
    }
559
560
    private function getCartApiUrl(string $urlFragment = ''): string
561
    {
562
        return '/api/v1/carts/' . $urlFragment;
563
    }
564
565
    /**
566
     * @return string
567
     */
568
    private function getCartItemListUrl(OrderInterface $cart)
569
    {
570
        return sprintf($this->getCartApiUrl('%s/items/'), (string) $cart->getId());
571
    }
572
573
    /**
574
     * @return string
575
     */
576
    private function getCartItemUrl(OrderInterface $cart, OrderItemInterface $cartItem)
577
    {
578
        return sprintf($this->getCartApiUrl('%s/items/%s'), $cart->getId(), $cartItem->getId());
579
    }
580
}
581