29 private $addressRepositoryMock;
34 private $filterBuilderMock;
39 private $criteriaBuilderMock;
44 private $objectManagerMock;
49 private $checkoutMock;
54 private $redirectMock;
58 $this->checkoutMock = $this->createMock(\
Magento\Multishipping\Model\Checkout\Type\Multishipping::class);
59 $this->objectManagerMock = $this->createMock(\
Magento\Framework\ObjectManagerInterface::class);
60 $this->objectManagerMock->expects($this->any())
62 ->with(\
Magento\Multishipping\Model\Checkout\Type\Multishipping::class)
63 ->willReturn($this->checkoutMock);
64 $this->contextMock = $this->createMock(\
Magento\Framework\
App\Action\Context::class);
65 $requestMock = $this->createMock(\
Magento\Framework\
App\RequestInterface::class);
66 $responseMock = $this->createMock(\
Magento\Framework\
App\ResponseInterface::class);
67 $this->redirectMock = $this->createMock(\
Magento\Framework\
App\
Response\RedirectInterface::class);
68 $this->contextMock->expects($this->any())->method(
'getObjectManager')->willReturn($this->objectManagerMock);
69 $this->contextMock->expects($this->any())->method(
'getRequest')->willReturn($requestMock);
70 $this->contextMock->expects($this->any())->method(
'getResponse')->willReturn($responseMock);
71 $this->contextMock->expects($this->any())->method(
'getRedirect')->willReturn($this->redirectMock);
73 $this->addressRepositoryMock = $this->createMock(\
Magento\Customer\Api\AddressRepositoryInterface::class);
74 $this->filterBuilderMock = $this->createMock(\
Magento\Framework\Api\FilterBuilder::class);
75 $this->criteriaBuilderMock = $this->createMock(\
Magento\Framework\Api\SearchCriteriaBuilder::class);
76 $this->controller = new \Magento\Multishipping\Controller\Checkout\Address\ShippingSaved(
78 $this->addressRepositoryMock,
79 $this->filterBuilderMock,
80 $this->criteriaBuilderMock
87 $customerMock = $this->createMock(\
Magento\Customer\Api\Data\CustomerInterface::class);
88 $customerMock->expects($this->any())->method(
'getId')->willReturn(
$customerId);
89 $this->checkoutMock->expects($this->any())->method(
'getCustomer')->willReturn($customerMock);
91 $this->mockCustomerAddressRepository(
93 [$this->createMock(\
Magento\Customer\Api\Data\AddressInterface::class)]
97 $this->checkoutMock->expects($this->once())->method(
'reset');
98 $this->controller->execute();
104 $customerMock = $this->createMock(\
Magento\Customer\Api\Data\CustomerInterface::class);
105 $customerMock->expects($this->any())->method(
'getId')->willReturn(
$customerId);
106 $this->checkoutMock->expects($this->any())->method(
'getCustomer')->willReturn($customerMock);
108 $this->mockCustomerAddressRepository(
111 $this->createMock(\
Magento\Customer\Api\Data\AddressInterface::class),
112 $this->createMock(\
Magento\Customer\Api\Data\AddressInterface::class),
117 $this->checkoutMock->expects($this->never())->method(
'reset');
118 $this->controller->execute();
129 $filterMock = $this->createMock(\
Magento\Framework\Api\Filter::class);
130 $this->filterBuilderMock->expects($this->once())->method(
'setField')->with(
'parent_id')->willReturnSelf();
131 $this->filterBuilderMock->expects($this->once())->method(
'setValue')->with(
$customerId)->willReturnSelf();
132 $this->filterBuilderMock->expects($this->once())->method(
'setConditionType')->with(
'eq')->willReturnSelf();
133 $this->filterBuilderMock->expects($this->once())->method(
'create')->willReturn($filterMock);
135 $searchCriteriaMock = $this->createMock(\
Magento\Framework\Api\SearchCriteria::class);
136 $this->criteriaBuilderMock->expects($this->once())->method(
'addFilters')->with([$filterMock])->willReturnSelf();
137 $this->criteriaBuilderMock->expects($this->once())->method(
'create')->willReturn($searchCriteriaMock);
139 $searchResultMock = $this->createMock(\
Magento\Customer\Api\Data\AddressSearchResultsInterface::class);
140 $this->addressRepositoryMock->expects($this->once())
142 ->with($searchCriteriaMock)
143 ->willReturn($searchResultMock);
145 $searchResultMock->expects($this->once())->method(
'getItems')->willReturn(
$addresses);
testExecuteDoesNotResetCheckoutIfCustomerHasMoreThanOneAddress()
testExecuteResetsCheckoutIfCustomerHasAddedNewShippingAddressAndItIsTheOnlyAddressHeHas()