37 private $shippingMethodUpdaterMock;
47 private $checkoutSessionMock;
57 private $responseMock;
72 private $resultFactoryMock;
77 private $messageManagerMock;
82 private $saveShippingMethod;
84 protected function setUp()
87 $contextMock = $this->getMockBuilder(Context::class)
88 ->disableOriginalConstructor()
90 $this->requestMock = $this->getMockBuilder(RequestInterface::class)
91 ->getMockForAbstractClass();
92 $this->redirectMock = $this->getMockBuilder(RedirectInterface::class)
93 ->getMockForAbstractClass();
94 $this->urlMock = $this->getMockBuilder(UrlInterface::class)
95 ->getMockForAbstractClass();
96 $this->responseMock = $this->getMockBuilder(ResponseInterface::class)
97 ->setMethods([
'setBody'])
98 ->getMockForAbstractClass();
99 $this->resultFactoryMock = $this->getMockBuilder(ResultFactory::class)
100 ->disableOriginalConstructor()
102 $this->checkoutSessionMock = $this->getMockBuilder(Session::class)
103 ->disableOriginalConstructor()
105 $this->configMock = $this->getMockBuilder(Config::class)
106 ->disableOriginalConstructor()
108 $this->shippingMethodUpdaterMock = $this->getMockBuilder(ShippingMethodUpdater::class)
109 ->disableOriginalConstructor()
111 $this->messageManagerMock = $this->getMockBuilder(ManagerInterface::class)
112 ->getMockForAbstractClass();
114 $contextMock->expects(self::once())
115 ->method(
'getRequest')
116 ->willReturn($this->requestMock);
117 $contextMock->expects(self::once())
118 ->method(
'getRedirect')
119 ->willReturn($this->redirectMock);
120 $contextMock->expects(self::once())
121 ->method(
'getResponse')
122 ->willReturn($this->responseMock);
123 $contextMock->expects(self::once())
125 ->willReturn($this->urlMock);
126 $contextMock->expects(self::once())
127 ->method(
'getResultFactory')
128 ->willReturn($this->resultFactoryMock);
129 $contextMock->expects(self::once())
130 ->method(
'getMessageManager')
131 ->willReturn($this->messageManagerMock);
136 $this->checkoutSessionMock,
137 $this->shippingMethodUpdaterMock
143 $resultHtml =
'<html>test</html>';
144 $quoteMock = $this->getQuoteMock();
145 $responsePageMock = $this->getResponsePageMock();
146 $layoutMock = $this->getLayoutMock();
147 $blockMock = $this->getBlockMock();
149 $quoteMock->expects(self::once())
150 ->method(
'getItemsCount')
153 $this->requestMock->expects(self::exactly(2))
157 [
'isAjax',
null,
true],
158 [
'shipping_method',
null,
'test-shipping-method']
162 $this->checkoutSessionMock->expects(self::once())
164 ->willReturn($quoteMock);
166 $this->shippingMethodUpdaterMock->expects(self::once())
168 ->with(
'test-shipping-method', $quoteMock);
170 $this->resultFactoryMock->expects(self::once())
173 ->willReturn($responsePageMock);
175 $responsePageMock->expects(self::once())
176 ->method(
'addHandle')
177 ->with(
'paypal_express_review_details')
180 $responsePageMock->expects(self::once())
181 ->method(
'getLayout')
182 ->willReturn($layoutMock);
184 $layoutMock->expects(self::once())
187 ->willReturn($blockMock);
189 $blockMock->expects(self::once())
191 ->willReturn($resultHtml);
193 $this->responseMock->expects(self::once())
197 $this->urlMock->expects(self::never())
200 $this->saveShippingMethod->execute();
205 $redirectPath =
'path/to/redirect';
206 $quoteMock = $this->getQuoteMock();
208 $quoteMock->expects(self::once())
209 ->method(
'getItemsCount')
212 $this->requestMock->expects(self::exactly(1))
216 [
'isAjax',
null,
false]
220 $this->checkoutSessionMock->expects(self::once())
222 ->willReturn($quoteMock);
224 $this->shippingMethodUpdaterMock->expects(self::never())
227 $this->messageManagerMock->expects(self::once())
228 ->method(
'addExceptionMessage')
230 self::isInstanceOf(
'\InvalidArgumentException'),
231 'Checkout failed to initialize. Verify and try again.' 234 $this->urlMock->expects(self::once())
236 ->with(
'*/*/review', [
'_secure' =>
true])
237 ->willReturn($redirectPath);
239 $this->redirectMock->expects(self::once())
241 ->with($this->responseMock, $redirectPath, []);
243 $this->saveShippingMethod->execute();
248 $redirectPath =
'path/to/redirect';
249 $quoteMock = $this->getQuoteMock();
251 $quoteMock->expects(self::once())
252 ->method(
'getItemsCount')
255 $this->requestMock->expects(self::exactly(1))
259 [
'isAjax',
null,
true]
263 $this->checkoutSessionMock->expects(self::once())
265 ->willReturn($quoteMock);
267 $this->shippingMethodUpdaterMock->expects(self::never())
270 $this->messageManagerMock->expects(self::once())
271 ->method(
'addExceptionMessage')
273 self::isInstanceOf(
'\InvalidArgumentException'),
274 'Checkout failed to initialize. Verify and try again.' 277 $this->urlMock->expects(self::once())
279 ->with(
'*/*/review', [
'_secure' =>
true])
280 ->willReturn($redirectPath);
282 $this->responseMock->expects(self::once())
284 ->with(sprintf(
'<script>window.location.href = "%s";</script>', $redirectPath));
286 $this->saveShippingMethod->execute();
292 private function getBlockMock()
294 return $this->getMockBuilder(Review::class)
295 ->disableOriginalConstructor()
302 private function getLayoutMock()
304 return $this->getMockBuilder(Layout::class)
305 ->disableOriginalConstructor()
312 private function getQuoteMock()
314 return $this->getMockBuilder(Quote::class)
315 ->disableOriginalConstructor()
322 private function getResponsePageMock()
324 return $this->getMockBuilder(Page::class)
325 ->disableOriginalConstructor()
testExecuteAjaxException()