Skip to content

Commit 9d6d843

Browse files
author
Mariana Lashch
committed
Merge branch '2.2-develop' of github.com:magento/magento2ce into fix-95898
2 parents 29cdda9 + 65c9a58 commit 9d6d843

File tree

22 files changed

+1037
-94
lines changed

22 files changed

+1037
-94
lines changed

app/code/Magento/Catalog/view/frontend/web/js/product/storage/data-storage.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ define([
3434
};
3535
}
3636

37+
/**
38+
* Set data to localStorage with support check.
39+
*
40+
* @param {String} namespace
41+
* @param {Object} data
42+
*/
43+
function setLocalStorageItem(namespace, data) {
44+
try {
45+
window.localStorage.setItem(namespace, JSON.stringify(data));
46+
} catch (e) {
47+
console.warn('localStorage is unavailable - skipping local caching of product data');
48+
console.error(e);
49+
}
50+
}
51+
3752
return {
3853

3954
/**
@@ -118,7 +133,7 @@ define([
118133
if (_.isEmpty(data)) {
119134
this.localStorage.removeAll();
120135
} else {
121-
this.localStorage.set(data);
136+
setLocalStorageItem(this.namespace, data);
122137
}
123138
},
124139

app/code/Magento/Catalog/view/frontend/web/js/product/storage/ids-storage.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@ define([
1111
], function ($, _, ko, utils) {
1212
'use strict';
1313

14+
/**
15+
* Set data to localStorage with support check.
16+
*
17+
* @param {String} namespace
18+
* @param {Object} data
19+
*/
20+
function setLocalStorageItem(namespace, data) {
21+
try {
22+
window.localStorage.setItem(namespace, JSON.stringify(data));
23+
} catch (e) {
24+
console.warn('localStorage is unavailable - skipping local caching of product data');
25+
console.error(e);
26+
}
27+
}
28+
1429
return {
1530

1631
/**
@@ -94,11 +109,7 @@ define([
94109
* Initializes handler to "data" property update
95110
*/
96111
internalDataHandler: function (data) {
97-
var localStorage = this.localStorage.get();
98-
99-
if (!utils.compare(data, localStorage).equal) {
100-
this.localStorage.set(data);
101-
}
112+
setLocalStorageItem(this.namespace, data);
102113
},
103114

104115
/**

app/code/Magento/Catalog/view/frontend/web/js/product/storage/storage-service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ define([
4747
* @param {*} data
4848
*/
4949
add: function (data) {
50-
if (!_.isEmpty(data) && !utils.compare(data, this.data()).equal) {
50+
if (!_.isEmpty(data)) {
5151
this.data(_.extend(utils.copy(this.data()), data));
5252
}
5353
},

app/code/Magento/Cms/view/adminhtml/templates/browser/content/uploader.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ require([
108108
fileTypes: /^image\/(gif|jpeg|png)$/,
109109
maxFileSize: <?= (int) $block->getFileSizeService()->getMaxFileSize() ?> * 10
110110
},
111-
<?= $block->escapeHtml($resizeConfig) ?>,
111+
<?= /* @noEscape */ $resizeConfig ?>,
112112
{
113113
action: 'save'
114114
}]

app/code/Magento/Newsletter/Model/Plugin/CustomerPlugin.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
namespace Magento\Newsletter\Model\Plugin;
77

88
use Magento\Customer\Api\CustomerRepositoryInterface as CustomerRepository;
9+
use Magento\Customer\Api\Data\CustomerExtensionInterface;
910
use Magento\Customer\Api\Data\CustomerInterface;
10-
use Magento\Newsletter\Model\SubscriberFactory;
1111
use Magento\Framework\Api\ExtensionAttributesFactory;
12-
use Magento\Newsletter\Model\ResourceModel\Subscriber;
13-
use Magento\Customer\Api\Data\CustomerExtensionInterface;
1412
use Magento\Framework\App\ObjectManager;
13+
use Magento\Newsletter\Model\ResourceModel\Subscriber;
14+
use Magento\Newsletter\Model\SubscriberFactory;
15+
use Magento\Store\Model\StoreManagerInterface;
1516

1617
class CustomerPlugin
1718
{
@@ -37,22 +38,30 @@ class CustomerPlugin
3738
*/
3839
private $customerSubscriptionStatus = [];
3940

41+
/**
42+
* @var StoreManagerInterface
43+
*/
44+
private $storeManager;
45+
4046
/**
4147
* Initialize dependencies.
4248
*
4349
* @param SubscriberFactory $subscriberFactory
4450
* @param ExtensionAttributesFactory|null $extensionFactory
4551
* @param Subscriber|null $subscriberResource
52+
* @param StoreManagerInterface|null $storeManager
4653
*/
4754
public function __construct(
4855
SubscriberFactory $subscriberFactory,
4956
ExtensionAttributesFactory $extensionFactory = null,
50-
Subscriber $subscriberResource = null
57+
Subscriber $subscriberResource = null,
58+
StoreManagerInterface $storeManager = null
5159
) {
5260
$this->subscriberFactory = $subscriberFactory;
5361
$this->extensionFactory = $extensionFactory
5462
?: ObjectManager::getInstance()->get(ExtensionAttributesFactory::class);
5563
$this->subscriberResource = $subscriberResource ?: ObjectManager::getInstance()->get(Subscriber::class);
64+
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
5665
}
5766

5867
/**
@@ -149,6 +158,8 @@ public function afterDelete(CustomerRepository $subject, $result, CustomerInterf
149158
public function afterGetById(CustomerRepository $subject, CustomerInterface $customer)
150159
{
151160
$extensionAttributes = $customer->getExtensionAttributes();
161+
$storeId = $this->storeManager->getStore()->getId();
162+
$customer->setStoreId($storeId);
152163
if ($extensionAttributes === null) {
153164
/** @var CustomerExtensionInterface $extensionAttributes */
154165
$extensionAttributes = $this->extensionFactory->create(CustomerInterface::class);

app/code/Magento/Newsletter/Test/Unit/Model/Plugin/CustomerPluginTest.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Magento\Customer\Api\Data\CustomerExtensionInterface;
1111
use Magento\Framework\Api\ExtensionAttributesFactory;
1212
use Magento\Newsletter\Model\ResourceModel\Subscriber;
13+
use Magento\Store\Model\Store;
14+
use Magento\Store\Model\StoreManagerInterface;
1315

1416
class CustomerPluginTest extends \PHPUnit\Framework\TestCase
1517
{
@@ -53,6 +55,11 @@ class CustomerPluginTest extends \PHPUnit\Framework\TestCase
5355
*/
5456
private $customerMock;
5557

58+
/**
59+
* @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
60+
*/
61+
private $storeManagerMock;
62+
5663
protected function setUp()
5764
{
5865
$this->subscriberFactory = $this->getMockBuilder(\Magento\Newsletter\Model\SubscriberFactory::class)
@@ -87,14 +94,17 @@ protected function setUp()
8794
->setMethods(["getExtensionAttributes"])
8895
->disableOriginalConstructor()
8996
->getMockForAbstractClass();
97+
$this->storeManagerMock = $this->createMock(StoreManagerInterface::class);
98+
9099
$this->subscriberFactory->expects($this->any())->method('create')->willReturn($this->subscriber);
91100
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
92101
$this->plugin = $this->objectManager->getObject(
93102
\Magento\Newsletter\Model\Plugin\CustomerPlugin::class,
94103
[
95104
'subscriberFactory' => $this->subscriberFactory,
96105
'extensionFactory' => $this->extensionFactoryMock,
97-
'subscriberResource' => $this->subscriberResourceMock
106+
'subscriberResource' => $this->subscriberResourceMock,
107+
'storeManager' => $this->storeManagerMock,
98108
]
99109
);
100110
}
@@ -198,6 +208,7 @@ public function testAfterGetByIdCreatesExtensionAttributesIfItIsNotSet(
198208
) {
199209
$subject = $this->createMock(\Magento\Customer\Api\CustomerRepositoryInterface::class);
200210
$subscriber = [$subscriberStatusKey => $subscriberStatusValue];
211+
$this->prepareStoreData();
201212
$this->extensionFactoryMock->expects($this->any())
202213
->method('create')
203214
->willReturn($this->customerExtensionMock);
@@ -223,6 +234,7 @@ public function testAfterGetByIdSetsIsSubscribedFlagIfItIsNotSet()
223234
{
224235
$subject = $this->createMock(\Magento\Customer\Api\CustomerRepositoryInterface::class);
225236
$subscriber = ['subscriber_id' => 1, 'subscriber_status' => 1];
237+
$this->prepareStoreData();
226238
$this->customerMock->expects($this->any())
227239
->method('getExtensionAttributes')
228240
->willReturn($this->customerExtensionMock);
@@ -255,4 +267,17 @@ public function afterGetByIdDataProvider()
255267
[null, null, false]
256268
];
257269
}
270+
271+
/**
272+
* Prepare store information
273+
*
274+
* @return void
275+
*/
276+
private function prepareStoreData()
277+
{
278+
$storeId = 1;
279+
$storeMock = $this->createMock(Store::class);
280+
$storeMock->expects($this->any())->method('getId')->willReturn($storeId);
281+
$this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($storeMock);
282+
}
258283
}

app/code/Magento/Swatches/Helper/Media.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
/**
1313
* Helper to move images from tmp to catalog directory
14+
*
1415
* @api
1516
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1617
* @since 100.0.2
@@ -19,7 +20,6 @@ class Media extends \Magento\Framework\App\Helper\AbstractHelper
1920
{
2021
/**
2122
* Swatch area inside media folder
22-
*
2323
*/
2424
const SWATCH_MEDIA_PATH = 'attribute/swatch';
2525

@@ -100,6 +100,8 @@ public function __construct(
100100
}
101101

102102
/**
103+
* Get swatch attribute image
104+
*
103105
* @param string $swatchType
104106
* @param string $file
105107
* @return string
@@ -110,13 +112,17 @@ public function getSwatchAttributeImage($swatchType, $file)
110112
$absoluteImagePath = $this->mediaDirectory
111113
->getAbsolutePath($this->getSwatchMediaPath() . '/' . $generationPath);
112114
if (!file_exists($absoluteImagePath)) {
113-
$this->generateSwatchVariations($file);
115+
try {
116+
$this->generateSwatchVariations($file);
117+
} catch (\Exception $e) {
118+
return '';
119+
}
114120
}
115121
return $this->getSwatchMediaUrl() . '/' . $generationPath;
116122
}
117123

118124
/**
119-
* move image from tmp to catalog dir
125+
* Move image from tmp to catalog dir
120126
*
121127
* @param string $file
122128
* @return string path
@@ -152,7 +158,7 @@ public function moveImageFromTmp($file)
152158
/**
153159
* Check whether file to move exists. Getting unique name
154160
*
155-
* @param <type> $file
161+
* @param string $file
156162
* @return string
157163
*/
158164
protected function getUniqueFileName($file)
@@ -176,6 +182,7 @@ protected function getUniqueFileName($file)
176182
*
177183
* @param string $imageUrl
178184
* @return $this
185+
* @throws \Exception
179186
*/
180187
public function generateSwatchVariations($imageUrl)
181188
{
@@ -234,7 +241,7 @@ protected function generateNamePath($imageConfig, $imageUrl, $swatchType)
234241
* Generate folder name WIDTHxHEIGHT based on config in view.xml
235242
*
236243
* @param string $swatchType
237-
* @param null $imageConfig
244+
* @param array|null $imageConfig
238245
* @return string
239246
*/
240247
public function getFolderNameSize($swatchType, $imageConfig = null)
@@ -336,6 +343,8 @@ protected function prepareFile($file)
336343
}
337344

338345
/**
346+
* Get registered themes
347+
*
339348
* @return \Magento\Theme\Model\ResourceModel\Theme\Collection
340349
*/
341350
private function getRegisteredThemes()

app/code/Magento/Swatches/Test/Unit/Helper/MediaTest.php

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,15 @@ protected function setUp()
9191

9292
/**
9393
* @dataProvider dataForFullPath
94+
* @param string $swatchType
95+
* @param string $expectedResult
9496
*/
9597
public function testGetSwatchAttributeImage($swatchType, $expectedResult)
9698
{
9799
$this->storeManagerMock
98100
->expects($this->once())
99101
->method('getStore')
100102
->willReturn($this->storeMock);
101-
102103
$this->storeMock
103104
->expects($this->once())
104105
->method('getBaseUrl')
@@ -107,11 +108,41 @@ public function testGetSwatchAttributeImage($swatchType, $expectedResult)
107108

108109
$this->generateImageConfig();
109110

110-
$this->testGenerateSwatchVariations();
111+
$image = $this->createPartialMock(\Magento\Framework\Image::class, [
112+
'resize',
113+
'save',
114+
'keepTransparency',
115+
'constrainOnly',
116+
'keepFrame',
117+
'keepAspectRatio',
118+
'backgroundColor',
119+
'quality'
120+
]);
121+
$this->imageFactoryMock->expects($this->atLeastOnce())
122+
->method('create')
123+
->willReturn($image);
124+
$image->expects($this->atLeastOnce())
125+
->method('resize')
126+
->will($this->returnSelf());
127+
$image->expects($this->atLeastOnce())
128+
->method('backgroundColor')
129+
->with([255, 255, 255])
130+
->willReturnSelf();
111131

112132
$result = $this->mediaHelperObject->getSwatchAttributeImage($swatchType, '/f/i/file.png');
133+
$this->assertEquals($expectedResult, $result);
134+
}
135+
136+
public function testGetSwatchAttributeImageWithMissingFile()
137+
{
138+
$this->generateImageConfig();
139+
140+
$this->imageFactoryMock->expects($this->atLeastOnce())
141+
->method('create')
142+
->willThrowException(new \Exception(''));
113143

114-
$this->assertEquals($result, $expectedResult);
144+
$result = $this->mediaHelperObject->getSwatchAttributeImage('swatch_image', '/f/i/file.png');
145+
$this->assertEquals('', $result);
115146
}
116147

117148
/**
@@ -195,6 +226,9 @@ public function testGetSwatchMediaUrl()
195226

196227
/**
197228
* @dataProvider dataForFolderName
229+
* @param string $swatchType
230+
* @param array|null $imageConfig
231+
* @param string $expectedResult
198232
*/
199233
public function testGetFolderNameSize($swatchType, $imageConfig, $expectedResult)
200234
{
@@ -293,6 +327,8 @@ public function testGetSwatchMediaPath()
293327

294328
/**
295329
* @dataProvider getSwatchTypes
330+
* @param string $swatchType
331+
* @param string $expectedResult
296332
*/
297333
public function testGetSwatchCachePath($swatchType, $expectedResult)
298334
{

0 commit comments

Comments
 (0)