Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InfoTest.php
Go to the documentation of this file.
1 <?php
8 
11 
12 class InfoTest extends \PHPUnit\Framework\TestCase
13 {
15  protected $info;
16 
19 
20  protected function setUp()
21  {
22  $this->objectManagerHelper = new ObjectManagerHelper($this);
23  $this->info = $this->objectManagerHelper->getObject(
24  \Magento\Paypal\Model\Info::class
25  );
26  }
27 
33  public function testGetPaymentInfo($additionalInfo, $expectation)
34  {
36  $paymentInfo = $this->objectManagerHelper->getObject(\Magento\Payment\Model\Info::class);
37  $paymentInfo->setAdditionalInformation($additionalInfo);
38  $this->assertEquals($expectation, $this->info->getPaymentInfo($paymentInfo));
39  }
40 
46  public function testGetPaymentInfoLabelValues($additionalInfo, $expectation)
47  {
49  $paymentInfo = $this->objectManagerHelper->getObject(\Magento\Payment\Model\Info::class);
50  $paymentInfo->setAdditionalInformation($additionalInfo);
51  $this->assertEquals(
52  $this->_prepareLabelValuesExpectation($expectation),
53  $this->info->getPaymentInfo($paymentInfo, true)
54  );
55  }
56 
62  public function testGetPublicPaymentInfo($additionalInfo, $expectation)
63  {
65  $paymentInfo = $this->objectManagerHelper->getObject(\Magento\Payment\Model\Info::class);
66  $paymentInfo->setAdditionalInformation($additionalInfo);
67  $this->assertEquals(
68  $this->_prepareLabelValuesExpectation($expectation),
69  $this->info->getPublicPaymentInfo($paymentInfo, true)
70  );
71  }
72 
78  public function testGetPublicPaymentInfoLabelValues($additionalInfo, $expectation)
79  {
81  $paymentInfo = $this->objectManagerHelper->getObject(\Magento\Payment\Model\Info::class);
82  $paymentInfo->setAdditionalInformation($additionalInfo);
83  $this->assertEquals($expectation, $this->info->getPublicPaymentInfo($paymentInfo));
84  }
85 
91  public function testImportToPayment($mapping, $expectation)
92  {
93  // we create $from object, based on mapping
94  $from = new \Magento\Framework\DataObject($mapping);
96  $paymentInfo = $this->objectManagerHelper->getObject(\Magento\Payment\Model\Info::class);
97  $this->info->importToPayment($from, $paymentInfo);
98  $this->assertEquals($expectation, $paymentInfo->getAdditionalInformation());
99  }
100 
106  public function testExportFromPayment($mapping, $expectation)
107  {
109  $paymentInfo = $this->objectManagerHelper->getObject(\Magento\Payment\Model\Info::class);
110  $paymentInfo->setAdditionalInformation($expectation);
111 
112  // we create $to empty object
113  $to = new \Magento\Framework\DataObject();
114  $this->info->exportFromPayment($paymentInfo, $to);
115  $this->assertEquals($mapping, $to->getData());
116  }
117 
123  public function testExportFromPaymentCustomMapping($mapping, $expectation)
124  {
126  $paymentInfo = $this->objectManagerHelper->getObject(\Magento\Payment\Model\Info::class);
127  $paymentInfo->setAdditionalInformation($expectation);
128 
129  // we create $to empty object
130  $to = new \Magento\Framework\DataObject();
131  $this->info->exportFromPayment($paymentInfo, $to, array_flip($mapping));
132  $this->assertEquals($mapping, $to->getData());
133  }
134 
141  private function _prepareLabelValuesExpectation($expectation)
142  {
143  $labelValueExpectation = [];
144  foreach ($expectation as $data) {
145  $labelValueExpectation[$data['label']] = $data['value'];
146  }
147  return $labelValueExpectation;
148  }
149 
155  public function additionalInfoDataProvider()
156  {
157  return include __DIR__ . '/_files/additional_info_data.php';
158  }
159 
166  {
167  return [
168  [
169  [
170  Info::PAYPAL_PAYER_EMAIL => Info::PAYPAL_PAYER_EMAIL,
171  Info::BUYER_TAX_ID => Info::BUYER_TAX_ID,
172  Info::BUYER_TAX_ID_TYPE => Info::BUYER_TAX_ID_TYPE_CNPJ,
173  ],
174  [
175  Info::PAYPAL_PAYER_EMAIL => [
176  'label' => 'Payer Email',
177  'value' => Info::PAYPAL_PAYER_EMAIL,
178  ],
179  Info::BUYER_TAX_ID => [
180  'label' => 'Buyer\'s Tax ID',
181  'value' => Info::BUYER_TAX_ID,
182  ],
183  Info::BUYER_TAX_ID_TYPE => [
184  'label' => 'Buyer\'s Tax ID Type',
185  'value' => 'CNPJ',
186  ]
187  ],
188  ],
189  [
190  [
191  Info::PAYPAL_PAYER_EMAIL => Info::PAYPAL_PAYER_EMAIL,
192  Info::BUYER_TAX_ID => Info::BUYER_TAX_ID,
193  Info::BUYER_TAX_ID_TYPE => Info::BUYER_TAX_ID_TYPE,
194  ],
195  [
196  Info::PAYPAL_PAYER_EMAIL => [
197  'label' => 'Payer Email',
198  'value' => Info::PAYPAL_PAYER_EMAIL,
199  ],
200  Info::BUYER_TAX_ID => [
201  'label' => 'Buyer\'s Tax ID',
202  'value' => Info::BUYER_TAX_ID,
203  ]
204  ]
205  ]
206  ];
207  }
208 
214  public function importToPaymentDataProvider()
215  {
216  return [
217  [
218  [
219  Info::PAYER_ID => Info::PAYPAL_PAYER_ID,
220  Info::PAYER_EMAIL => Info::PAYPAL_PAYER_EMAIL,
221  Info::PAYER_STATUS => Info::PAYPAL_PAYER_STATUS,
222  Info::ADDRESS_ID => Info::PAYPAL_ADDRESS_ID,
223  Info::ADDRESS_STATUS => Info::PAYPAL_ADDRESS_STATUS,
224  Info::PROTECTION_EL => Info::PAYPAL_PROTECTION_ELIGIBILITY,
225  Info::FRAUD_FILTERS => Info::PAYPAL_FRAUD_FILTERS,
226  Info::CORRELATION_ID => Info::PAYPAL_CORRELATION_ID,
227  Info::AVS_CODE => Info::PAYPAL_AVS_CODE,
228  Info::CVV_2_MATCH => Info::PAYPAL_CVV_2_MATCH,
229  Info::BUYER_TAX_ID => Info::BUYER_TAX_ID,
230  Info::BUYER_TAX_ID_TYPE => Info::BUYER_TAX_ID_TYPE,
231  Info::PAYMENT_STATUS => Info::PAYMENT_STATUS_GLOBAL,
232  Info::PENDING_REASON => Info::PENDING_REASON_GLOBAL,
233  Info::IS_FRAUD => Info::IS_FRAUD_GLOBAL,
234  ],
235  [
236  Info::PAYPAL_PAYER_ID => Info::PAYPAL_PAYER_ID,
237  Info::PAYPAL_PAYER_EMAIL => Info::PAYPAL_PAYER_EMAIL,
238  Info::PAYPAL_PAYER_STATUS => Info::PAYPAL_PAYER_STATUS,
239  Info::PAYPAL_ADDRESS_ID => Info::PAYPAL_ADDRESS_ID,
240  Info::PAYPAL_ADDRESS_STATUS => Info::PAYPAL_ADDRESS_STATUS,
241  Info::PAYPAL_PROTECTION_ELIGIBILITY => Info::PAYPAL_PROTECTION_ELIGIBILITY,
242  Info::PAYPAL_FRAUD_FILTERS => Info::PAYPAL_FRAUD_FILTERS,
243  Info::PAYPAL_CORRELATION_ID => Info::PAYPAL_CORRELATION_ID,
244  Info::PAYPAL_AVS_CODE => Info::PAYPAL_AVS_CODE,
245  Info::PAYPAL_CVV_2_MATCH => Info::PAYPAL_CVV_2_MATCH,
246  Info::BUYER_TAX_ID => Info::BUYER_TAX_ID,
247  Info::BUYER_TAX_ID_TYPE => Info::BUYER_TAX_ID_TYPE,
248  Info::PAYMENT_STATUS_GLOBAL => Info::PAYMENT_STATUS_GLOBAL,
249  Info::PENDING_REASON_GLOBAL => Info::PENDING_REASON_GLOBAL,
250  Info::IS_FRAUD_GLOBAL => Info::IS_FRAUD_GLOBAL
251  ],
252  ]
253  ];
254  }
255 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$paymentInfo