|
7 | 7 |
|
8 | 8 | class DataTest extends \PHPUnit_Framework_TestCase
|
9 | 9 | {
|
| 10 | + /** |
| 11 | + * @var string |
| 12 | + */ |
| 13 | + private static $htmlTransactionId = |
| 14 | + '<a target="_blank" href="https://www%1$s.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=%2$s">%2$s</a>'; |
| 15 | + |
| 16 | + /** |
| 17 | + * @var string |
| 18 | + */ |
| 19 | + private static $txnId = 'XXX123123XXX'; |
| 20 | + |
10 | 21 | /**
|
11 | 22 | * @var \Magento\Payment\Api\PaymentMethodListInterface|\PHPUnit_Framework_MockObject_MockObject
|
12 | 23 | */
|
@@ -37,13 +48,10 @@ protected function setUp()
|
37 | 48 | \Magento\Payment\Model\Method\InstanceFactory::class
|
38 | 49 | )->disableOriginalConstructor()->getMock();
|
39 | 50 |
|
40 |
| - $this->configMock = $this->getMock( |
41 |
| - \Magento\Paypal\Model\Config::class, |
42 |
| - [], |
43 |
| - [], |
44 |
| - '', |
45 |
| - false |
46 |
| - ); |
| 51 | + $this->configMock = $this->getMockBuilder(\Magento\Paypal\Model\Config::class) |
| 52 | + ->disableOriginalConstructor() |
| 53 | + ->getMock(); |
| 54 | + |
47 | 55 | $configMockFactory = $this->getMockBuilder(\Magento\Paypal\Model\ConfigFactory::class)
|
48 | 56 | ->disableOriginalConstructor()
|
49 | 57 | ->setMethods(['create'])
|
@@ -138,34 +146,68 @@ public function getBillingAgreementMethodsDataProvider()
|
138 | 146 | }
|
139 | 147 |
|
140 | 148 | /**
|
| 149 | + * Sandbox mode |
| 150 | + * Expected link <a target="_blank" href="https://www.sandbox.paypal.com/...</a> |
| 151 | + * |
141 | 152 | * @param string $methodCode
|
142 |
| - * @param string $htmlTransactionId |
143 | 153 | * @dataProvider testGetHtmlTransactionIdProvider
|
144 | 154 | */
|
145 |
| - public function testGetHtmlTransactionId($methodCode, $htmlTransactionId) |
| 155 | + public function testGetHtmlTransactionSandboxLink($methodCode) |
146 | 156 | {
|
147 |
| - $txnId = 'XXX123123XXX'; |
148 |
| - $htmlTransactionId = sprintf($htmlTransactionId, 'sandbox', $txnId); |
| 157 | + $expectedLink = sprintf(self::$htmlTransactionId, '.sandbox', self::$txnId); |
149 | 158 |
|
150 |
| - $this->configMock->expects($this->any()) |
| 159 | + $this->configMock->expects($this->once()) |
151 | 160 | ->method('getValue')
|
152 |
| - ->with($this->stringContains('sandboxFlag')) |
| 161 | + ->with('sandboxFlag') |
153 | 162 | ->willReturn(true);
|
154 | 163 |
|
155 |
| - $this->assertEquals($htmlTransactionId, $this->_helper->getHtmlTransactionId($methodCode, $txnId)); |
| 164 | + $this->assertEquals( |
| 165 | + $expectedLink, |
| 166 | + $this->_helper->getHtmlTransactionId($methodCode, self::$txnId) |
| 167 | + ); |
| 168 | + } |
| 169 | + |
| 170 | + /** |
| 171 | + * Real mode |
| 172 | + * Expected link <a target="_blank" href="https://www.paypal.com/... </a> |
| 173 | + * |
| 174 | + * @param string $methodCode |
| 175 | + * @dataProvider testGetHtmlTransactionIdProvider |
| 176 | + */ |
| 177 | + public function testGetHtmlTransactionRealLink($methodCode) |
| 178 | + { |
| 179 | + $expectedLink = sprintf(self::$htmlTransactionId, '', self::$txnId); |
| 180 | + |
| 181 | + $this->configMock->expects($this->once()) |
| 182 | + ->method('getValue') |
| 183 | + ->with('sandboxFlag') |
| 184 | + ->willReturn(false); |
| 185 | + |
| 186 | + $this->assertEquals( |
| 187 | + $expectedLink, |
| 188 | + $this->_helper->getHtmlTransactionId($methodCode, self::$txnId) |
| 189 | + ); |
156 | 190 | }
|
157 | 191 |
|
158 | 192 | /**
|
159 | 193 | * @return array
|
160 | 194 | */
|
161 | 195 | public function testGetHtmlTransactionIdProvider()
|
162 | 196 | {
|
163 |
| - $htmlTransactionId = |
164 |
| - '<a target="_blank" href="https://www.%1$s.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=%2$s">%2$s</a>'; |
165 | 197 | return [
|
166 |
| - ['paypal_express', $htmlTransactionId], |
167 |
| - ['payflow_express', 'XXX123123XXX'], |
168 |
| - ['hosted_pro', $htmlTransactionId] |
| 198 | + ['paypal_express'], |
| 199 | + ['hosted_pro'] |
169 | 200 | ];
|
170 | 201 | }
|
| 202 | + |
| 203 | + /** |
| 204 | + * Invokes with method not in payment list |
| 205 | + * Expected result just returned txtId: "XXX123123XXX" |
| 206 | + */ |
| 207 | + public function testGetHtmlTransactionMethodNotInPaymentList() |
| 208 | + { |
| 209 | + $methodCode = 'payflow_express'; |
| 210 | + |
| 211 | + $this->assertEquals(self::$txnId, $this->_helper->getHtmlTransactionId($methodCode, self::$txnId)); |
| 212 | + } |
171 | 213 | }
|
0 commit comments