Skip to content

Commit c6586ab

Browse files
Shubham SharmaShubham Sharma
authored andcommitted
Merge remote-tracking branch 'upstream/2.2-develop' into 2.2-develop
2 parents 26a9520 + fdcab41 commit c6586ab

File tree

63 files changed

+1241
-144
lines changed

Some content is hidden

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

63 files changed

+1241
-144
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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\Backend\Block\DataProviders;
9+
10+
use Magento\Framework\View\Element\Block\ArgumentInterface;
11+
12+
/**
13+
* Provides additional data for image uploader
14+
*/
15+
class UploadConfig implements ArgumentInterface
16+
{
17+
/**
18+
* @var \Magento\Framework\App\Config\ScopeConfigInterface
19+
*/
20+
private $config;
21+
22+
/**
23+
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
24+
*/
25+
public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $config)
26+
{
27+
$this->config = $config;
28+
}
29+
30+
/**
31+
* Get image resize configuration
32+
*
33+
* @return int
34+
*/
35+
public function getIsResizeEnabled(): int
36+
{
37+
return (int)$this->config->getValue('system/upload_configuration/enable_resize');
38+
}
39+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Backend\Test\Unit\Block\DataProviders;
7+
8+
use Magento\Framework\App\Config\ScopeConfigInterface as ScopeConfig;
9+
use Magento\Backend\Block\DataProviders\UploadConfig;
10+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
11+
12+
class UploadConfigTest extends \PHPUnit\Framework\TestCase
13+
{
14+
/**
15+
* @var ScopeConfig|\PHPUnit_Framework_MockObject_MockObject
16+
*/
17+
private $config;
18+
19+
/**
20+
* @var ObjectManagerHelper
21+
*/
22+
private $objectManagerHelper;
23+
24+
/**
25+
* @var UploadConfig
26+
*/
27+
private $uploadConfig;
28+
29+
protected function setUp()
30+
{
31+
$this->config = $this->getMockBuilder(ScopeConfig::class)
32+
->setMethods(['getValue'])
33+
->getMockForAbstractClass();
34+
$this->objectManagerHelper = new ObjectManagerHelper($this);
35+
$this->uploadConfig = $this->objectManagerHelper->getObject(
36+
UploadConfig::class,
37+
[
38+
'config' => $this->config
39+
]
40+
);
41+
}
42+
43+
/**
44+
* @dataProvider configValuesDataProvider()
45+
* @param int $configValue
46+
* @param int $expectedValue
47+
* @return void
48+
*/
49+
public function testGetIsResizeEnabled(int $configValue, int $expectedValue)
50+
{
51+
$this->config->expects($this->once())
52+
->method('getValue')
53+
->with('system/upload_configuration/enable_resize')
54+
->willReturn($configValue);
55+
$this->assertEquals($expectedValue, $this->uploadConfig->getIsResizeEnabled());
56+
}
57+
58+
public function configValuesDataProvider(): array
59+
{
60+
return [
61+
[1, 1],
62+
[0, 0]
63+
];
64+
}
65+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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\Backend\Test\Unit\Service\V1;
9+
10+
use Magento\Backend\Service\V1\ModuleService;
11+
use Magento\Framework\Module\ModuleListInterface;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
13+
14+
/**
15+
* Module List Service Test
16+
*
17+
* Covers \Magento\Sales\Model\ValidatorResultMerger
18+
*/
19+
class ModuleServiceTest extends \PHPUnit\Framework\TestCase
20+
{
21+
/**
22+
* Testable Object
23+
*
24+
* @var ModuleService
25+
*/
26+
private $moduleService;
27+
28+
/**
29+
* @var ModuleListInterface|\PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
private $moduleListMock;
32+
33+
/**
34+
* Object Manager
35+
*
36+
* @var ObjectManager
37+
*/
38+
private $objectManager;
39+
40+
/**
41+
* Set Up
42+
*
43+
* @return void
44+
*/
45+
protected function setUp()
46+
{
47+
$this->moduleListMock = $this->createMock(ModuleListInterface::class);
48+
$this->objectManager = new ObjectManager($this);
49+
$this->moduleService = $this->objectManager->getObject(
50+
ModuleService::class,
51+
[
52+
'moduleList' => $this->moduleListMock,
53+
]
54+
);
55+
}
56+
57+
/**
58+
* Test getModules method
59+
*
60+
* @return void
61+
*/
62+
public function testGetModules()
63+
{
64+
$moduleNames = ['Magento_Backend', 'Magento_Catalog', 'Magento_Customer'];
65+
$this->moduleListMock->expects($this->once())->method('getNames')->willReturn($moduleNames);
66+
67+
$expected = $moduleNames;
68+
$actual = $this->moduleService->getModules();
69+
$this->assertEquals($expected, $actual);
70+
}
71+
}

app/code/Magento/Backend/etc/adminhtml/system.xml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,15 +322,26 @@
322322
</group>
323323
<group id="upload_configuration" translate="label" type="text" sortOrder="1000" showInDefault="1" showInWebsite="1" showInStore="1">
324324
<label>Images Upload Configuration</label>
325-
<field id="max_width" translate="label comment" type="text" sortOrder="100" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
325+
<field id="enable_resize" translate="label" type="select" sortOrder="200" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
326+
<label>Enable Frontend Resize</label>
327+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
328+
<comment>Resize performed via javascript before file upload.</comment>
329+
</field>
330+
<field id="max_width" translate="label comment" type="text" sortOrder="300" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
326331
<label>Maximum Width</label>
327332
<validate>validate-greater-than-zero validate-number required-entry</validate>
328333
<comment>Maximum allowed width for uploaded image.</comment>
334+
<depends>
335+
<field id="enable_resize">1</field>
336+
</depends>
329337
</field>
330-
<field id="max_height" translate="label comment" type="text" sortOrder="200" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
338+
<field id="max_height" translate="label comment" type="text" sortOrder="400" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
331339
<label>Maximum Height</label>
332340
<validate>validate-greater-than-zero validate-number required-entry</validate>
333341
<comment>Maximum allowed height for uploaded image.</comment>
342+
<depends>
343+
<field id="enable_resize">1</field>
344+
</depends>
334345
</field>
335346
</group>
336347
</section>

app/code/Magento/Backend/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<enable_charts>1</enable_charts>
3030
</dashboard>
3131
<upload_configuration>
32+
<enable_resize>1</enable_resize>
3233
<max_width>1920</max_width>
3334
<max_height>1200</max_height>
3435
</upload_configuration>

app/code/Magento/Backend/view/adminhtml/templates/media/uploader.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"Magento_Backend/js/media-uploader" : {
1515
"maxFileSize": <?= /* @escapeNotVerified */ $block->getFileSizeService()->getMaxFileSize() ?>,
1616
"maxWidth":<?= /* @escapeNotVerified */ $block->getImageUploadMaxWidth() ?> ,
17-
"maxHeight": <?= /* @escapeNotVerified */ $block->getImageUploadMaxHeight() ?>
17+
"maxHeight": <?= /* @escapeNotVerified */ $block->getImageUploadMaxHeight() ?>,
18+
"isResizeEnabled": <?= /* @noEscape */ $block->getImageUploadConfigData()->getIsResizeEnabled() ?>
1819
}
1920
}'
2021
>

app/code/Magento/Backend/view/adminhtml/web/js/media-uploader.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,20 @@ define([
2525
* @private
2626
*/
2727
_create: function () {
28-
var
29-
self = this,
30-
progressTmpl = mageTemplate('[data-template="uploader"]');
28+
var self = this,
29+
progressTmpl = mageTemplate('[data-template="uploader"]'),
30+
isResizeEnabled = this.options.isResizeEnabled,
31+
resizeConfiguration = {
32+
action: 'resize',
33+
maxWidth: this.options.maxWidth,
34+
maxHeight: this.options.maxHeight
35+
};
36+
37+
if (!isResizeEnabled) {
38+
resizeConfiguration = {
39+
action: 'resize'
40+
};
41+
}
3142

3243
this.element.find('input[type=file]').fileupload({
3344
dataType: 'json',
@@ -44,8 +55,7 @@ define([
4455
* @param {Object} data
4556
*/
4657
add: function (e, data) {
47-
var
48-
fileSize,
58+
var fileSize,
4959
tmpl;
5060

5161
$.each(data.files, function (index, file) {
@@ -115,11 +125,9 @@ define([
115125
process: [{
116126
action: 'load',
117127
fileTypes: /^image\/(gif|jpeg|png)$/
118-
}, {
119-
action: 'resize',
120-
maxWidth: this.options.maxWidth,
121-
maxHeight: this.options.maxHeight
122-
}, {
128+
},
129+
resizeConfiguration,
130+
{
123131
action: 'save'
124132
}]
125133
});

app/code/Magento/Braintree/Model/Ui/PayPal/ConfigProvider.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ public function __construct(Config $config, ResolverInterface $resolver)
4141
}
4242

4343
/**
44-
* Retrieve assoc array of checkout configuration
44+
* Retrieve assoc array of checkout configuration.
4545
*
4646
* @return array
4747
*/
48-
public function getConfig()
48+
public function getConfig(): array
4949
{
50+
$requireBillingAddressAll = \Magento\Paypal\Model\Config::REQUIRE_BILLING_ADDRESS_ALL;
51+
5052
return [
5153
'payment' => [
5254
self::PAYPAL_CODE => [
@@ -60,6 +62,8 @@ public function getConfig()
6062
'vaultCode' => self::PAYPAL_VAULT_CODE,
6163
'skipOrderReview' => $this->config->isSkipOrderReview(),
6264
'paymentIcon' => $this->config->getPayPalIcon(),
65+
'isRequiredBillingAddress' =>
66+
(int)$this->config->isRequiredBillingAddress() === $requireBillingAddressAll,
6367
]
6468
]
6569
];

app/code/Magento/Braintree/Test/Unit/Model/Ui/PayPal/ConfigProviderTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ protected function setUp()
4747
}
4848

4949
/**
50-
* Run test getConfig method
50+
* Run test getConfig method.
5151
*
5252
* @param array $expected
53+
* @return void
5354
* @dataProvider getConfigDataProvider
5455
*/
5556
public function testGetConfig($expected)
@@ -77,13 +78,16 @@ public function testGetConfig($expected)
7778
'width' => 30, 'height' => 26, 'url' => 'https://icon.test.url'
7879
]);
7980

81+
$this->config->method('isRequiredBillingAddress')
82+
->willReturn(1);
83+
8084
self::assertEquals($expected, $this->configProvider->getConfig());
8185
}
8286

8387
/**
8488
* @return array
8589
*/
86-
public function getConfigDataProvider()
90+
public function getConfigDataProvider(): array
8791
{
8892
return [
8993
[
@@ -101,7 +105,8 @@ public function getConfigDataProvider()
101105
'skipOrderReview' => false,
102106
'paymentIcon' => [
103107
'width' => 30, 'height' => 26, 'url' => 'https://icon.test.url'
104-
]
108+
],
109+
'isRequiredBillingAddress' => true,
105110
]
106111
]
107112
]

app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ define([
206206
beforePlaceOrder: function (data) {
207207
this.setPaymentMethodNonce(data.nonce);
208208

209-
if (quote.billingAddress() === null && typeof data.details.billingAddress !== 'undefined') {
209+
if ((this.isRequiredBillingAddress() || quote.billingAddress() === null) &&
210+
typeof data.details.billingAddress !== 'undefined'
211+
) {
210212
this.setBillingAddress(data.details, data.details.billingAddress);
211213
}
212214

@@ -264,6 +266,14 @@ define([
264266
return window.checkoutConfig.payment[this.getCode()].isAllowShippingAddressOverride;
265267
},
266268

269+
/**
270+
* Is billing address required from PayPal side.
271+
* @returns {Boolean}
272+
*/
273+
isRequiredBillingAddress: function () {
274+
return window.checkoutConfig.payment[this.getCode()].isRequiredBillingAddress;
275+
},
276+
267277
/**
268278
* Get configuration for PayPal
269279
* @returns {Object}

0 commit comments

Comments
 (0)