| 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\Core\Model\OrderInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Sylius\Component\Order\Model\OrderItemInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Symfony\Component\HttpFoundation\Response; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @author Łukasz Chruściel <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | final class CartApiTest extends JsonApiTestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     private static $authorizedHeaderWithContentType = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         'CONTENT_TYPE' => 'application/json', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     private static $authorizedHeaderWithAccept = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         'ACCEPT' => 'application/json', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     public function it_denies_getting_an_cart_for_non_authenticated_user() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $this->client->request('GET', '/api/v1/carts/-1'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     public function it_returns_not_found_response_when_requesting_details_of_an_cart_which_does_not_exist() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $this->loadFixturesFromFile('authentication/api_administrator.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $this->client->request('GET', '/api/v1/carts/-1', [], [], static::$authorizedHeaderWithAccept); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     public function it_allows_to_get_cart() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $this->loadFixturesFromFile('authentication/api_administrator.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $cartData = $this->loadFixturesFromFile('resources/cart.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         /** @var OrderInterface $cart */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $cart = $cartData['order_001']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $this->client->request('GET', $this->getCartUrl($cart), [], [], static::$authorizedHeaderWithAccept); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $this->assertResponse($response, 'cart/show_response', Response::HTTP_OK); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     public function it_does_not_show_orders_in_state_other_than_cart() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $this->loadFixturesFromFile('authentication/api_administrator.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $orderData = $this->loadFixturesFromFile('resources/order.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         /** @var OrderInterface $cart */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $order = $orderData['order_001']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         $this->client->request('GET', $this->getCartUrl($order), [], [], static::$authorizedHeaderWithAccept); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     public function it_denies_creating_cart_for_non_authenticated_user() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         $this->client->request('POST', '/api/v1/carts/'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     public function it_does_not_allow_to_create_cart_without_specifying_required_data() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         $this->loadFixturesFromFile('authentication/api_administrator.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         $this->client->request('POST', '/api/v1/carts/', [], [], static::$authorizedHeaderWithContentType); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         $this->assertResponse($response, 'cart/create_validation_fail_response', Response::HTTP_BAD_REQUEST); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     public function it_allows_to_create_cart() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         $this->loadFixturesFromFile('authentication/api_administrator.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |         $this->loadFixturesFromFile('resources/cart.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         $data = | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | <<<EOT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |             "customer": "[email protected]", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |             "channel": "WEB", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |             "locale_code": "en_US" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | EOT; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         $this->client->request('POST', '/api/v1/carts/', [], [], static::$authorizedHeaderWithContentType, $data); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |         $this->assertResponse($response, 'cart/show_response', Response::HTTP_CREATED); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |     public function it_denies_getting_carts_for_non_authenticated_user() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |         $this->client->request('GET', '/api/v1/carts/'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |         $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     public function it_allows_to_get_carts_list() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |         $this->loadFixturesFromFile('authentication/api_administrator.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |         $this->loadFixturesFromFile('resources/cart.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |         $this->client->request('GET', '/api/v1/carts/', [], [], static::$authorizedHeaderWithAccept); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |         $this->assertResponse($response, 'cart/index_response', Response::HTTP_OK); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |     public function it_does_not_allow_to_list_carts_in_state_different_than_cart() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |         $this->loadFixturesFromFile('authentication/api_administrator.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |         $this->loadFixturesFromFile('resources/order.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |         $this->client->request('GET', '/api/v1/carts/', [], [], static::$authorizedHeaderWithAccept); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |         $this->assertResponse($response, 'cart/empty_index_response', Response::HTTP_OK); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |     public function it_denies_carts_deletion_for_non_authenticated_user() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |         $this->loadFixturesFromFile('authentication/api_administrator.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |         $carts = $this->loadFixturesFromFile('resources/cart.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |         /** @var OrderInterface $cart */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |         $cart = $carts['order_001']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |         $this->client->request('DELETE', $this->getCartUrl($cart)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |         $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |     public function it_returns_not_found_response_when_trying_to_delete_cart_which_does_not_exist() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |         $this->loadFixturesFromFile('authentication/api_administrator.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |         $this->client->request('DELETE', '/api/v1/carts/-1', [], [], static::$authorizedHeaderWithContentType); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |         $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |     public function it_allows_to_delete_cart() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |         $this->loadFixturesFromFile('authentication/api_administrator.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |         $carts = $this->loadFixturesFromFile('resources/cart.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |         /** @var OrderInterface $cart */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |         $cart = $carts['order_001']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |         $this->client->request('DELETE', $this->getCartUrl($cart), [], [], static::$authorizedHeaderWithContentType); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |         $this->assertResponseCode($response, Response::HTTP_NO_CONTENT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |         $this->client->request('GET', $this->getCartUrl($cart), [], [], static::$authorizedHeaderWithContentType); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |         $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |     public function it_does_not_allow_to_delete_orders_in_state_different_than_cart() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |         $this->loadFixturesFromFile('authentication/api_administrator.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |         $orders = $this->loadFixturesFromFile('resources/order.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |         /** @var OrderItemInterface $order */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |         $order = $orders['order_001']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |         $this->client->request('DELETE', $this->getCartUrl($order), [], [], static::$authorizedHeaderWithContentType); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |         $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |     public function it_denies_adding_a_product_to_cart_for_non_authenticated_user() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |         $this->client->request('POST', '/api/v1/carts/1/items/'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |         $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |     public function it_does_not_allow_to_add_item_to_cart_without_providing_required_fields() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |         $this->loadFixturesFromFile('authentication/api_administrator.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |         $carts = $this->loadFixturesFromFile('resources/cart.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |         /** @var OrderInterface $cart */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |         $cart = $carts['order_001']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |         $this->client->request('POST', $this->getCartItemListUrl($cart), [], [], static::$authorizedHeaderWithContentType); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |         $this->assertResponse($response, 'cart/add_to_cart_validation_fail_response', Response::HTTP_BAD_REQUEST); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |     public function it_adds_an_item_to_the_cart() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |         $this->loadFixturesFromFile('authentication/api_administrator.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |         $carts = $this->loadFixturesFromFile('resources/cart.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |         /** @var OrderInterface $cart */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |         $cart = $carts['order_001']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |         $data = | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  | <<<EOT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |             "variant": "MUG_SW", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |             "quantity": 1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  | EOT; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |         $this->client->request('POST', $this->getCartItemListUrl($cart), [], [], static::$authorizedHeaderWithContentType, $data); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |         $this->assertResponse($response, 'cart/add_to_cart_response', Response::HTTP_CREATED); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |     public function it_does_not_allow_to_add_item_with_negative_quantity() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |         $this->loadFixturesFromFile('authentication/api_administrator.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  |         $carts = $this->loadFixturesFromFile('resources/cart.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  |         /** @var OrderInterface $cart */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  |         $cart = $carts['order_001']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  |         $data = | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  | <<<EOT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  |             "variant": "MUG_SW", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  |             "quantity": -1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  | EOT; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  |         $this->client->request('POST', $this->getCartItemListUrl($cart), [], [], static::$authorizedHeaderWithContentType, $data); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  |         $this->assertResponse($response, 'cart/add_to_cart_quantity_validation_fail_response', Response::HTTP_BAD_REQUEST); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  |     public function it_adds_an_item_to_the_cart_with_quantity_bigger_than_one() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  |         $this->loadFixturesFromFile('authentication/api_administrator.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  |         $carts = $this->loadFixturesFromFile('resources/cart.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  |         /** @var OrderInterface $cart */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  |         $cart = $carts['order_001']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  |         $data = | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  | <<<EOT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  |             "variant": "MUG_SW", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  |             "quantity": 3 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 |  |  | EOT; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 |  |  |         $this->client->request('POST', $this->getCartItemListUrl($cart), [], [], static::$authorizedHeaderWithContentType, $data); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 |  |  |         $this->assertResponse($response, 'cart/add_to_cart_with_bigger_quantity_response', Response::HTTP_CREATED); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 350 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 352 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 |  |  |     public function it_adds_an_item_with_tracked_variant_to_the_cart() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 |  |  |         $this->loadFixturesFromFile('authentication/api_administrator.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 |  |  |         $carts = $this->loadFixturesFromFile('resources/cart.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 358 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 359 |  |  |         /** @var OrderInterface $cart */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 360 |  |  |         $cart = $carts['order_001']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 361 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 362 |  |  |         $data = | 
            
                                                                                                            
                            
            
                                    
            
            
                | 363 |  |  | <<<EOT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 364 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 365 |  |  |             "variant": "HARD_AVAILABLE_MUG", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 366 |  |  |             "quantity": 1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 367 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 368 |  |  | EOT; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 369 |  |  |         $this->client->request('POST', $this->getCartItemListUrl($cart), [], [], static::$authorizedHeaderWithContentType, $data); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 370 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 371 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 372 |  |  |         $this->assertResponse($response, 'cart/add_to_cart_hard_available_item_response', Response::HTTP_CREATED); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 373 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 374 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 375 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 376 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 377 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 378 |  |  |     public function it_checks_if_requested_variant_is_available() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 379 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 380 |  |  |         $this->loadFixturesFromFile('authentication/api_administrator.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 381 |  |  |         $carts = $this->loadFixturesFromFile('resources/cart.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 382 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 383 |  |  |         /** @var OrderInterface $cart */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 384 |  |  |         $cart = $carts['order_001']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 385 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 386 |  |  |         $data = | 
            
                                                                                                            
                            
            
                                    
            
            
                | 387 |  |  | <<<EOT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 388 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 389 |  |  |             "variant": "HARD_AVAILABLE_MUG", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 390 |  |  |             "quantity": 3 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 391 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 392 |  |  | EOT; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 393 |  |  |         $this->client->request('POST', $this->getCartItemListUrl($cart), [], [], static::$authorizedHeaderWithContentType, $data); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 394 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 395 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 396 |  |  |         $this->assertResponse($response, 'cart/add_to_cart_hard_available_item_validation_error_response', Response::HTTP_BAD_REQUEST); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 397 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 398 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 399 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 400 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 401 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 402 |  |  |     public function it_denies_updating_a_cart_item_quantity_for_non_authenticated_user() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 403 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 404 |  |  |         $this->client->request('PUT', '/api/v1/carts/1/items/1'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 405 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 406 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 407 |  |  |         $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 408 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 409 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 410 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 411 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 412 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 413 |  |  |     public function it_does_not_allow_to_update_items_variant() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 414 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 415 |  |  |         $this->loadFixturesFromFile('authentication/api_administrator.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 416 |  |  |         $fulfilledCart = $this->loadFixturesFromFile('resources/fulfilled_cart.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 417 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 418 |  |  |         /** @var OrderInterface $cart */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 419 |  |  |         $cart = $fulfilledCart['fulfilled_cart']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 420 |  |  |         /** @var OrderItemInterface $cartItem */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 421 |  |  |         $cartItem = $fulfilledCart['sw_mug_item']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 422 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 423 |  |  |         $data = | 
            
                                                                                                            
                            
            
                                    
            
            
                | 424 |  |  | <<<EOT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 425 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 426 |  |  |             "variant": "MUG_SW" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 427 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 428 |  |  | EOT; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 429 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 430 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 431 |  |  |         $this->client->request('PUT', $this->getCartItemUrl($cart, $cartItem), [], [], static::$authorizedHeaderWithContentType, $data); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 432 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 433 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 434 |  |  |         $this->assertResponse($response, 'cart/update_cart_item_validation_fail_response', Response::HTTP_BAD_REQUEST); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 435 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 436 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 437 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 438 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 439 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 440 |  |  |     public function it_updates_item_quantity() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 441 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 442 |  |  |         $this->loadFixturesFromFile('authentication/api_administrator.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 443 |  |  |         $fulfilledCart = $this->loadFixturesFromFile('resources/fulfilled_cart.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 444 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 445 |  |  |         /** @var OrderInterface $cart */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 446 |  |  |         $cart = $fulfilledCart['fulfilled_cart']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 447 |  |  |         /** @var OrderItemInterface $cartItem */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 448 |  |  |         $cartItem = $fulfilledCart['sw_mug_item']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 449 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 450 |  |  |         $data = | 
            
                                                                                                            
                            
            
                                    
            
            
                | 451 |  |  | <<<EOT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 452 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 453 |  |  |             "quantity": 3 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 454 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 455 |  |  | EOT; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 456 |  |  |         $this->client->request('PUT', $this->getCartItemUrl($cart, $cartItem), [], [], static::$authorizedHeaderWithContentType, $data); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 457 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 458 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 459 |  |  |         $this->assertResponseCode($response, Response::HTTP_NO_CONTENT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 460 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 461 |  |  |         $this->client->request('GET', $this->getCartUrl($cart), [], [], static::$authorizedHeaderWithAccept); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 462 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 463 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 464 |  |  |         $this->assertResponse($response, 'cart/increase_quantity_response', Response::HTTP_OK); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 465 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 466 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 467 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 468 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 469 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 470 |  |  |     public function it_checks_if_requested_variant_is_available_during_quantity_update() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 471 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 472 |  |  |         $this->loadFixturesFromFile('authentication/api_administrator.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 473 |  |  |         $fulfilledCart = $this->loadFixturesFromFile('resources/fulfilled_cart.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 474 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 475 |  |  |         /** @var OrderInterface $cart */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 476 |  |  |         $cart = $fulfilledCart['fulfilled_cart']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 477 |  |  |         /** @var OrderItemInterface $cartItem */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 478 |  |  |         $cartItem = $fulfilledCart['hard_available_mug_item']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 479 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 480 |  |  |         $data = | 
            
                                                                                                            
                            
            
                                    
            
            
                | 481 |  |  | <<<EOT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 482 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 483 |  |  |             "quantity": 3 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 484 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 485 |  |  | EOT; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 486 |  |  |         $this->client->request('PUT', $this->getCartItemUrl($cart, $cartItem), [], [], static::$authorizedHeaderWithContentType, $data); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 487 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 488 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 489 |  |  |         $this->assertResponse($response, 'cart/update_hard_available_cart_item_validation_error_response', Response::HTTP_BAD_REQUEST); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 490 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 491 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 492 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 493 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 494 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 495 |  |  |     public function it_denies_carts_item_deletion_for_non_authenticated_user() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 496 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 497 |  |  |         $this->client->request('DELETE', '/api/v1/carts/-1/items/-1'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 498 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 499 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 500 |  |  |         $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 501 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 502 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 503 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 504 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 505 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 506 |  |  |     public function it_returns_not_found_response_when_trying_to_delete_cart_item_which_does_not_exist() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 507 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 508 |  |  |         $this->loadFixturesFromFile('authentication/api_administrator.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 509 |  |  |         $fulfilledCart = $this->loadFixturesFromFile('resources/fulfilled_cart.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 510 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 511 |  |  |         /** @var OrderInterface $cart */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 512 |  |  |         $cart = $fulfilledCart['fulfilled_cart']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 513 |  |  |         $url = sprintf('/api/v1/carts/%s/items/-1', $cart->getId()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 514 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 515 |  |  |         $this->client->request('DELETE', $url, [], [], static::$authorizedHeaderWithContentType); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 516 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 517 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 518 |  |  |         $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 519 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 520 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 521 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 522 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 523 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 524 |  |  |     public function it_allows_to_delete_cart_item() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 525 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 526 |  |  |         $this->loadFixturesFromFile('authentication/api_administrator.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 527 |  |  |         $fulfilledCart = $this->loadFixturesFromFile('resources/fulfilled_cart.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 528 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 529 |  |  |         /** @var OrderInterface $cart */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 530 |  |  |         $cart = $fulfilledCart['fulfilled_cart']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 531 |  |  |         /** @var OrderItemInterface $cartItem */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 532 |  |  |         $cartItem = $fulfilledCart['hard_available_mug_item']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 533 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 534 |  |  |         $this->client->request('DELETE', $this->getCartItemUrl($cart, $cartItem), [], [], static::$authorizedHeaderWithContentType); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 535 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 536 |  |  |         $response = $this->client->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 537 |  |  |         $this->assertResponseCode($response, Response::HTTP_NO_CONTENT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 538 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 539 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 540 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 541 |  |  |      * @param OrderInterface $cart | 
            
                                                                                                            
                            
            
                                    
            
            
                | 542 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 543 |  |  |      * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 544 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 545 |  |  |     private function getCartUrl(OrderInterface $cart) | 
            
                                                                        
                            
            
                                    
            
            
                | 546 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 547 |  |  |         return '/api/v1/carts/' . $cart->getId(); | 
            
                                                                        
                            
            
                                    
            
            
                | 548 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 549 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 550 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 551 |  |  |      * @param OrderInterface $cart | 
            
                                                                                                            
                            
            
                                    
            
            
                | 552 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 553 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 554 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 555 |  |  |     private function getCartItemListUrl(OrderInterface $cart) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 556 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 557 |  |  |         return sprintf('/api/v1/carts/%s/items/', $cart->getId()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 558 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 559 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 560 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 561 |  |  |      * @param OrderInterface $cart | 
            
                                                                                                            
                            
            
                                    
            
            
                | 562 |  |  |      * @param OrderItemInterface $cartItem | 
            
                                                                                                            
                            
            
                                    
            
            
                | 563 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 564 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 565 |  |  |     private function getCartItemUrl(OrderInterface $cart, OrderItemInterface $cartItem) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 566 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 567 |  |  |         return sprintf('/api/v1/carts/%s/items/%s', $cart->getId(), $cartItem->getId()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 568 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 569 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 570 |  |  |  | 
            
                        
Late static binding only has effect in subclasses. A
finalclass 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.