@@ -53,22 +53,52 @@ protected function setUp()
53
53
54
54
/**
55
55
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
56
+ * @magentoApiDataFixture Magento/OfflineShipping/_files/enable_offline_shipping_methods.php
56
57
* @magentoApiDataFixture Magento/OfflineShipping/_files/tablerates_weight.php
57
- * @magentoApiDataFixture Magento/Checkout/_files/enable_all_shipping_methods.php
58
- * @dataProvider offlineShippingMethodDataProvider()
59
- * @param string $carrier
60
- * @param string $method
58
+ *
59
+ * @param string $carrierCode
60
+ * @param string $methodCode
61
61
* @param float $amount
62
62
* @param string $label
63
+ * @dataProvider offlineShippingMethodDataProvider
63
64
*/
64
- public function testSetOfflineShippingMethod (string $ carrier , string $ method , float $ amount , string $ label )
65
+ public function testSetOfflineShippingMethod (string $ carrierCode , string $ methodCode , float $ amount , string $ label )
65
66
{
66
- $ this ->setShippingMethodAndCheckResponse (
67
- $ carrier ,
68
- $ method ,
69
- $ amount ,
70
- $ label
67
+ $ quote = $ this ->quoteFactory ->create ();
68
+ $ this ->quoteResource ->load (
69
+ $ quote ,
70
+ 'test_order_1 ' ,
71
+ 'reserved_order_id '
72
+ );
73
+ $ maskedQuoteId = $ this ->quoteIdToMaskedId ->execute ((int )$ quote ->getId ());
74
+ $ shippingAddressId = (int )$ quote ->getShippingAddress ()->getId ();
75
+
76
+ $ query = $ this ->getQuery (
77
+ $ maskedQuoteId ,
78
+ $ shippingAddressId ,
79
+ $ carrierCode ,
80
+ $ methodCode
71
81
);
82
+
83
+ $ response = $ this ->sendRequestWithToken ($ query );
84
+
85
+ $ addressesInformation = $ response ['setShippingMethodsOnCart ' ]['cart ' ]['shipping_addresses ' ];
86
+ self ::assertEquals ($ addressesInformation [0 ]['selected_shipping_method ' ]['carrier_code ' ], $ carrierCode );
87
+ self ::assertEquals ($ addressesInformation [0 ]['selected_shipping_method ' ]['method_code ' ], $ methodCode );
88
+ self ::assertEquals ($ addressesInformation [0 ]['selected_shipping_method ' ]['amount ' ], $ amount );
89
+ self ::assertEquals ($ addressesInformation [0 ]['selected_shipping_method ' ]['label ' ], $ label );
90
+ }
91
+
92
+ /**
93
+ * @return array
94
+ */
95
+ public function offlineShippingMethodDataProvider ()
96
+ {
97
+ return [
98
+ 'flatrate_flatrate ' => ['flatrate ' , 'flatrate ' , 10 , 'Flat Rate - Fixed ' ],
99
+ 'tablerate_bestway ' => ['tablerate ' , 'bestway ' , 10 , 'Best Way - Table Rate ' ],
100
+ 'freeshipping_freeshipping ' => ['freeshipping ' , 'freeshipping ' , 0 , 'Free Shipping - Free ' ],
101
+ ];
72
102
}
73
103
74
104
/**
@@ -89,23 +119,21 @@ public function testSetShippingMethodTwiceInOneRequest()
89
119
90
120
$ query = <<<QUERY
91
121
mutation {
92
- setShippingMethodsOnCart(input:
93
- {
94
- cart_id: " $ maskedQuoteId",
95
- shipping_methods: [
122
+ setShippingMethodsOnCart(input: {
123
+ cart_id: " $ maskedQuoteId"
124
+ shipping_methods: [
96
125
{
97
126
cart_address_id: $ shippingAddressId
98
- method_code: "flatrate"
99
127
carrier_code: "flatrate"
128
+ method_code: "flatrate"
100
129
}
101
130
{
102
131
cart_address_id: $ shippingAddressId
103
- method_code: "freeshipping"
104
132
carrier_code: "freeshipping"
133
+ method_code: "freeshipping"
105
134
}
106
- ]
107
- }) {
108
-
135
+ ]
136
+ }) {
109
137
cart {
110
138
shipping_addresses {
111
139
selected_shipping_method {
@@ -115,98 +143,41 @@ public function testSetShippingMethodTwiceInOneRequest()
115
143
amount
116
144
}
117
145
}
118
- }
146
+ }
119
147
}
120
148
}
121
149
QUERY ;
122
-
123
150
self ::expectExceptionMessage ('You cannot specify multiple shipping methods. ' );
124
151
$ this ->sendRequestWithToken ($ query );
125
152
}
126
153
127
- /**
128
- * Data provider for base offline shipping methods
129
- *
130
- * @return array
131
- */
132
- public function offlineShippingMethodDataProvider ()
133
- {
134
- return [
135
- ['flatrate ' , 'flatrate ' , 10 , 'Flat Rate - Fixed ' ],
136
- ['tablerate ' , 'bestway ' , 10 , 'Best Way - Table Rate ' ],
137
- ['freeshipping ' , 'freeshipping ' , 0 , 'Free Shipping - Free ' ]
138
- ];
139
- }
140
-
141
- /**
142
- * Send request for setting the requested shipping method and check the output
143
- *
144
- * @param string $shippingCarrierCode
145
- * @param string $shippingMethodCode
146
- * @param float $shippingAmount
147
- * @param string $shippingLabel
148
- * @throws \Magento\Framework\Exception\AuthenticationException
149
- * @throws \Magento\Framework\Exception\NoSuchEntityException
150
- */
151
- private function setShippingMethodAndCheckResponse (
152
- string $ shippingCarrierCode ,
153
- string $ shippingMethodCode ,
154
- float $ shippingAmount ,
155
- string $ shippingLabel
156
- ) {
157
- $ quote = $ this ->quoteFactory ->create ();
158
- $ this ->quoteResource ->load (
159
- $ quote ,
160
- 'test_order_1 ' ,
161
- 'reserved_order_id '
162
- );
163
- $ shippingAddress = $ quote ->getShippingAddress ();
164
- $ shippingAddressId = $ shippingAddress ->getId ();
165
- $ maskedQuoteId = $ this ->quoteIdToMaskedId ->execute ((int )$ quote ->getId ());
166
-
167
- $ query = $ this ->getQuery (
168
- $ maskedQuoteId ,
169
- $ shippingMethodCode ,
170
- $ shippingCarrierCode ,
171
- $ shippingAddressId
172
- );
173
-
174
- $ response = $ this ->sendRequestWithToken ($ query );
175
-
176
- $ addressesInformation = $ response ['setShippingMethodsOnCart ' ]['cart ' ]['shipping_addresses ' ];
177
- self ::assertEquals ($ addressesInformation [0 ]['selected_shipping_method ' ]['carrier_code ' ], $ shippingCarrierCode );
178
- self ::assertEquals ($ addressesInformation [0 ]['selected_shipping_method ' ]['method_code ' ], $ shippingMethodCode );
179
- self ::assertEquals ($ addressesInformation [0 ]['selected_shipping_method ' ]['amount ' ], $ shippingAmount );
180
- self ::assertEquals ($ addressesInformation [0 ]['selected_shipping_method ' ]['label ' ], $ shippingLabel );
181
- }
182
-
183
154
/**
184
155
* Generates query for setting the specified shipping method on cart
185
156
*
157
+ * @param int $shippingAddressId
186
158
* @param string $maskedQuoteId
187
- * @param string $shippingMethodCode
188
- * @param string $shippingCarrierCode
189
- * @param string $shippingAddressId
159
+ * @param string $carrierCode
160
+ * @param string $methodCode
190
161
* @return string
191
162
*/
192
163
private function getQuery (
193
164
string $ maskedQuoteId ,
194
- string $ shippingMethodCode ,
195
- string $ shippingCarrierCode ,
196
- string $ shippingAddressId
197
- ) : string {
165
+ int $ shippingAddressId ,
166
+ string $ carrierCode ,
167
+ string $ methodCode
168
+ ): string {
198
169
return <<<QUERY
199
170
mutation {
200
- setShippingMethodsOnCart(input:
201
- {
202
- cart_id: " $ maskedQuoteId ",
203
- shipping_methods: [ {
171
+ setShippingMethodsOnCart(input: {
172
+ cart_id: " $ maskedQuoteId "
173
+ shipping_methods: [
174
+ {
204
175
cart_address_id: $ shippingAddressId
205
- method_code : " $ shippingMethodCode "
206
- carrier_code : " $ shippingCarrierCode "
207
- }]
208
- }) {
209
-
176
+ carrier_code : " $ carrierCode "
177
+ method_code : " $ methodCode "
178
+ }
179
+ ]
180
+ }) {
210
181
cart {
211
182
shipping_addresses {
212
183
selected_shipping_method {
@@ -216,9 +187,9 @@ private function getQuery(
216
187
amount
217
188
}
218
189
}
219
- }
190
+ }
220
191
}
221
- }
192
+ }
222
193
QUERY ;
223
194
}
224
195
@@ -236,4 +207,4 @@ private function sendRequestWithToken(string $query): array
236
207
237
208
return $ this ->graphQlQuery ($ query , [], '' , $ headerMap );
238
209
}
239
- }
210
+ }
0 commit comments