Skip to content

Commit ca53c80

Browse files
author
Volodymyr Klymenko
authored
Merge pull request #1284 from magento-east/pr-218
[East] Bugfix for 2.1.8
2 parents 0ad9891 + ca1c4bd commit ca53c80

File tree

4 files changed

+114
-20
lines changed

4 files changed

+114
-20
lines changed

app/code/Magento/Paypal/Model/Payflow/Service/Request/SecureToken.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Paypal\Model\Payflow\Service\Request;
78

89
use Magento\Framework\Math\Random;
@@ -11,7 +12,6 @@
1112
use Magento\Paypal\Model\Payflow\Transparent;
1213
use Magento\Paypal\Model\Payflowpro;
1314
use Magento\Quote\Model\Quote;
14-
use Magento\Sales\Model\Order\Payment;
1515

1616
/**
1717
* Class SecureToken
@@ -64,6 +64,7 @@ public function requestToken(Quote $quote)
6464
$request->setTrxtype(Payflowpro::TRXTYPE_AUTH_ONLY);
6565
$request->setVerbosity('HIGH');
6666
$request->setAmt(0);
67+
$request->setCurrency($quote->getBaseCurrencyCode());
6768
$request->setCreatesecuretoken('Y');
6869
$request->setSecuretokenid($this->mathRandom->getUniqueHash());
6970
$request->setReturnurl($this->url->getUrl('paypal/transparent/response'));

app/code/Magento/Paypal/Test/Unit/Model/Payflow/Service/Request/SecureTokenTest.php

Lines changed: 85 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Paypal\Test\Unit\Model\Payflow\Service\Request;
78

89
use Magento\Framework\Math\Random;
910
use Magento\Framework\DataObject;
1011
use Magento\Framework\UrlInterface;
1112
use Magento\Paypal\Model\Payflow\Service\Request\SecureToken;
1213
use Magento\Paypal\Model\Payflow\Transparent;
14+
use Magento\Paypal\Model\PayflowConfig;
15+
use Magento\Quote\Model\Quote;
1316

1417
/**
1518
* Test class for \Magento\Paypal\Model\Payflow\Service\Request\SecureToken
@@ -36,11 +39,16 @@ class SecureTokenTest extends \PHPUnit_Framework_TestCase
3639
*/
3740
protected $url;
3841

42+
/** @var DataObject */
43+
private $request;
44+
3945
protected function setUp()
4046
{
41-
$this->url = $this->getMock('Magento\Framework\UrlInterface', [], [], '', false);
42-
$this->mathRandom = $this->getMock('Magento\Framework\Math\Random', [], [], '', false);
43-
$this->transparent = $this->getMock('Magento\Paypal\Model\Payflow\Transparent', [], [], '', false);
47+
$this->url = $this->buildMock(UrlInterface::class);
48+
$this->mathRandom = $this->buildMock(Random::class);
49+
$this->request = new DataObject();
50+
51+
$this->transparent = $this->buildPaymentService($this->request);
4452

4553
$this->model = new SecureToken(
4654
$this->url,
@@ -49,34 +57,93 @@ protected function setUp()
4957
);
5058
}
5159

60+
/**
61+
* Test Request Token
62+
*/
5263
public function testRequestToken()
5364
{
54-
$request = new DataObject();
5565
$secureTokenID = 'Sdj46hDokds09c8k2klaGJdKLl032ekR';
5666

57-
$this->transparent->expects($this->once())
58-
->method('buildBasicRequest')
59-
->willReturn($request);
60-
$this->transparent->expects($this->once())
61-
->method('fillCustomerContacts');
62-
$this->transparent->expects($this->once())
63-
->method('getConfig')
64-
->willReturn($this->getMock('Magento\Paypal\Model\PayflowConfig', [], [], '', false));
65-
$this->transparent->expects($this->once())
66-
->method('postRequest')
67-
->willReturn(new DataObject());
68-
6967
$this->mathRandom->expects($this->once())
7068
->method('getUniqueHash')
7169
->willReturn($secureTokenID);
7270

7371
$this->url->expects($this->exactly(3))
7472
->method('getUrl');
7573

76-
$quote = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false);
74+
/** @var Quote | \PHPUnit_Framework_MockObject_MockObject $quote */
75+
$quote = $this->buildMock(Quote::class);
76+
77+
$this->model->requestToken($quote);
78+
79+
$this->assertEquals($secureTokenID, $this->request->getSecuretokenid());
80+
}
81+
82+
/**
83+
* Test request currency
84+
*
85+
* @dataProvider currencyProvider
86+
* @param $currency
87+
*/
88+
public function testCurrency($currency)
89+
{
90+
/** @var Quote | \PHPUnit_Framework_MockObject_MockObject $quote */
91+
$quote = $this->buildMock(Quote::class, ['getBaseCurrencyCode']);
92+
$quote->expects(self::atLeastOnce())
93+
->method('getBaseCurrencyCode')
94+
->willReturn($currency);
7795

7896
$this->model->requestToken($quote);
7997

80-
$this->assertEquals($secureTokenID, $request->getSecuretokenid());
98+
$this->assertEquals($currency, $this->request->getCurrency());
99+
}
100+
101+
/**
102+
* Builds default mock object
103+
*
104+
* @param string $class className
105+
* @param array|null $methods
106+
* @return \PHPUnit_Framework_MockObject_MockObject
107+
*/
108+
private function buildMock($class, array $methods = [])
109+
{
110+
return $this->getMockBuilder($class)
111+
->disableOriginalConstructor()
112+
->setMethods($methods)
113+
->getMock();
114+
}
115+
116+
/**
117+
* Creates payment method service
118+
*
119+
* @param DataObject $request
120+
* @return Transparent | \PHPUnit_Framework_MockObject_MockObject
121+
*/
122+
private function buildPaymentService(DataObject $request)
123+
{
124+
$service = $this->buildMock(Transparent::class);
125+
$service->expects($this->once())
126+
->method('buildBasicRequest')
127+
->willReturn($request);
128+
$service->expects($this->once())
129+
->method('fillCustomerContacts');
130+
$service->expects($this->once())
131+
->method('getConfig')
132+
->willReturn($this->buildMock(PayflowConfig::class));
133+
$service->expects($this->once())
134+
->method('postRequest')
135+
->willReturn(new DataObject());
136+
137+
return $service;
138+
}
139+
140+
/**
141+
* DataProvider for testing currency
142+
*
143+
* @return array
144+
*/
145+
public function currencyProvider()
146+
{
147+
return [['GBP'], [null], ['USD']];
81148
}
82149
}

dev/tests/functional/tests/app/Magento/Dhl/Test/TestCase/OnePageCheckoutTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<data name="shipping/shipping_method" xsi:type="string">Express easy</data>
1818
<data name="cart/data/shipping_method" xsi:type="string">Express easy</data>
1919
<data name="payment/method" xsi:type="string">checkmo</data>
20-
<data name="configData" xsi:type="string">checkmo, dhl_eu, shipping_origin_CH, config_base_currency_ch</data>
20+
<data name="configData" xsi:type="string">checkmo, dhl_eu, shipping_origin_GB, config_base_currency_gb</data>
2121
<data name="tag" xsi:type="string">test_type:3rd_party_test</data>
2222
<constraint name="Magento\Checkout\Test\Constraint\AssertOrderSuccessPlacedMessage" />
2323
<constraint name="Magento\Checkout\Test\Constraint\AssertMinicartEmpty" />

dev/tests/functional/tests/app/Magento/Shipping/Test/Repository/ConfigData.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,31 @@
111111
<item name="value" xsi:type="string">Weinbergstrasse 4</item>
112112
</field>
113113
</dataset>
114+
<dataset name="shipping_origin_GB">
115+
<field name="shipping/origin/country_id" xsi:type="array">
116+
<item name="scope" xsi:type="string">carriers</item>
117+
<item name="scope_id" xsi:type="number">1</item>
118+
<item name="label" xsi:type="string">United Kingdom</item>
119+
<item name="value" xsi:type="string">GB</item>
120+
</field>
121+
<field name="shipping/origin/postcode" xsi:type="array">
122+
<item name="scope" xsi:type="string">shipping</item>
123+
<item name="scope_id" xsi:type="number">1</item>
124+
<item name="label" xsi:type="string"/>
125+
<item name="value" xsi:type="string">SW1W 8JA</item>
126+
</field>
127+
<field name="shipping/origin/city" xsi:type="array">
128+
<item name="scope" xsi:type="string">shipping</item>
129+
<item name="scope_id" xsi:type="number">1</item>
130+
<item name="label" xsi:type="string"/>
131+
<item name="value" xsi:type="string">London</item>
132+
</field>
133+
<field name="shipping/origin/street_line1" xsi:type="array">
134+
<item name="scope" xsi:type="string">shipping</item>
135+
<item name="scope_id" xsi:type="number">1</item>
136+
<item name="label" xsi:type="string"/>
137+
<item name="value" xsi:type="string">Bourne St</item>
138+
</field>
139+
</dataset>
114140
</repository>
115141
</config>

0 commit comments

Comments
 (0)