Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PayflowlinkTest.php
Go to the documentation of this file.
1 <?php
7 
12 
16 class PayflowlinkTest extends \PHPUnit\Framework\TestCase
17 {
19  protected $model;
20 
22  protected $infoInstance;
23 
25  protected $payflowRequest;
26 
28  protected $paypalConfig;
29 
31  protected $store;
32 
34  private $gatewayMock;
35 
37  protected $scopeConfigMock;
38 
39  protected function setUp()
40  {
41  $this->store = $this->createMock(\Magento\Store\Model\Store::class);
42  $storeManager = $this->createMock(
43  \Magento\Store\Model\StoreManagerInterface::class
44  );
45  $this->paypalConfig = $this->getMockBuilder(\Magento\Paypal\Model\Config::class)
46  ->disableOriginalConstructor()
47  ->getMock();
48 
49  $configFactoryMock = $this->getMockBuilder(\Magento\Payment\Model\Method\ConfigInterfaceFactory::class)
50  ->setMethods(['create'])
51  ->disableOriginalConstructor()
52  ->getMock();
53 
54  $requestFactory = $this->getMockBuilder(\Magento\Paypal\Model\Payflow\RequestFactory::class)
55  ->setMethods(['create'])
56  ->disableOriginalConstructor()
57  ->getMock();
58 
59  $this->payflowRequest = $this->getMockBuilder(\Magento\Paypal\Model\Payflow\Request::class)
60  ->disableOriginalConstructor()
61  ->getMock();
62 
63  $this->infoInstance = $this->getMockBuilder(\Magento\Sales\Model\Order\Payment::class)
64  ->disableOriginalConstructor()
65  ->getMock();
66 
67  $this->scopeConfigMock = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
68  ->getMockForAbstractClass();
69 
70  $this->gatewayMock = $this->getMockBuilder(\Magento\Paypal\Model\Payflow\Service\Gateway::class)
71  ->disableOriginalConstructor()
72  ->getMock();
73 
74  $storeManager->expects($this->any())->method('getStore')->will($this->returnValue($this->store));
75  $configFactoryMock->expects($this->any())
76  ->method('create')
77  ->willReturn($this->paypalConfig);
78  $this->payflowRequest->expects($this->any())
79  ->method('__call')
80  ->will($this->returnCallback(function ($method) {
81  if (strpos($method, 'set') === 0) {
82  return $this->payflowRequest;
83  }
84  return null;
85  }));
86  $requestFactory->expects($this->any())->method('create')->will($this->returnValue($this->payflowRequest));
87 
88  $helper = new ObjectManagerHelper($this);
89  $this->model = $helper->getObject(
90  \Magento\Paypal\Model\Payflowlink::class,
91  [
92  'scopeConfig' => $this->scopeConfigMock,
93  'storeManager' => $storeManager,
94  'configFactory' => $configFactoryMock,
95  'requestFactory' => $requestFactory,
96  'gateway' => $this->gatewayMock,
97  ]
98  );
99  $this->model->setInfoInstance($this->infoInstance);
100  }
101 
102  public function testInitialize()
103  {
104  $storeId = 1;
105  $order = $this->createMock(\Magento\Sales\Model\Order::class);
106  $order->expects($this->exactly(2))
107  ->method('getStoreId')
108  ->willReturn($storeId);
109  $this->infoInstance->expects($this->any())
110  ->method('getOrder')
111  ->willReturn($order);
112  $this->infoInstance->expects($this->any())
113  ->method('setAdditionalInformation')
114  ->willReturnSelf();
115  $this->paypalConfig->expects($this->once())
116  ->method('getBuildNotationCode')
117  ->willReturn('build notation code');
118 
119  $response = new \Magento\Framework\DataObject(
120  [
121  'result' => '0',
122  'pnref' => 'V19A3D27B61E',
123  'respmsg' => 'Approved',
124  'authcode' => '510PNI',
125  'hostcode' => 'A',
126  'request_id' => 'f930d3dc6824c1f7230c5529dc37ae5e',
127  'result_code' => '0',
128  ]
129  );
130  $this->gatewayMock->expects($this->once())
131  ->method('postRequest')
132  ->willReturn($response);
133 
134  $this->payflowRequest->expects($this->exactly(3))
135  ->method('setData')
136  ->willReturnMap(
137  [
138  [
139  'user' => null,
140  'vendor' => null,
141  'partner' => null,
142  'pwd' => null,
143  'verbosity' => null,
144  'BUTTONSOURCE' => 'build notation code',
145  'tender' => 'C',
146  ],
147  $this->returnSelf()
148  ],
149  ['USER1', 1, $this->returnSelf()],
150  ['USER2', 'a20d3dc6824c1f7780c5529dc37ae5e', $this->returnSelf()]
151  );
152 
153  $stateObject = new \Magento\Framework\DataObject();
154  $this->model->initialize(\Magento\Paypal\Model\Config::PAYMENT_ACTION_AUTH, $stateObject);
155  self::assertEquals($storeId, $this->model->getStore(), '{Store} should be set');
156  }
157 
163  public function testIsActive($expectedResult, $configResult)
164  {
165  $storeId = 15;
166  $this->scopeConfigMock->expects($this->once())
167  ->method('getValue')
168  ->with(
169  "payment/payflow_link/active",
171  $storeId
172  )->willReturn($configResult);
173 
174  $this->assertEquals($expectedResult, $this->model->isActive($storeId));
175  }
176 
180  public function dataProviderForTestIsActive()
181  {
182  return [
183  [false, '0'],
184  [true, '1']
185  ];
186  }
187 
191  public function testGetInfoBlockType()
192  {
193  static::assertEquals(Info::class, $this->model->getInfoBlockType());
194  }
195 }
$response
Definition: 404.php:11
$helper
Definition: iframe.phtml:13
$order
Definition: order.php:55
$storeManager
$method
Definition: info.phtml:13