7
7
8
8
namespace Magento \GraphQl \Quote \Customer ;
9
9
10
+ use Magento \Framework \Exception \AuthenticationException ;
10
11
use Magento \GraphQl \Quote \GetMaskedQuoteIdByReservedOrderId ;
11
12
use Magento \Integration \Api \CustomerTokenServiceInterface ;
12
13
use Magento \TestFramework \Helper \Bootstrap ;
@@ -38,14 +39,19 @@ protected function setUp(): void
38
39
}
39
40
40
41
/**
42
+ * @magentoConfigFixture default_store tax/calculation/shipping_includes_tax 1
43
+ * @magentoConfigFixture default_store tax/cart_display/shipping 2
44
+ * @magentoConfigFixture default_store tax/classes/shipping_tax_class 2
45
+ * @magentoConfigFixture default_store tax/display/shipping 2
41
46
* @magentoApiDataFixture Magento/Customer/_files/customer.php
42
47
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
43
48
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
44
49
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
50
+ * @magentoApiDataFixture Magento/Tax/_files/tax_rule_region_1_al.php
45
51
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
46
52
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
47
53
*/
48
- public function testGetSelectedShippingMethod ()
54
+ public function testGetSelectedShippingMethodWithTax (): void
49
55
{
50
56
$ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
51
57
@@ -78,16 +84,159 @@ public function testGetSelectedShippingMethod()
78
84
self ::assertEquals (10 , $ amount ['value ' ]);
79
85
self ::assertArrayHasKey ('currency ' , $ amount );
80
86
self ::assertEquals ('USD ' , $ amount ['currency ' ]);
87
+
88
+ self ::assertArrayHasKey ('price_excl_tax ' , $ shippingAddress ['selected_shipping_method ' ]);
89
+ $ priceExclTax = $ shippingAddress ['selected_shipping_method ' ]['price_excl_tax ' ];
90
+
91
+ self ::assertArrayHasKey ('value ' , $ priceExclTax );
92
+ self ::assertEquals (10 , $ priceExclTax ['value ' ]);
93
+ self ::assertArrayHasKey ('currency ' , $ priceExclTax );
94
+ self ::assertEquals ('USD ' , $ priceExclTax ['currency ' ]);
95
+
96
+ self ::assertArrayHasKey ('amount ' , $ shippingAddress ['selected_shipping_method ' ]);
97
+ $ priceInclTax = $ shippingAddress ['selected_shipping_method ' ]['price_incl_tax ' ];
98
+
99
+ self ::assertArrayHasKey ('value ' , $ priceInclTax );
100
+ self ::assertEquals (10.75 , $ priceInclTax ['value ' ]);
101
+ self ::assertArrayHasKey ('currency ' , $ priceInclTax );
102
+ self ::assertEquals ('USD ' , $ priceInclTax ['currency ' ]);
103
+ }
104
+
105
+ /**
106
+ * @magentoConfigFixture default_store tax/calculation/shipping_includes_tax 1
107
+ * @magentoConfigFixture default_store tax/cart_display/shipping 2
108
+ * @magentoConfigFixture default_store tax/classes/shipping_tax_class 2
109
+ * @magentoConfigFixture default_store tax/display/shipping 2
110
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
111
+ * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
112
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
113
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
114
+ * @magentoApiDataFixture Magento/Tax/_files/tax_rule_region_1_al.php
115
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_canada_address.php
116
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
117
+ */
118
+ public function testGetSelectedShippingMethodWithAddressWithoutTax (): void
119
+ {
120
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
121
+
122
+ $ query = $ this ->getQuery ($ maskedQuoteId );
123
+ $ response = $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
124
+
125
+ self ::assertArrayHasKey ('cart ' , $ response );
126
+ self ::assertArrayHasKey ('shipping_addresses ' , $ response ['cart ' ]);
127
+ self ::assertCount (1 , $ response ['cart ' ]['shipping_addresses ' ]);
128
+
129
+ $ shippingAddress = current ($ response ['cart ' ]['shipping_addresses ' ]);
130
+ self ::assertArrayHasKey ('selected_shipping_method ' , $ shippingAddress );
131
+
132
+ self ::assertArrayHasKey ('carrier_code ' , $ shippingAddress ['selected_shipping_method ' ]);
133
+ self ::assertEquals ('flatrate ' , $ shippingAddress ['selected_shipping_method ' ]['carrier_code ' ]);
134
+
135
+ self ::assertArrayHasKey ('method_code ' , $ shippingAddress ['selected_shipping_method ' ]);
136
+ self ::assertEquals ('flatrate ' , $ shippingAddress ['selected_shipping_method ' ]['method_code ' ]);
137
+
138
+ self ::assertArrayHasKey ('carrier_title ' , $ shippingAddress ['selected_shipping_method ' ]);
139
+ self ::assertEquals ('Flat Rate ' , $ shippingAddress ['selected_shipping_method ' ]['carrier_title ' ]);
140
+
141
+ self ::assertArrayHasKey ('method_title ' , $ shippingAddress ['selected_shipping_method ' ]);
142
+ self ::assertEquals ('Fixed ' , $ shippingAddress ['selected_shipping_method ' ]['method_title ' ]);
143
+
144
+ self ::assertArrayHasKey ('amount ' , $ shippingAddress ['selected_shipping_method ' ]);
145
+ $ amount = $ shippingAddress ['selected_shipping_method ' ]['amount ' ];
146
+
147
+ self ::assertArrayHasKey ('value ' , $ amount );
148
+ self ::assertEquals (10 , $ amount ['value ' ]);
149
+ self ::assertArrayHasKey ('currency ' , $ amount );
150
+ self ::assertEquals ('USD ' , $ amount ['currency ' ]);
151
+
152
+ self ::assertArrayHasKey ('price_excl_tax ' , $ shippingAddress ['selected_shipping_method ' ]);
153
+ $ priceExclTax = $ shippingAddress ['selected_shipping_method ' ]['price_excl_tax ' ];
154
+
155
+ self ::assertArrayHasKey ('value ' , $ priceExclTax );
156
+ self ::assertEquals (10 , $ priceExclTax ['value ' ]);
157
+ self ::assertArrayHasKey ('currency ' , $ priceExclTax );
158
+ self ::assertEquals ('USD ' , $ priceExclTax ['currency ' ]);
159
+
160
+ self ::assertArrayHasKey ('amount ' , $ shippingAddress ['selected_shipping_method ' ]);
161
+ $ priceInclTax = $ shippingAddress ['selected_shipping_method ' ]['price_incl_tax ' ];
162
+
163
+ self ::assertArrayHasKey ('value ' , $ priceInclTax );
164
+ self ::assertEquals (10 , $ priceInclTax ['value ' ]);
165
+ self ::assertArrayHasKey ('currency ' , $ priceInclTax );
166
+ self ::assertEquals ('USD ' , $ priceInclTax ['currency ' ]);
81
167
}
82
168
83
169
/**
170
+ * @magentoConfigFixture default_store tax/calculation/shipping_includes_tax 0
171
+ * @magentoConfigFixture default_store tax/cart_display/shipping 1
172
+ * @magentoConfigFixture default_store tax/classes/shipping_tax_class 0
173
+ * @magentoConfigFixture default_store tax/display/shipping 1
84
174
* @magentoApiDataFixture Magento/Customer/_files/customer.php
85
175
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
86
176
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
87
177
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
88
178
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
179
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
89
180
*/
90
- public function testGetSelectedShippingMethodBeforeSet ()
181
+ public function testGetSelectedShippingMethodWithoutTax (): void
182
+ {
183
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
184
+
185
+ $ query = $ this ->getQuery ($ maskedQuoteId );
186
+ $ response = $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
187
+
188
+ self ::assertArrayHasKey ('cart ' , $ response );
189
+ self ::assertArrayHasKey ('shipping_addresses ' , $ response ['cart ' ]);
190
+ self ::assertCount (1 , $ response ['cart ' ]['shipping_addresses ' ]);
191
+
192
+ $ shippingAddress = current ($ response ['cart ' ]['shipping_addresses ' ]);
193
+ self ::assertArrayHasKey ('selected_shipping_method ' , $ shippingAddress );
194
+
195
+ self ::assertArrayHasKey ('carrier_code ' , $ shippingAddress ['selected_shipping_method ' ]);
196
+ self ::assertEquals ('flatrate ' , $ shippingAddress ['selected_shipping_method ' ]['carrier_code ' ]);
197
+
198
+ self ::assertArrayHasKey ('method_code ' , $ shippingAddress ['selected_shipping_method ' ]);
199
+ self ::assertEquals ('flatrate ' , $ shippingAddress ['selected_shipping_method ' ]['method_code ' ]);
200
+
201
+ self ::assertArrayHasKey ('carrier_title ' , $ shippingAddress ['selected_shipping_method ' ]);
202
+ self ::assertEquals ('Flat Rate ' , $ shippingAddress ['selected_shipping_method ' ]['carrier_title ' ]);
203
+
204
+ self ::assertArrayHasKey ('method_title ' , $ shippingAddress ['selected_shipping_method ' ]);
205
+ self ::assertEquals ('Fixed ' , $ shippingAddress ['selected_shipping_method ' ]['method_title ' ]);
206
+
207
+ self ::assertArrayHasKey ('amount ' , $ shippingAddress ['selected_shipping_method ' ]);
208
+ $ amount = $ shippingAddress ['selected_shipping_method ' ]['amount ' ];
209
+
210
+ self ::assertArrayHasKey ('value ' , $ amount );
211
+ self ::assertEquals (10 , $ amount ['value ' ]);
212
+ self ::assertArrayHasKey ('currency ' , $ amount );
213
+ self ::assertEquals ('USD ' , $ amount ['currency ' ]);
214
+
215
+ self ::assertArrayHasKey ('price_excl_tax ' , $ shippingAddress ['selected_shipping_method ' ]);
216
+ $ priceExclTax = $ shippingAddress ['selected_shipping_method ' ]['price_excl_tax ' ];
217
+
218
+ self ::assertArrayHasKey ('value ' , $ priceExclTax );
219
+ self ::assertEquals (10 , $ priceExclTax ['value ' ]);
220
+ self ::assertArrayHasKey ('currency ' , $ priceExclTax );
221
+ self ::assertEquals ('USD ' , $ priceExclTax ['currency ' ]);
222
+
223
+ self ::assertArrayHasKey ('amount ' , $ shippingAddress ['selected_shipping_method ' ]);
224
+ $ priceInclTax = $ shippingAddress ['selected_shipping_method ' ]['price_incl_tax ' ];
225
+
226
+ self ::assertArrayHasKey ('value ' , $ priceInclTax );
227
+ self ::assertEquals (10 , $ priceInclTax ['value ' ]);
228
+ self ::assertArrayHasKey ('currency ' , $ priceInclTax );
229
+ self ::assertEquals ('USD ' , $ priceInclTax ['currency ' ]);
230
+ }
231
+
232
+ /**
233
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
234
+ * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
235
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
236
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
237
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
238
+ */
239
+ public function testGetSelectedShippingMethodBeforeSet (): void
91
240
{
92
241
$ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
93
242
@@ -112,7 +261,7 @@ public function testGetSelectedShippingMethodBeforeSet()
112
261
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
113
262
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
114
263
*/
115
- public function testGetSelectedShippingMethodFromGuestCart ()
264
+ public function testGetSelectedShippingMethodFromGuestCart (): void
116
265
{
117
266
$ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
118
267
$ query = $ this ->getQuery ($ maskedQuoteId );
@@ -132,7 +281,7 @@ public function testGetSelectedShippingMethodFromGuestCart()
132
281
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
133
282
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
134
283
*/
135
- public function testGetSelectedShippingMethodFromAnotherCustomerCart ()
284
+ public function testGetSelectedShippingMethodFromAnotherCustomerCart (): void
136
285
{
137
286
$ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
138
287
$ query = $ this ->getQuery ($ maskedQuoteId );
@@ -150,7 +299,7 @@ public function testGetSelectedShippingMethodFromAnotherCustomerCart()
150
299
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
151
300
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
152
301
*/
153
- public function testGetGetSelectedShippingMethodIfShippingMethodIsNotSet ()
302
+ public function testGetGetSelectedShippingMethodIfShippingMethodIsNotSet (): void
154
303
{
155
304
$ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
156
305
$ query = $ this ->getQuery ($ maskedQuoteId );
@@ -170,7 +319,7 @@ public function testGetGetSelectedShippingMethodIfShippingMethodIsNotSet()
170
319
* @magentoApiDataFixture Magento/Customer/_files/customer.php
171
320
*
172
321
*/
173
- public function testGetGetSelectedShippingMethodOfNonExistentCart ()
322
+ public function testGetGetSelectedShippingMethodOfNonExistentCart (): void
174
323
{
175
324
$ this ->expectException (\Exception::class);
176
325
$ this ->expectExceptionMessage ('Could not find a cart with ID "non_existent_masked_id" ' );
@@ -185,12 +334,12 @@ public function testGetGetSelectedShippingMethodOfNonExistentCart()
185
334
* @param string $username
186
335
* @param string $password
187
336
* @return array
337
+ * @throws AuthenticationException
188
338
*/
189
339
private function getHeaderMap (string $ username = 'customer@example.com ' , string $ password = 'password ' ): array
190
340
{
191
341
$ customerToken = $ this ->customerTokenService ->createCustomerAccessToken ($ username , $ password );
192
- $ headerMap = ['Authorization ' => 'Bearer ' . $ customerToken ];
193
- return $ headerMap ;
342
+ return ['Authorization ' => 'Bearer ' . $ customerToken ];
194
343
}
195
344
196
345
/**
@@ -216,6 +365,14 @@ private function getQuery(string $maskedQuoteId): string
216
365
value
217
366
currency
218
367
}
368
+ price_excl_tax {
369
+ value
370
+ currency
371
+ }
372
+ price_incl_tax {
373
+ value
374
+ currency
375
+ }
219
376
}
220
377
}
221
378
}
0 commit comments