5
5
*/
6
6
namespace Magento \Checkout \Test \Unit \Model ;
7
7
8
+ use Magento \Quote \Model \QuoteAddressValidator ;
9
+
8
10
/**
9
11
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
10
12
* @SuppressWarnings(PHPMD.TooManyFields)
@@ -149,6 +151,7 @@ protected function setUp()
149
151
$ this ->getMock (\Magento \Quote \Api \Data \CartExtensionFactory::class, ['create ' ], [], '' , false );
150
152
$ this ->shippingFactoryMock =
151
153
$ this ->getMock (\Magento \Quote \Model \ShippingFactory::class, ['create ' ], [], '' , false );
154
+ $ this ->addressValidatorMock = $ this ->getMock (QuoteAddressValidator::class, [], [], '' , false );
152
155
153
156
$ this ->model = $ this ->objectManager ->getObject (
154
157
\Magento \Checkout \Model \ShippingInformationManagement::class,
@@ -157,6 +160,7 @@ protected function setUp()
157
160
'paymentDetailsFactory ' => $ this ->paymentDetailsFactoryMock ,
158
161
'cartTotalsRepository ' => $ this ->cartTotalsRepositoryMock ,
159
162
'quoteRepository ' => $ this ->quoteRepositoryMock ,
163
+ 'addressValidator ' => $ this ->addressValidatorMock ,
160
164
]
161
165
);
162
166
$ this ->objectManager ->setBackwardCompatibleProperty (
@@ -183,22 +187,8 @@ protected function setUp()
183
187
public function testSaveAddressInformationIfCartIsEmpty ()
184
188
{
185
189
$ cartId = 100 ;
186
- $ carrierCode = 'carrier_code ' ;
187
- $ shippingMethod = 'shipping_method ' ;
188
190
$ addressInformationMock = $ this ->getMock (\Magento \Checkout \Api \Data \ShippingInformationInterface::class);
189
191
190
- $ billingAddress = $ this ->getMock (\Magento \Quote \Api \Data \AddressInterface::class);
191
- $ addressInformationMock ->expects ($ this ->once ())
192
- ->method ('getShippingAddress ' )
193
- ->willReturn ($ this ->shippingAddressMock );
194
- $ addressInformationMock ->expects ($ this ->once ())->method ('getBillingAddress ' )->willReturn ($ billingAddress );
195
- $ addressInformationMock ->expects ($ this ->once ())->method ('getShippingCarrierCode ' )->willReturn ($ carrierCode );
196
- $ addressInformationMock ->expects ($ this ->once ())->method ('getShippingMethodCode ' )->willReturn ($ shippingMethod );
197
-
198
- $ this ->shippingAddressMock ->expects ($ this ->once ())->method ('getCountryId ' )->willReturn ('USA ' );
199
-
200
- $ this ->setShippingAssignmentsMocks ($ carrierCode . '_ ' . $ shippingMethod );
201
-
202
192
$ this ->quoteMock ->expects ($ this ->once ())->method ('getItemsCount ' )->willReturn (0 );
203
193
$ this ->quoteRepositoryMock ->expects ($ this ->once ())
204
194
->method ('getActive ' )
@@ -271,21 +261,19 @@ private function setShippingAssignmentsMocks($shippingMethod)
271
261
public function testSaveAddressInformationIfShippingAddressNotSet ()
272
262
{
273
263
$ cartId = 100 ;
274
- $ carrierCode = 'carrier_code ' ;
275
- $ shippingMethod = 'shipping_method ' ;
276
264
$ addressInformationMock = $ this ->getMock (\Magento \Checkout \Api \Data \ShippingInformationInterface::class);
277
-
278
265
$ addressInformationMock ->expects ($ this ->once ())
279
266
->method ('getShippingAddress ' )
280
267
->willReturn ($ this ->shippingAddressMock );
281
- $ addressInformationMock ->expects ($ this ->once ())->method ('getShippingCarrierCode ' )->willReturn ($ carrierCode );
282
- $ addressInformationMock ->expects ($ this ->once ())->method ('getShippingMethodCode ' )->willReturn ($ shippingMethod );
283
-
284
- $ billingAddress = $ this ->getMock (\Magento \Quote \Api \Data \AddressInterface::class);
285
- $ addressInformationMock ->expects ($ this ->once ())->method ('getBillingAddress ' )->willReturn ($ billingAddress );
286
268
287
269
$ this ->shippingAddressMock ->expects ($ this ->once ())->method ('getCountryId ' )->willReturn (null );
288
270
271
+ $ this ->quoteRepositoryMock ->expects ($ this ->once ())
272
+ ->method ('getActive ' )
273
+ ->with ($ cartId )
274
+ ->willReturn ($ this ->quoteMock );
275
+ $ this ->quoteMock ->expects ($ this ->once ())->method ('getItemsCount ' )->willReturn (100 );
276
+
289
277
$ this ->model ->saveAddressInformation ($ cartId , $ addressInformationMock );
290
278
}
291
279
@@ -300,6 +288,9 @@ public function testSaveAddressInformationIfCanNotSaveQuote()
300
288
$ shippingMethod = 'shipping_method ' ;
301
289
$ addressInformationMock = $ this ->getMock (\Magento \Checkout \Api \Data \ShippingInformationInterface::class);
302
290
291
+ $ this ->addressValidatorMock ->expects ($ this ->exactly (2 ))
292
+ ->method ('validateForCart ' );
293
+
303
294
$ this ->quoteRepositoryMock ->expects ($ this ->once ())
304
295
->method ('getActive ' )
305
296
->with ($ cartId )
@@ -341,6 +332,9 @@ public function testSaveAddressInformationIfCarrierCodeIsInvalid()
341
332
$ shippingMethod = 'shipping_method ' ;
342
333
$ addressInformationMock = $ this ->getMock (\Magento \Checkout \Api \Data \ShippingInformationInterface::class);
343
334
335
+ $ this ->addressValidatorMock ->expects ($ this ->exactly (2 ))
336
+ ->method ('validateForCart ' );
337
+
344
338
$ this ->quoteRepositoryMock ->expects ($ this ->once ())
345
339
->method ('getActive ' )
346
340
->with ($ cartId )
@@ -382,6 +376,9 @@ public function testSaveAddressInformation()
382
376
$ shippingMethod = 'shipping_method ' ;
383
377
$ addressInformationMock = $ this ->getMock (\Magento \Checkout \Api \Data \ShippingInformationInterface::class);
384
378
379
+ $ this ->addressValidatorMock ->expects ($ this ->exactly (2 ))
380
+ ->method ('validateForCart ' );
381
+
385
382
$ this ->quoteRepositoryMock ->expects ($ this ->once ())
386
383
->method ('getActive ' )
387
384
->with ($ cartId )
0 commit comments