@@ -82,6 +82,11 @@ class ShippingInformationManagementTest extends \PHPUnit\Framework\TestCase
82
82
*/
83
83
private $ shippingMock ;
84
84
85
+ /**
86
+ * @var \PHPUnit_Framework_MockObject_MockObject
87
+ */
88
+ private $ addressValidatorMock ;
89
+
85
90
protected function setUp ()
86
91
{
87
92
$ this ->objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
@@ -141,6 +146,9 @@ protected function setUp()
141
146
$ this ->createPartialMock (\Magento \Quote \Api \Data \CartExtensionFactory::class, ['create ' ]);
142
147
$ this ->shippingFactoryMock =
143
148
$ this ->createPartialMock (\Magento \Quote \Model \ShippingFactory::class, ['create ' ]);
149
+ $ this ->addressValidatorMock = $ this ->createMock (
150
+ \Magento \Quote \Model \QuoteAddressValidator::class
151
+ );
144
152
145
153
$ this ->model = $ this ->objectManager ->getObject (
146
154
\Magento \Checkout \Model \ShippingInformationManagement::class,
@@ -151,7 +159,8 @@ protected function setUp()
151
159
'quoteRepository ' => $ this ->quoteRepositoryMock ,
152
160
'shippingAssignmentFactory ' => $ this ->shippingAssignmentFactoryMock ,
153
161
'cartExtensionFactory ' => $ this ->cartExtensionFactoryMock ,
154
- 'shippingFactory ' => $ this ->shippingFactoryMock
162
+ 'shippingFactory ' => $ this ->shippingFactoryMock ,
163
+ 'addressValidator ' => $ this ->addressValidatorMock ,
155
164
]
156
165
);
157
166
}
@@ -163,22 +172,8 @@ protected function setUp()
163
172
public function testSaveAddressInformationIfCartIsEmpty ()
164
173
{
165
174
$ cartId = 100 ;
166
- $ carrierCode = 'carrier_code ' ;
167
- $ shippingMethod = 'shipping_method ' ;
168
175
$ addressInformationMock = $ this ->createMock (\Magento \Checkout \Api \Data \ShippingInformationInterface::class);
169
176
170
- $ billingAddress = $ this ->createMock (\Magento \Quote \Api \Data \AddressInterface::class);
171
- $ addressInformationMock ->expects ($ this ->once ())
172
- ->method ('getShippingAddress ' )
173
- ->willReturn ($ this ->shippingAddressMock );
174
- $ addressInformationMock ->expects ($ this ->once ())->method ('getBillingAddress ' )->willReturn ($ billingAddress );
175
- $ addressInformationMock ->expects ($ this ->once ())->method ('getShippingCarrierCode ' )->willReturn ($ carrierCode );
176
- $ addressInformationMock ->expects ($ this ->once ())->method ('getShippingMethodCode ' )->willReturn ($ shippingMethod );
177
-
178
- $ this ->shippingAddressMock ->expects ($ this ->once ())->method ('getCountryId ' )->willReturn ('USA ' );
179
-
180
- $ this ->setShippingAssignmentsMocks ($ carrierCode . '_ ' . $ shippingMethod );
181
-
182
177
$ this ->quoteMock ->expects ($ this ->once ())->method ('getItemsCount ' )->willReturn (0 );
183
178
$ this ->quoteRepositoryMock ->expects ($ this ->once ())
184
179
->method ('getActive ' )
@@ -244,21 +239,19 @@ private function setShippingAssignmentsMocks($shippingMethod)
244
239
public function testSaveAddressInformationIfShippingAddressNotSet ()
245
240
{
246
241
$ cartId = 100 ;
247
- $ carrierCode = 'carrier_code ' ;
248
- $ shippingMethod = 'shipping_method ' ;
249
242
$ addressInformationMock = $ this ->createMock (\Magento \Checkout \Api \Data \ShippingInformationInterface::class);
250
-
251
243
$ addressInformationMock ->expects ($ this ->once ())
252
244
->method ('getShippingAddress ' )
253
245
->willReturn ($ this ->shippingAddressMock );
254
- $ addressInformationMock ->expects ($ this ->once ())->method ('getShippingCarrierCode ' )->willReturn ($ carrierCode );
255
- $ addressInformationMock ->expects ($ this ->once ())->method ('getShippingMethodCode ' )->willReturn ($ shippingMethod );
256
-
257
- $ billingAddress = $ this ->createMock (\Magento \Quote \Api \Data \AddressInterface::class);
258
- $ addressInformationMock ->expects ($ this ->once ())->method ('getBillingAddress ' )->willReturn ($ billingAddress );
259
246
260
247
$ this ->shippingAddressMock ->expects ($ this ->once ())->method ('getCountryId ' )->willReturn (null );
261
248
249
+ $ this ->quoteRepositoryMock ->expects ($ this ->once ())
250
+ ->method ('getActive ' )
251
+ ->with ($ cartId )
252
+ ->willReturn ($ this ->quoteMock );
253
+ $ this ->quoteMock ->expects ($ this ->once ())->method ('getItemsCount ' )->willReturn (100 );
254
+
262
255
$ this ->model ->saveAddressInformation ($ cartId , $ addressInformationMock );
263
256
}
264
257
@@ -273,6 +266,9 @@ public function testSaveAddressInformationIfCanNotSaveQuote()
273
266
$ shippingMethod = 'shipping_method ' ;
274
267
$ addressInformationMock = $ this ->createMock (\Magento \Checkout \Api \Data \ShippingInformationInterface::class);
275
268
269
+ $ this ->addressValidatorMock ->expects ($ this ->exactly (2 ))
270
+ ->method ('validateForCart ' );
271
+
276
272
$ this ->quoteRepositoryMock ->expects ($ this ->once ())
277
273
->method ('getActive ' )
278
274
->with ($ cartId )
@@ -314,6 +310,9 @@ public function testSaveAddressInformationIfCarrierCodeIsInvalid()
314
310
$ shippingMethod = 'shipping_method ' ;
315
311
$ addressInformationMock = $ this ->createMock (\Magento \Checkout \Api \Data \ShippingInformationInterface::class);
316
312
313
+ $ this ->addressValidatorMock ->expects ($ this ->exactly (2 ))
314
+ ->method ('validateForCart ' );
315
+
317
316
$ this ->quoteRepositoryMock ->expects ($ this ->once ())
318
317
->method ('getActive ' )
319
318
->with ($ cartId )
@@ -355,6 +354,9 @@ public function testSaveAddressInformation()
355
354
$ shippingMethod = 'shipping_method ' ;
356
355
$ addressInformationMock = $ this ->createMock (\Magento \Checkout \Api \Data \ShippingInformationInterface::class);
357
356
357
+ $ this ->addressValidatorMock ->expects ($ this ->exactly (2 ))
358
+ ->method ('validateForCart ' );
359
+
358
360
$ this ->quoteRepositoryMock ->expects ($ this ->once ())
359
361
->method ('getActive ' )
360
362
->with ($ cartId )
0 commit comments