10 use \Magento\Quote\Model\ShippingAddressManagement;
55 private $addressRepository;
60 private $amountErrorMessageMock;
64 $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
65 $this->quoteRepositoryMock = $this->createMock(\
Magento\
Quote\Api\CartRepositoryInterface::class);
66 $this->scopeConfigMock = $this->createMock(\
Magento\Framework\
App\
Config\ScopeConfigInterface::class);
68 $this->quoteAddressMock = $this->createPartialMock(\
Magento\
Quote\Model\
Quote\Address::class, [
70 'setCollectShippingRates',
75 'getCustomerAddressId',
76 'getSaveInAddressBook',
78 'importCustomerAddressData',
79 'setSaveInAddressBook',
81 $this->validatorMock = $this->createMock(\
Magento\
Quote\Model\QuoteAddressValidator::class);
82 $this->totalsCollectorMock = $this->createMock(\
Magento\
Quote\Model\
Quote\TotalsCollector::class);
83 $this->addressRepository = $this->createMock(\
Magento\Customer\Api\AddressRepositoryInterface::class);
85 $this->amountErrorMessageMock = $this->createPartialMock(
90 $this->service = $this->objectManager->getObject(
93 'quoteRepository' => $this->quoteRepositoryMock,
94 'addressValidator' => $this->validatorMock,
95 'logger' => $this->createMock(\Psr\Log\LoggerInterface::class),
96 'scopeConfig' => $this->scopeConfigMock,
97 'totalsCollector' => $this->totalsCollectorMock,
98 'addressRepository' => $this->addressRepository
109 $quoteMock = $this->createMock(\
Magento\
Quote\Model\Quote::class);
110 $this->quoteRepositoryMock->expects($this->once())
111 ->method(
'getActive')
113 ->will($this->returnValue($quoteMock));
115 $this->validatorMock->expects($this->once())->method(
'validate')
118 $this->service->assign(
'cart654', $this->quoteAddressMock);
124 $customerAddressId = 150;
126 $quoteMock = $this->createPartialMock(
128 [
'getIsMultiShipping',
'isVirtual',
'validateMinimumAmount',
'setShippingAddress',
'getShippingAddress']
130 $this->quoteRepositoryMock->expects($this->once())
131 ->method(
'getActive')
133 ->willReturn($quoteMock);
134 $quoteMock->expects($this->once())->method(
'isVirtual')->will($this->returnValue(
false));
135 $quoteMock->expects($this->once())
136 ->method(
'setShippingAddress')
137 ->with($this->quoteAddressMock)
140 $this->quoteAddressMock->expects($this->once())->method(
'getSaveInAddressBook')->willReturn(1);
141 $this->quoteAddressMock->expects($this->once())->method(
'getSameAsBilling')->willReturn(1);
142 $this->quoteAddressMock->expects($this->once())->method(
'getCustomerAddressId')->willReturn($customerAddressId);
144 $customerAddressMock = $this->createMock(\
Magento\Customer\Api\Data\AddressInterface::class);
146 $this->addressRepository->expects($this->once())
148 ->with($customerAddressId)
149 ->willReturn($customerAddressMock);
151 $this->validatorMock->expects($this->once())->method(
'validate')
152 ->with($this->quoteAddressMock)
155 $quoteMock->expects($this->exactly(3))->method(
'getShippingAddress')->willReturn($this->quoteAddressMock);
156 $this->quoteAddressMock->expects($this->once())
157 ->method(
'importCustomerAddressData')
158 ->with($customerAddressMock)
161 $this->quoteAddressMock->expects($this->once())->method(
'setSameAsBilling')->with(1)->willReturnSelf();
162 $this->quoteAddressMock->expects($this->once())->method(
'setSaveInAddressBook')->with(1)->willReturnSelf();
163 $this->quoteAddressMock->expects($this->once())
164 ->method(
'setCollectShippingRates')
168 $this->quoteAddressMock->expects($this->once())->method(
'save')->willReturnSelf();
169 $this->quoteAddressMock->expects($this->once())->method(
'getId')->will($this->returnValue($addressId));
171 $this->assertEquals($addressId, $this->service->assign(
'cart867', $this->quoteAddressMock));
180 $quoteMock = $this->createMock(\
Magento\
Quote\Model\Quote::class);
181 $this->quoteRepositoryMock->expects($this->once())
182 ->method(
'getActive')
184 ->will($this->returnValue($quoteMock));
185 $quoteMock->expects($this->once())->method(
'isVirtual')->will($this->returnValue(
true));
186 $quoteMock->expects($this->never())->method(
'setShippingAddress');
188 $this->quoteAddressMock->expects($this->never())->method(
'getCustomerAddressId');
189 $this->quoteAddressMock->expects($this->never())->method(
'setSaveInAddressBook');
191 $quoteMock->expects($this->never())->method(
'save');
193 $this->service->assign(
'cart867', $this->quoteAddressMock);
202 $this->quoteAddressMock->expects($this->once())->method(
'save')->willThrowException(
203 new \
Exception(
'The address failed to save. Verify the address and try again.')
206 $customerAddressId = 150;
208 $quoteMock = $this->createPartialMock(
210 [
'getIsMultiShipping',
'isVirtual',
'validateMinimumAmount',
'setShippingAddress',
'getShippingAddress']
212 $this->quoteRepositoryMock->expects($this->once())
213 ->method(
'getActive')
215 ->willReturn($quoteMock);
216 $quoteMock->expects($this->once())->method(
'isVirtual')->will($this->returnValue(
false));
217 $quoteMock->expects($this->once())
218 ->method(
'setShippingAddress')
219 ->with($this->quoteAddressMock)
222 $customerAddressMock = $this->createMock(\
Magento\Customer\Api\Data\AddressInterface::class);
224 $this->addressRepository->expects($this->once())
226 ->with($customerAddressId)
227 ->willReturn($customerAddressMock);
229 $this->validatorMock->expects($this->once())->method(
'validate')
230 ->with($this->quoteAddressMock)
233 $this->quoteAddressMock->expects($this->once())->method(
'getSaveInAddressBook')->willReturn(1);
234 $this->quoteAddressMock->expects($this->once())->method(
'getSameAsBilling')->willReturn(1);
235 $this->quoteAddressMock->expects($this->once())->method(
'getCustomerAddressId')->willReturn($customerAddressId);
237 $quoteMock->expects($this->exactly(2))->method(
'getShippingAddress')->willReturn($this->quoteAddressMock);
238 $this->quoteAddressMock->expects($this->once())
239 ->method(
'importCustomerAddressData')
240 ->with($customerAddressMock)
243 $this->quoteAddressMock->expects($this->once())->method(
'setSameAsBilling')->with(1)->willReturnSelf();
244 $this->quoteAddressMock->expects($this->once())->method(
'setSaveInAddressBook')->with(1)->willReturnSelf();
245 $this->quoteAddressMock->expects($this->once())
246 ->method(
'setCollectShippingRates')
250 $this->service->assign(
'cart867', $this->quoteAddressMock);
255 $quoteMock = $this->createMock(\
Magento\
Quote\Model\Quote::class);
256 $this->quoteRepositoryMock->expects($this->once())->method(
'getActive')->with(
'cartId')->will(
257 $this->returnValue($quoteMock)
261 $quoteMock->expects($this->any())->method(
'getShippingAddress')->will($this->returnValue($addressMock));
262 $quoteMock->expects($this->any())->method(
'isVirtual')->will($this->returnValue(
false));
263 $this->assertEquals($addressMock, $this->service->get(
'cartId'));
272 $quoteMock = $this->createMock(\
Magento\
Quote\Model\Quote::class);
273 $this->quoteRepositoryMock->expects($this->once())->method(
'getActive')->with(
'cartId')->will(
274 $this->returnValue($quoteMock)
277 $quoteMock->expects($this->any())->method(
'isVirtual')->will($this->returnValue(
true));
278 $quoteMock->expects($this->never())->method(
'getShippingAddress');
280 $this->service->get(
'cartId');
testSetAddressForVirtualProduct()
testSetAddressValidationFailed()
testSetAddressWithInabilityToSaveQuote()
testGetAddressOfQuoteWithVirtualProducts()