18 private $objectManager;
58 private $shippingAssignmentFactoryMock;
63 private $cartExtensionFactoryMock;
68 private $shippingFactoryMock;
73 private $cartExtensionMock;
78 private $shippingAssignmentMock;
83 private $shippingMock;
87 $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
88 $this->paymentMethodManagementMock = $this->createMock(
89 \
Magento\
Quote\Api\PaymentMethodManagementInterface::class
91 $this->paymentDetailsFactoryMock = $this->createPartialMock(
92 \
Magento\Checkout\Model\PaymentDetailsFactory::class,
95 $this->cartTotalsRepositoryMock = $this->createMock(\
Magento\
Quote\Api\CartTotalRepositoryInterface::class);
96 $this->quoteRepositoryMock = $this->createMock(\
Magento\
Quote\Api\CartRepositoryInterface::class);
97 $this->shippingAddressMock = $this->createPartialMock(
100 'getSaveInAddressBook',
102 'getCustomerAddressId',
103 'setShippingAddress',
104 'getShippingAddress',
105 'setSaveInAddressBook',
107 'setCollectShippingRates',
109 'importCustomerAddressData',
111 'getShippingRateByCode',
117 $this->quoteMock = $this->createPartialMock(
122 'getIsMultiShipping',
123 'setIsMultiShipping',
124 'validateMinimumAmount',
126 'setShippingAddress',
127 'getShippingAddress',
129 'getExtensionAttributes',
130 'setExtensionAttributes',
138 $this->shippingAssignmentFactoryMock =
139 $this->createPartialMock(\
Magento\
Quote\Model\ShippingAssignmentFactory::class, [
'create']);
140 $this->cartExtensionFactoryMock =
141 $this->createPartialMock(\
Magento\
Quote\Api\Data\CartExtensionFactory::class, [
'create']);
142 $this->shippingFactoryMock =
143 $this->createPartialMock(\
Magento\
Quote\Model\ShippingFactory::class, [
'create']);
145 $this->model = $this->objectManager->getObject(
146 \
Magento\Checkout\Model\ShippingInformationManagement::class,
148 'paymentMethodManagement' => $this->paymentMethodManagementMock,
149 'paymentDetailsFactory' => $this->paymentDetailsFactoryMock,
150 'cartTotalsRepository' => $this->cartTotalsRepositoryMock,
151 'quoteRepository' => $this->quoteRepositoryMock,
152 'shippingAssignmentFactory' => $this->shippingAssignmentFactoryMock,
153 'cartExtensionFactory' => $this->cartExtensionFactoryMock,
154 'shippingFactory' => $this->shippingFactoryMock
166 $carrierCode =
'carrier_code';
168 $addressInformationMock = $this->createMock(\
Magento\Checkout\Api\Data\ShippingInformationInterface::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);
178 $this->shippingAddressMock->expects($this->once())->method(
'getCountryId')->willReturn(
'USA');
180 $this->setShippingAssignmentsMocks($carrierCode .
'_' .
$shippingMethod);
182 $this->quoteMock->expects($this->once())->method(
'getItemsCount')->willReturn(0);
183 $this->quoteRepositoryMock->expects($this->once())
184 ->method(
'getActive')
186 ->willReturn($this->quoteMock);
188 $this->model->saveAddressInformation(
$cartId, $addressInformationMock);
196 $this->quoteMock->expects($this->once())->method(
'getExtensionAttributes')->willReturn(
null);
197 $this->shippingAddressMock->expects($this->once())->method(
'setLimitCarrier');
198 $this->cartExtensionMock = $this->createPartialMock(
200 [
'getShippingAssignments',
'setShippingAssignments']
202 $this->cartExtensionFactoryMock->expects($this->once())
204 ->willReturn($this->cartExtensionMock);
205 $this->cartExtensionMock->expects($this->once())->method(
'getShippingAssignments')->willReturn(
null);
207 $this->shippingAssignmentMock = $this->createMock(
210 $this->shippingAssignmentFactoryMock->expects($this->once())
212 ->willReturn($this->shippingAssignmentMock);
213 $this->shippingAssignmentMock->expects($this->once())->method(
'getShipping')->willReturn(
null);
215 $this->shippingMock = $this->createMock(\
Magento\
Quote\Model\Shipping::class);
216 $this->shippingFactoryMock->expects($this->once())->method(
'create')->willReturn($this->shippingMock);
218 $this->shippingMock->expects($this->once())
219 ->method(
'setAddress')
220 ->with($this->shippingAddressMock)
222 $this->shippingMock->expects($this->once())->method(
'setMethod')->with(
$shippingMethod)->willReturnSelf();
224 $this->shippingAssignmentMock->expects($this->once())
225 ->method(
'setShipping')
226 ->with($this->shippingMock)
229 $this->cartExtensionMock->expects($this->once())
230 ->method(
'setShippingAssignments')
231 ->with([$this->shippingAssignmentMock])
234 $this->quoteMock->expects($this->once())
235 ->method(
'setExtensionAttributes')
236 ->with($this->cartExtensionMock)
247 $carrierCode =
'carrier_code';
249 $addressInformationMock = $this->createMock(\
Magento\Checkout\Api\Data\ShippingInformationInterface::class);
251 $addressInformationMock->expects($this->once())
252 ->method(
'getShippingAddress')
253 ->willReturn($this->shippingAddressMock);
254 $addressInformationMock->expects($this->once())->method(
'getShippingCarrierCode')->willReturn($carrierCode);
255 $addressInformationMock->expects($this->once())->method(
'getShippingMethodCode')->willReturn(
$shippingMethod);
258 $addressInformationMock->expects($this->once())->method(
'getBillingAddress')->willReturn(
$billingAddress);
260 $this->shippingAddressMock->expects($this->once())->method(
'getCountryId')->willReturn(
null);
262 $this->model->saveAddressInformation(
$cartId, $addressInformationMock);
272 $carrierCode =
'carrier_code';
274 $addressInformationMock = $this->createMock(\
Magento\Checkout\Api\Data\ShippingInformationInterface::class);
276 $this->quoteRepositoryMock->expects($this->once())
277 ->method(
'getActive')
279 ->willReturn($this->quoteMock);
281 $addressInformationMock->expects($this->once())
282 ->method(
'getShippingAddress')
283 ->willReturn($this->shippingAddressMock);
284 $addressInformationMock->expects($this->once())->method(
'getShippingCarrierCode')->willReturn($carrierCode);
285 $addressInformationMock->expects($this->once())->method(
'getShippingMethodCode')->willReturn(
$shippingMethod);
288 $addressInformationMock->expects($this->once())->method(
'getBillingAddress')->willReturn(
$billingAddress);
290 $this->shippingAddressMock->expects($this->once())->method(
'getCountryId')->willReturn(
'USA');
292 $this->setShippingAssignmentsMocks($carrierCode .
'_' .
$shippingMethod);
294 $this->quoteMock->expects($this->once())->method(
'getItemsCount')->willReturn(100);
295 $this->quoteMock->expects($this->once())->method(
'setIsMultiShipping')->with(
false)->willReturnSelf();
296 $this->quoteMock->expects($this->once())->method(
'setBillingAddress')->with(
$billingAddress)->willReturnSelf();
298 $this->quoteRepositoryMock->expects($this->once())
300 ->with($this->quoteMock)
303 $this->model->saveAddressInformation(
$cartId, $addressInformationMock);
313 $carrierCode =
'carrier_code';
315 $addressInformationMock = $this->createMock(\
Magento\Checkout\Api\Data\ShippingInformationInterface::class);
317 $this->quoteRepositoryMock->expects($this->once())
318 ->method(
'getActive')
320 ->willReturn($this->quoteMock);
321 $addressInformationMock->expects($this->once())
322 ->method(
'getShippingAddress')
323 ->willReturn($this->shippingAddressMock);
324 $addressInformationMock->expects($this->once())->method(
'getShippingCarrierCode')->willReturn($carrierCode);
325 $addressInformationMock->expects($this->once())->method(
'getShippingMethodCode')->willReturn(
$shippingMethod);
328 $addressInformationMock->expects($this->once())->method(
'getBillingAddress')->willReturn(
$billingAddress);
329 $this->shippingAddressMock->expects($this->once())->method(
'getCountryId')->willReturn(
'USA');
331 $this->setShippingAssignmentsMocks($carrierCode .
'_' .
$shippingMethod);
333 $this->quoteMock->expects($this->once())->method(
'getItemsCount')->willReturn(100);
334 $this->quoteMock->expects($this->once())->method(
'setIsMultiShipping')->with(
false)->willReturnSelf();
335 $this->quoteMock->expects($this->once())->method(
'setBillingAddress')->with(
$billingAddress)->willReturnSelf();
336 $this->quoteMock->expects($this->once())->method(
'getShippingAddress')->willReturn($this->shippingAddressMock);
338 $this->quoteRepositoryMock->expects($this->once())
340 ->with($this->quoteMock);
342 $this->shippingAddressMock->expects($this->once())->method(
'getShippingMethod')->willReturn(
$shippingMethod);
343 $this->shippingAddressMock->expects($this->once())
344 ->method(
'getShippingRateByCode')
348 $this->model->saveAddressInformation(
$cartId, $addressInformationMock);
354 $carrierCode =
'carrier_code';
356 $addressInformationMock = $this->createMock(\
Magento\Checkout\Api\Data\ShippingInformationInterface::class);
358 $this->quoteRepositoryMock->expects($this->once())
359 ->method(
'getActive')
361 ->willReturn($this->quoteMock);
362 $addressInformationMock->expects($this->once())
363 ->method(
'getShippingAddress')
364 ->willReturn($this->shippingAddressMock);
365 $addressInformationMock->expects($this->once())->method(
'getShippingCarrierCode')->willReturn($carrierCode);
366 $addressInformationMock->expects($this->once())->method(
'getShippingMethodCode')->willReturn(
$shippingMethod);
369 $addressInformationMock->expects($this->once())->method(
'getBillingAddress')->willReturn(
$billingAddress);
370 $this->shippingAddressMock->expects($this->once())->method(
'getCountryId')->willReturn(
'USA');
372 $this->setShippingAssignmentsMocks($carrierCode .
'_' .
$shippingMethod);
374 $this->quoteMock->expects($this->once())->method(
'getItemsCount')->willReturn(100);
375 $this->quoteMock->expects($this->once())->method(
'setIsMultiShipping')->with(
false)->willReturnSelf();
376 $this->quoteMock->expects($this->once())->method(
'setBillingAddress')->with(
$billingAddress)->willReturnSelf();
377 $this->quoteMock->expects($this->once())->method(
'getShippingAddress')->willReturn($this->shippingAddressMock);
379 $this->quoteRepositoryMock->expects($this->once())
381 ->with($this->quoteMock);
383 $this->shippingAddressMock->expects($this->once())->method(
'getShippingMethod')->willReturn(
$shippingMethod);
384 $this->shippingAddressMock->expects($this->once())
385 ->method(
'getShippingRateByCode')
387 ->willReturn(
'rates');
389 $paymentDetailsMock = $this->createMock(\
Magento\Checkout\Api\Data\PaymentDetailsInterface::class);
390 $this->paymentDetailsFactoryMock->expects($this->once())->method(
'create')->willReturn($paymentDetailsMock);
392 $paymentMethodMock = $this->createMock(\
Magento\
Quote\Api\Data\PaymentMethodInterface::class);
393 $this->paymentMethodManagementMock->expects($this->once())
396 ->willReturn([$paymentMethodMock]);
398 $cartTotalsMock = $this->createMock(\
Magento\
Quote\Api\Data\TotalsInterface::class);
399 $this->cartTotalsRepositoryMock->expects($this->once())
402 ->willReturn($cartTotalsMock);
404 $paymentDetailsMock->expects($this->once())
405 ->method(
'setPaymentMethods')
406 ->with([$paymentMethodMock])
408 $paymentDetailsMock->expects($this->once())->method(
'setTotals')->with()->willReturnSelf($cartTotalsMock);
412 $this->model->saveAddressInformation(
$cartId, $addressInformationMock)