7
7
8
8
namespace Magento \GraphQl \Ups ;
9
9
10
+ use Magento \GraphQl \Quote \GetMaskedQuoteIdByReservedOrderId ;
11
+ use Magento \GraphQl \Quote \GetQuoteShippingAddressIdByReservedQuoteId ;
10
12
use Magento \Integration \Api \CustomerTokenServiceInterface ;
11
- use Magento \Quote \Model \QuoteFactory ;
12
- use Magento \Quote \Model \QuoteIdToMaskedQuoteIdInterface ;
13
- use Magento \Quote \Model \ResourceModel \Quote as QuoteResource ;
14
13
use Magento \TestFramework \Helper \Bootstrap ;
15
14
use Magento \TestFramework \TestCase \GraphQlAbstract ;
16
15
17
16
/**
18
- * Test for setting "UPS" shipping method on cart
17
+ * Test for setting "UPS" shipping method on cart. Current class covers the next UPS shipping methods:
18
+ *
19
+ * | Code | Label
20
+ * --------------------------------------
21
+ * | 1DM | Next Day Air Early AM
22
+ * | 1DA | Next Day Air
23
+ * | 2DA | 2nd Day Air
24
+ * | 3DS | 3 Day Select
25
+ * | GND | Ground
26
+ * | STD | Canada Standard
27
+ * | XPR | Worldwide Express
28
+ * | WXS | Worldwide Express Saver
29
+ * | XDM | Worldwide Express Plus
30
+ * | XPD | Worldwide Expedited
31
+ *
32
+ * Current class does not cover these UPS shipping methods (depends on address and sandbox settings)
33
+ *
34
+ * | Code | Label
35
+ * --------------------------------------
36
+ * | 1DML | Next Day Air Early AM Letter
37
+ * | 1DAL | Next Day Air Letter
38
+ * | 1DAPI | Next Day Air Intra (Puerto Rico)
39
+ * | 1DP | Next Day Air Saver
40
+ * | 1DPL | Next Day Air Saver Letter
41
+ * | 2DM | 2nd Day Air AM
42
+ * | 2DML | 2nd Day Air AM Letter
43
+ * | 2DAL | 2nd Day Air Letter
44
+ * | GNDCOM | Ground Commercial
45
+ * | GNDRES | Ground Residential
46
+ * | XPRL | Worldwide Express Letter
47
+ * | XDML | Worldwide Express Plus Letter
19
48
*/
20
49
class SetUpsShippingMethodsOnCartTest extends GraphQlAbstract
21
50
{
22
51
/**
23
- * Defines carrier code for "UPS" shipping method
24
- */
25
- const CARRIER_CODE = 'ups ' ;
26
-
27
- /**
28
- * Defines method code for the "Ground" UPS shipping
52
+ * Defines carrier label for "UPS" shipping method
29
53
*/
30
- const CARRIER_METHOD_CODE_GROUND = 'GND ' ;
54
+ const CARRIER_LABEL = 'United Parcel Service ' ;
31
55
32
56
/**
33
- * @var QuoteFactory
57
+ * Defines carrier code for "UPS" shipping method
34
58
*/
35
- private $ quoteFactory ;
59
+ const CARRIER_CODE = ' ups ' ;
36
60
37
61
/**
38
62
* @var CustomerTokenServiceInterface
39
63
*/
40
64
private $ customerTokenService ;
41
65
42
66
/**
43
- * @var QuoteResource
67
+ * @var GetMaskedQuoteIdByReservedOrderId
44
68
*/
45
- private $ quoteResource ;
69
+ private $ getMaskedQuoteIdByReservedOrderId ;
46
70
47
71
/**
48
- * @var QuoteIdToMaskedQuoteIdInterface
72
+ * @var GetQuoteShippingAddressIdByReservedQuoteId
49
73
*/
50
- private $ quoteIdToMaskedId ;
74
+ private $ getQuoteShippingAddressIdByReservedQuoteId ;
51
75
52
76
/**
53
77
* @inheritdoc
54
78
*/
55
79
protected function setUp ()
56
80
{
57
81
$ objectManager = Bootstrap::getObjectManager ();
58
- $ this ->quoteResource = $ objectManager ->get (QuoteResource::class);
59
- $ this ->quoteFactory = $ objectManager ->get (QuoteFactory::class);
60
- $ this ->quoteIdToMaskedId = $ objectManager ->get (QuoteIdToMaskedQuoteIdInterface::class);
61
82
$ this ->customerTokenService = $ objectManager ->get (CustomerTokenServiceInterface::class);
83
+ $ this ->getMaskedQuoteIdByReservedOrderId = $ objectManager ->get (GetMaskedQuoteIdByReservedOrderId::class);
84
+ $ this ->getQuoteShippingAddressIdByReservedQuoteId = $ objectManager ->get (
85
+ GetQuoteShippingAddressIdByReservedQuoteId::class
86
+ );
62
87
}
63
88
64
89
/**
65
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
66
- * @magentoApiDataFixture Magento/Ups/_files/enable_ups_shipping_method.php
90
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
91
+ * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
92
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
93
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
94
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
95
+ * @magentoApiDataFixture Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php
96
+ *
97
+ * @dataProvider dataProviderShippingMethods
98
+ * @param string $methodCode
99
+ * @param string $methodLabel
67
100
*/
68
- public function testSetUpsShippingMethod ()
101
+ public function testSetUpsShippingMethod (string $ methodCode , string $ methodLabel )
69
102
{
70
- $ quote = $ this ->quoteFactory ->create ();
71
- $ this ->quoteResource ->load ($ quote , 'test_order_1 ' , 'reserved_order_id ' );
72
- $ maskedQuoteId = $ this ->quoteIdToMaskedId ->execute ((int )$ quote ->getId ());
73
- $ shippingAddressId = (int )$ quote ->getShippingAddress ()->getId ();
74
-
75
- $ query = $ this ->getAddUpsShippingMethodQuery (
76
- $ maskedQuoteId ,
77
- $ shippingAddressId ,
78
- self ::CARRIER_CODE ,
79
- self ::CARRIER_METHOD_CODE_GROUND
103
+ $ quoteReservedId = 'test_quote ' ;
104
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ($ quoteReservedId );
105
+ $ shippingAddressId = $ this ->getQuoteShippingAddressIdByReservedQuoteId ->execute ($ quoteReservedId );
106
+
107
+ $ query = $ this ->getQuery ($ maskedQuoteId , $ shippingAddressId , self ::CARRIER_CODE , $ methodCode );
108
+ $ response = $ this ->sendRequestWithToken ($ query );
109
+
110
+ self ::assertArrayHasKey ('setShippingMethodsOnCart ' , $ response );
111
+ self ::assertArrayHasKey ('cart ' , $ response ['setShippingMethodsOnCart ' ]);
112
+ self ::assertArrayHasKey ('shipping_addresses ' , $ response ['setShippingMethodsOnCart ' ]['cart ' ]);
113
+ self ::assertCount (1 , $ response ['setShippingMethodsOnCart ' ]['cart ' ]['shipping_addresses ' ]);
114
+
115
+ $ shippingAddress = current ($ response ['setShippingMethodsOnCart ' ]['cart ' ]['shipping_addresses ' ]);
116
+ self ::assertArrayHasKey ('selected_shipping_method ' , $ shippingAddress );
117
+
118
+ self ::assertArrayHasKey ('carrier_code ' , $ shippingAddress ['selected_shipping_method ' ]);
119
+ self ::assertEquals (self ::CARRIER_CODE , $ shippingAddress ['selected_shipping_method ' ]['carrier_code ' ]);
120
+
121
+ self ::assertArrayHasKey ('method_code ' , $ shippingAddress ['selected_shipping_method ' ]);
122
+ self ::assertEquals ($ methodCode , $ shippingAddress ['selected_shipping_method ' ]['method_code ' ]);
123
+
124
+ self ::assertArrayHasKey ('label ' , $ shippingAddress ['selected_shipping_method ' ]);
125
+ self ::assertEquals (
126
+ self ::CARRIER_LABEL . ' - ' . $ methodLabel ,
127
+ $ shippingAddress ['selected_shipping_method ' ]['label ' ]
80
128
);
129
+ }
81
130
131
+ /**
132
+ * @return array
133
+ */
134
+ public function dataProviderShippingMethods (): array
135
+ {
136
+ return [
137
+ 'Next Day Air Early AM ' => ['1DM ' , 'Next Day Air Early AM ' ],
138
+ 'Next Day Air ' => ['1DA ' , 'Next Day Air ' ],
139
+ '2nd Day Air ' => ['2DA ' , '2nd Day Air ' ],
140
+ '3 Day Select ' => ['3DS ' , '3 Day Select ' ],
141
+ 'Ground ' => ['GND ' , 'Ground ' ],
142
+ ];
143
+ }
144
+
145
+ /**
146
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
147
+ * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
148
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
149
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
150
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_canada_address.php
151
+ * @magentoApiDataFixture Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php
152
+ *
153
+ * @dataProvider dataProviderShippingMethodsBasedOnCanadaAddress
154
+ * @param string $methodCode
155
+ * @param string $methodLabel
156
+ */
157
+ public function testSetUpsShippingMethodBasedOnCanadaAddress (string $ methodCode , string $ methodLabel )
158
+ {
159
+ $ quoteReservedId = 'test_quote ' ;
160
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ($ quoteReservedId );
161
+ $ shippingAddressId = $ this ->getQuoteShippingAddressIdByReservedQuoteId ->execute ($ quoteReservedId );
162
+
163
+ $ query = $ this ->getQuery ($ maskedQuoteId , $ shippingAddressId , self ::CARRIER_CODE , $ methodCode );
82
164
$ response = $ this ->sendRequestWithToken ($ query );
83
- $ addressesInformation = $ response ['setShippingMethodsOnCart ' ]['cart ' ]['shipping_addresses ' ];
84
- $ expectedResult = [
85
- 'carrier_code ' => self ::CARRIER_CODE ,
86
- 'method_code ' => self ::CARRIER_METHOD_CODE_GROUND ,
87
- 'label ' => 'United Parcel Service - Ground ' ,
165
+
166
+ self ::assertArrayHasKey ('setShippingMethodsOnCart ' , $ response );
167
+ self ::assertArrayHasKey ('cart ' , $ response ['setShippingMethodsOnCart ' ]);
168
+ self ::assertArrayHasKey ('shipping_addresses ' , $ response ['setShippingMethodsOnCart ' ]['cart ' ]);
169
+ self ::assertCount (1 , $ response ['setShippingMethodsOnCart ' ]['cart ' ]['shipping_addresses ' ]);
170
+
171
+ $ shippingAddress = current ($ response ['setShippingMethodsOnCart ' ]['cart ' ]['shipping_addresses ' ]);
172
+ self ::assertArrayHasKey ('selected_shipping_method ' , $ shippingAddress );
173
+
174
+ self ::assertArrayHasKey ('carrier_code ' , $ shippingAddress ['selected_shipping_method ' ]);
175
+ self ::assertEquals (self ::CARRIER_CODE , $ shippingAddress ['selected_shipping_method ' ]['carrier_code ' ]);
176
+
177
+ self ::assertArrayHasKey ('method_code ' , $ shippingAddress ['selected_shipping_method ' ]);
178
+ self ::assertEquals ($ methodCode , $ shippingAddress ['selected_shipping_method ' ]['method_code ' ]);
179
+
180
+ self ::assertArrayHasKey ('label ' , $ shippingAddress ['selected_shipping_method ' ]);
181
+ self ::assertEquals (
182
+ self ::CARRIER_LABEL . ' - ' . $ methodLabel ,
183
+ $ shippingAddress ['selected_shipping_method ' ]['label ' ]
184
+ );
185
+ }
186
+
187
+ /**
188
+ * @return array
189
+ */
190
+ public function dataProviderShippingMethodsBasedOnCanadaAddress (): array
191
+ {
192
+ return [
193
+ 'Canada Standard ' => ['STD ' , 'Canada Standard ' ],
194
+ 'Worldwide Express ' => ['XPR ' , 'Worldwide Express ' ],
195
+ 'Worldwide Express Saver ' => ['WXS ' , 'Worldwide Express Saver ' ],
196
+ 'Worldwide Express Plus ' => ['XDM ' , 'Worldwide Express Plus ' ],
88
197
];
89
- self ::assertEquals ($ addressesInformation [0 ]['selected_shipping_method ' ], $ expectedResult );
90
198
}
91
199
92
200
/**
@@ -98,7 +206,7 @@ public function testSetUpsShippingMethod()
98
206
* @param string $methodCode
99
207
* @return string
100
208
*/
101
- private function getAddUpsShippingMethodQuery (
209
+ private function getQuery (
102
210
string $ maskedQuoteId ,
103
211
int $ shippingAddressId ,
104
212
string $ carrierCode ,
0 commit comments