Skip to content

Commit 42dc1ce

Browse files
committed
Merge remote-tracking branch 'remotes/origin/MAGETWO-69607' into MPI-PR-Bugfixes
2 parents 9ebd710 + af54910 commit 42dc1ce

File tree

5 files changed

+97
-21
lines changed

5 files changed

+97
-21
lines changed

app/code/Magento/Braintree/Gateway/Request/ChannelDataBuilder.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,16 @@
55
*/
66
namespace Magento\Braintree\Gateway\Request;
77

8-
use Magento\Payment\Gateway\Request\BuilderInterface;
8+
use Magento\Framework\App\ObjectManager;
99
use Magento\Framework\App\ProductMetadataInterface;
10+
use Magento\Payment\Gateway\Config\Config;
11+
use Magento\Payment\Gateway\Request\BuilderInterface;
1012

1113
/**
1214
* Class BnCodeDataBuilder
1315
*/
1416
class ChannelDataBuilder implements BuilderInterface
1517
{
16-
/**
17-
* @var ProductMetadataInterface
18-
*/
19-
private $productMetadata;
20-
2118
/**
2219
* @var string
2320
*/
@@ -28,23 +25,36 @@ class ChannelDataBuilder implements BuilderInterface
2825
*/
2926
private static $channelValue = 'Magento2_Cart_%s_BT';
3027

28+
/**
29+
* @var ProductMetadataInterface
30+
*/
31+
private $productMetadata;
32+
33+
/**
34+
* @var Config
35+
*/
36+
private $config;
37+
3138
/**
3239
* Constructor
3340
*
3441
* @param ProductMetadataInterface $productMetadata
42+
* @param Config $config
3543
*/
36-
public function __construct(ProductMetadataInterface $productMetadata)
44+
public function __construct(ProductMetadataInterface $productMetadata, Config $config = null)
3745
{
3846
$this->productMetadata = $productMetadata;
47+
$this->config = $config ?: ObjectManager::getInstance()->get(Config::class);
3948
}
4049

4150
/**
4251
* @inheritdoc
4352
*/
4453
public function build(array $buildSubject)
4554
{
55+
$channel = $this->config->getValue('channel');
4656
return [
47-
self::$channel => sprintf(self::$channelValue, $this->productMetadata->getEdition())
57+
self::$channel => $channel ?: sprintf(self::$channelValue, $this->productMetadata->getEdition())
4858
];
4959
}
5060
}

app/code/Magento/Braintree/Test/Unit/Gateway/Request/ChannelDataBuilderTest.php

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
use Magento\Braintree\Gateway\Request\ChannelDataBuilder;
99
use Magento\Framework\App\ProductMetadataInterface;
10+
use Magento\Payment\Gateway\Config\Config;
11+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1012

1113
/**
1214
* Class PaymentDataBuilderTest
@@ -16,19 +18,32 @@
1618
class ChannelDataBuilderTest extends \PHPUnit_Framework_TestCase
1719
{
1820
/**
19-
* @var ProductMetadataInterface|\PHPUnit_Framework_MockObject_MockObject
21+
* @var ProductMetadataInterface|MockObject
2022
*/
21-
private $productMetadataMock;
23+
private $productMetadata;
24+
25+
/**
26+
* @var Config|MockObject
27+
*/
28+
private $config;
2229

2330
/**
2431
* @var ChannelDataBuilder
2532
*/
2633
private $builder;
2734

35+
/**
36+
* @inheritdoc
37+
*/
2838
protected function setUp()
2939
{
30-
$this->productMetadataMock = $this->getMock(ProductMetadataInterface::class);
31-
$this->builder = new ChannelDataBuilder($this->productMetadataMock);
40+
$this->productMetadata = $this->getMockBuilder(ProductMetadataInterface::class)
41+
->disableOriginalConstructor()
42+
->getMock();
43+
$this->config = $this->getMockBuilder(Config::class)
44+
->disableOriginalConstructor()
45+
->getMock();
46+
$this->builder = new ChannelDataBuilder($this->productMetadata, $this->config);
3247
}
3348

3449
/**
@@ -40,11 +55,37 @@ protected function setUp()
4055
public function testBuild($edition, array $expected)
4156
{
4257
$buildSubject = [];
43-
$this->productMetadataMock->expects(static::once())
44-
->method('getEdition')
58+
59+
$this->config->method('getValue')
60+
->with(self::equalTo('channel'))
61+
->willReturn(null);
62+
63+
$this->productMetadata->method('getEdition')
4564
->willReturn($edition);
4665

47-
$this->assertEquals($expected, $this->builder->build($buildSubject));
66+
self::assertEquals($expected, $this->builder->build($buildSubject));
67+
}
68+
69+
/**
70+
* Checks a case when a channel provided via payment method configuration.
71+
*/
72+
public function testBuildWithChannelFromConfig()
73+
{
74+
$channel = 'Magento2_Cart_ConfigEdition_BT';
75+
76+
$this->config->method('getValue')
77+
->with(self::equalTo('channel'))
78+
->willReturn($channel);
79+
80+
$this->productMetadata->expects(self::never())
81+
->method('getEdition');
82+
83+
self::assertEquals(
84+
[
85+
'channel' => $channel
86+
],
87+
$this->builder->build([])
88+
);
4889
}
4990

5091
/**

app/code/Magento/Braintree/etc/di.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@
187187
</type>
188188
<!-- END command managers section for Vault -->
189189

190+
<type name="Magento\Braintree\Gateway\Request\ChannelDataBuilder">
191+
<arguments>
192+
<argument name="config" xsi:type="object">Magento\Braintree\Gateway\Config\Config</argument>
193+
</arguments>
194+
</type>
195+
190196
<!-- Braintree commands -->
191197
<virtualType name="BraintreeAuthorizeCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
192198
<arguments>

app/code/Magento/Paypal/Model/AbstractConfig.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,8 @@ public function isMethodSupportedForCountry($method = null, $countryCode = null)
335335
*/
336336
public function getBuildNotationCode()
337337
{
338-
return sprintf(self::$bnCode, $this->getProductMetadata()->getEdition());
338+
$notationCode = $this->_scopeConfig->getValue('paypal/notation_code', ScopeInterface::SCOPE_STORES);
339+
return $notationCode ?: sprintf(self::$bnCode, $this->getProductMetadata()->getEdition());
339340
}
340341

341342
/**

app/code/Magento/Paypal/Test/Unit/Model/AbstractConfigTest.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,16 @@ public function testIsMethodActive()
290290
$this->config->isMethodActive('method');
291291
}
292292

293+
/**
294+
* Checks a case, when notation code based on Magento edition.
295+
*/
293296
public function testGetBuildNotationCode()
294297
{
295-
$productMetadata = $this->getMock(ProductMetadataInterface::class, [], [], '', false);
296-
$productMetadata->expects($this->once())
297-
->method('getEdition')
298-
->will($this->returnValue('SomeEdition'));
298+
$productMetadata = $this->getMockBuilder(ProductMetadataInterface::class)
299+
->disableOriginalConstructor()
300+
->getMock();
301+
$productMetadata->method('getEdition')
302+
->willReturn('SomeEdition');
299303

300304
$objectManagerHelper = new ObjectManagerHelper($this);
301305
$objectManagerHelper->setBackwardCompatibleProperty(
@@ -304,6 +308,20 @@ public function testGetBuildNotationCode()
304308
$productMetadata
305309
);
306310

307-
$this->assertEquals('Magento_Cart_SomeEdition', $this->config->getBuildNotationCode());
311+
self::assertEquals('Magento_Cart_SomeEdition', $this->config->getBuildNotationCode());
312+
}
313+
314+
/**
315+
* Checks a case, when notation code should be provided from configuration.
316+
*/
317+
public function testBuildNotationCodeFromConfig()
318+
{
319+
$notationCode = 'Magento_Cart_EditionFromConfig';
320+
321+
$this->scopeConfigMock->method('getValue')
322+
->with(self::equalTo('paypal/notation_code'), self::equalTo('stores'))
323+
->willReturn($notationCode);
324+
325+
self::assertEquals($notationCode, $this->config->getBuildNotationCode());
308326
}
309327
}

0 commit comments

Comments
 (0)