Skip to content

Commit 71f2c90

Browse files
committed
Merge branch '2.3-develop' into MC-18527-merge-release
2 parents 5232cc8 + ba8602a commit 71f2c90

File tree

38 files changed

+1000
-228
lines changed

38 files changed

+1000
-228
lines changed

app/code/Magento/Catalog/Helper/Image.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,31 +213,29 @@ protected function setImageProperties()
213213

214214
// Set 'keep frame' flag
215215
$frame = $this->getFrame();
216-
if (!empty($frame)) {
217-
$this->_getModel()->setKeepFrame($frame);
218-
}
216+
$this->_getModel()->setKeepFrame($frame);
219217

220218
// Set 'constrain only' flag
221219
$constrain = $this->getAttribute('constrain');
222-
if (!empty($constrain)) {
220+
if (null !== $constrain) {
223221
$this->_getModel()->setConstrainOnly($constrain);
224222
}
225223

226224
// Set 'keep aspect ratio' flag
227225
$aspectRatio = $this->getAttribute('aspect_ratio');
228-
if (!empty($aspectRatio)) {
226+
if (null !== $aspectRatio) {
229227
$this->_getModel()->setKeepAspectRatio($aspectRatio);
230228
}
231229

232230
// Set 'transparency' flag
233231
$transparency = $this->getAttribute('transparency');
234-
if (!empty($transparency)) {
232+
if (null !== $transparency) {
235233
$this->_getModel()->setKeepTransparency($transparency);
236234
}
237235

238236
// Set background color
239237
$background = $this->getAttribute('background');
240-
if (!empty($background)) {
238+
if (null !== $background) {
241239
$this->_getModel()->setBackgroundColor($background);
242240
}
243241

app/code/Magento/Catalog/Model/View/Asset/Image.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,31 +88,31 @@ public function __construct(
8888
}
8989

9090
/**
91-
* {@inheritdoc}
91+
* @inheritdoc
9292
*/
9393
public function getUrl()
9494
{
9595
return $this->context->getBaseUrl() . DIRECTORY_SEPARATOR . $this->getImageInfo();
9696
}
9797

9898
/**
99-
* {@inheritdoc}
99+
* @inheritdoc
100100
*/
101101
public function getContentType()
102102
{
103103
return $this->contentType;
104104
}
105105

106106
/**
107-
* {@inheritdoc}
107+
* @inheritdoc
108108
*/
109109
public function getPath()
110110
{
111111
return $this->context->getPath() . DIRECTORY_SEPARATOR . $this->getImageInfo();
112112
}
113113

114114
/**
115-
* {@inheritdoc}
115+
* @inheritdoc
116116
*/
117117
public function getSourceFile()
118118
{
@@ -131,23 +131,24 @@ public function getSourceContentType()
131131
}
132132

133133
/**
134-
* {@inheritdoc}
134+
* @inheritdoc
135135
*/
136136
public function getContent()
137137
{
138138
return null;
139139
}
140140

141141
/**
142-
* {@inheritdoc}
142+
* @inheritdoc
143143
*/
144144
public function getFilePath()
145145
{
146146
return $this->filePath;
147147
}
148148

149149
/**
150-
* {@inheritdoc}
150+
* @inheritdoc
151+
*
151152
* @return ContextInterface
152153
*/
153154
public function getContext()
@@ -156,7 +157,7 @@ public function getContext()
156157
}
157158

158159
/**
159-
* {@inheritdoc}
160+
* @inheritdoc
160161
*/
161162
public function getModule()
162163
{
@@ -191,20 +192,21 @@ private function getImageInfo()
191192

192193
/**
193194
* Converting bool into a string representation
194-
* @param $miscParams
195+
*
196+
* @param array $miscParams
195197
* @return array
196198
*/
197-
private function convertToReadableFormat($miscParams)
199+
private function convertToReadableFormat(array $miscParams)
198200
{
199201
$miscParams['image_height'] = 'h:' . ($miscParams['image_height'] ?? 'empty');
200202
$miscParams['image_width'] = 'w:' . ($miscParams['image_width'] ?? 'empty');
201203
$miscParams['quality'] = 'q:' . ($miscParams['quality'] ?? 'empty');
202204
$miscParams['angle'] = 'r:' . ($miscParams['angle'] ?? 'empty');
203-
$miscParams['keep_aspect_ratio'] = (isset($miscParams['keep_aspect_ratio']) ? '' : 'non') . 'proportional';
204-
$miscParams['keep_frame'] = (isset($miscParams['keep_frame']) ? '' : 'no') . 'frame';
205-
$miscParams['keep_transparency'] = (isset($miscParams['keep_transparency']) ? '' : 'no') . 'transparency';
206-
$miscParams['constrain_only'] = (isset($miscParams['constrain_only']) ? 'do' : 'not') . 'constrainonly';
207-
$miscParams['background'] = isset($miscParams['background'])
205+
$miscParams['keep_aspect_ratio'] = (!empty($miscParams['keep_aspect_ratio']) ? '' : 'non') . 'proportional';
206+
$miscParams['keep_frame'] = (!empty($miscParams['keep_frame']) ? '' : 'no') . 'frame';
207+
$miscParams['keep_transparency'] = (!empty($miscParams['keep_transparency']) ? '' : 'no') . 'transparency';
208+
$miscParams['constrain_only'] = (!empty($miscParams['constrain_only']) ? 'do' : 'not') . 'constrainonly';
209+
$miscParams['background'] = !empty($miscParams['background'])
208210
? 'rgb' . implode(',', $miscParams['background'])
209211
: 'nobackground';
210212
return $miscParams;

app/code/Magento/Catalog/Test/Unit/Helper/ImageTest.php

Lines changed: 108 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Catalog\Test\Unit\Helper;
78

89
use Magento\Catalog\Helper\Image;
@@ -29,6 +30,11 @@ class ImageTest extends \PHPUnit\Framework\TestCase
2930
*/
3031
protected $assetRepository;
3132

33+
/**
34+
* @var \Magento\Framework\Config\View|\PHPUnit\Framework\MockObject\MockObject
35+
*/
36+
protected $configView;
37+
3238
/**
3339
* @var \Magento\Framework\View\ConfigInterface|\PHPUnit_Framework_MockObject_MockObject
3440
*/
@@ -58,6 +64,10 @@ protected function setUp()
5864
->disableOriginalConstructor()
5965
->getMock();
6066

67+
$this->configView = $this->getMockBuilder(\Magento\Framework\Config\View::class)
68+
->disableOriginalConstructor()
69+
->getMock();
70+
6171
$this->viewConfig = $this->getMockBuilder(\Magento\Framework\View\ConfigInterface::class)
6272
->getMockForAbstractClass();
6373

@@ -151,23 +161,89 @@ public function initDataProvider()
151161
];
152162
}
153163

164+
/**
165+
* @param array $data - optional 'frame' key
166+
* @param bool $whiteBorders view config
167+
* @param bool $expectedKeepFrame
168+
* @dataProvider initKeepFrameDataProvider
169+
*/
170+
public function testInitKeepFrame($data, $whiteBorders, $expectedKeepFrame)
171+
{
172+
$imageId = 'test_image_id';
173+
$attributes = [];
174+
175+
$productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
176+
->disableOriginalConstructor()
177+
->getMock();
178+
179+
$this->prepareAttributes($data, $imageId);
180+
181+
$this->configView->expects(isset($data['frame']) ? $this->never() : $this->once())
182+
->method('getVarValue')
183+
->with('Magento_Catalog', 'product_image_white_borders')
184+
->willReturn($whiteBorders);
185+
186+
$this->viewConfig->expects($this->once())
187+
->method('getViewConfig')
188+
->willReturn($this->configView);
189+
190+
$this->image->expects($this->once())
191+
->method('setKeepFrame')
192+
->with($expectedKeepFrame)
193+
->willReturnSelf();
194+
195+
$this->helper->init($productMock, $imageId, $attributes);
196+
}
197+
198+
/**
199+
* @return array
200+
*/
201+
public function initKeepFrameDataProvider()
202+
{
203+
return [
204+
// when frame defined explicitly, it wins
205+
[
206+
'mediaImage' => [
207+
'frame' => 1,
208+
],
209+
'whiteBorders' => true,
210+
'expected' => true,
211+
],
212+
[
213+
'mediaImage' => [
214+
'frame' => 0,
215+
],
216+
'whiteBorders' => true,
217+
'expected' => false,
218+
],
219+
// when frame is not defined, var is used
220+
[
221+
'mediaImage' => [],
222+
'whiteBorders' => true,
223+
'expected' => true,
224+
],
225+
[
226+
'mediaImage' => [],
227+
'whiteBorders' => false,
228+
'expected' => false,
229+
],
230+
];
231+
}
232+
154233
/**
155234
* @param $data
156235
* @param $imageId
157236
*/
158237
protected function prepareAttributes($data, $imageId)
159238
{
160-
$configViewMock = $this->getMockBuilder(\Magento\Framework\Config\View::class)
161-
->disableOriginalConstructor()
162-
->getMock();
163-
$configViewMock->expects($this->once())
239+
$this->configView->expects($this->once())
164240
->method('getMediaAttributes')
165241
->with('Magento_Catalog', Image::MEDIA_TYPE_CONFIG_NODE, $imageId)
166242
->willReturn($data);
167243

168244
$this->viewConfig->expects($this->once())
169245
->method('getViewConfig')
170-
->willReturn($configViewMock);
246+
->willReturn($this->configView);
171247
}
172248

173249
/**
@@ -220,32 +296,34 @@ protected function prepareWatermarkProperties($data)
220296
{
221297
$this->scopeConfig->expects($this->any())
222298
->method('getValue')
223-
->willReturnMap([
299+
->willReturnMap(
224300
[
225-
'design/watermark/' . $data['type'] . '_image',
226-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
227-
null,
228-
$data['watermark']
229-
],
230-
[
231-
'design/watermark/' . $data['type'] . '_imageOpacity',
232-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
233-
null,
234-
$data['watermark_opacity']
235-
],
236-
[
237-
'design/watermark/' . $data['type'] . '_position',
238-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
239-
null,
240-
$data['watermark_position']
241-
],
242-
[
243-
'design/watermark/' . $data['type'] . '_size',
244-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
245-
null,
246-
$data['watermark_size']
247-
],
248-
]);
301+
[
302+
'design/watermark/' . $data['type'] . '_image',
303+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
304+
null,
305+
$data['watermark']
306+
],
307+
[
308+
'design/watermark/' . $data['type'] . '_imageOpacity',
309+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
310+
null,
311+
$data['watermark_opacity']
312+
],
313+
[
314+
'design/watermark/' . $data['type'] . '_position',
315+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
316+
null,
317+
$data['watermark_position']
318+
],
319+
[
320+
'design/watermark/' . $data['type'] . '_size',
321+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
322+
null,
323+
$data['watermark_size']
324+
],
325+
]
326+
);
249327

250328
$this->image->expects($this->any())
251329
->method('setWatermarkFile')

0 commit comments

Comments
 (0)