DataTest.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Authorizenet\Test\Unit\Helper;
  7. class DataTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * Last 4 digit of cc
  11. */
  12. const LAST4 = 1111;
  13. /**
  14. * Transaction ID
  15. */
  16. const TRID = '2217041665';
  17. /**
  18. * @var \Magento\Authorizenet\Helper\Data
  19. */
  20. protected $dataHelper;
  21. /**
  22. * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $storeManagerMock;
  25. protected function setUp()
  26. {
  27. $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  28. $this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
  29. ->getMockForAbstractClass();
  30. $this->dataHelper = $helper->getObject(
  31. \Magento\Authorizenet\Helper\Data::class,
  32. ['storeManager' => $this->storeManagerMock]
  33. );
  34. }
  35. /**
  36. * @param $type
  37. * @param $amount
  38. * @param $exception
  39. * @param $additionalMessage
  40. * @param $expected
  41. * @dataProvider getMessagesParamDataProvider
  42. */
  43. public function testGetTransactionMessage($type, $amount, $exception, $additionalMessage, $expected)
  44. {
  45. $currency = $this->createPartialMock(\Magento\Directory\Model\Currency::class, ['formatTxt', '__wakeup']);
  46. $currency->expects($this->any())
  47. ->method('formatTxt')
  48. ->will($this->returnValue($amount));
  49. $order = $this->createPartialMock(\Magento\Sales\Model\Order::class, ['getBaseCurrency', '__wakeup']);
  50. $order->expects($this->any())
  51. ->method('getBaseCurrency')
  52. ->will($this->returnValue($currency));
  53. $payment = $this->createPartialMock(\Magento\Payment\Model\Info::class, ['getOrder', '__wakeup']);
  54. $payment->expects($this->any())
  55. ->method('getOrder')
  56. ->will($this->returnValue($order));
  57. $card = new \Magento\Framework\DataObject(['cc_last_4' => self::LAST4]);
  58. $message = $this->dataHelper->getTransactionMessage(
  59. $payment,
  60. $type,
  61. self::TRID,
  62. $card,
  63. $amount,
  64. $exception,
  65. $additionalMessage
  66. );
  67. $this->assertEquals($expected, $message);
  68. }
  69. /**
  70. * @return array
  71. */
  72. public function getMessagesParamDataProvider()
  73. {
  74. $amount = 12.30;
  75. $additionalMessage = 'Addition message.';
  76. return [
  77. [
  78. 'AUTH_ONLY',
  79. $amount,
  80. false,
  81. $additionalMessage,
  82. 'Credit Card: xxxx-' . self::LAST4 . ' amount 12.3 authorize - successful. '
  83. . 'Authorize.Net Transaction ID ' . self::TRID . '. Addition message.',
  84. ],
  85. [
  86. 'AUTH_CAPTURE',
  87. $amount,
  88. 'some exception',
  89. false,
  90. 'Credit Card: xxxx-' . self::LAST4 . ' amount 12.3 authorize and capture - failed. '
  91. . 'Authorize.Net Transaction ID ' . self::TRID . '. some exception'
  92. ],
  93. [
  94. 'CREDIT',
  95. false,
  96. false,
  97. $additionalMessage,
  98. 'Credit Card: xxxx-' . self::LAST4 . ' refund - successful. '
  99. . 'Authorize.Net Transaction ID ' . self::TRID . '. Addition message.'
  100. ],
  101. ];
  102. }
  103. public function testGetRelayUrl()
  104. {
  105. $storeId = 10;
  106. $baseUrl = 'http://base.url/';
  107. $storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
  108. ->disableOriginalConstructor()
  109. ->getMock();
  110. $storeMock->expects($this->once())
  111. ->method('getBaseUrl')
  112. ->with(\Magento\Framework\UrlInterface::URL_TYPE_LINK)
  113. ->willReturn($baseUrl);
  114. $this->storeManagerMock->expects($this->once())
  115. ->method('getStore')
  116. ->with($storeId)
  117. ->willReturn($storeMock);
  118. $this->assertSame(
  119. 'http://base.url/authorizenet/directpost_payment/response',
  120. $this->dataHelper->getRelayUrl($storeId)
  121. );
  122. }
  123. /**
  124. * @param string $code
  125. * @param string $expected
  126. *
  127. * @dataProvider getFdsFilterActionLabelDataProvider
  128. */
  129. public function testGetFdsFilterActionLabel($code, $expected)
  130. {
  131. $this->assertSame($expected, (string)$this->dataHelper->getFdsFilterActionLabel($code));
  132. }
  133. /**
  134. * @return array
  135. */
  136. public function getFdsFilterActionLabelDataProvider()
  137. {
  138. return [
  139. ['decline ', 'Decline'],
  140. ['hold', 'Hold'],
  141. ['authAndHold', 'Authorize and Hold'],
  142. ['report', 'Report Only'],
  143. ['unknown_status', 'unknown_status']
  144. ];
  145. }
  146. /**
  147. * @param string $code
  148. * @param string $expected
  149. *
  150. * @dataProvider getTransactionStatusLabelDataProvider
  151. */
  152. public function testGetTransactionStatusLabel($code, $expected)
  153. {
  154. $this->assertSame($expected, (string)$this->dataHelper->getTransactionStatusLabel($code));
  155. }
  156. /**
  157. * @return array
  158. */
  159. public function getTransactionStatusLabelDataProvider()
  160. {
  161. return [
  162. ['authorizedPendingCapture', 'Authorized/Pending Capture'],
  163. ['capturedPendingSettlement', 'Captured/Pending Settlement'],
  164. ['refundSettledSuccessfully', 'Refund/Settled Successfully'],
  165. ['refundPendingSettlement', 'Refund/Pending Settlement'],
  166. ['declined', 'Declined'],
  167. ['expired', 'Expired'],
  168. ['voided', 'Voided'],
  169. ['FDSPendingReview', 'FDS - Pending Review'],
  170. ['FDSAuthorizedPendingReview', 'FDS - Authorized/Pending Review'],
  171. ['unknown_status', 'unknown_status']
  172. ];
  173. }
  174. }