PayflowExpressTest.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Test\Unit\Model;
  7. use Magento\Sales\Model\Order\Payment\Transaction;
  8. use Magento\Paypal\Model\Payflow;
  9. class PayflowExpressTest extends \PHPUnit\Framework\TestCase
  10. {
  11. /**
  12. * @var \Magento\Paypal\Model\PayflowExpress
  13. */
  14. protected $_model;
  15. /**
  16. * @var \PHPUnit_Framework_MockObject_MockObject
  17. */
  18. protected $transactionRepository;
  19. /**
  20. * Payflow pro transaction key
  21. */
  22. const TRANSPORT_PAYFLOW_TXN_ID = 'Payflow pro transaction key';
  23. protected function setUp()
  24. {
  25. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  26. $proFactory = $this->getMockBuilder(
  27. \Magento\Paypal\Model\ProFactory::class
  28. )->disableOriginalConstructor()->setMethods(['create'])->getMock();
  29. $api = $this->createMock(\Magento\Paypal\Model\Api\Nvp::class);
  30. $paypalPro = $this->getMockBuilder(
  31. \Magento\Paypal\Model\Pro::class
  32. )->disableOriginalConstructor()->setMethods([])->getMock();
  33. $this->transactionRepository = $this->getMockBuilder(\Magento\Sales\Api\TransactionRepositoryInterface::class)
  34. ->disableOriginalConstructor()
  35. ->setMethods(['getByTransactionType'])
  36. ->getMockForAbstractClass();
  37. $paypalPro->expects($this->any())->method('getApi')->will($this->returnValue($api));
  38. $proFactory->expects($this->once())->method('create')->will($this->returnValue($paypalPro));
  39. $this->_model = $objectManager->getObject(
  40. \Magento\Paypal\Model\PayflowExpress::class,
  41. ['proFactory' => $proFactory, 'transactionRepository' => $this->transactionRepository]
  42. );
  43. }
  44. public function testCanRefundCaptureNotExist()
  45. {
  46. $paymentInfo = $this->_getPreparedPaymentInfo();
  47. $paymentInfo->expects($this->once())->method('getOrder')->willReturnSelf();
  48. $this->transactionRepository->expects($this->once())
  49. ->method('getByTransactionType')
  50. ->with(Transaction::TYPE_CAPTURE)
  51. ->willReturn(false);
  52. $this->assertFalse($this->_model->canRefund());
  53. }
  54. public function testCanRefundCaptureExistNoAdditionalInfo()
  55. {
  56. $paymentInfo = $this->_getPreparedPaymentInfo();
  57. $captureTransaction = $this->_getCaptureTransaction();
  58. $captureTransaction->expects($this->once())->method('getAdditionalInformation')->with(
  59. Payflow\Pro::TRANSPORT_PAYFLOW_TXN_ID
  60. )->will($this->returnValue(null));
  61. $paymentInfo->expects($this->once())->method('getOrder')->willReturnSelf();
  62. $this->transactionRepository->expects($this->once())
  63. ->method('getByTransactionType')
  64. ->with(Transaction::TYPE_CAPTURE)
  65. ->willReturn($captureTransaction);
  66. $this->assertFalse($this->_model->canRefund());
  67. }
  68. public function testCanRefundCaptureExistValid()
  69. {
  70. $paymentInfo = $this->_getPreparedPaymentInfo();
  71. $captureTransaction = $this->_getCaptureTransaction();
  72. $captureTransaction->expects($this->once())->method('getAdditionalInformation')->with(
  73. Payflow\Pro::TRANSPORT_PAYFLOW_TXN_ID
  74. )->will($this->returnValue(self::TRANSPORT_PAYFLOW_TXN_ID));
  75. $paymentInfo->expects($this->once())->method('getOrder')->willReturnSelf();
  76. $this->transactionRepository->expects($this->once())
  77. ->method('getByTransactionType')
  78. ->with(Transaction::TYPE_CAPTURE)
  79. ->willReturn($captureTransaction);
  80. $this->assertTrue($this->_model->canRefund());
  81. }
  82. /**
  83. * Prepares payment info mock and adds it to the model
  84. *
  85. * @return \PHPUnit_Framework_MockObject_MockObject
  86. */
  87. protected function _getPreparedPaymentInfo()
  88. {
  89. $paymentInfo = $this->getMockBuilder(
  90. \Magento\Sales\Model\Order\Payment::class
  91. )->disableOriginalConstructor()->setMethods([])->getMock();
  92. $this->_model->setData('info_instance', $paymentInfo);
  93. return $paymentInfo;
  94. }
  95. /**
  96. * Prepares capture transaction
  97. *
  98. * @return \PHPUnit_Framework_MockObject_MockObject
  99. */
  100. protected function _getCaptureTransaction()
  101. {
  102. return $this->getMockBuilder(
  103. \Magento\Sales\Model\Order\Payment\Transaction::class
  104. )->disableOriginalConstructor()->setMethods([])->getMock();
  105. }
  106. public function testCanFetchTransactionInfo()
  107. {
  108. $this->assertEquals(false, $this->_model->canFetchTransactionInfo());
  109. }
  110. public function testCanReviewPayment()
  111. {
  112. $this->assertEquals(false, $this->_model->canReviewPayment());
  113. }
  114. }