public function testUnHold() { $this->orderRepositoryMock->expects($this->once())->method('get')->with(123)->willReturn($this->orderMock); $this->orderRepositoryMock->expects($this->once())->method('save')->with($this->orderMock)->willReturn($this->orderMock); $this->orderMock->expects($this->once())->method('unHold')->willReturn($this->orderMock); $this->assertTrue($this->orderService->unHold(123)); }
public function testEmailNoOrderId() { $this->request->expects($this->once()) ->method('getParam') ->with('order_id') ->will($this->returnValue(null)); $this->orderRepositoryMock->expects($this->once()) ->method('get') ->with(null) ->willThrowException( new \Magento\Framework\Exception\NoSuchEntityException(__('Requested entity doesn\'t exist')) ); $this->messageManager->expects($this->once()) ->method('addError') ->with('This order no longer exists.'); $this->actionFlag->expects($this->once()) ->method('set') ->with('', 'no-dispatch', true) ->will($this->returnValue(true)); $this->resultRedirect->expects($this->once()) ->method('setPath') ->with('sales/*/') ->willReturnSelf(); $this->assertInstanceOf( 'Magento\Backend\Model\View\Result\Redirect', $this->orderEmail->executeInternal() ); }
/** * Tests what happens if the customer is logged in and the order does or does not allow reorders. * * @param bool $orderCanReorder * @return void * @dataProvider getOrderCanReorder */ public function testCanReorderCustomerLoggedInAndOrderCanReorder($orderCanReorder) { $this->setupOrderMock(true); $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(true)); $this->orderMock->expects($this->once())->method('canReorder')->will($this->returnValue($orderCanReorder)); $this->repositoryMock->expects($this->once())->method('get')->with(1)->willReturn($this->orderMock); $this->assertEquals($orderCanReorder, $this->helper->canReorder(1)); }
public function testExecuteUpdateAction() { $orderId = 30; $action = 'update'; $this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->willReturn($orderId); $this->requestMock->expects($this->at(1))->method('getParam')->with('action')->willReturn($action); $this->resultRedirectFactoryMock->expects($this->once())->method('create')->willReturn($this->resultRedirectMock); $this->orderRepositoryMock->expects($this->once())->method('get')->with($orderId)->willReturn($this->orderMock); $this->orderMock->expects($this->any())->method('getEntityId')->willReturn($orderId); $this->orderMock->expects($this->any())->method('getPayment')->willReturn($this->paymentMock); $this->orderRepositoryMock->expects($this->once())->method('save')->with($this->orderMock)->willReturnSelf(); $this->paymentMock->expects($this->once())->method('update'); $this->paymentMock->expects($this->any())->method('getIsTransactionApproved')->willReturn(true); $this->messageManagerMock->expects($this->once())->method('addSuccess'); $this->resultRedirectMock->expects($this->once())->method('setPath')->with('sales/order/view')->willReturnSelf(); $result = $this->reviewPayment->execute(); $this->assertEquals($this->resultRedirectMock, $result); }
protected function initOrder() { $orderIdParam = 111; $this->requestMock->expects($this->atLeastOnce()) ->method('getParam') ->with('order_id') ->willReturn($orderIdParam); $this->orderRepositoryMock->expects($this->once()) ->method('get') ->with($orderIdParam) ->willReturn($this->orderMock); }
public function testPartialCaptureCloneTransaction() { $amount = self::AUTH_AMOUNT; $paymentId = 1005; $authTransactionId = 1006; $braintreeTransactionId = '4fg7hj'; $paymentObject = $this->setupPaymentObjectForCapture($paymentId); $this->setupSalesTransaction($paymentId, 1); //one existing capture transaction $authTransactionMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order\\Payment\\Transaction')->disableOriginalConstructor()->getMock(); $authTransactionMock->expects($this->any())->method('getId')->willReturn($authTransactionId); $authTransactionMock->expects($this->once())->method('getAdditionalInformation')->with('token')->willReturn(self::CC_TOKEN); $authTransactionMock->expects($this->once())->method('getTxnId')->willReturn($braintreeTransactionId); $this->setupAuthTransaction($paymentId, $authTransactionMock); $this->braintreeCreditCardMock->expects($this->once())->method('find')->with(self::CC_TOKEN)->willThrowException(new \Exception('not found')); $braintreeResultData = ['transaction' => \Braintree_Transaction::factory(['id' => self::AUTH_TRAN_ID, 'creditCard' => ['token' => null, 'last4' => self::AUTH_CC_LAST_4, 'expirationMonth' => '10', 'expirationYear' => '2020', 'bin' => 'bin'], 'avsErrorResponseCode' => null, 'avsPostalCodeResponseCode' => 'M', 'avsStreetAddressResponseCode' => 'M', 'cvvResponseCode' => 'M', 'gatewayRejectionReason' => null, 'processorAuthorizationCode' => 'S02T5Q', 'processorResponseCode' => '1000', 'processorResponseText' => 'Approved'])]; $resultSuccess = $this->setupSuccessResponse($braintreeResultData); $this->braintreeTransactionMock->expects($this->once())->method('cloneTransaction')->with($braintreeTransactionId, ['amount' => $amount, 'options' => ['submitForSettlement' => true]])->willReturn($resultSuccess); $paymentObject->setParentId('1'); $order = $this->getMockBuilder('Magento\\Sales\\Api\\Data\\OrderInterface')->getMockForAbstractClass(); $order->expects($this->once())->method('getTotalDue')->willReturn(10.02); $this->orderRepository->expects($this->once())->method('get')->willReturn($order); $this->model->capture($paymentObject, $amount); $this->assertEquals(PaymentMethod::STATUS_APPROVED, $paymentObject->getStatus()); $this->assertEquals($amount, $paymentObject->getAmount()); $this->assertEquals(self::AUTH_TRAN_ID, $paymentObject->getCcTransId()); $this->assertEquals(self::AUTH_CC_LAST_4, $paymentObject->getCcLast4()); }
protected function setupPaymentObjectForCapture($paymentId) { $order = $this->getMockBuilder('Magento\\Sales\\Api\\Data\\OrderInterface')->getMockForAbstractClass(); $order->expects(static::any())->method('getTotalDue')->willReturn(self::TOTAL_AMOUNT); $this->orderRepository->expects(static::any())->method('get')->willReturn($order); $currencyMock = $this->getPriceCurrencyMock(); $paymentObject = $this->objectManagerHelper->getObject('Magento\\Sales\\Model\\Order\\Payment', ['priceCurrency' => $currencyMock, 'orderRepository' => $this->orderRepository, 'data' => ['id' => $paymentId, 'cc_trans_id' => self::AUTH_TRAN_ID]]); return $paymentObject; }