diff --git a/app/code/Magento/Catalog/Model/ImageExtractor.php b/app/code/Magento/Catalog/Model/ImageExtractor.php index 977e76509afd2..2b521cc732a2a 100644 --- a/app/code/Magento/Catalog/Model/ImageExtractor.php +++ b/app/code/Magento/Catalog/Model/ImageExtractor.php @@ -5,10 +5,11 @@ */ namespace Magento\Catalog\Model; -use Magento\Catalog\Model\Product\Attribute\Backend\Media\ImageEntryConverter; use Magento\Catalog\Helper\Image; +use Magento\Catalog\Model\Product\Attribute\Backend\Media\ImageEntryConverter; +use Magento\Framework\View\Xsd\Media\TypeDataExtractorInterface; -class ImageExtractor implements \Magento\Framework\View\Xsd\Media\TypeDataExtractorInterface +class ImageExtractor implements TypeDataExtractorInterface { /** * Extract configuration data of images from the DOM structure @@ -30,8 +31,11 @@ public function process(\DOMElement $mediaNode, $mediaParentTag) if ($attribute->nodeType != XML_ELEMENT_NODE) { continue; } - if ($attribute->tagName == 'background') { + $attributeTagName = $attribute->tagName; + if ($attributeTagName === 'background') { $nodeValue = $this->processImageBackground($attribute->nodeValue); + } elseif ($attributeTagName === 'width' || $attributeTagName === 'height') { + $nodeValue = intval($attribute->nodeValue); } else { $nodeValue = $attribute->nodeValue; } @@ -55,6 +59,7 @@ private function processImageBackground($backgroundString) $backgroundArray = []; if (preg_match($pattern, $backgroundString, $backgroundArray)) { array_shift($backgroundArray); + $backgroundArray = array_map('intval', $backgroundArray); } return $backgroundArray; } diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ImageExtractorTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ImageExtractorTest.php index 23b17ed8b5304..c952af85ea6e1 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ImageExtractorTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ImageExtractorTest.php @@ -23,7 +23,7 @@ protected function setUp() public function testProcess() { $expectedArray = include(__DIR__ . '/_files/converted_view.php'); - $this->assertEquals($expectedArray, $this->model->process($this->getDomElement(), 'media')); + $this->assertSame($expectedArray, $this->model->process($this->getDomElement(), 'media')); } /**