Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/2.2-develop' into #14020-Cart-…
Browse files Browse the repository at this point in the history
…Sales-Rule-with-negated-condition-over-special-price-does-not-work-for-configurable-products
  • Loading branch information
novikor committed Aug 12, 2018
2 parents 5c3154b + 840d5b2 commit 51adb9d
Show file tree
Hide file tree
Showing 40 changed files with 714 additions and 121 deletions.
10 changes: 7 additions & 3 deletions app/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@
&& isset($_SERVER['HTTP_ACCEPT'])
&& strpos($_SERVER['HTTP_ACCEPT'], 'text/html') !== false
) {
$profilerFlag = isset($_SERVER['MAGE_PROFILER']) && strlen($_SERVER['MAGE_PROFILER'])
$profilerConfig = isset($_SERVER['MAGE_PROFILER']) && strlen($_SERVER['MAGE_PROFILER'])
? $_SERVER['MAGE_PROFILER']
: trim(file_get_contents(BP . '/var/profiler.flag'));

\Magento\Framework\Profiler::applyConfig(
$profilerFlag,
if ($profilerConfig) {
$profilerConfig = json_decode($profilerConfig, true) ?: $profilerConfig;
}

Magento\Framework\Profiler::applyConfig(
$profilerConfig,
BP,
!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Braintree\Test\Unit\Model\InstantPurchase\CreditCard;

use Magento\Braintree\Gateway\Config\Config;
use Magento\Braintree\Model\InstantPurchase\CreditCard\AvailabilityChecker;

/**
* @covers \Magento\Braintree\Model\InstantPurchase\CreditCard\AvailabilityChecker
*/
class AvailabilityCheckerTest extends \PHPUnit\Framework\TestCase
{
/**
* Testable Object
*
* @var AvailabilityChecker
*/
private $availabilityChecker;

/**
* @var Config|\PHPUnit_Framework_MockObject_MockObject
*/
private $configMock;

/**
* Set Up
*
* @return void
*/
protected function setUp()
{
$this->configMock = $this->createMock(Config::class);
$this->availabilityChecker = new AvailabilityChecker($this->configMock);
}

/**
* Test isAvailable method
*
* @dataProvider isAvailableDataProvider
*
* @param bool $isVerify3DSecure
* @param bool $expected
*
* @return void
*/
public function testIsAvailable(bool $isVerify3DSecure, bool $expected)
{
$this->configMock->expects($this->once())->method('isVerify3DSecure')->willReturn($isVerify3DSecure);
$actual = $this->availabilityChecker->isAvailable();
self::assertEquals($expected, $actual);
}

/**
* Data provider for isAvailable method test
*
* @return array
*/
public function isAvailableDataProvider()
{
return [
[true, false],
[false, true],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Braintree\Test\Unit\Model\InstantPurchase;

use Magento\Braintree\Gateway\Command\GetPaymentNonceCommand;
use Magento\Braintree\Model\InstantPurchase\PaymentAdditionalInformationProvider;
use Magento\Payment\Gateway\Command\Result\ArrayResult;
use Magento\Vault\Api\Data\PaymentTokenInterface;

/**
* @covers \Magento\Braintree\Model\InstantPurchase\PaymentAdditionalInformationProvider
*/
class PaymentAdditionalInformationProviderTest extends \PHPUnit\Framework\TestCase
{
/**
* Testable Object
*
* @var PaymentAdditionalInformationProvider
*/
private $paymentAdditionalInformationProvider;

/**
* @var GetPaymentNonceCommand|\PHPUnit_Framework_MockObject_MockObject
*/
private $getPaymentNonceCommandMock;

/**
* @var PaymentTokenInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $paymentTokenMock;

/**
* @var ArrayResult|\PHPUnit_Framework_MockObject_MockObject
*/
private $arrayResultMock;

/**
* Set Up
*
* @return void
*/
protected function setUp()
{
$this->getPaymentNonceCommandMock = $this->createMock(GetPaymentNonceCommand::class);
$this->paymentTokenMock = $this->createMock(PaymentTokenInterface::class);
$this->arrayResultMock = $this->createMock(ArrayResult::class);
$this->paymentAdditionalInformationProvider = new PaymentAdditionalInformationProvider(
$this->getPaymentNonceCommandMock
);
}

/**
* Test getAdditionalInformation method
*
* @return void
*/
public function testGetAdditionalInformation()
{
$customerId = 15;
$publicHash = '3n4b7sn48g';
$paymentMethodNonce = 'test';

$this->paymentTokenMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
$this->paymentTokenMock->expects($this->once())->method('getPublicHash')->willReturn($publicHash);
$this->getPaymentNonceCommandMock->expects($this->once())->method('execute')->with([
PaymentTokenInterface::CUSTOMER_ID => $customerId,
PaymentTokenInterface::PUBLIC_HASH => $publicHash,
])->willReturn($this->arrayResultMock);
$this->arrayResultMock->expects($this->once())->method('get')
->willReturn(['paymentMethodNonce' => $paymentMethodNonce]);

$expected = [
'payment_method_nonce' => $paymentMethodNonce,
];
$actual = $this->paymentAdditionalInformationProvider->getAdditionalInformation($this->paymentTokenMock);
self::assertEquals($expected, $actual);
}
}
138 changes: 138 additions & 0 deletions app/code/Magento/Braintree/Test/Unit/Model/LocaleResolverTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Braintree\Test\Unit\Model;

use Magento\Braintree\Gateway\Config\PayPal\Config;
use Magento\Braintree\Model\LocaleResolver;
use Magento\Framework\Locale\ResolverInterface;

/**
* @covers \Magento\Braintree\Model\LocaleResolver
*/
class LocaleResolverTest extends \PHPUnit\Framework\TestCase
{
/**
* Testable Object
*
* @var LocaleResolver
*/
private $localeResolver;

/**
* @var Config|\PHPUnit_Framework_MockObject_MockObject
*/
private $configMock;

/**
* @var ResolverInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $resolverMock;

/**
* Set Up
*
* @return void
*/
protected function setUp()
{
$this->configMock = $this->createMock(Config::class);
$this->resolverMock = $this->createMock(ResolverInterface::class);
$this->localeResolver = new LocaleResolver($this->resolverMock, $this->configMock);
}

/**
* Test getDefaultLocalePath method
*
* @return void
*/
public function testGetDefaultLocalePath()
{
$expected = 'general/locale/code';
$this->resolverMock->expects($this->once())->method('getDefaultLocalePath')->willReturn($expected);
$actual = $this->localeResolver->getDefaultLocalePath();
self::assertEquals($expected, $actual);
}

/**
* Test setDefaultLocale method
*
* @return void
*/
public function testSetDefaultLocale()
{
$defaultLocale = 'en_US';
$this->resolverMock->expects($this->once())->method('setDefaultLocale')->with($defaultLocale);
$this->localeResolver->setDefaultLocale($defaultLocale);
}

/**
* Test getDefaultLocale method
*
* @return void
*/
public function testGetDefaultLocale()
{
$expected = 'fr_FR';
$this->resolverMock->expects($this->once())->method('getDefaultLocale')->willReturn($expected);
$actual = $this->localeResolver->getDefaultLocale();
self::assertEquals($expected, $actual);
}

/**
* Test setLocale method
*
* @return void
*/
public function testSetLocale()
{
$locale = 'en_GB';
$this->resolverMock->expects($this->once())->method('setLocale')->with($locale);
$this->localeResolver->setLocale($locale);
}

/**
* Test getLocale method
*
* @return void
*/
public function testGetLocale()
{
$locale = 'en_TEST';
$allowedLocales = 'en_US,en_GB,en_AU,da_DK,fr_FR,fr_CA,de_DE,zh_HK,it_IT,nl_NL';
$this->resolverMock->expects($this->once())->method('getLocale')->willReturn($locale);
$this->configMock->expects($this->once())->method('getValue')->with('supported_locales')
->willReturn($allowedLocales);

$expected = 'en_US';
$actual = $this->localeResolver->getLocale();
self::assertEquals($expected, $actual);
}

/**
* Test emulate method
*
* @return void
*/
public function testEmulate()
{
$scopeId = 12;
$this->resolverMock->expects($this->once())->method('emulate')->with($scopeId);
$this->localeResolver->emulate($scopeId);
}

/**
* Test revert method
*
* @return void
*/
public function testRevert()
{
$this->resolverMock->expects($this->once())->method('revert');
$this->localeResolver->revert();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Model\Indexer\Product\Eav;

/**
* Abstract action reindex class
*/
abstract class AbstractAction
{
/**
* Config path for enable EAV indexer
*/
const ENABLE_EAV_INDEXER = 'catalog/search/enable_eav_indexer';

/**
* EAV Indexers by type
*
Expand All @@ -27,17 +34,27 @@ abstract class AbstractAction
*/
protected $_eavDecimalFactory;

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
private $scopeConfig;

/**
* AbstractAction constructor.
* @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalFactory $eavDecimalFactory
* @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory $eavSourceFactory
* @param \Magento\Framework\App\Config\ScopeConfigInterface|null $scopeConfig
*/
public function __construct(
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalFactory $eavDecimalFactory,
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory $eavSourceFactory
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory $eavSourceFactory,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig = null
) {
$this->_eavDecimalFactory = $eavDecimalFactory;
$this->_eavSourceFactory = $eavSourceFactory;
$this->scopeConfig = $scopeConfig ?: \Magento\Framework\App\ObjectManager::getInstance()->get(
\Magento\Framework\App\Config\ScopeConfigInterface::class
);
}

/**
Expand Down Expand Up @@ -90,6 +107,9 @@ public function getIndexer($type)
*/
public function reindex($ids = null)
{
if (!$this->isEavIndexerEnabled()) {
return;
}
foreach ($this->getIndexers() as $indexer) {
if ($ids === null) {
$indexer->reindexAll();
Expand Down Expand Up @@ -147,4 +167,19 @@ protected function processRelations($indexer, $ids, $onlyParents = false)
$childIds = $onlyParents ? [] : $indexer->getRelationsByParent($parentIds);
return array_unique(array_merge($ids, $childIds, $parentIds));
}

/**
* Get EAV indexer status
*
* @return bool
*/
private function isEavIndexerEnabled(): bool
{
$eavIndexerStatus = $this->scopeConfig->getValue(
self::ENABLE_EAV_INDEXER,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);

return (bool)$eavIndexerStatus;
}
}
Loading

0 comments on commit 51adb9d

Please sign in to comment.