Пример #1
0
 public function testExecuteException()
 {
     $this->setupCart();
     $exceptionMsg = new \Magento\Framework\Phrase('error');
     $exception = new \Magento\Framework\Exception\LocalizedException($exceptionMsg);
     $this->checkoutMock->expects($this->once())->method('place')->with(null)->willThrowException($exception);
     $this->messageManager->expects($this->once())->method('addError')->with($exceptionMsg);
     $resultRedirect = $this->getMockBuilder('\\Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock();
     $resultRedirect->expects($this->once())->method('setPath')->with('checkout/cart')->willReturnSelf();
     $this->resultFactoryMock->expects($this->once())->method('create')->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT)->willReturn($resultRedirect);
     $this->assertEquals($resultRedirect, $this->controller->execute());
 }
 public function testExecuteException()
 {
     $html = '<script>window.location.href = ' . self::REVIEW_URL . ';</script>';
     $shippingMethod = 'flat_rate';
     $this->requestMock->expects($this->at(0))->method('getParam')->with('isAjax')->willReturn(true);
     $this->requestMock->expects($this->at(1))->method('getParam')->with('shipping_method')->willReturn($shippingMethod);
     $this->setupCart();
     $exceptionMsg = new \Magento\Framework\Phrase('error');
     $exception = new \Magento\Framework\Exception\LocalizedException($exceptionMsg);
     $this->checkoutMock->expects($this->once())->method('updateShippingMethod')->with($shippingMethod)->willThrowException($exception);
     $this->messageManager->expects($this->once())->method('addExceptionMessage')->with($exception, $exceptionMsg);
     $this->responseMock->expects($this->once())->method('setBody')->with($html);
     $this->controller->execute();
 }
Пример #3
0
 public function testExecuteException()
 {
     $paymentMethodNonce = 'nonce';
     $email = '*****@*****.**';
     $billingAddress = ['someAddress'];
     $details = ['email' => $email, 'billingAddress' => $billingAddress];
     $detailsEncoded = json_encode($details);
     $this->requestMock->expects($this->at(0))->method('getParam')->with('payment_method_nonce')->willReturn($paymentMethodNonce);
     $this->requestMock->expects($this->at(1))->method('getParam')->with('details')->willReturn($detailsEncoded);
     $this->setupCart();
     $errorMsg = new \Magento\Framework\Phrase('error');
     $exception = new \Magento\Framework\Exception\LocalizedException($errorMsg);
     $this->messageManagerMock->expects($this->once())->method('addExceptionMessage')->with($exception, $errorMsg);
     $this->checkoutMock->expects($this->once())->method('initializeQuoteForReview')->with($paymentMethodNonce, ['email' => $email])->willThrowException($exception);
     $resultRedirect = $this->getMockBuilder('\\Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock();
     $resultRedirect->expects($this->once())->method('setPath')->with('checkout/cart')->willReturnSelf();
     $this->resultFactoryMock->expects($this->once())->method('create')->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT)->willReturn($resultRedirect);
     $this->assertEquals($resultRedirect, $this->controller->execute());
 }