23 use Magento\Sales\Model\OrderFactory;
24 use PHPUnit_Framework_MockObject_MockObject as MockObject;
58 private $checkoutSession;
63 private $orderFactory;
68 private $checkoutHelper;
93 private $objectManager;
98 private $paymentFailures;
103 private $eventManagerMock;
112 $this->context = $this->getMockBuilder(Context::class)
113 ->disableOriginalConstructor()
116 $this->view = $this->getMockBuilder(ViewInterface::class)
119 $this->request = $this->getMockBuilder(Http::class)
120 ->disableOriginalConstructor()
121 ->setMethods([
'getParam'])
124 $this->layout = $this->getMockBuilder(LayoutInterface::class)
127 $this->block = $this->getMockBuilder(Success::class)
128 ->disableOriginalConstructor()
131 $this->orderFactory = $this->getMockBuilder(OrderFactory::class)
132 ->disableOriginalConstructor()
133 ->setMethods([
'create'])
136 $this->checkoutHelper = $this->getMockBuilder(Checkout::class)
137 ->disableOriginalConstructor()
140 $this->order = $this->getMockBuilder(Order::class)
141 ->disableOriginalConstructor()
144 $this->payment = $this->getMockBuilder(Payment::class)
145 ->disableOriginalConstructor()
148 $this->checkoutSession = $this->getMockBuilder(Session::class)
149 ->disableOriginalConstructor()
150 ->setMethods([
'getLastRealOrderId',
'getLastRealOrder',
'restoreQuote'])
153 $this->quote = $this->getMockBuilder(CartInterface::class)
154 ->disableOriginalConstructor()
157 $this->paymentFailures = $this->getMockBuilder(PaymentFailuresInterface::class)
158 ->disableOriginalConstructor()
161 $this->eventManagerMock = $this->getMockBuilder(ManagerInterface::class)
162 ->disableOriginalConstructor()
165 $this->context->method(
'getView')
166 ->willReturn($this->view);
167 $this->context->method(
'getRequest')
168 ->willReturn($this->request);
169 $this->context->method(
'getEventManager')
170 ->willReturn($this->eventManagerMock);
172 $this->returnUrl = $this->objectManager->getObject(
175 'context' => $this->context,
176 'checkoutSession' => $this->checkoutSession,
177 'orderFactory' => $this->orderFactory,
178 'checkoutHelper' => $this->checkoutHelper,
179 'paymentFailures' => $this->paymentFailures,
193 $this->withOrder(self::LAST_REAL_ORDER_ID, $state);
195 $this->checkoutSession->method(
'getLastRealOrderId')
196 ->willReturn(self::LAST_REAL_ORDER_ID);
198 $this->block->method(
'setData')
199 ->with(
'goto_success_page',
true)
202 $this->eventManagerMock->expects($this->once())
204 ->with(
'paypal_checkout_success', $this->arrayHasKey(
'order'));
206 $result = $this->returnUrl->execute();
234 $errMessage =
'Transaction has been canceled.';
236 $this->withOrder(self::LAST_REAL_ORDER_ID, $state);
237 $this->withCheckoutSession(self::LAST_REAL_ORDER_ID, $restoreQuote);
239 $this->request->method(
'getParam')
241 ->willReturn($errMessage);
243 $this->payment->method(
'getMethod')
246 $this->checkoutHelper->method(
'cancelCurrentOrder')
247 ->with(self::equalTo($errMessage));
249 $this->withBlockContent($expectedGotoSection,
'Your payment has been declined. Please try again.');
251 $this->returnUrl->execute();
283 $this->checkoutSession->method(
'getLastRealOrderId')
284 ->willReturn(self::LAST_REAL_ORDER_ID);
286 $this->withBlockContent(
false,
'Requested payment method does not match with order.');
288 $this->payment->expects(self::once())
289 ->method(
'getMethod')
290 ->willReturn(
'something_else');
292 $this->returnUrl->execute();
304 $this->withCheckoutSession(self::LAST_REAL_ORDER_ID,
true);
306 $this->request->method(
'getParam')
308 ->willReturn($errorMsg);
310 $this->checkoutHelper->method(
'cancelCurrentOrder')
311 ->with(self::equalTo($errorMsgEscaped));
313 $this->withBlockContent(
'paymentMethod',
'Your payment has been declined. Please try again.');
315 $this->payment->method(
'getMethod')
318 $this->returnUrl->execute();
329 [
'simple',
'simple'],
330 [
'<script>alert(1)</script>',
'alert(1)'],
331 [
'<div style="background-image:url(javascript:alert(1))">',
'']
342 $this->withCheckoutSession(self::LAST_REAL_ORDER_ID,
true);
344 $this->request->method(
'getParam')
346 ->willReturn(
'message');
348 $this->withBlockContent(
'paymentMethod',
'Your payment has been declined. Please try again.');
350 $this->payment->method(
'getMethod')
353 $returnUrl = $this->objectManager->getObject(PayflowadvancedReturnUrl::class, [
354 'context' => $this->context,
355 'checkoutSession' => $this->checkoutSession,
356 'orderFactory' => $this->orderFactory,
357 'checkoutHelper' => $this->checkoutHelper,
358 'paymentFailures' => $this->paymentFailures,
361 $returnUrl->execute();
371 private function withOrder($incrementId, $state)
373 $this->orderFactory->method(
'create')
374 ->willReturn($this->order);
376 $this->order->method(
'loadByIncrementId')
380 $this->order->method(
'getIncrementId')
381 ->willReturn($incrementId);
383 $this->order->method(
'getState')
384 ->willReturn($state);
386 $this->order->method(
'getPayment')
387 ->willReturn($this->payment);
395 private function withLayout()
397 $this->view->method(
'getLayout')
398 ->willReturn($this->layout);
400 $this->layout->method(
'getBlock')
401 ->willReturn($this->block);
410 private function withCheckoutSession($orderId, $restoreQuote)
412 $this->checkoutSession->method(
'getLastRealOrderId')
413 ->willReturn($orderId);
415 $this->checkoutSession->method(
'getLastRealOrder')
416 ->willReturn($this->order);
418 $this->checkoutSession->method(
'restoreQuote')
419 ->willReturn($restoreQuote);
429 private function withBlockContent($gotoSection, $errMsg)
431 $this->block->expects(self::at(0))
433 ->with(
'goto_section', self::equalTo($gotoSection))
436 $this->block->expects(self::at(1))
438 ->with(
'error_msg', self::equalTo(
__($errMsg)))
testCheckXSSEscaped($errorMsg, $errorMsgEscaped)
testExecuteAllowedOrderState($state)
const METHOD_PAYFLOWADVANCED
testCheckAdvancedAcceptingByPaymentMethod()
notAllowedOrderStateDataProvider()
checkXSSEscapedDataProvider()
const STATE_PENDING_PAYMENT
allowedOrderStateDataProvider()
const STATE_PAYMENT_REVIEW
testExecuteNotAllowedOrderState($state, $restoreQuote, $expectedGotoSection)
testCheckRejectByPaymentMethod()