54 $quoteMethods = [
'setIsActive',
'setIsPersistent',
'__wakeUp'];
55 $eventMethods = [
'getQuote',
'__wakeUp'];
56 $this->quoteMock = $this->createPartialMock(\
Magento\Quote\Model\Quote::class, $quoteMethods);
57 $this->helperMock = $this->createMock(\
Magento\Persistent\Helper\Data::class);
58 $this->sessionHelperMock = $this->createMock(\
Magento\Persistent\Helper\Session::class);
59 $this->eventManagerMock = $this->createPartialMock(\
Magento\Framework\Event::class, $eventMethods);
60 $this->customerSessionMock = $this->createMock(\
Magento\Customer\Model\Session::class);
61 $this->observerMock = $this->createMock(\
Magento\Framework\Event\Observer::class);
62 $this->quoteManagerMock = $this->createMock(\
Magento\Persistent\Model\QuoteManager::class);
63 $this->model = new \Magento\Persistent\Observer\SetQuotePersistentDataObserver(
64 $this->sessionHelperMock,
66 $this->quoteManagerMock,
67 $this->customerSessionMock
73 $this->sessionHelperMock->expects($this->once())->method(
'isPersistent')->will($this->returnValue(
false));
74 $this->observerMock->expects($this->never())->method(
'getEvent');
75 $this->model->execute($this->observerMock);
80 $this->sessionHelperMock->expects($this->once())->method(
'isPersistent')->will($this->returnValue(
true));
82 ->expects($this->once())
84 ->will($this->returnValue($this->eventManagerMock));
85 $this->eventManagerMock->expects($this->once())->method(
'getQuote');
86 $this->customerSessionMock->expects($this->never())->method(
'isLoggedIn');
87 $this->model->execute($this->observerMock);
92 $this->sessionHelperMock->expects($this->exactly(2))->method(
'isPersistent')->will($this->returnValue(
true));
94 ->expects($this->once())
96 ->will($this->returnValue($this->eventManagerMock));
97 $this->eventManagerMock
98 ->expects($this->once())
100 ->will($this->returnValue($this->quoteMock));
101 $this->customerSessionMock->expects($this->once())->method(
'isLoggedIn')->will($this->returnValue(
false));
102 $this->helperMock->expects($this->once())->method(
'isShoppingCartPersist')->will($this->returnValue(
false));
103 $this->quoteManagerMock->expects($this->once())->method(
'isPersistent')->will($this->returnValue(
true));
104 $this->quoteMock->expects($this->once())->method(
'setIsPersistent')->with(
true);
105 $this->model->execute($this->observerMock);
testExecuteWhenSessionIsNotPersistent()
testExecuteWhenSessionIsPersistent()
testExecuteWhenQuoteNotExist()