@@ -71,21 +71,25 @@ public function testShippingMethodWithVirtualProduct()
71
71
);
72
72
73
73
self ::expectException (\Exception::class);
74
- self ::expectExceptionMessage ('Carrier with such method not found: ' . $ methodCode . ' , ' . $ methodCode . ' ' );
74
+ self ::expectExceptionMessage ('You can \' t set shipping methods for virtual products ' );
75
75
$ this ->graphQlQuery ($ query );
76
76
}
77
77
78
78
/**
79
- * @magentoApiDataFixture Magento/Checkout /_files/quote_with_simple_product_saved .php
79
+ * @magentoApiDataFixture Magento/Sales /_files/guest_quote_with_addresses .php
80
80
*/
81
81
public function testShippingMethodWithSimpleProduct ()
82
82
{
83
83
$ methodCode = 'flatrate ' ;
84
84
$ carrierCode = 'flatrate ' ;
85
- $ reservedOrderId = 'test_order_with_simple_product_without_address ' ;
85
+ $ reservedOrderId = 'guest_quote ' ;
86
86
87
87
$ maskedQuoteId = $ this ->getMaskedQuoteIdByReversedQuoteId ($ reservedOrderId );
88
- $ quoteAddressId = $ this ->getQuoteAddressIdByReversedQuoteId ($ reservedOrderId );
88
+
89
+ /** @var Quote $quote */
90
+ $ quote = $ this ->quoteFactory ->create ();
91
+ $ this ->quoteResource ->load ($ quote , $ reservedOrderId , 'reserved_order_id ' );
92
+ $ quoteAddressId = (int ) $ quote ->getShippingAddress ()->getId ();
89
93
90
94
$ query = $ this ->prepareMutationQuery (
91
95
$ maskedQuoteId ,
@@ -108,28 +112,42 @@ public function testShippingMethodWithSimpleProduct()
108
112
109
113
/**
110
114
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
115
+ * @dataProvider dataProviderWithMissedRequiredParameters
116
+ * @param int $addressId
117
+ * @param string $message
111
118
* @expectedException \Exception
112
- * @expectedExceptionMessage Required parameter "cart_address_id" is missing.
113
119
*/
114
- public function testShippingMethodWithSimpleProductWithoutAddress ()
120
+ public function testShippingMethodWithSimpleProductWithoutAddress (int $ addressId , string $ message )
115
121
{
116
122
$ methodCode = 'flatrate ' ;
117
123
$ carrierCode = 'flatrate ' ;
118
124
$ reservedOrderId = 'test_order_with_simple_product_without_address ' ;
119
125
120
126
$ maskedQuoteId = $ this ->getMaskedQuoteIdByReversedQuoteId ($ reservedOrderId );
121
- $ quoteAddressId = 0 ;
122
-
123
127
$ query = $ this ->prepareMutationQuery (
124
128
$ maskedQuoteId ,
125
129
$ methodCode ,
126
130
$ carrierCode ,
127
- $ quoteAddressId
131
+ $ addressId
128
132
);
129
133
134
+ $ this ->expectExceptionMessage ($ message );
130
135
$ this ->graphQlQuery ($ query );
131
136
}
132
137
138
+ /**
139
+ * @return array
140
+ */
141
+ public function dataProviderWithMissedRequiredParameters ()
142
+ {
143
+ return [
144
+ 'shipping_methods ' => [
145
+ 0 ,
146
+ 'Required parameter "cart_address_id" is missing. ' ,
147
+ ]
148
+ ];
149
+ }
150
+
133
151
/**
134
152
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
135
153
* @expectedException \Exception
@@ -213,16 +231,15 @@ public function testSetShippingMethodIfAddressIsNotBelongToCart()
213
231
214
232
/**
215
233
* @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php
216
- * @expectedException \Magento\Framework\Exception\NoSuchEntityException
217
- * @expectedExceptionMessage No such entity with cartId = 0
234
+ * @expectedException \Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException
235
+ * @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
218
236
*/
219
237
public function testSetShippingMethodToNonExistentCart ()
220
238
{
221
239
$ methodCode = 'flatrate ' ;
222
240
$ carrierCode = 'flatrate ' ;
223
- $ reservedOrderId = 'non_existent_cart_reversed_quote_id ' ;
224
241
225
- $ maskedQuoteId = $ this -> getMaskedQuoteIdByReversedQuoteId ( $ reservedOrderId ) ;
242
+ $ maskedQuoteId = ' non_existent_masked_id ' ;
226
243
$ quoteAddressId = 1 ;
227
244
228
245
$ query = $ this ->prepareMutationQuery (
@@ -235,41 +252,6 @@ public function testSetShippingMethodToNonExistentCart()
235
252
$ this ->graphQlQuery ($ query );
236
253
}
237
254
238
- /**
239
- * @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php
240
- */
241
- public function testSetShippingMethodToGuestCart ()
242
- {
243
- $ methodCode = 'flatrate ' ;
244
- $ carrierCode = 'flatrate ' ;
245
- $ reservedOrderId = 'guest_quote ' ;
246
-
247
- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReversedQuoteId ($ reservedOrderId );
248
-
249
- /** @var Quote $quote */
250
- $ quote = $ this ->quoteFactory ->create ();
251
- $ this ->quoteResource ->load ($ quote , $ reservedOrderId , 'reserved_order_id ' );
252
- $ quoteAddressId = (int ) $ quote ->getShippingAddress ()->getId ();
253
-
254
- $ query = $ this ->prepareMutationQuery (
255
- $ maskedQuoteId ,
256
- $ methodCode ,
257
- $ carrierCode ,
258
- $ quoteAddressId
259
- );
260
-
261
- $ response = $ this ->graphQlQuery ($ query );
262
-
263
- self ::assertArrayHasKey ('setShippingMethodsOnCart ' , $ response );
264
- self ::assertArrayHasKey ('cart ' , $ response ['setShippingMethodsOnCart ' ]);
265
- self ::assertArrayHasKey ('shipping_addresses ' , $ response ['setShippingMethodsOnCart ' ]['cart ' ]);
266
-
267
- $ shippingMethod = current ($ response ['setShippingMethodsOnCart ' ]['cart ' ]['shipping_addresses ' ]);
268
- self ::assertArrayHasKey ('selected_shipping_method ' , $ shippingMethod );
269
- self ::assertEquals ($ carrierCode , $ shippingMethod ['selected_shipping_method ' ]['carrier_code ' ]);
270
- self ::assertEquals ($ methodCode , $ shippingMethod ['selected_shipping_method ' ]['method_code ' ]);
271
- }
272
-
273
255
/**
274
256
* @magentoApiDataFixture Magento/Sales/_files/guest_quote_with_addresses.php
275
257
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php
0 commit comments