Example #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());
 }
Example #2
0
    /**
     * @dataProvider initializeQuoteForReviewDataProvider
     */
    public function testInitializeQuoteForReview(
        $paymentMethodNonce,
        $details,
        $expectedShipping,
        $expectedBilling,
        $expectedPaymentAdditionalInfo
    ) {
        $this->verifyIgnoreAddressValidation();
        $this->quoteMock->expects($this->any())
            ->method('getIsVirtual')
            ->willReturn(false);

        $paymentMock = $this->getMockBuilder('\Magento\Quote\Model\Quote\Payment')
            ->disableOriginalConstructor()
            ->getMock();
        $paymentMock->expects($this->once())
            ->method('setMethod')
            ->with(PayPal::METHOD_CODE);

        $this->quoteMock->expects($this->any())
            ->method('getPayment')
            ->willReturn($paymentMock);

        foreach ($expectedShipping as $methodName => $value) {
            $this->shippingAddressMock->expects($this->once())
                ->method($methodName)
                ->with($value)
                ->willReturnSelf();
        }
        foreach ($expectedBilling as $methodName => $value) {
            $this->billingAddressMock->expects($this->once())
                ->method($methodName)
                ->with($value)
                ->willReturnSelf();
        }
        $index = 1;
        foreach ($expectedPaymentAdditionalInfo as $key => $value) {
            $paymentMock->expects($this->at($index))
                ->method('setAdditionalInformation')
                ->with($key, $value);
            $index++;
        }

        $this->quoteMock->expects($this->once())
            ->method('collectTotals');
        $this->quoteRepositoryMock->expects($this->once())
            ->method('save')
            ->with($this->quoteMock);

        $this->model->initializeQuoteForReview($paymentMethodNonce, $details);
    }
 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();
 }
 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());
 }