62 $this->sessionMock = $this->createMock(\
Magento\Persistent\Helper\Session::class);
63 $this->customerSessionMock = $this->createMock(\
Magento\Customer\Model\Session::class);
64 $this->persistentHelperMock = $this->createMock(\
Magento\Persistent\Helper\Data::class);
65 $this->observerMock = $this->createPartialMock(
66 \
Magento\Framework\Event\Observer::class,
67 [
'getControllerAction',
'__wakeUp']
69 $this->quoteManagerMock = $this->createMock(\
Magento\Persistent\Model\QuoteManager::class);
70 $this->eventManagerMock = $this->createMock(\
Magento\Framework\Event\ManagerInterface::class);
71 $this->checkoutSessionMock = $this->createMock(\
Magento\Checkout\Model\Session::class);
72 $this->requestMock = $this->getMockBuilder(\
Magento\Framework\
App\RequestInterface::class)
73 ->disableOriginalConstructor()
74 ->setMethods([
'getRequestUri',
'getServer'])
75 ->getMockForAbstractClass();
77 $this->model = new \Magento\Persistent\Observer\CheckExpirePersistentQuoteObserver(
79 $this->persistentHelperMock,
80 $this->quoteManagerMock,
81 $this->eventManagerMock,
82 $this->customerSessionMock,
83 $this->checkoutSessionMock,
90 $this->persistentHelperMock
91 ->expects($this->once())
92 ->method(
'canProcess')
93 ->with($this->observerMock)
95 $this->persistentHelperMock->expects($this->never())->method(
'isEnabled');
96 $this->model->execute($this->observerMock);
101 $this->persistentHelperMock
102 ->expects($this->once())
103 ->method(
'canProcess')
104 ->with($this->observerMock)
106 $this->persistentHelperMock->expects($this->once())->method(
'isEnabled')->willReturn(
false);
107 $this->eventManagerMock->expects($this->never())->method(
'dispatch');
108 $this->model->execute($this->observerMock);
125 \PHPUnit\Framework\MockObject\Matcher\InvokedCount $expireCounter,
126 \PHPUnit\Framework\MockObject\Matcher\InvokedCount $dispatchCounter,
127 \PHPUnit\Framework\MockObject\Matcher\InvokedCount $setCustomerIdCounter
129 $this->persistentHelperMock
130 ->expects($this->once())
131 ->method(
'canProcess')
132 ->with($this->observerMock)
134 $this->persistentHelperMock->expects($this->once())->method(
'isEnabled')->willReturn(
true);
135 $this->sessionMock->expects($this->once())->method(
'isPersistent')->willReturn(
false);
136 $this->customerSessionMock
137 ->expects($this->atLeastOnce())
138 ->method(
'isLoggedIn')
140 $this->checkoutSessionMock
141 ->expects($this->atLeastOnce())
142 ->method(
'getQuoteId')
144 $this->eventManagerMock->expects($dispatchCounter)->method(
'dispatch');
145 $this->quoteManagerMock->expects($expireCounter)->method(
'expire');
146 $this->customerSessionMock
147 ->expects($setCustomerIdCounter)
148 ->method(
'setCustomerId')
151 $this->requestMock->expects($this->atLeastOnce())->method(
'getRequestUri')->willReturn($refererUri);
153 ->expects($this->atLeastOnce())
154 ->method(
'getServer')
155 ->with(
'HTTP_REFERER')
156 ->willReturn($requestUri);
157 $this->model->execute($this->observerMock);
169 'refererUri' =>
'checkout',
170 'requestUri' =>
'index',
171 'expireCounter' => $this->never(),
172 'dispatchCounter' => $this->never(),
173 'setCustomerIdCounter' => $this->never(),
176 'refererUri' =>
'checkout',
177 'requestUri' =>
'checkout',
178 'expireCounter' => $this->never(),
179 'dispatchCounter' => $this->never(),
180 'setCustomerIdCounter' => $this->never(),
183 'refererUri' =>
'index',
184 'requestUri' =>
'checkout',
185 'expireCounter' => $this->never(),
186 'dispatchCounter' => $this->never(),
187 'setCustomerIdCounter' => $this->never(),
190 'refererUri' =>
'index',
191 'requestUri' =>
'index',
192 'expireCounter' => $this->once(),
193 'dispatchCounter' => $this->once(),
194 'setCustomerIdCounter' => $this->once(),
testExecuteWhenPersistentIsNotEnabled()
testExecuteWhenPersistentIsEnabled(string $refererUri, string $requestUri, \PHPUnit\Framework\MockObject\Matcher\InvokedCount $expireCounter, \PHPUnit\Framework\MockObject\Matcher\InvokedCount $dispatchCounter, \PHPUnit\Framework\MockObject\Matcher\InvokedCount $setCustomerIdCounter)
testExecuteWhenCanNotApplyPersistentData()