56 $this->persistentSessionMock = $this->createMock(\
Magento\Persistent\Helper\Session::class);
58 $this->createPartialMock(\
Magento\Persistent\Model\Session::class, [
64 'removePersistentCookie',
67 $this->persistentDataMock = $this->createMock(\
Magento\Persistent\Helper\Data::class);
68 $this->checkoutSessionMock = $this->createMock(\
Magento\Checkout\Model\Session::class);
70 $this->abstractCollectionMock =
71 $this->createMock(\
Magento\Eav\Model\Entity\Collection\AbstractCollection::class);
73 $this->quoteRepositoryMock = $this->createMock(\
Magento\Quote\Api\CartRepositoryInterface::class);
74 $this->quoteMock = $this->createPartialMock(\
Magento\Quote\Model\Quote::class, [
77 'getPaymentsCollection',
78 'getAddressesCollection',
82 'setCustomerFirstname',
83 'setCustomerLastname',
96 $this->persistentSessionMock,
97 $this->persistentDataMock,
98 $this->checkoutSessionMock,
99 $this->quoteRepositoryMock
105 $this->checkoutSessionMock->expects($this->once())
106 ->method(
'getQuote')->will($this->returnValue(
null));
107 $this->quoteMock->expects($this->never())->method(
'getId');
109 $this->persistentSessionMock->expects($this->once())
110 ->method(
'getSession')->will($this->returnValue($this->sessionMock));
111 $this->sessionMock->expects($this->once())
112 ->method(
'removePersistentCookie')->will($this->returnValue($this->sessionMock));
114 $this->model->setGuest(
false);
119 $this->checkoutSessionMock->expects($this->once())
120 ->method(
'getQuote')->will($this->returnValue($this->quoteMock));
121 $this->quoteMock->expects($this->once())->method(
'getId')->will($this->returnValue(
null));
122 $this->persistentDataMock->expects($this->never())->method(
'isShoppingCartPersist');
124 $this->persistentSessionMock->expects($this->once())
125 ->method(
'getSession')->will($this->returnValue($this->sessionMock));
126 $this->sessionMock->expects($this->once())
127 ->method(
'removePersistentCookie')->will($this->returnValue($this->sessionMock));
129 $this->model->setGuest(
false);
134 $this->checkoutSessionMock->expects($this->once())
135 ->method(
'getQuote')->will($this->returnValue($this->quoteMock));
136 $this->quoteMock->expects($this->once())->method(
'getId')->will($this->returnValue(11));
137 $this->persistentDataMock->expects($this->once())
138 ->method(
'isShoppingCartPersist')->will($this->returnValue(
false));
139 $this->quoteMock->expects($this->once())->method(
'getIsPersistent')->will($this->returnValue(
false));
140 $this->checkoutSessionMock->expects($this->once())
141 ->method(
'clearQuote')->will($this->returnValue($this->checkoutSessionMock));
142 $this->checkoutSessionMock->expects($this->once())->method(
'clearStorage');
143 $this->quoteMock->expects($this->never())->method(
'getPaymentsCollection');
145 $this->model->setGuest(
true);
150 $this->checkoutSessionMock->expects($this->once())
151 ->method(
'getQuote')->will($this->returnValue($this->quoteMock));
152 $this->quoteMock->expects($this->once())->method(
'getId')->will($this->returnValue(11));
153 $this->persistentDataMock->expects($this->never())->method(
'isShoppingCartPersist');
154 $this->quoteMock->expects($this->once())
155 ->method(
'getPaymentsCollection')->will($this->returnValue($this->abstractCollectionMock));
156 $this->quoteMock->expects($this->once())
157 ->method(
'getAddressesCollection')->will($this->returnValue($this->abstractCollectionMock));
158 $this->abstractCollectionMock->expects($this->exactly(2))->method(
'walk')->with(
'delete');
159 $this->quoteMock->expects($this->once())
160 ->method(
'setIsActive')->with(
true)->will($this->returnValue($this->quoteMock));
161 $this->quoteMock->expects($this->once())
162 ->method(
'setCustomerId')->with(
null)->will($this->returnValue($this->quoteMock));
163 $this->quoteMock->expects($this->once())
164 ->method(
'setCustomerEmail')->with(
null)->will($this->returnValue($this->quoteMock));
165 $this->quoteMock->expects($this->once())
166 ->method(
'setCustomerFirstname')->with(
null)->will($this->returnValue($this->quoteMock));
167 $this->quoteMock->expects($this->once())
168 ->method(
'setCustomerLastname')->with(
null)->will($this->returnValue($this->quoteMock));
169 $this->quoteMock->expects($this->once())->method(
'setCustomerGroupId')
170 ->with(\
Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID)
171 ->will($this->returnValue($this->quoteMock));
172 $this->quoteMock->expects($this->once())
173 ->method(
'setIsPersistent')->with(
false)->will($this->returnValue($this->quoteMock));
174 $this->quoteMock->expects($this->once())
175 ->method(
'removeAllAddresses')->will($this->returnValue($this->quoteMock));
176 $quoteAddressMock = $this->createMock(\
Magento\Quote\Model\Quote\Address::class);
177 $this->quoteMock->expects($this->once())
178 ->method(
'getShippingAddress')->will($this->returnValue($quoteAddressMock));
179 $this->quoteMock->expects($this->once())
180 ->method(
'getBillingAddress')->will($this->returnValue($quoteAddressMock));
181 $this->quoteMock->expects($this->once())->method(
'collectTotals')->will($this->returnValue($this->quoteMock));
182 $this->quoteRepositoryMock->expects($this->once())->method(
'save')->with($this->quoteMock);
183 $this->persistentSessionMock->expects($this->once())
184 ->method(
'getSession')->will($this->returnValue($this->sessionMock));
185 $this->sessionMock->expects($this->once())
186 ->method(
'removePersistentCookie')->will($this->returnValue($this->sessionMock));
188 $this->model->setGuest(
false);
193 $this->checkoutSessionMock->expects($this->once())
194 ->method(
'setLoadInactive')->will($this->returnValue($this->sessionMock));
196 $this->sessionMock->expects($this->once())->method(
'getQuote')->will($this->returnValue($this->quoteMock));
198 $this->quoteMock->expects($this->once())->method(
'getIsActive')->will($this->returnValue(11));
199 $this->quoteMock->expects($this->once())->method(
'getCustomerId')->will($this->returnValue(22));
201 $this->checkoutSessionMock->expects($this->once())
202 ->method(
'setCustomerData')->with(
null)->will($this->returnValue($this->sessionMock));
204 $this->sessionMock->expects($this->once())
205 ->method(
'clearQuote')->will($this->returnValue($this->sessionMock));
206 $this->sessionMock->expects($this->once())
207 ->method(
'clearStorage')->will($this->returnValue($this->sessionMock));
208 $this->quoteMock->expects($this->never())->method(
'setIsActive');
210 $this->model->expire();
215 $this->checkoutSessionMock->expects($this->once())
216 ->method(
'setLoadInactive')->will($this->returnValue($this->sessionMock));
217 $this->sessionMock->expects($this->once())->method(
'getQuote')->will($this->returnValue($this->quoteMock));
218 $this->quoteMock->expects($this->once())->method(
'getIsActive')->will($this->returnValue(0));
219 $this->checkoutSessionMock->expects($this->never())->method(
'setCustomerData');
220 $this->quoteMock->expects($this->once())
221 ->method(
'setIsActive')
223 ->will($this->returnValue($this->quoteMock));
224 $this->quoteMock->expects($this->once())
225 ->method(
'setIsPersistent')
227 ->will($this->returnValue($this->quoteMock));
228 $this->quoteMock->expects($this->once())
229 ->method(
'setCustomerId')
231 ->will($this->returnValue($this->quoteMock));
232 $this->quoteMock->expects($this->once())
233 ->method(
'setCustomerGroupId')
234 ->with(\
Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID)
235 ->will($this->returnValue($this->quoteMock));
237 $this->model->expire();
243 $addressArgs = [
'customerAddressId' =>
null];
244 $customerIdArgs = [
'customerId' =>
null];
245 $emailArgs = [
'email' =>
null];
247 $this->checkoutSessionMock->expects($this->once())
248 ->method(
'getQuoteId')->willReturn(
$quoteId);
249 $this->quoteMock->expects($this->once())->method(
'getId')->willReturn(
$quoteId);
250 $this->quoteRepositoryMock->expects($this->once())->method(
'get')->with(
$quoteId)->willReturn($this->quoteMock);
251 $this->quoteMock->expects($this->once())
252 ->method(
'setIsActive')->with(
true)->willReturn($this->quoteMock);
253 $this->quoteMock->expects($this->once())
254 ->method(
'setCustomerId')->with(
null)->willReturn($this->quoteMock);
255 $this->quoteMock->expects($this->once())
256 ->method(
'setCustomerEmail')->with(
null)->willReturn($this->quoteMock);
257 $this->quoteMock->expects($this->once())
258 ->method(
'setCustomerFirstname')->with(
null)->willReturn($this->quoteMock);
259 $this->quoteMock->expects($this->once())
260 ->method(
'setCustomerLastname')->with(
null)->willReturn($this->quoteMock);
261 $this->quoteMock->expects($this->once())->method(
'setCustomerGroupId')
262 ->with(\
Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID)
263 ->willReturn($this->quoteMock);
264 $this->quoteMock->expects($this->once())
265 ->method(
'setIsPersistent')->with(
false)->willReturn($this->quoteMock);
266 $this->quoteMock->expects($this->exactly(3))
267 ->method(
'getAddressesCollection')->willReturn($this->abstractCollectionMock);
268 $this->abstractCollectionMock->expects($this->exactly(3))->method(
'walk')->with($this->logicalOr(
269 $this->equalTo(
'setCustomerAddressId'),
270 $this->equalTo($addressArgs),
271 $this->equalTo(
'setCustomerId'),
272 $this->equalTo($customerIdArgs),
273 $this->equalTo(
'setEmail'),
274 $this->equalTo($emailArgs)
276 $this->quoteMock->expects($this->once())->method(
'collectTotals')->willReturn($this->quoteMock);
277 $this->persistentSessionMock->expects($this->once())
278 ->method(
'getSession')->willReturn($this->sessionMock);
279 $this->sessionMock->expects($this->once())
280 ->method(
'removePersistentCookie')->willReturn($this->sessionMock);
281 $this->quoteRepositoryMock->expects($this->once())->method(
'save')->with($this->quoteMock);
283 $this->model->convertCustomerCartToGuest();
288 $this->checkoutSessionMock->expects($this->once())
289 ->method(
'getQuoteId')->willReturn(
null);
290 $this->quoteRepositoryMock->expects($this->once())->method(
'get')->with(
null)->willReturn(
null);
291 $this->model->convertCustomerCartToGuest();
296 $this->checkoutSessionMock->expects($this->once())
297 ->method(
'getQuoteId')->willReturn(1);
298 $quoteWithNoId = $this->quoteMock = $this->createMock(\
Magento\Quote\Model\Quote::class);
299 $quoteWithNoId->expects($this->once())->method(
'getId')->willReturn(
null);
300 $this->quoteRepositoryMock->expects($this->once())->method(
'get')->with(1)->willReturn($quoteWithNoId);
301 $this->quoteMock->expects($this->once())->method(
'getId')->willReturn(1);
302 $this->model->convertCustomerCartToGuest();
testSetGuestWithEmptyQuote()
testConvertCustomerCartToGuestWithEmptyQuote()
testConvertCustomerCartToGuest()
testSetGuestWhenShoppingCartAndQuoteAreNotPersistent()
testSetGuestWithEmptyQuoteId()
testConvertCustomerCartToGuestWithEmptyQuoteId()
testExpireWithActiveQuoteAndCustomerId()