Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataTest.php
Go to the documentation of this file.
1 <?php
7 
8 class DataTest extends \PHPUnit\Framework\TestCase
9 {
13  const LAST4 = 1111;
14 
18  const TRID = '2217041665';
19 
23  protected $dataHelper;
24 
28  protected $storeManagerMock;
29 
30  protected function setUp()
31  {
32  $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
33 
34  $this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
35  ->getMockForAbstractClass();
36 
37  $this->dataHelper = $helper->getObject(
38  \Magento\Authorizenet\Helper\Data::class,
39  ['storeManager' => $this->storeManagerMock]
40  );
41  }
42 
51  public function testGetTransactionMessage($type, $amount, $exception, $additionalMessage, $expected)
52  {
53  $currency = $this->createPartialMock(\Magento\Directory\Model\Currency::class, ['formatTxt', '__wakeup']);
54  $currency->expects($this->any())
55  ->method('formatTxt')
56  ->will($this->returnValue($amount));
57  $order = $this->createPartialMock(\Magento\Sales\Model\Order::class, ['getBaseCurrency', '__wakeup']);
58  $order->expects($this->any())
59  ->method('getBaseCurrency')
60  ->will($this->returnValue($currency));
61  $payment = $this->createPartialMock(\Magento\Payment\Model\Info::class, ['getOrder', '__wakeup']);
62  $payment->expects($this->any())
63  ->method('getOrder')
64  ->will($this->returnValue($order));
65  $card = new \Magento\Framework\DataObject(['cc_last_4' => self::LAST4]);
66  $message = $this->dataHelper->getTransactionMessage(
67  $payment,
68  $type,
69  self::TRID,
70  $card,
71  $amount,
72  $exception,
73  $additionalMessage
74  );
75 
76  $this->assertEquals($expected, $message);
77  }
78 
82  public function getMessagesParamDataProvider()
83  {
84  $amount = 12.30;
85  $additionalMessage = 'Addition message.';
86  return [
87  [
88  'AUTH_ONLY',
89  $amount,
90  false,
91  $additionalMessage,
92  'Credit Card: xxxx-' . self::LAST4 . ' amount 12.3 authorize - successful. '
93  . 'Authorize.Net Transaction ID ' . self::TRID . '. Addition message.',
94  ],
95  [
96  'AUTH_CAPTURE',
97  $amount,
98  'some exception',
99  false,
100  'Credit Card: xxxx-' . self::LAST4 . ' amount 12.3 authorize and capture - failed. '
101  . 'Authorize.Net Transaction ID ' . self::TRID . '. some exception'
102  ],
103  [
104  'CREDIT',
105  false,
106  false,
107  $additionalMessage,
108  'Credit Card: xxxx-' . self::LAST4 . ' refund - successful. '
109  . 'Authorize.Net Transaction ID ' . self::TRID . '. Addition message.'
110  ],
111  ];
112  }
113 
114  public function testGetRelayUrl()
115  {
116  $storeId = 10;
117  $baseUrl = 'http://base.url/';
118 
119  $storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
120  ->disableOriginalConstructor()
121  ->getMock();
122 
123  $storeMock->expects($this->once())
124  ->method('getBaseUrl')
125  ->with(\Magento\Framework\UrlInterface::URL_TYPE_LINK)
126  ->willReturn($baseUrl);
127 
128  $this->storeManagerMock->expects($this->once())
129  ->method('getStore')
130  ->with($storeId)
131  ->willReturn($storeMock);
132 
133  $this->assertSame(
134  'http://base.url/authorizenet/directpost_payment/response',
135  $this->dataHelper->getRelayUrl($storeId)
136  );
137  }
138 
145  public function testGetFdsFilterActionLabel($code, $expected)
146  {
147  $this->assertSame($expected, (string)$this->dataHelper->getFdsFilterActionLabel($code));
148  }
149 
154  {
155  return [
156  ['decline ', 'Decline'],
157  ['hold', 'Hold'],
158  ['authAndHold', 'Authorize and Hold'],
159  ['report', 'Report Only'],
160  ['unknown_status', 'unknown_status']
161  ];
162  }
163 
170  public function testGetTransactionStatusLabel($code, $expected)
171  {
172  $this->assertSame($expected, (string)$this->dataHelper->getTransactionStatusLabel($code));
173  }
174 
179  {
180  return [
181  ['authorizedPendingCapture', 'Authorized/Pending Capture'],
182  ['capturedPendingSettlement', 'Captured/Pending Settlement'],
183  ['refundSettledSuccessfully', 'Refund/Settled Successfully'],
184  ['refundPendingSettlement', 'Refund/Pending Settlement'],
185  ['declined', 'Declined'],
186  ['expired', 'Expired'],
187  ['voided', 'Voided'],
188  ['FDSPendingReview', 'FDS - Pending Review'],
189  ['FDSAuthorizedPendingReview', 'FDS - Authorized/Pending Review'],
190  ['unknown_status', 'unknown_status']
191  ];
192  }
193 }
$helper
Definition: iframe.phtml:13
$order
Definition: order.php:55
$message
$amount
Definition: order.php:14
$payment
Definition: order.php:17
$type
Definition: item.phtml:13
testGetTransactionMessage($type, $amount, $exception, $additionalMessage, $expected)
Definition: DataTest.php:51
$code
Definition: info.phtml:12