Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TransactionMapTest.php
Go to the documentation of this file.
1 <?php
7 
8 use Braintree\Transaction;
9 use Braintree\Transaction\PayPalDetails;
10 use DateTime;
17 
23 class TransactionMapTest extends \PHPUnit\Framework\TestCase
24 {
28  private $transactionStub;
29 
33  private $attributeValueFactoryMock;
34 
38  private $defaultRenderer;
39 
43  private $rendererMock;
44 
48  protected function setUp()
49  {
50  $this->attributeValueFactoryMock = $this->getMockBuilder(AttributeValueFactory::class)
51  ->setMethods(['create'])
52  ->disableOriginalConstructor()
53  ->getMock();
54  $this->defaultRenderer = Phrase::getRenderer();
55  $this->rendererMock = $this->getMockBuilder(RendererInterface::class)
56  ->getMock();
57  }
58 
65  public function testGetCustomAttributes($transaction)
66  {
67  $this->transactionStub = Transaction::factory($transaction);
68 
70  $fieldsQty = count($fields);
71 
72  $this->attributeValueFactoryMock->expects($this->exactly($fieldsQty))
73  ->method('create')
74  ->willReturnCallback(function () {
75  return new AttributeValue();
76  });
77 
78  $map = new TransactionMap(
79  $this->attributeValueFactoryMock,
80  $this->transactionStub
81  );
82 
83  Phrase::setRenderer($this->rendererMock);
84 
86  $result = $map->getCustomAttributes();
87 
88  $this->assertEquals($fieldsQty, count($result));
89  $this->assertInstanceOf(AttributeValue::class, $result[1]);
90  $this->assertEquals($transaction['id'], $result[0]->getValue());
91  $this->assertEquals($transaction['paypalDetails']->paymentId, $result[4]->getValue());
92  $this->assertEquals(
93  $transaction['createdAt']->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT),
94  $result[6]->getValue()
95  );
96  $this->assertEquals(implode(', ', $transaction['refundIds']), $result[11]->getValue());
97  $this->assertEquals($transaction['merchantAccountId'], $result[1]->getValue());
98  $this->assertEquals($transaction['orderId'], $result[2]->getValue());
99  $this->assertEquals($transaction['amount'], $result[7]->getValue());
100  $this->assertEquals($transaction['processorSettlementResponseCode'], $result[8]->getValue());
101  $this->assertEquals($transaction['processorSettlementResponseText'], $result[10]->getValue());
102  $this->assertEquals($transaction['settlementBatchId'], $result[12]->getValue());
103  $this->assertEquals($transaction['currencyIsoCode'], $result[13]->getValue());
104 
105  $this->rendererMock->expects($this->at(0))
106  ->method('render')
107  ->with([$transaction['paymentInstrumentType']])
108  ->willReturn('Credit card');
109  $this->assertEquals('Credit card', $result[3]->getValue()->render());
110 
111  $this->rendererMock->expects($this->at(0))
112  ->method('render')
113  ->with([$transaction['type']])
114  ->willReturn('Sale');
115  $this->assertEquals('Sale', $result[5]->getValue()->render());
116 
117  $this->rendererMock->expects($this->at(0))
118  ->method('render')
119  ->with([$transaction['status']])
120  ->willReturn('Pending for settlement');
121  $this->assertEquals('Pending for settlement', $result[9]->getValue()->render());
122  }
123 
127  public function getConfigDataProvider()
128  {
129  return [
130  [
131  'transaction' => [
132  'id' => 1,
133  'createdAt' => new \DateTime(),
134  'paypalDetails' => new PayPalDetails(['paymentId' => 10]),
135  'refundIds' => [1, 2, 3, 4, 5],
136  'merchantAccountId' => 'MerchantId',
137  'orderId' => 1,
138  'paymentInstrumentType' => 'credit_card',
139  'type' => 'sale',
140  'amount' => '$19.99',
141  'processorSettlementResponseCode' => 1,
142  'status' => 'pending_for_settlement',
143  'processorSettlementResponseText' => 'sample text',
144  'settlementBatchId' => 2,
145  'currencyIsoCode' => 'USD'
146  ]
147  ]
148  ];
149  }
150 
154  protected function tearDown()
155  {
156  Phrase::setRenderer($this->defaultRenderer);
157  }
158 }
$transaction
$fields
Definition: details.phtml:14
static setRenderer(RendererInterface $renderer)
Definition: Phrase.php:46