/**
  * @dataProvider notIsValidDataProvider
  * @param $data
  * @param $result
  */
 public function testNotIsValid($data, $result)
 {
     $provider = $this->getMockForAbstractClass('Magento\\Checkout\\Model\\Agreements\\AgreementsProviderInterface');
     $provider->expects($this->once())->method('getRequiredAgreementIds')->will($this->returnValue([1, 3, '4']));
     $this->object = $this->objectManagerHelper->getObject('Magento\\Checkout\\Model\\Agreements\\AgreementsValidator', ['list' => [$provider]]);
     $this->assertEquals($result, $this->object->isValid($data));
 }
Exemplo n.º 2
0
 /**
  * Test for execute method
  *
  * @return void
  */
 public function testExecuteWithSuccessOrderSave()
 {
     $testData = $this->getExecuteWithSuccessOrderSaveTestData();
     $redirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock();
     $paymentMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Payment')->disableOriginalConstructor()->getMock();
     $checkoutMock = $this->getMockBuilder('Magento\\Checkout\\Model\\Session')->disableOriginalConstructor()->setMethods(['getRedirectUrl'])->getMock();
     $resultJsonMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->getMock();
     $redirectMock->expects($this->never())->method('setPath')->with('*/*/')->willReturn('redirect');
     $this->formKeyValidatorMock->expects($this->once())->method('validate')->with($this->requestMock)->willReturn(true);
     $this->resultRedirectFactoryMock->expects($this->never())->method('create')->willReturn($redirectMock);
     $this->objectManagerMock->expects($this->atLeastOnce())->method('get')->willReturnMap($testData['objectManager.get']);
     // call _expireAjax method
     $this->expireAjaxFlowHasItemsFalse();
     $this->requestMock->expects($this->atLeastOnce())->method('getPost')->willReturnMap($testData['request.getPost']);
     $this->agreementsValidatorMock->expects($this->once())->method('isValid')->with($testData['agreementsValidator.isValid'])->willReturn(true);
     $this->quoteMock->expects($this->atLeastOnce())->method('getPayment')->willReturn($paymentMock);
     $paymentMock->expects($this->once())->method('setQuote')->with($this->quoteMock);
     $paymentMock->expects($this->once())->method('importData')->with($testData['payment.importData']);
     $this->onepageMock->expects($this->once())->method('saveOrder');
     $this->onepageMock->expects($this->once())->method('getCheckout')->willReturn($checkoutMock);
     $checkoutMock->expects($this->once())->method('getRedirectUrl')->willReturn(null);
     $this->eventManagerMock->expects($this->once())->method('dispatch')->withConsecutive($this->equalTo('checkout_controller_onepage_saveOrder'), $this->countOf(2));
     $this->resultJsonFactoryMock->expects($this->once())->method('create')->willReturn($resultJsonMock);
     $resultJsonMock->expects($this->once())->method('setData')->with($testData['resultJson.setData'])->willReturnSelf();
     $this->assertEquals($resultJsonMock, $this->controller->execute());
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function placeOrder($cartId, $agreements = null, PaymentInterface $paymentMethod = null)
 {
     if (!$this->agreementsValidator->isValid($agreements)) {
         throw new \Magento\Framework\Exception\CouldNotSaveException(__('Please agree to all the terms and conditions before placing the order.'));
     }
     $quote = $this->quoteRepository->getActive($cartId);
     if ($paymentMethod) {
         $paymentMethod->setChecks([\Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_CHECKOUT, \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_COUNTRY, \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_CURRENCY, \Magento\Payment\Model\Method\AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX, \Magento\Payment\Model\Method\AbstractMethod::CHECK_ZERO_TOTAL]);
         $quote->getPayment()->setQuote($quote);
         $data = $paymentMethod->getData();
         if (isset($data['additional_data'])) {
             $data = array_merge($data, (array) $data['additional_data']);
             unset($data['additional_data']);
         }
         $quote->getPayment()->importData($data);
     }
     if ($quote->getCheckoutMethod() === self::METHOD_GUEST) {
         $quote->setCustomerId(null);
         $quote->setCustomerEmail($quote->getBillingAddress()->getEmail());
         $quote->setCustomerIsGuest(true);
         $quote->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID);
     }
     $order = $this->submit($quote);
     $this->checkoutSession->setLastQuoteId($quote->getId());
     $this->checkoutSession->setLastSuccessQuoteId($quote->getId());
     $this->checkoutSession->setLastOrderId($order->getId());
     $this->checkoutSession->setLastRealOrderId($order->getIncrementId());
     $this->eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $quote]);
     return $order->getId();
 }