Skip to content

Commit 35e1392

Browse files
author
Korshenko, Oleksii(okorshenko)
committed
Merge pull request #437 from magento-sparta/MDVA-144-GA-2-0-2
[SUPPORT] MDVA-144
2 parents 71dab8d + 92f1418 commit 35e1392

File tree

39 files changed

+1879
-332
lines changed

39 files changed

+1879
-332
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Longtext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function render(\Magento\Framework\DataObject $row)
3030
$truncateLength = $this->getColumn()->getTruncate();
3131
}
3232
$text = $this->filterManager->truncate(parent::_getValue($row), ['length' => $truncateLength]);
33-
if ($this->getColumn()->getEscape()) {
33+
if (!$this->getColumn()->hasEscape() || $this->getColumn()->getEscape()) {
3434
$text = $this->escapeHtml($text);
3535
}
3636
if ($this->getColumn()->getNl2br()) {

app/code/Magento/Catalog/Model/Product.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ public function getStoreIds()
796796
*/
797797
public function getAttributes($groupId = null, $skipSuper = false)
798798
{
799-
$productAttributes = $this->getTypeInstance()->getEditableAttributes($this);
799+
$productAttributes = $this->getTypeInstance()->getSetAttributes($this);
800800
if ($groupId) {
801801
$attributes = [];
802802
foreach ($productAttributes as $attribute) {
@@ -1212,9 +1212,6 @@ public function getSpecialToDate()
12121212
return $this->_getData('special_to_date');
12131213
}
12141214

1215-
/*******************************************************************************
1216-
** Linked products API
1217-
*/
12181215
/**
12191216
* Retrieve array of related products
12201217
*
@@ -1461,9 +1458,6 @@ public function setProductLinks(array $links = null)
14611458
return $this;
14621459
}
14631460

1464-
/*******************************************************************************
1465-
** Media API
1466-
*/
14671461
/**
14681462
* Retrieve attributes for media gallery
14691463
*
@@ -1490,7 +1484,7 @@ public function getMediaAttributes()
14901484
*/
14911485
public function getMediaAttributeValues()
14921486
{
1493-
$mediaAttributeCodes = array_keys($this->getMediaAttributes());
1487+
$mediaAttributeCodes = $this->_catalogProductMediaConfig->getMediaAttributeCodes();
14941488
$mediaAttributeValues = [];
14951489
foreach ($mediaAttributeCodes as $attributeCode) {
14961490
$mediaAttributeValues[$attributeCode] = $this->getData($attributeCode);
@@ -2386,7 +2380,6 @@ public function toFlatArray()
23862380
return $dataArray;
23872381
}
23882382

2389-
//@codeCoverageIgnoreEnd
23902383
/**
23912384
* Set product sku
23922385
*

app/code/Magento/Catalog/Model/Product/Attribute/Backend/AbstractMedia.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ public function getImage(\Magento\Catalog\Model\Product $product, $file)
311311
*/
312312
public function clearMediaAttribute(\Magento\Catalog\Model\Product $product, $mediaAttribute)
313313
{
314-
$mediaAttributeCodes = array_keys($product->getMediaAttributes());
314+
$mediaAttributeCodes = $this->mediaConfig->getMediaAttributeCodes();
315315

316316
if (is_array($mediaAttribute)) {
317317
foreach ($mediaAttribute as $attribute) {
@@ -336,7 +336,7 @@ public function clearMediaAttribute(\Magento\Catalog\Model\Product $product, $me
336336
*/
337337
public function setMediaAttribute(\Magento\Catalog\Model\Product $product, $mediaAttribute, $value)
338338
{
339-
$mediaAttributeCodes = array_keys($product->getMediaAttributes());
339+
$mediaAttributeCodes = $this->mediaConfig->getMediaAttributeCodes();
340340

341341
if (is_array($mediaAttribute)) {
342342
foreach ($mediaAttribute as $atttribute) {
@@ -351,6 +351,15 @@ public function setMediaAttribute(\Magento\Catalog\Model\Product $product, $medi
351351
return $this;
352352
}
353353

354+
/**
355+
* get media attribute codes
356+
* @return array
357+
*/
358+
public function getMediaAttributeCodes()
359+
{
360+
return $this->mediaConfig->getMediaAttributeCodes();
361+
}
362+
354363
/**
355364
* Retrieve resource model
356365
*
@@ -395,7 +404,6 @@ public function duplicateImageFromTmp($file)
395404
return str_replace('\\', '/', $destinationFile);
396405
}
397406

398-
399407
/**
400408
* Check whether file to move exists. Getting unique name
401409
*

app/code/Magento/Catalog/Model/Product/Media/Config.php

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
namespace Magento\Catalog\Model\Product\Media;
1010

11+
use Magento\Eav\Model\Entity\Attribute;
12+
use Magento\Store\Model\StoreManagerInterface;
13+
use Magento\Framework\App\ObjectManager;
14+
1115
/**
1216
* Catalog product media config
1317
*
@@ -18,18 +22,55 @@ class Config implements ConfigInterface
1822
/**
1923
* Store manager
2024
*
21-
* @var \Magento\Store\Model\StoreManagerInterface
25+
* @var StoreManagerInterface
2226
*/
2327
protected $storeManager;
2428

2529
/**
26-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
30+
* @var Attribute
31+
*/
32+
private $attributeHelper;
33+
34+
/**
35+
* @param StoreManagerInterface $storeManager
2736
*/
28-
public function __construct(\Magento\Store\Model\StoreManagerInterface $storeManager)
37+
public function __construct(StoreManagerInterface $storeManager)
2938
{
3039
$this->storeManager = $storeManager;
3140
}
3241

42+
/**
43+
* The getter function to get the attributeHelper for real application code
44+
*
45+
* @deprecated
46+
*
47+
* @return Attribute
48+
*/
49+
private function getAttributeHelper()
50+
{
51+
if ($this->attributeHelper === null) {
52+
$this->attributeHelper = ObjectManager::getInstance()->get('Magento\Eav\Model\Entity\Attribute');
53+
}
54+
return $this->attributeHelper;
55+
}
56+
57+
/**
58+
* The setter function to inject the mocked attributeHelper during unit test
59+
*
60+
* @deprecated
61+
*
62+
* @throws \LogicException
63+
*
64+
* @param Attribute $attributeHelper
65+
*/
66+
public function setAttributeHelper(Attribute $attributeHelper)
67+
{
68+
if ($this->attributeHelper != null) {
69+
throw new \LogicException(__('productFactory is already set'));
70+
}
71+
$this->attributeHelper = $attributeHelper;
72+
}
73+
3374
/**
3475
* Filesystem directory path of product images
3576
* relatively to media folder
@@ -156,4 +197,12 @@ protected function _prepareFile($file)
156197
{
157198
return ltrim(str_replace('\\', '/', $file), '/');
158199
}
200+
201+
/**
202+
* @return array
203+
*/
204+
public function getMediaAttributeCodes()
205+
{
206+
return $this->getAttributeHelper()->getAttributeCodesByFrontendType('media_image');
207+
}
159208
}

app/code/Magento/Catalog/Model/Product/Type/AbstractType.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ abstract class AbstractType
2525
protected $_typeId;
2626

2727
/**
28-
*
2928
* @var array
3029
*/
3130
protected $_editableAttributes;
@@ -294,15 +293,7 @@ public function attributesCompare($attributeOne, $attributeTwo)
294293
*/
295294
public function getEditableAttributes($product)
296295
{
297-
$cacheKey = '_cache_editable_attributes';
298-
if (!$product->hasData($cacheKey)) {
299-
$editableAttributes = [];
300-
foreach ($this->getSetAttributes($product) as $attributeCode => $attribute) {
301-
$editableAttributes[$attributeCode] = $attribute;
302-
}
303-
$product->setData($cacheKey, $editableAttributes);
304-
}
305-
return $product->getData($cacheKey);
296+
return $this->getSetAttributes($product);
306297
}
307298

308299
/**

app/code/Magento/Catalog/Test/Unit/Model/Product/Type/AbstractTypeTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ public function testGetAttributeById()
8080
$this->assertNull($this->model->getAttributeById(0, $this->product));
8181
}
8282

83+
/**
84+
* @deprecated
85+
*/
8386
public function testGetEditableAttributes()
8487
{
8588
$expected = [$this->attribute];

app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ class ProductTest extends \PHPUnit_Framework_TestCase
173173
*/
174174
protected $eventManagerMock;
175175

176+
/** @var \PHPUnit_Framework_MockObject_MockObject */
177+
protected $mediaConfig;
178+
176179
/**
177180
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
178181
*/
@@ -348,6 +351,7 @@ public function setUp()
348351
$this->converterMock
349352
);
350353

354+
$this->mediaConfig = $this->getMock('Magento\Catalog\Model\Product\Media\Config', [], [], '', false);
351355
$this->objectManagerHelper = new ObjectManagerHelper($this);
352356
$this->model = $this->objectManagerHelper->getObject(
353357
'Magento\Catalog\Model\Product',
@@ -374,6 +378,7 @@ public function setUp()
374378
'entityCollectionProvider' => $this->entityCollectionProviderMock,
375379
'linkTypeProvider' => $this->linkTypeProviderMock,
376380
'mediaGalleryEntryConverterPool' => $this->mediaGalleryEntryConverterPoolMock,
381+
'catalogProductMediaConfig' => $this->mediaConfig,
377382
'data' => ['id' => 1]
378383
]
379384
);
@@ -383,7 +388,7 @@ public function setUp()
383388
public function testGetAttributes()
384389
{
385390
$productType = $this->getMockBuilder('Magento\Catalog\Model\Product\Type\AbstractType')
386-
->setMethods(['getEditableAttributes'])
391+
->setMethods(['getSetAttributes'])
387392
->disableOriginalConstructor()
388393
->getMockForAbstractClass();
389394
$this->productTypeInstanceMock->expects($this->any())->method('factory')->will(
@@ -394,7 +399,7 @@ public function testGetAttributes()
394399
->disableOriginalConstructor()
395400
->getMockForAbstractClass();
396401
$attribute->expects($this->any())->method('isInGroup')->will($this->returnValue(true));
397-
$productType->expects($this->any())->method('getEditableAttributes')->will(
402+
$productType->expects($this->any())->method('getSetAttributes')->will(
398403
$this->returnValue([$attribute])
399404
);
400405
$expect = [$attribute];
@@ -1004,7 +1009,7 @@ public function testSetProductLinks()
10041009
protected function setupMediaAttributes()
10051010
{
10061011
$productType = $this->getMockBuilder('Magento\Catalog\Model\Product\Type\AbstractType')
1007-
->setMethods(['getEditableAttributes'])
1012+
->setMethods(['getSetAttributes'])
10081013
->disableOriginalConstructor()
10091014
->getMockForAbstractClass();
10101015
$this->productTypeInstanceMock->expects($this->any())->method('factory')->will(
@@ -1033,7 +1038,7 @@ protected function setupMediaAttributes()
10331038
->willReturn($frontendMock);
10341039
$attributeSmallImage->expects($this->any())->method('getAttributeCode')->willReturn('small_image');
10351040

1036-
$productType->expects($this->any())->method('getEditableAttributes')->will(
1041+
$productType->expects($this->any())->method('getSetAttributes')->will(
10371042
$this->returnValue(['image' => $attributeImage, 'small_image' => $attributeSmallImage])
10381043
);
10391044

@@ -1052,8 +1057,8 @@ public function getMediaAttributes()
10521057

10531058
public function testGetMediaAttributeValues()
10541059
{
1055-
$this->setupMediaAttributes();
1056-
1060+
$this->mediaConfig->expects($this->once())->method('getMediaAttributeCodes')
1061+
->willReturn(['image', 'small_image']);
10571062
$this->model->setData('image', 'imageValue');
10581063
$this->model->setData('small_image', 'smallImageValue');
10591064

@@ -1070,29 +1075,6 @@ public function testGetGalleryAttributeBackendNon()
10701075
$this->assertNull($this->model->getGalleryAttributeBackend());
10711076
}
10721077

1073-
public function testGetGalleryAttributeBackend()
1074-
{
1075-
$productType = $this->getMockBuilder('Magento\Catalog\Model\Product\Type\AbstractType')
1076-
->setMethods(['getEditableAttributes'])
1077-
->disableOriginalConstructor()
1078-
->getMockForAbstractClass();
1079-
$this->productTypeInstanceMock->expects($this->any())->method('factory')->will(
1080-
$this->returnValue($productType)
1081-
);
1082-
1083-
$attributeMediaGallery = $this->getMockBuilder('\Magento\Eav\Model\Entity\Attribute\AbstractAttribute')
1084-
->setMethods(['__wakeup', 'getAttributeCode', 'getBackend'])
1085-
->disableOriginalConstructor()
1086-
->getMockForAbstractClass();
1087-
$attributeMediaGallery->expects($this->any())->method('getAttributeCode')->willReturn('media_gallery');
1088-
$expectedValue = 'expected';
1089-
$attributeMediaGallery->expects($this->once())->method('getBackend')->willReturn($expectedValue);
1090-
1091-
$productType->expects($this->once())->method('getEditableAttributes')
1092-
->willReturn(['media_gallery' => $attributeMediaGallery]);
1093-
$this->assertEquals($expectedValue, $this->model->getGalleryAttributeBackend());
1094-
}
1095-
10961078
public function testGetMediaGalleryEntriesNone()
10971079
{
10981080
$this->assertNull($this->model->getMediaGalleryEntries());

0 commit comments

Comments
 (0)