Skip to content

Commit 569e6e4

Browse files
committed
Merge remote-tracking branch 'mainline/2.2-develop' into MAGETWO-87437
2 parents a63527b + 33d39af commit 569e6e4

File tree

97 files changed

+1262
-339
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+1262
-339
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
);

app/code/Magento/Backend/Helper/Dashboard/Order.php

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @api
1414
* @since 100.0.2
1515
*/
16-
class Order extends \Magento\Backend\Helper\Dashboard\AbstractDashboard
16+
class Order extends AbstractDashboard
1717
{
1818
/**
1919
* @var \Magento\Reports\Model\ResourceModel\Order\Collection
@@ -29,32 +29,25 @@ class Order extends \Magento\Backend\Helper\Dashboard\AbstractDashboard
2929
/**
3030
* @param \Magento\Framework\App\Helper\Context $context
3131
* @param \Magento\Reports\Model\ResourceModel\Order\Collection $orderCollection
32+
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
3233
*/
3334
public function __construct(
3435
\Magento\Framework\App\Helper\Context $context,
35-
\Magento\Reports\Model\ResourceModel\Order\Collection $orderCollection
36+
\Magento\Reports\Model\ResourceModel\Order\Collection $orderCollection,
37+
\Magento\Store\Model\StoreManagerInterface $storeManager = null
3638
) {
3739
$this->_orderCollection = $orderCollection;
38-
parent::__construct($context);
39-
}
40+
$this->_storeManager = $storeManager ?: ObjectManager::getInstance()
41+
->get(\Magento\Store\Model\StoreManagerInterface::class);
4042

41-
/**
42-
* The getter function to get the new StoreManager dependency
43-
*
44-
* @return \Magento\Store\Model\StoreManagerInterface
45-
*
46-
* @deprecated 100.1.0
47-
*/
48-
private function getStoreManager()
49-
{
50-
if ($this->_storeManager === null) {
51-
$this->_storeManager = ObjectManager::getInstance()->get(\Magento\Store\Model\StoreManagerInterface::class);
52-
}
53-
return $this->_storeManager;
43+
parent::__construct($context);
5444
}
5545

5646
/**
5747
* @return void
48+
*
49+
* @throws \Magento\Framework\Exception\LocalizedException
50+
* @throws \Magento\Framework\Exception\NoSuchEntityException
5851
*/
5952
protected function _initCollection()
6053
{
@@ -65,15 +58,15 @@ protected function _initCollection()
6558
if ($this->getParam('store')) {
6659
$this->_collection->addFieldToFilter('store_id', $this->getParam('store'));
6760
} elseif ($this->getParam('website')) {
68-
$storeIds = $this->getStoreManager()->getWebsite($this->getParam('website'))->getStoreIds();
61+
$storeIds = $this->_storeManager->getWebsite($this->getParam('website'))->getStoreIds();
6962
$this->_collection->addFieldToFilter('store_id', ['in' => implode(',', $storeIds)]);
7063
} elseif ($this->getParam('group')) {
71-
$storeIds = $this->getStoreManager()->getGroup($this->getParam('group'))->getStoreIds();
64+
$storeIds = $this->_storeManager->getGroup($this->getParam('group'))->getStoreIds();
7265
$this->_collection->addFieldToFilter('store_id', ['in' => implode(',', $storeIds)]);
7366
} elseif (!$this->_collection->isLive()) {
7467
$this->_collection->addFieldToFilter(
7568
'store_id',
76-
['eq' => $this->getStoreManager()->getStore(\Magento\Store\Model\Store::ADMIN_CODE)->getId()]
69+
['eq' => $this->_storeManager->getStore(\Magento\Store\Model\Store::ADMIN_CODE)->getId()]
7770
);
7871
}
7972
$this->_collection->load();
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: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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\PayPal;
9+
10+
use Magento\Braintree\Model\InstantPurchase\CreditCard\TokenFormatter as PaypalTokenFormatter;
11+
use Magento\Vault\Api\Data\PaymentTokenInterface;
12+
13+
class TokenFormatterTest extends \PHPUnit\Framework\TestCase
14+
{
15+
/**
16+
* @var PaymentTokenInterface|\PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
private $paymentTokenMock;
19+
20+
/**
21+
* @var PaypalTokenFormatter
22+
*/
23+
private $paypalTokenFormatter;
24+
25+
/**
26+
* @var array
27+
*/
28+
private $tokenDetails = [
29+
'type' => 'visa',
30+
'maskedCC' => '4444************9999',
31+
'expirationDate' => '07-07-2025'
32+
];
33+
34+
protected function setUp()
35+
{
36+
$this->paymentTokenMock = $this->getMockBuilder(PaymentTokenInterface::class)
37+
->getMockForAbstractClass();
38+
39+
$this->paypalTokenFormatter = new PaypalTokenFormatter();
40+
}
41+
42+
public function testFormatPaymentTokenWithKnownCardType()
43+
{
44+
$this->tokenDetails['type'] = key(PaypalTokenFormatter::$baseCardTypes);
45+
$this->paymentTokenMock->expects($this->once())
46+
->method('getTokenDetails')
47+
->willReturn(json_encode($this->tokenDetails));
48+
49+
$formattedString = sprintf(
50+
'%s: %s, %s: %s (%s: %s)',
51+
__('Credit Card'),
52+
reset(PaypalTokenFormatter::$baseCardTypes),
53+
__('ending'),
54+
$this->tokenDetails['maskedCC'],
55+
__('expires'),
56+
$this->tokenDetails['expirationDate']
57+
);
58+
59+
self::assertEquals($formattedString, $this->paypalTokenFormatter->formatPaymentToken($this->paymentTokenMock));
60+
}
61+
62+
public function testFormatPaymentTokenWithUnknownCardType()
63+
{
64+
$this->paymentTokenMock->expects($this->once())
65+
->method('getTokenDetails')
66+
->willReturn(json_encode($this->tokenDetails));
67+
68+
$formattedString = sprintf(
69+
'%s: %s, %s: %s (%s: %s)',
70+
__('Credit Card'),
71+
$this->tokenDetails['type'],
72+
__('ending'),
73+
$this->tokenDetails['maskedCC'],
74+
__('expires'),
75+
$this->tokenDetails['expirationDate']
76+
);
77+
78+
self::assertEquals($formattedString, $this->paypalTokenFormatter->formatPaymentToken($this->paymentTokenMock));
79+
}
80+
81+
public function testFormatPaymentTokenWithWrongData()
82+
{
83+
unset($this->tokenDetails['type']);
84+
85+
$this->paymentTokenMock->expects($this->once())
86+
->method('getTokenDetails')
87+
->willReturn(json_encode($this->tokenDetails));
88+
self::expectException('\InvalidArgumentException');
89+
90+
$this->paypalTokenFormatter->formatPaymentToken($this->paymentTokenMock);
91+
}
92+
}
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+
}

0 commit comments

Comments
 (0)