Example #1
0
 public function testAfterGetOptions()
 {
     $quote = $this->getMockBuilder('Magento\\Sales\\Model\\Quote')->disableOriginalConstructor()->getMock();
     $this->sessionMock->expects($this->once())->method('getQuote')->will($this->returnValue($quote));
     $this->filterMock->expects($this->once())->method('hasRecurringItems')->with($quote)->will($this->returnValue(true));
     $this->assertArrayHasKey('hasRecurringItems', $this->payment->afterGetOptions($this->getMock('\\Magento\\Checkout\\Block\\Onepage\\Payment', array(), array(), '', false), array()));
 }
Example #2
0
 protected function setUp()
 {
     $this->markTestIncomplete();
     $this->messageManager = $this->getMockForAbstractClass('Magento\\Framework\\Message\\ManagerInterface');
     $this->config = $this->getMock('Magento\\Paypal\\Model\\Config', [], [], '', false);
     $this->request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
     $this->quote = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false);
     $this->quote->expects($this->any())->method('hasItems')->will($this->returnValue(true));
     $this->redirect = $this->getMockForAbstractClass('Magento\\Framework\\App\\Response\\RedirectInterface');
     $this->response = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false);
     $this->customerData = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
     $this->checkout = $this->getMock('Magento\\Paypal\\Model\\Express\\Checkout', [], [], '', false);
     $this->customerSession = $this->getMock('Magento\\Customer\\Model\\Session', [], [], '', false);
     $this->customerSession->expects($this->any())->method('getCustomerDataObject')->will($this->returnValue($this->customerData));
     $this->checkoutSession = $this->getMock('Magento\\Checkout\\Model\\Session', [], [], '', false);
     $this->checkoutFactory = $this->getMock('Magento\\Paypal\\Model\\Express\\Checkout\\Factory', [], [], '', false);
     $this->checkoutFactory->expects($this->any())->method('create')->will($this->returnValue($this->checkout));
     $this->checkoutSession->expects($this->any())->method('getQuote')->will($this->returnValue($this->quote));
     $this->session = $this->getMock('Magento\\Framework\\Session\\Generic', [], [], '', false);
     $objectManager = $this->getMock('Magento\\Framework\\ObjectManagerInterface');
     $this->objectManagerCallback = function ($className) {
         if ($className == 'Magento\\Paypal\\Model\\Config') {
             return $this->config;
         }
         return $this->getMock($className, [], [], '', false);
     };
     $objectManager->expects($this->any())->method('get')->will($this->returnCallback(function ($className) {
         return call_user_func($this->objectManagerCallback, $className);
     }));
     $objectManager->expects($this->any())->method('create')->will($this->returnCallback(function ($className) {
         return call_user_func($this->objectManagerCallback, $className);
     }));
     $helper = new ObjectManagerHelper($this);
     $this->model = $helper->getObject('\\Magento\\\\Paypal\\Controller\\Express\\' . $this->name, ['messageManager' => $this->messageManager, 'response' => $this->response, 'redirect' => $this->redirect, 'request' => $this->request, 'customerSession' => $this->customerSession, 'checkoutSession' => $this->checkoutSession, 'checkoutFactory' => $this->checkoutFactory, 'paypalSession' => $this->session, 'objectManager' => $objectManager]);
 }
Example #3
0
 public function testSalesQuoteSaveAfter()
 {
     $observer = $this->getMock('Magento\\Framework\\Event\\Observer', [], [], '', false);
     $observer->expects($this->once())->method('getEvent')->will($this->returnValue(new \Magento\Framework\Object(['quote' => new \Magento\Framework\Object(['is_checkout_cart' => 1, 'id' => 7])])));
     $this->checkoutSession->expects($this->once())->method('getQuoteId')->with(7);
     $this->object->salesQuoteSaveAfter($observer);
 }
 /**
  * @param bool $isValid
  * @dataProvider addBillingAgreementToSessionDataProvider
  */
 public function testAddBillingAgreementToSession($isValid)
 {
     $agreement = $this->getMock('Magento\\Paypal\\Model\\Billing\\Agreement', [], [], '', false);
     $agreement->expects($this->once())->method('isValid')->will($this->returnValue($isValid));
     $comment = $this->getMockForAbstractClass('Magento\\Framework\\Model\\AbstractModel', [], '', false, true, true, ['__wakeup']);
     $order = $this->getMock('Magento\\Sales\\Model\\Order', [], [], '', false);
     $order->expects($this->once())->method('addStatusHistoryComment')->with($isValid ? __('Created billing agreement #%1.', 'agreement reference id') : __('We can\'t create a billing agreement for this order.'))->will($this->returnValue($comment));
     if ($isValid) {
         $agreement->expects($this->any())->method('__call')->with('getReferenceId')->will($this->returnValue('agreement reference id'));
         $agreement->expects($this->once())->method('addOrderRelation')->with($order);
         $order->expects(new MethodInvokedAtIndex(0))->method('addRelatedObject')->with($agreement);
         $this->_checkoutSession->expects($this->once())->method('__call')->with('setLastBillingAgreementReferenceId', ['agreement reference id']);
     } else {
         $this->_checkoutSession->expects($this->once())->method('__call')->with('unsLastBillingAgreementReferenceId');
         $agreement->expects($this->never())->method('__call');
     }
     $order->expects(new MethodInvokedAtIndex($isValid ? 1 : 0))->method('addRelatedObject')->with($comment);
     $payment = $this->getMock('Magento\\Sales\\Model\\Order\\Payment', [], [], '', false);
     $payment->expects($this->once())->method('__call')->with('getBillingAgreementData')->will($this->returnValue('not empty'));
     $payment->expects($this->once())->method('getOrder')->will($this->returnValue($order));
     $agreement->expects($this->once())->method('importOrderPayment')->with($payment)->will($this->returnValue($agreement));
     $this->_event->setPayment($payment);
     $this->_agreementFactory->expects($this->once())->method('create')->will($this->returnValue($agreement));
     $this->_model->execute($this->_observer);
 }
 public function testAfterGenerateXmlNoDepersonalize()
 {
     $expectedResult = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false);
     $this->depersonalizeCheckerMock->expects($this->once())->method('checkIfDepersonalize')->willReturn(false);
     $this->checkoutSessionMock->expects($this->never())->method('clearStorage')->will($this->returnValue($expectedResult));
     $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult);
     $this->assertEquals($expectedResult, $actualResult);
 }
 /**
  * Run test for execute method (exception)
  *
  * @expectedException \Magento\Framework\Exception\LocalizedException
  * @expectedExceptionMessage Wrong type of request.
  */
 public function testExecuteException()
 {
     $this->contextMock = $this->getMockBuilder('Magento\\Framework\\App\\Action\\Context')->disableOriginalConstructor()->getMock();
     $this->contextMock->expects(static::once())->method('getRequest')->willReturn($this->getRequestMock(false));
     $this->checkoutSessionMock = $this->getMockBuilder('Magento\\Checkout\\Model\\Session')->disableOriginalConstructor()->getMock();
     $this->checkoutSessionMock->expects(static::never())->method('getQuote');
     $getButtonData = new GetButtonData($this->contextMock, $this->checkoutSessionMock);
     $getButtonData->execute();
 }
 protected function setupCart()
 {
     $quoteMock = $this->getMockBuilder('\\Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->setMethods(['hasItems', 'getHasError', 'getPayment'])->getMock();
     $quoteMock->expects($this->any())->method('hasItems')->willReturn(true);
     $quoteMock->expects($this->any())->method('getHasError')->willReturn(false);
     $this->checkoutSessionMock->expects($this->any())->method('getQuote')->willReturn($quoteMock);
     $this->checkoutFactoryMock->expects($this->any())->method('create')->willReturn($this->checkoutMock);
     return $quoteMock;
 }
Example #8
0
 /**
  * Test method afterGenerateXml
  */
 public function testAfterGenerateXml()
 {
     $expectedResult = $this->getMock('Magento\\Framework\\View\\Layout', array(), array(), '', false);
     $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(true));
     $this->cacheConfigMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
     $this->requestMock->expects($this->once($this->once()))->method('isAjax')->will($this->returnValue(false));
     $this->layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(true));
     $this->checkoutSessionMock->expects($this->once())->method('clearStorage')->will($this->returnValue($expectedResult));
     $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult);
     $this->assertEquals($expectedResult, $actualResult);
 }
Example #9
0
 protected function setUp()
 {
     $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->checkoutSession = $this->getMock('Magento\\Checkout\\Model\\Session', [], [], '', false);
     $this->checkoutHelper = $this->getMock('Magento\\Checkout\\Helper\\Data', [], [], '', false);
     $this->itemPriceRenderer = $this->getMock('Magento\\Tax\\Block\\Item\\Price\\Renderer', [], [], '', false);
     $this->checkoutCart = $this->getMock('Magento\\Checkout\\CustomerData\\Cart', [], [], '', false);
     $this->quote = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false);
     $this->checkoutSession->expects($this->any())->method('getQuote')->willReturn($this->quote);
     $this->cart = $helper->getObject('Magento\\Tax\\Plugin\\Checkout\\CustomerData\\Cart', ['checkoutSession' => $this->checkoutSession, 'checkoutHelper' => $this->checkoutHelper, 'itemPriceRenderer' => $this->itemPriceRenderer]);
 }
Example #10
0
 /**
  * @param bool $result
  * @param bool $quoteHasItems
  * @param bool $isMultiShipping
  * @param bool $hasItemsWithDecimalQty
  * @param bool $validateMinimumAmount
  * @param int $itemsSummaryQty
  * @param int $itemVirtualQty
  * @param int $maximumQty
  * @dataProvider isMultishippingCheckoutAvailableDataProvider
  */
 public function testIsMultishippingCheckoutAvailable($result, $quoteHasItems, $isMultiShipping, $hasItemsWithDecimalQty, $validateMinimumAmount, $itemsSummaryQty, $itemVirtualQty, $maximumQty)
 {
     $this->scopeConfigMock->expects($this->once())->method('isSetFlag')->with(\Magento\Multishipping\Helper\Data::XML_PATH_CHECKOUT_MULTIPLE_AVAILABLE)->will($this->returnValue($isMultiShipping));
     $this->checkoutSessionMock->expects($this->once())->method('getQuote')->will($this->returnValue($this->quoteMock));
     $this->quoteMock->expects($this->once())->method('hasItems')->will($this->returnValue($quoteHasItems));
     $this->quoteMock->expects($this->any())->method('hasItemsWithDecimalQty')->will($this->returnValue($hasItemsWithDecimalQty));
     $this->quoteMock->expects($this->any())->method('validateMinimumAmount')->with(true)->will($this->returnValue($validateMinimumAmount));
     $this->quoteMock->expects($this->any())->method('getItemsSummaryQty')->will($this->returnValue($itemsSummaryQty));
     $this->quoteMock->expects($this->any())->method('getItemVirtualQty')->will($this->returnValue($itemVirtualQty));
     $this->scopeConfigMock->expects($this->any())->method('getValue')->with(\Magento\Multishipping\Helper\Data::XML_PATH_CHECKOUT_MULTIPLE_MAXIMUM_QUANTITY)->will($this->returnValue($maximumQty));
     $this->assertEquals($result, $this->helper->isMultishippingCheckoutAvailable());
 }
Example #11
0
 public function prepare()
 {
     $this->contextMock = $this->getMock('Magento\\Framework\\View\\Element\\Template\\Context', [], [], '', false);
     $this->checkoutSessionMock = $this->getMock('Magento\\Checkout\\Model\\Session', [], [], '', false);
     $this->orderFactoryMock = $this->getMock('Magento\\Sales\\Model\\OrderFactory', ['getQuote'], [], '', false);
     $this->hssHelperMock = $this->getMock('Magento\\Paypal\\Helper\\Hss', [], [], '', false);
     $this->paymentDataMock = $this->getMock('Magento\\Payment\\Helper\\Data', [], [], '', false);
     $this->quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', ['getPayment', '__wakeup'], [], '', false);
     $this->paymentMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Payment', [], [], '', false);
     $this->checkoutSessionMock->expects($this->any())->method('getQuote')->will($this->returnValue($this->quoteMock));
     $this->quoteMock->expects($this->any())->method('getPayment')->will($this->returnValue($this->paymentMock));
     $this->hssHelperMock->expects($this->any())->method('getHssMethods')->will($this->returnValue([]));
 }
Example #12
0
 protected function setUp()
 {
     $this->checkoutSession = $this->getMock('Magento\\Checkout\\Model\\Session', [], [], '', false);
     $this->taxHelper = $this->getMock('Magento\\Tax\\Helper\\Data', [], [], '', false);
     $objectManagerHelper = new ObjectManagerHelper($this);
     $this->model = $objectManagerHelper->getObject('Magento\\Checkout\\Block\\Onepage\\Progress', ['resourceSession' => $this->checkoutSession, 'taxData' => $this->taxHelper]);
     $this->shippingAddress = $this->getMock('Magento\\Sales\\Model\\Quote\\Address', ['getShippingRateByCode', '__wakeup'], [], '', false);
     $this->store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $quote = $this->getMock('Magento\\Sales\\Model\\Quote', [], [], '', false);
     $quote->expects($this->any())->method('getShippingAddress')->will($this->returnValue($this->shippingAddress));
     $quote->expects($this->any())->method('getStore')->will($this->returnValue($this->store));
     $this->checkoutSession->expects($this->any())->method('getQuote')->will($this->returnValue($quote));
 }
Example #13
0
 /**
  * @param bool $hasOrderId
  * @param bool $isOrderCancelled
  * @param bool $expectedResult
  * @dataProvider cancelCurrentOrderDataProvider
  */
 public function testCancelCurrentOrder($hasOrderId, $isOrderCancelled, $expectedResult)
 {
     $comment = 'Some test comment';
     $order = $this->_getOrderMock($hasOrderId, ['registerCancellation', 'save']);
     $order->setData('state', $isOrderCancelled ? \Magento\Sales\Model\Order::STATE_CANCELED : 'some another state');
     if ($expectedResult) {
         $order->expects($this->once())->method('registerCancellation')->with($this->equalTo($comment))->will($this->returnSelf());
         $order->expects($this->once())->method('save');
     } else {
         $order->expects($this->never())->method('registerCancellation');
         $order->expects($this->never())->method('save');
     }
     $this->_session->expects($this->any())->method('getLastRealOrder')->will($this->returnValue($order));
     $this->assertEquals($expectedResult, $this->_checkout->cancelCurrentOrder($comment));
 }
Example #14
0
 /**
  * @param bool $isLoggedIn
  * @param bool $isAllowedGuestCheckout
  * @dataProvider skipShortcutForGuestDataProvider
  */
 public function testSkipShortcutForGuest($isLoggedIn, $isAllowedGuestCheckout, $expected)
 {
     $this->customerSessionMock->expects($this->any())->method('isLoggedIn')->willReturn($isLoggedIn);
     $quoteMock = $this->getMockBuilder('\\Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->getMock();
     $this->checkoutSessionMock->expects($this->any())->method('getQuote')->willReturn($quoteMock);
     $this->checkoutDataMock->expects($this->any())->method('isAllowedGuestCheckout')->willReturn($isAllowedGuestCheckout);
     $this->assertEquals($expected, $this->block->skipShortcutForGuest());
 }
 public function testIsQuoteSummaryValidTrue()
 {
     $isInCatalog = false;
     $quote = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->setMethods(['getGrandTotal', 'validateMinimumAmount', '__wakeup'])->getMock();
     $this->sessionMock->expects($this->once())->method('getQuote')->will($this->returnValue($quote));
     $quote->expects($this->once())->method('validateMinimumAmount')->will($this->returnValue(true));
     $quote->expects($this->once())->method('getGrandTotal')->will($this->returnValue(1));
     $this->assertTrue($this->checkoutValidator->isQuoteSummaryValid($isInCatalog));
 }
Example #16
0
 public function testGetLastOrderId()
 {
     $orderIncrementId = 100001;
     $orderId = 1;
     $this->checkoutSessionMock->expects($this->once())->method('getLastOrderId')->will($this->returnValue($orderId));
     $orderMock = $this->getMock('Magento\\Sales\\Model\\Order', ['load', 'getIncrementId', '__wakeup'], [], '', false);
     $orderMock->expects($this->once())->method('load')->with($orderId)->will($this->returnSelf());
     $orderMock->expects($this->once())->method('getIncrementId')->will($this->returnValue($orderIncrementId));
     $this->orderFactoryMock->expects($this->once())->method('create')->will($this->returnValue($orderMock));
     $this->assertEquals($orderIncrementId, $this->onepage->getLastOrderId());
 }
Example #17
0
 public function testExecute()
 {
     $quoteId = 123;
     $orderId = 'orderId';
     $orderIncrementId = 125;
     $quoteMock = $this->setupCart();
     $this->checkoutMock->expects($this->once())->method('place')->with(null);
     $this->checkoutSessionMock->expects($this->once())->method('clearHelperData');
     $quoteMock->expects($this->once())->method('getId')->willReturn($quoteId);
     $this->checkoutSessionMock->expects($this->once())->method('setLastQuoteId')->with($quoteId)->willReturnSelf();
     $this->checkoutSessionMock->expects($this->once())->method('setLastSuccessQuoteId')->with($quoteId)->willReturnSelf();
     $orderMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock();
     $orderMock->expects($this->once())->method('getId')->willReturn($orderId);
     $orderMock->expects($this->once())->method('getIncrementId')->willReturn($orderIncrementId);
     $this->checkoutMock->expects($this->once())->method('getOrder')->willReturn($orderMock);
     $this->checkoutSessionMock->expects($this->once())->method('setLastOrderId')->with($orderId)->willReturnSelf();
     $this->checkoutSessionMock->expects($this->once())->method('setLastRealOrderId')->with($orderIncrementId)->willReturnSelf();
     $resultRedirect = $this->getMockBuilder('\\Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock();
     $resultRedirect->expects($this->once())->method('setPath')->with('checkout/onepage/success')->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()
 {
     $redirectPath = 'path/to/redirect';
     $quoteMock = $this->getQuoteMock();
     $quoteMock->expects(self::once())->method('getItemsCount')->willReturn(0);
     $this->requestMock->expects(self::exactly(1))->method('getParam')->willReturnMap([['isAjax', null, true]]);
     $this->checkoutSessionMock->expects(self::once())->method('getQuote')->willReturn($quoteMock);
     $this->shippingMethodUpdaterMock->expects(self::never())->method('execute');
     $this->messageManagerMock->expects(self::once())->method('addExceptionMessage')->with(self::isInstanceOf('\\InvalidArgumentException'), 'We can\'t initialize checkout.');
     $this->urlMock->expects(self::once())->method('getUrl')->with('*/*/review', ['_secure' => true])->willReturn($redirectPath);
     $this->responseMock->expects(self::once())->method('setBody')->with(sprintf('<script>window.location.href = "%s";</script>', $redirectPath));
     $this->saveShippingMethod->execute();
 }
Example #19
0
 /**
  * @param boolean $useQty
  * @dataProvider useQtyDataProvider
  */
 public function testGetSummaryQty($useQty)
 {
     $quoteId = 1;
     $itemsCount = 1;
     $quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', ['getItemsCount', 'getItemsQty', '__wakeup'], [], '', false);
     $this->checkoutSessionMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock));
     $this->checkoutSessionMock->expects($this->at(2))->method('getQuoteId')->will($this->returnValue($quoteId));
     $this->customerSessionMock->expects($this->any())->method('isLoggedIn')->will($this->returnValue(true));
     $this->scopeConfigMock->expects($this->once())->method('getValue')->with('checkout/cart_link/use_qty', \Magento\Framework\Store\ScopeInterface::SCOPE_STORE)->will($this->returnValue($useQty));
     $qtyMethodName = $useQty ? 'getItemsQty' : 'getItemsCount';
     $quoteMock->expects($this->once())->method($qtyMethodName)->will($this->returnValue($itemsCount));
     $this->assertEquals($itemsCount, $this->cart->getSummaryQty());
 }
Example #20
0
 public function testExecuteException()
 {
     $agreement = ['test-data'];
     $quote = $this->getQuoteMock();
     $quote->expects(self::once())->method('getItemsCount')->willReturn(0);
     $resultMock = $this->getResultMock();
     $resultMock->expects(self::once())->method('setPath')->with('checkout/cart')->willReturnSelf();
     $this->resultFactoryMock->expects(self::once())->method('create')->with(ResultFactory::TYPE_REDIRECT)->willReturn($resultMock);
     $this->requestMock->expects(self::once())->method('getPostValue')->with('agreement', [])->willReturn($agreement);
     $this->checkoutSessionMock->expects(self::once())->method('getQuote')->willReturn($quote);
     $this->orderPlaceMock->expects(self::never())->method('execute');
     $this->messageManagerMock->expects(self::once())->method('addExceptionMessage')->with(self::isInstanceOf('\\InvalidArgumentException'), 'We can\'t initialize checkout.');
     self::assertEquals($this->placeOrder->execute(), $resultMock);
 }
 public function testExecuteException()
 {
     $result = '{}';
     $quoteMock = $this->getQuoteMock();
     $resultRedirectMock = $this->getResultRedirectMock();
     $quoteMock->expects(self::once())->method('getItemsCount')->willReturn(1);
     $this->requestMock->expects(self::once())->method('getPostValue')->with('result', '{}')->willReturn($result);
     $this->checkoutSessionMock->expects(self::once())->method('getQuote')->willReturn($quoteMock);
     $this->quoteUpdaterMock->expects(self::never())->method('execute');
     $this->messageManagerMock->expects(self::once())->method('addExceptionMessage')->with(self::isInstanceOf('\\InvalidArgumentException'), 'Data of request cannot be empty.');
     $this->resultFactoryMock->expects(self::once())->method('create')->with(ResultFactory::TYPE_REDIRECT)->willReturn($resultRedirectMock);
     $resultRedirectMock->expects(self::once())->method('setPath')->with('checkout/cart')->willReturnSelf();
     self::assertEquals($this->review->execute(), $resultRedirectMock);
 }
Example #22
0
 public function testExecuteExceptionPaymentWithoutNonce()
 {
     $result = '{}';
     $quoteMock = $this->getQuoteMock();
     $resultRedirectMock = $this->getResultRedirectMock();
     $quoteMock->expects(self::once())->method('getItemsCount')->willReturn(1);
     $paymentMock = $this->getMockBuilder(\Magento\Quote\Model\Quote\Payment::class)->disableOriginalConstructor()->getMock();
     $quoteMock->expects(self::once())->method('getPayment')->willReturn($paymentMock);
     $this->requestMock->expects(self::once())->method('getPostValue')->with('result', '{}')->willReturn($result);
     $this->checkoutSessionMock->expects(self::once())->method('getQuote')->willReturn($quoteMock);
     $this->messageManagerMock->expects(self::once())->method('addExceptionMessage')->with(self::isInstanceOf(\Magento\Framework\Exception\LocalizedException::class), 'We can\'t initialize checkout.');
     $this->resultFactoryMock->expects(self::once())->method('create')->with(ResultFactory::TYPE_REDIRECT)->willReturn($resultRedirectMock);
     $resultRedirectMock->expects(self::once())->method('setPath')->with('checkout/cart')->willReturnSelf();
     self::assertEquals($this->review->execute(), $resultRedirectMock);
 }
 /**
  * @param $state
  * @param $restoreQuote
  * @param $expectedGotoSection
  * @dataProvider testNotAllowedOrderStateDataProvider
  */
 public function testExecuteNotAllowedOrderState($state, $restoreQuote, $expectedGotoSection)
 {
     $lastRealOrderId = '000000001';
     $this->viewMock->expects($this->once())->method('getLayout')->will($this->returnValue($this->layoutMock));
     $this->layoutMock->expects($this->once())->method('getBlock')->will($this->returnValue($this->blockMock));
     $this->checkoutSessionMock->expects($this->any())->method('getLastRealOrderId')->will($this->returnValue($lastRealOrderId));
     $this->checkoutSessionMock->expects($this->any())->method('getLastRealOrder')->will($this->returnValue($this->orderMock));
     $this->checkoutSessionMock->expects($this->any())->method('restoreQuote')->will($this->returnValue($restoreQuote));
     $this->orderFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->orderMock));
     $this->orderMock->expects($this->once())->method('loadByIncrementId')->with($lastRealOrderId)->will($this->returnSelf());
     $this->orderMock->expects($this->once())->method('getIncrementId')->will($this->returnValue($lastRealOrderId));
     $this->orderMock->expects($this->once())->method('getState')->will($this->returnValue($state));
     $this->blockMock->expects($this->at(0))->method('setData')->with('goto_section', $expectedGotoSection)->will($this->returnSelf());
     $this->blockMock->expects($this->at(1))->method('setData')->with('error_msg', __('Your payment has been declined. Please try again.'))->will($this->returnSelf());
     $this->returnUrl->execute();
 }
Example #24
0
 /**
  * @dataProvider getConfigDataProvider
  */
 public function testGetConfig($configData, $vaultData, $tokenNonceMap, $expectedResult)
 {
     foreach ($configData as $key => $value) {
         $this->configMock->expects($this->any())->method($key)->willReturn($value);
     }
     foreach ($vaultData as $key => $value) {
         $this->vaultMock->expects($this->any())->method($key)->willReturn($value);
     }
     $this->vaultMock->expects($this->any())->method('generatePaymentMethodToken')->willReturnMap($tokenNonceMap);
     $quoteMock = $this->getMockBuilder('\\Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->getMock();
     $quoteMock->expects($this->once())->method('getBillingAddress')->willReturn(new \Magento\Framework\Object(['country_id' => 'US']));
     $this->checkoutSessionMock->expects($this->once())->method('getQuote')->willReturn($quoteMock);
     $cardTypeMap = [['Visa', 'VI'], ['Master Card', 'MA'], ['American Express', 'AE'], ['Discover Card', 'DI']];
     $this->helperMock->expects($this->any())->method('getCcTypeCodeByName')->willReturnMap($cardTypeMap);
     $this->helperMock->expects($this->once())->method('getTodayMonth')->willReturn(self::TODAY_MONTH);
     $this->helperMock->expects($this->once())->method('getTodayYear')->willReturn(self::TODAY_YEAR);
     $this->helperMock->expects($this->once())->method('getCcAvailableCardTypes')->willReturn($this->availableCardTypes);
     $this->customerSessionMock->expects($this->any())->method('isLoggedIn')->willReturn(true);
     $this->urlBuilderMock->expects($this->once())->method('getUrl')->with('braintree/creditcard/generate')->willReturn(self::PAYMENT_NONCE_GENERATION_URL);
     $this->assertEquals($expectedResult, $this->model->getConfig());
 }
Example #25
0
 public function testProcessAddToCart()
 {
     $wishlistId = 1;
     $customerId = 2;
     $url = 'http://some.pending/url';
     $message = 'some error msg';
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $event = $this->getMockBuilder('Magento\\Framework\\Event')->setMethods(['getRequest', 'getResponse'])->disableOriginalConstructor()->getMock();
     $request = $this->getMockBuilder('Magento\\Framework\\App\\RequestInterface')->getMock();
     $response = $this->getMockBuilder('Magento\\Framework\\App\\ResponseInterface')->setMethods(['setRedirect'])->getMockForAbstractClass();
     $wishlists = $this->getMockBuilder('Magento\\Wishlist\\Model\\Resource\\Wishlist\\Collection')->disableOriginalConstructor()->getMock();
     $loadedWishlist = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist\\Item')->setMethods(['getId', 'delete'])->disableOriginalConstructor()->getMock();
     $eventObserver->expects($this->any())->method('getEvent')->willReturn($event);
     $request->expects($this->any())->method('getParam')->with('wishlist_next')->willReturn(true);
     $event->expects($this->once())->method('getRequest')->willReturn($request);
     $this->checkoutSession->expects($this->once())->method('getSharedWishlist');
     $this->checkoutSession->expects($this->once())->method('getWishlistPendingMessages')->willReturn([$message]);
     $this->checkoutSession->expects($this->once())->method('getWishlistPendingUrls')->willReturn([$url]);
     $this->checkoutSession->expects($this->once())->method('getWishlistIds');
     $this->checkoutSession->expects($this->once())->method('getSingleWishlistId')->willReturn($wishlistId);
     $this->customerSession->expects($this->once())->method('isLoggedIn')->willReturn(true);
     $this->customerSession->expects($this->once())->method('getCustomerId')->willReturn($customerId);
     $this->wishlist->expects($this->once())->method('loadByCustomerId')->with($this->logicalOr($customerId, true))->willReturnSelf();
     $this->wishlist->expects($this->once())->method('getItemCollection')->willReturn($wishlists);
     $loadedWishlist->expects($this->once())->method('getId')->willReturn($wishlistId);
     $loadedWishlist->expects($this->once())->method('delete');
     $wishlists->expects($this->once())->method('load')->willReturn([$loadedWishlist]);
     $this->checkoutSession->expects($this->once())->method('setWishlistIds')->with([])->willReturnSelf();
     $this->checkoutSession->expects($this->once())->method('setSingleWishlistId')->with(null)->willReturnSelf();
     $this->checkoutSession->expects($this->once())->method('setWishlistPendingUrls')->with([])->willReturnSelf();
     $this->checkoutSession->expects($this->once())->method('setWishlistPendingMessages')->with([])->willReturnSelf();
     $this->messageManager->expects($this->once())->method('addError')->with($message)->willReturnSelf();
     $event->expects($this->once())->method('getResponse')->willReturn($response);
     $response->expects($this->once())->method('setRedirect')->with($url);
     $this->checkoutSession->expects($this->once())->method('setNoCartRedirect')->with(true);
     /** @var $eventObserver \Magento\Framework\Event\Observer */
     $this->observer->processAddToCart($eventObserver);
 }
 public function testRestoreQuote()
 {
     $this->session->expects(static::once())->method('restoreQuote')->willReturn(true);
     static::assertTrue($this->checkout->restoreQuote());
 }
Example #27
0
 public function setUp()
 {
     $this->directpostSessionMock = $this->getMockBuilder('Magento\\Authorizenet\\Model\\Directpost\\Session')->disableOriginalConstructor()->getMock();
     $this->quoteMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->getMock();
     $this->checkoutSessionMock = $this->getMockBuilder('Magento\\Checkout\\Model\\Session')->disableOriginalConstructor()->getMock();
     $this->checkoutSessionMock->expects($this->any())->method('getQuote')->will($this->returnValue($this->quoteMock));
     $this->objectManagerMock = $this->getMockBuilder('Magento\\Framework\\ObjectManagerInterface')->getMockForAbstractClass();
     $this->objectManagerMock->expects($this->any())->method('get')->willReturnMap([['Magento\\Authorizenet\\Model\\Directpost\\Session', $this->directpostSessionMock], ['Magento\\Checkout\\Model\\Session', $this->checkoutSessionMock]]);
     $this->coreRegistryMock = $this->getMockBuilder('Magento\\Framework\\Registry')->disableOriginalConstructor()->getMock();
     $this->dataFactoryMock = $this->getMockBuilder('Magento\\Authorizenet\\Helper\\DataFactory')->disableOriginalConstructor()->getMock();
     $this->cartManagementMock = $this->getMockBuilder('Magento\\Quote\\Api\\CartManagementInterface')->disableOriginalConstructor()->getMock();
     $this->onepageCheckout = $this->getMockBuilder('Magento\\Checkout\\Model\\Type\\Onepage')->disableOriginalConstructor()->getMock();
     $this->jsonHelperMock = $this->getMockBuilder('Magento\\Framework\\Json\\Helper\\Data')->disableOriginalConstructor()->getMock();
     $this->requestMock = $this->getMockBuilder('Magento\\Framework\\App\\RequestInterface')->getMockForAbstractClass();
     $this->responseMock = $this->getMockBuilder('Magento\\Framework\\App\\Response\\Http')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->objectManager = new ObjectManager($this);
     $this->placeOrderController = $this->objectManager->getObject('Magento\\Authorizenet\\Controller\\Directpost\\Payment\\Place', ['request' => $this->requestMock, 'response' => $this->responseMock, 'objectManager' => $this->objectManagerMock, 'coreRegistry' => $this->coreRegistryMock, 'dataFactory' => $this->dataFactoryMock, 'cartManagement' => $this->cartManagementMock, 'onepageCheckout' => $this->onepageCheckout, 'jsonHelper' => $this->jsonHelperMock]);
 }
Example #28
0
 private function initCheckoutSessionMock($orderId, $restoreQuote)
 {
     $this->checkoutSessionMock->expects($this->any())->method('getLastRealOrderId')->will($this->returnValue($orderId));
     $this->checkoutSessionMock->expects($this->any())->method('getLastRealOrder')->will($this->returnValue($this->orderMock));
     $this->checkoutSessionMock->expects($this->any())->method('restoreQuote')->will($this->returnValue($restoreQuote));
 }