Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PayflowConfigTest.php
Go to the documentation of this file.
1 <?php
7 
15 
19 class PayflowConfigTest extends \PHPUnit\Framework\TestCase
20 {
21 
25  protected $scopeConfigMock;
26 
31 
35  protected $config;
36 
37  protected function setUp()
38  {
39  $this->scopeConfigMock = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
40  ->setMethods(['getValue', 'isSetFlag'])
41  ->getMockForAbstractClass();
42  $this->methodInterfaceMock = $this->getMockBuilder(\Magento\Payment\Model\MethodInterface::class)
43  ->getMockForAbstractClass();
44 
45  $om = new ObjectManager($this);
46  $this->config = $om->getObject(
47  \Magento\Paypal\Model\PayflowConfig::class,
48  [
49  'scopeConfig' => $this->scopeConfigMock
50  ]
51  );
52  }
53 
60  public function testGetTrxType($paymentAction, $expectedValue)
61  {
62  $this->scopeConfigMock->expects($this->any())
63  ->method('getValue')
64  ->willReturn($paymentAction);
65 
66  $this->assertEquals($expectedValue, $this->config->getTrxType());
67  }
68 
72  public function getTrxTypeDataProvider()
73  {
74  return [
77  ['other', null],
78  ];
79  }
80 
87  public function testGetPaymentAction($paymentAction, $expectedValue)
88  {
89  $this->scopeConfigMock->expects($this->any())
90  ->method('getValue')
91  ->willReturn($paymentAction);
92 
93  $this->assertEquals($expectedValue, $this->config->getPaymentAction());
94  }
95 
99  public function getPaymentActionDataProvider()
100  {
101  return [
104  ['other', null],
105  ];
106  }
107 
109  {
110  $this->scopeConfigMock->expects($this->never())
111  ->method('getValue');
112  $this->methodInterfaceMock->expects($this->once())
113  ->method('getConfigData')
114  ->with('transaction_url_test_mode')
115  ->willReturn('transaction_url_test_mode');
116 
117  $this->config->setMethodInstance($this->methodInterfaceMock);
118  $this->assertEquals('transaction_url_test_mode', $this->config->getTransactionUrl(1));
119  }
120 
122  {
123  $this->scopeConfigMock->expects($this->never())
124  ->method('getValue');
125  $this->methodInterfaceMock->expects($this->once())
126  ->method('getConfigData')
127  ->with('transaction_url')
128  ->willReturn('transaction_url');
129 
130  $this->config->setMethodInstance($this->methodInterfaceMock);
131  $this->assertEquals('transaction_url', $this->config->getTransactionUrl(0));
132  }
133 
135  {
136  $this->scopeConfigMock->expects($this->once())
137  ->method('getValue')
138  ->willReturn(1);
139  $this->methodInterfaceMock->expects($this->once())
140  ->method('getConfigData')
141  ->with('transaction_url_test_mode')
142  ->willReturn('transaction_url_test_mode');
143 
144  $this->config->setMethodInstance($this->methodInterfaceMock);
145  $this->assertEquals('transaction_url_test_mode', $this->config->getTransactionUrl());
146  }
147 
149  {
150  $this->scopeConfigMock->expects($this->once())
151  ->method('getValue')
152  ->willReturn(0);
153  $this->methodInterfaceMock->expects($this->once())
154  ->method('getConfigData')
155  ->with('transaction_url')
156  ->willReturn('transaction_url');
157 
158  $this->config->setMethodInstance($this->methodInterfaceMock);
159  $this->assertEquals('transaction_url', $this->config->getTransactionUrl());
160  }
161 
169  public function testIsMethodActive(array $expectsMethods, $currentMethod, $result)
170  {
171  $this->config->setStoreId(5);
172 
173  $this->scopeConfigMock->expects($this->any())
174  ->method('getValue')
175  ->with('paypal/general/merchant_country')
176  ->will($this->returnValue('US'));
177 
178  $i = 0;
179  foreach ($expectsMethods as $method => $isActive) {
180  $this->scopeConfigMock->expects($this->at($i++))
181  ->method('isSetFlag')
182  ->with(
183  "payment/{$method}/active",
185  5
186  )->willReturn($isActive);
187  }
188 
189  $this->assertEquals($result, $this->config->isMethodActive($currentMethod));
190  }
191 
196  {
197  return [
198  [
199  'expectsMethods' => [
202  ],
203  'currentMethod' => Config::METHOD_PAYMENT_PRO,
204  'result' => true,
205  ],
206  [
207  'expectsMethods' => [
209  ],
210  'currentMethod' => Config::METHOD_PAYFLOWPRO,
211  'result' => true,
212  ],
213  [
214  'expectsMethods' => [
217  ],
218  'currentMethod' => 777,
219  'result' => false,
220  ],
221  ];
222  }
223 }
testGetPaymentAction($paymentAction, $expectedValue)
testGetTrxType($paymentAction, $expectedValue)
$method
Definition: info.phtml:13
$om
testIsMethodActive(array $expectsMethods, $currentMethod, $result)
$i
Definition: gallery.phtml:31