Skip to content

Commit 09ac761

Browse files
MAGETWO-63406: [Github] Paypal Payment Order Transaction ID Link will result to 404 not found
- Fixed returned link - Fixed unit tests
1 parent d166004 commit 09ac761

File tree

2 files changed

+63
-21
lines changed

2 files changed

+63
-21
lines changed

app/code/Magento/Paypal/Helper/Data.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class Data extends \Magento\Framework\App\Helper\AbstractHelper
1616
{
1717
const HTML_TRANSACTION_ID =
18-
'<a target="_blank" href="https://www.%1$s.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=%2$s">%2$s</a>';
18+
'<a target="_blank" href="https://www%1$s.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=%2$s">%2$s</a>';
1919

2020
/**
2121
* Cache for shouldAskToCreateBillingAgreement()
@@ -133,7 +133,7 @@ public function getHtmlTransactionId($methodCode, $txnId)
133133
if (in_array($methodCode, $this->methodCodes)) {
134134
/** @var \Magento\Paypal\Model\Config $config */
135135
$config = $this->configFactory->create()->setMethod($methodCode);
136-
$sandboxFlag = ($config->getValue('sandboxFlag') ? 'sandbox' : '');
136+
$sandboxFlag = ($config->getValue('sandboxFlag') ? '.sandbox' : '');
137137
return sprintf(self::HTML_TRANSACTION_ID, $sandboxFlag, $txnId);
138138
}
139139
return $txnId;

app/code/Magento/Paypal/Test/Unit/Helper/DataTest.php

Lines changed: 61 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77

88
class DataTest extends \PHPUnit_Framework_TestCase
99
{
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+
1021
/**
1122
* @var \Magento\Payment\Api\PaymentMethodListInterface|\PHPUnit_Framework_MockObject_MockObject
1223
*/
@@ -37,13 +48,10 @@ protected function setUp()
3748
\Magento\Payment\Model\Method\InstanceFactory::class
3849
)->disableOriginalConstructor()->getMock();
3950

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+
4755
$configMockFactory = $this->getMockBuilder(\Magento\Paypal\Model\ConfigFactory::class)
4856
->disableOriginalConstructor()
4957
->setMethods(['create'])
@@ -138,34 +146,68 @@ public function getBillingAgreementMethodsDataProvider()
138146
}
139147

140148
/**
149+
* Sandbox mode
150+
* Expected link <a target="_blank" href="https://www.sandbox.paypal.com/...</a>
151+
*
141152
* @param string $methodCode
142-
* @param string $htmlTransactionId
143153
* @dataProvider testGetHtmlTransactionIdProvider
144154
*/
145-
public function testGetHtmlTransactionId($methodCode, $htmlTransactionId)
155+
public function testGetHtmlTransactionSandboxLink($methodCode)
146156
{
147-
$txnId = 'XXX123123XXX';
148-
$htmlTransactionId = sprintf($htmlTransactionId, 'sandbox', $txnId);
157+
$expectedLink = sprintf(self::$htmlTransactionId, '.sandbox', self::$txnId);
149158

150-
$this->configMock->expects($this->any())
159+
$this->configMock->expects($this->once())
151160
->method('getValue')
152-
->with($this->stringContains('sandboxFlag'))
161+
->with('sandboxFlag')
153162
->willReturn(true);
154163

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+
);
156190
}
157191

158192
/**
159193
* @return array
160194
*/
161195
public function testGetHtmlTransactionIdProvider()
162196
{
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>';
165197
return [
166-
['paypal_express', $htmlTransactionId],
167-
['payflow_express', 'XXX123123XXX'],
168-
['hosted_pro', $htmlTransactionId]
198+
['paypal_express'],
199+
['hosted_pro']
169200
];
170201
}
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+
}
171213
}

0 commit comments

Comments
 (0)