Skip to content

Commit 51adb9d

Browse files
committed
Merge remote-tracking branch 'upstream/2.2-develop' into magento#14020-Cart-Sales-Rule-with-negated-condition-over-special-price-does-not-work-for-configurable-products
2 parents 5c3154b + 840d5b2 commit 51adb9d

File tree

40 files changed

+714
-121
lines changed

40 files changed

+714
-121
lines changed

app/bootstrap.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,16 @@
5454
&& isset($_SERVER['HTTP_ACCEPT'])
5555
&& strpos($_SERVER['HTTP_ACCEPT'], 'text/html') !== false
5656
) {
57-
$profilerFlag = isset($_SERVER['MAGE_PROFILER']) && strlen($_SERVER['MAGE_PROFILER'])
57+
$profilerConfig = isset($_SERVER['MAGE_PROFILER']) && strlen($_SERVER['MAGE_PROFILER'])
5858
? $_SERVER['MAGE_PROFILER']
5959
: trim(file_get_contents(BP . '/var/profiler.flag'));
6060

61-
\Magento\Framework\Profiler::applyConfig(
62-
$profilerFlag,
61+
if ($profilerConfig) {
62+
$profilerConfig = json_decode($profilerConfig, true) ?: $profilerConfig;
63+
}
64+
65+
Magento\Framework\Profiler::applyConfig(
66+
$profilerConfig,
6367
BP,
6468
!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'
6569
);
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Braintree\Test\Unit\Model\InstantPurchase\CreditCard;
9+
10+
use Magento\Braintree\Gateway\Config\Config;
11+
use Magento\Braintree\Model\InstantPurchase\CreditCard\AvailabilityChecker;
12+
13+
/**
14+
* @covers \Magento\Braintree\Model\InstantPurchase\CreditCard\AvailabilityChecker
15+
*/
16+
class AvailabilityCheckerTest extends \PHPUnit\Framework\TestCase
17+
{
18+
/**
19+
* Testable Object
20+
*
21+
* @var AvailabilityChecker
22+
*/
23+
private $availabilityChecker;
24+
25+
/**
26+
* @var Config|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
private $configMock;
29+
30+
/**
31+
* Set Up
32+
*
33+
* @return void
34+
*/
35+
protected function setUp()
36+
{
37+
$this->configMock = $this->createMock(Config::class);
38+
$this->availabilityChecker = new AvailabilityChecker($this->configMock);
39+
}
40+
41+
/**
42+
* Test isAvailable method
43+
*
44+
* @dataProvider isAvailableDataProvider
45+
*
46+
* @param bool $isVerify3DSecure
47+
* @param bool $expected
48+
*
49+
* @return void
50+
*/
51+
public function testIsAvailable(bool $isVerify3DSecure, bool $expected)
52+
{
53+
$this->configMock->expects($this->once())->method('isVerify3DSecure')->willReturn($isVerify3DSecure);
54+
$actual = $this->availabilityChecker->isAvailable();
55+
self::assertEquals($expected, $actual);
56+
}
57+
58+
/**
59+
* Data provider for isAvailable method test
60+
*
61+
* @return array
62+
*/
63+
public function isAvailableDataProvider()
64+
{
65+
return [
66+
[true, false],
67+
[false, true],
68+
];
69+
}
70+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Braintree\Test\Unit\Model\InstantPurchase;
9+
10+
use Magento\Braintree\Gateway\Command\GetPaymentNonceCommand;
11+
use Magento\Braintree\Model\InstantPurchase\PaymentAdditionalInformationProvider;
12+
use Magento\Payment\Gateway\Command\Result\ArrayResult;
13+
use Magento\Vault\Api\Data\PaymentTokenInterface;
14+
15+
/**
16+
* @covers \Magento\Braintree\Model\InstantPurchase\PaymentAdditionalInformationProvider
17+
*/
18+
class PaymentAdditionalInformationProviderTest extends \PHPUnit\Framework\TestCase
19+
{
20+
/**
21+
* Testable Object
22+
*
23+
* @var PaymentAdditionalInformationProvider
24+
*/
25+
private $paymentAdditionalInformationProvider;
26+
27+
/**
28+
* @var GetPaymentNonceCommand|\PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
private $getPaymentNonceCommandMock;
31+
32+
/**
33+
* @var PaymentTokenInterface|\PHPUnit_Framework_MockObject_MockObject
34+
*/
35+
private $paymentTokenMock;
36+
37+
/**
38+
* @var ArrayResult|\PHPUnit_Framework_MockObject_MockObject
39+
*/
40+
private $arrayResultMock;
41+
42+
/**
43+
* Set Up
44+
*
45+
* @return void
46+
*/
47+
protected function setUp()
48+
{
49+
$this->getPaymentNonceCommandMock = $this->createMock(GetPaymentNonceCommand::class);
50+
$this->paymentTokenMock = $this->createMock(PaymentTokenInterface::class);
51+
$this->arrayResultMock = $this->createMock(ArrayResult::class);
52+
$this->paymentAdditionalInformationProvider = new PaymentAdditionalInformationProvider(
53+
$this->getPaymentNonceCommandMock
54+
);
55+
}
56+
57+
/**
58+
* Test getAdditionalInformation method
59+
*
60+
* @return void
61+
*/
62+
public function testGetAdditionalInformation()
63+
{
64+
$customerId = 15;
65+
$publicHash = '3n4b7sn48g';
66+
$paymentMethodNonce = 'test';
67+
68+
$this->paymentTokenMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
69+
$this->paymentTokenMock->expects($this->once())->method('getPublicHash')->willReturn($publicHash);
70+
$this->getPaymentNonceCommandMock->expects($this->once())->method('execute')->with([
71+
PaymentTokenInterface::CUSTOMER_ID => $customerId,
72+
PaymentTokenInterface::PUBLIC_HASH => $publicHash,
73+
])->willReturn($this->arrayResultMock);
74+
$this->arrayResultMock->expects($this->once())->method('get')
75+
->willReturn(['paymentMethodNonce' => $paymentMethodNonce]);
76+
77+
$expected = [
78+
'payment_method_nonce' => $paymentMethodNonce,
79+
];
80+
$actual = $this->paymentAdditionalInformationProvider->getAdditionalInformation($this->paymentTokenMock);
81+
self::assertEquals($expected, $actual);
82+
}
83+
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Braintree\Test\Unit\Model;
9+
10+
use Magento\Braintree\Gateway\Config\PayPal\Config;
11+
use Magento\Braintree\Model\LocaleResolver;
12+
use Magento\Framework\Locale\ResolverInterface;
13+
14+
/**
15+
* @covers \Magento\Braintree\Model\LocaleResolver
16+
*/
17+
class LocaleResolverTest extends \PHPUnit\Framework\TestCase
18+
{
19+
/**
20+
* Testable Object
21+
*
22+
* @var LocaleResolver
23+
*/
24+
private $localeResolver;
25+
26+
/**
27+
* @var Config|\PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
private $configMock;
30+
31+
/**
32+
* @var ResolverInterface|\PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
private $resolverMock;
35+
36+
/**
37+
* Set Up
38+
*
39+
* @return void
40+
*/
41+
protected function setUp()
42+
{
43+
$this->configMock = $this->createMock(Config::class);
44+
$this->resolverMock = $this->createMock(ResolverInterface::class);
45+
$this->localeResolver = new LocaleResolver($this->resolverMock, $this->configMock);
46+
}
47+
48+
/**
49+
* Test getDefaultLocalePath method
50+
*
51+
* @return void
52+
*/
53+
public function testGetDefaultLocalePath()
54+
{
55+
$expected = 'general/locale/code';
56+
$this->resolverMock->expects($this->once())->method('getDefaultLocalePath')->willReturn($expected);
57+
$actual = $this->localeResolver->getDefaultLocalePath();
58+
self::assertEquals($expected, $actual);
59+
}
60+
61+
/**
62+
* Test setDefaultLocale method
63+
*
64+
* @return void
65+
*/
66+
public function testSetDefaultLocale()
67+
{
68+
$defaultLocale = 'en_US';
69+
$this->resolverMock->expects($this->once())->method('setDefaultLocale')->with($defaultLocale);
70+
$this->localeResolver->setDefaultLocale($defaultLocale);
71+
}
72+
73+
/**
74+
* Test getDefaultLocale method
75+
*
76+
* @return void
77+
*/
78+
public function testGetDefaultLocale()
79+
{
80+
$expected = 'fr_FR';
81+
$this->resolverMock->expects($this->once())->method('getDefaultLocale')->willReturn($expected);
82+
$actual = $this->localeResolver->getDefaultLocale();
83+
self::assertEquals($expected, $actual);
84+
}
85+
86+
/**
87+
* Test setLocale method
88+
*
89+
* @return void
90+
*/
91+
public function testSetLocale()
92+
{
93+
$locale = 'en_GB';
94+
$this->resolverMock->expects($this->once())->method('setLocale')->with($locale);
95+
$this->localeResolver->setLocale($locale);
96+
}
97+
98+
/**
99+
* Test getLocale method
100+
*
101+
* @return void
102+
*/
103+
public function testGetLocale()
104+
{
105+
$locale = 'en_TEST';
106+
$allowedLocales = 'en_US,en_GB,en_AU,da_DK,fr_FR,fr_CA,de_DE,zh_HK,it_IT,nl_NL';
107+
$this->resolverMock->expects($this->once())->method('getLocale')->willReturn($locale);
108+
$this->configMock->expects($this->once())->method('getValue')->with('supported_locales')
109+
->willReturn($allowedLocales);
110+
111+
$expected = 'en_US';
112+
$actual = $this->localeResolver->getLocale();
113+
self::assertEquals($expected, $actual);
114+
}
115+
116+
/**
117+
* Test emulate method
118+
*
119+
* @return void
120+
*/
121+
public function testEmulate()
122+
{
123+
$scopeId = 12;
124+
$this->resolverMock->expects($this->once())->method('emulate')->with($scopeId);
125+
$this->localeResolver->emulate($scopeId);
126+
}
127+
128+
/**
129+
* Test revert method
130+
*
131+
* @return void
132+
*/
133+
public function testRevert()
134+
{
135+
$this->resolverMock->expects($this->once())->method('revert');
136+
$this->localeResolver->revert();
137+
}
138+
}

app/code/Magento/Catalog/Model/Indexer/Product/Eav/AbstractAction.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Model\Indexer\Product\Eav;
79

810
/**
911
* Abstract action reindex class
1012
*/
1113
abstract class AbstractAction
1214
{
15+
/**
16+
* Config path for enable EAV indexer
17+
*/
18+
const ENABLE_EAV_INDEXER = 'catalog/search/enable_eav_indexer';
19+
1320
/**
1421
* EAV Indexers by type
1522
*
@@ -27,17 +34,27 @@ abstract class AbstractAction
2734
*/
2835
protected $_eavDecimalFactory;
2936

37+
/**
38+
* @var \Magento\Framework\App\Config\ScopeConfigInterface
39+
*/
40+
private $scopeConfig;
41+
3042
/**
3143
* AbstractAction constructor.
3244
* @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalFactory $eavDecimalFactory
3345
* @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory $eavSourceFactory
46+
* @param \Magento\Framework\App\Config\ScopeConfigInterface|null $scopeConfig
3447
*/
3548
public function __construct(
3649
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalFactory $eavDecimalFactory,
37-
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory $eavSourceFactory
50+
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory $eavSourceFactory,
51+
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig = null
3852
) {
3953
$this->_eavDecimalFactory = $eavDecimalFactory;
4054
$this->_eavSourceFactory = $eavSourceFactory;
55+
$this->scopeConfig = $scopeConfig ?: \Magento\Framework\App\ObjectManager::getInstance()->get(
56+
\Magento\Framework\App\Config\ScopeConfigInterface::class
57+
);
4158
}
4259

4360
/**
@@ -90,6 +107,9 @@ public function getIndexer($type)
90107
*/
91108
public function reindex($ids = null)
92109
{
110+
if (!$this->isEavIndexerEnabled()) {
111+
return;
112+
}
93113
foreach ($this->getIndexers() as $indexer) {
94114
if ($ids === null) {
95115
$indexer->reindexAll();
@@ -147,4 +167,19 @@ protected function processRelations($indexer, $ids, $onlyParents = false)
147167
$childIds = $onlyParents ? [] : $indexer->getRelationsByParent($parentIds);
148168
return array_unique(array_merge($ids, $childIds, $parentIds));
149169
}
170+
171+
/**
172+
* Get EAV indexer status
173+
*
174+
* @return bool
175+
*/
176+
private function isEavIndexerEnabled(): bool
177+
{
178+
$eavIndexerStatus = $this->scopeConfig->getValue(
179+
self::ENABLE_EAV_INDEXER,
180+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
181+
);
182+
183+
return (bool)$eavIndexerStatus;
184+
}
150185
}

0 commit comments

Comments
 (0)