18 private $cartRepositoryMock;
23 private $checkoutSessionMock;
28 private $addressRepositoryMock;
32 $this->cartRepositoryMock = $this->createMock(\
Magento\Quote\Api\CartRepositoryInterface::class);
33 $this->checkoutSessionMock = $this->createMock(\
Magento\Checkout\Model\Session::class);
34 $this->addressRepositoryMock = $this->createMock(\
Magento\Customer\Api\AddressRepositoryInterface::class);
35 $this->model = new \Magento\Multishipping\Model\Cart\Controller\CartPlugin(
36 $this->cartRepositoryMock,
37 $this->checkoutSessionMock,
38 $this->addressRepositoryMock
45 $customerAddressId = 200;
46 $quoteMock = $this->createPartialMock(\
Magento\Quote\Model\Quote::class, [
47 'isMultipleShippingAddresses',
48 'getAllShippingAddresses',
53 $this->checkoutSessionMock->expects($this->once())->method(
'getQuote')->willReturn($quoteMock);
55 $addressMock = $this->createMock(\
Magento\Quote\Model\Quote\Address::class);
56 $addressMock->expects($this->once())->method(
'getId')->willReturn($addressId);
58 $quoteMock->expects($this->once())->method(
'isMultipleShippingAddresses')->willReturn(
true);
59 $quoteMock->expects($this->once())->method(
'getAllShippingAddresses')->willReturn([$addressMock]);
60 $quoteMock->expects($this->once())->method(
'removeAddress')->with($addressId)->willReturnSelf();
62 $shippingAddressMock = $this->createMock(\
Magento\Quote\Model\Quote\Address::class);
63 $quoteMock->expects($this->once())->method(
'getShippingAddress')->willReturn($shippingAddressMock);
64 $customerMock = $this->createMock(\
Magento\Customer\Api\Data\CustomerInterface::class);
65 $quoteMock->expects($this->once())->method(
'getCustomer')->willReturn($customerMock);
66 $customerMock->expects($this->once())->method(
'getDefaultShipping')->willReturn($customerAddressId);
68 $customerAddressMock = $this->createMock(\
Magento\Customer\Api\Data\AddressInterface::class);
69 $this->addressRepositoryMock->expects($this->once())
71 ->with($customerAddressId)
72 ->willReturn($customerAddressMock);
74 $shippingAddressMock->expects($this->once())
75 ->method(
'importCustomerAddressData')
76 ->with($customerAddressMock)
79 $this->cartRepositoryMock->expects($this->once())->method(
'save')->with($quoteMock);
81 $this->model->beforeDispatch(
82 $this->createMock(\
Magento\Checkout\Controller\Cart::class),
83 $this->createMock(\
Magento\Framework\
App\RequestInterface::class)