Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PayflowExpressTest.php
Go to the documentation of this file.
1 <?php
8 
11 
12 class PayflowExpressTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $_model;
18 
23 
27  const TRANSPORT_PAYFLOW_TXN_ID = 'Payflow pro transaction key';
28 
29  protected function setUp()
30  {
31  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
32  $proFactory = $this->getMockBuilder(
33  \Magento\Paypal\Model\ProFactory::class
34  )->disableOriginalConstructor()->setMethods(['create'])->getMock();
35  $api = $this->createMock(\Magento\Paypal\Model\Api\Nvp::class);
36  $paypalPro = $this->getMockBuilder(
37  \Magento\Paypal\Model\Pro::class
38  )->disableOriginalConstructor()->setMethods([])->getMock();
39  $this->transactionRepository = $this->getMockBuilder(\Magento\Sales\Api\TransactionRepositoryInterface::class)
40  ->disableOriginalConstructor()
41  ->setMethods(['getByTransactionType'])
42  ->getMockForAbstractClass();
43  $paypalPro->expects($this->any())->method('getApi')->will($this->returnValue($api));
44 
45  $proFactory->expects($this->once())->method('create')->will($this->returnValue($paypalPro));
46 
47  $this->_model = $objectManager->getObject(
48  \Magento\Paypal\Model\PayflowExpress::class,
49  ['proFactory' => $proFactory, 'transactionRepository' => $this->transactionRepository]
50  );
51  }
52 
53  public function testCanRefundCaptureNotExist()
54  {
56  $paymentInfo->expects($this->once())->method('getOrder')->willReturnSelf();
57  $this->transactionRepository->expects($this->once())
58  ->method('getByTransactionType')
60  ->willReturn(false);
61  $this->assertFalse($this->_model->canRefund());
62  }
63 
65  {
67  $captureTransaction = $this->_getCaptureTransaction();
68  $captureTransaction->expects($this->once())->method('getAdditionalInformation')->with(
70  )->will($this->returnValue(null));
71  $paymentInfo->expects($this->once())->method('getOrder')->willReturnSelf();
72  $this->transactionRepository->expects($this->once())
73  ->method('getByTransactionType')
75  ->willReturn($captureTransaction);
76  $this->assertFalse($this->_model->canRefund());
77  }
78 
80  {
82  $captureTransaction = $this->_getCaptureTransaction();
83  $captureTransaction->expects($this->once())->method('getAdditionalInformation')->with(
85  )->will($this->returnValue(self::TRANSPORT_PAYFLOW_TXN_ID));
86  $paymentInfo->expects($this->once())->method('getOrder')->willReturnSelf();
87  $this->transactionRepository->expects($this->once())
88  ->method('getByTransactionType')
90  ->willReturn($captureTransaction);
91  $this->assertTrue($this->_model->canRefund());
92  }
93 
99  protected function _getPreparedPaymentInfo()
100  {
101  $paymentInfo = $this->getMockBuilder(
102  \Magento\Sales\Model\Order\Payment::class
103  )->disableOriginalConstructor()->setMethods([])->getMock();
104  $this->_model->setData('info_instance', $paymentInfo);
105  return $paymentInfo;
106  }
107 
113  protected function _getCaptureTransaction()
114  {
115  return $this->getMockBuilder(
116  \Magento\Sales\Model\Order\Payment\Transaction::class
117  )->disableOriginalConstructor()->setMethods([])->getMock();
118  }
119 
120  public function testCanFetchTransactionInfo()
121  {
122  $this->assertEquals(false, $this->_model->canFetchTransactionInfo());
123  }
124 
125  public function testCanReviewPayment()
126  {
127  $this->assertEquals(false, $this->_model->canReviewPayment());
128  }
129 }
$objectManager
Definition: bootstrap.php:17
$paymentInfo