Skip to content

Commit f18377b

Browse files
🔃 [EngCom] Public Pull Requests - 2.2-develop
Accepted Public Pull Requests: - magento#13498: issue magento#13497 - Method getUrl in Magento\Catalog\Model\Product\Attribu� (by @igortregub) - magento#13494: Fixing of Problem with updating stock item qty and stock status (by @nuzil) - magento#13132: Update the Emogrifier dependency to ^2.0.0 (by @oliverklee)
2 parents 5c2b4a1 + 62304f4 commit f18377b

File tree

7 files changed

+90
-45
lines changed

7 files changed

+90
-45
lines changed

app/code/Magento/Catalog/Model/Product/Attribute/Frontend/Image.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,28 @@
99
*
1010
* @author Magento Core Team <[email protected]>
1111
*/
12+
1213
namespace Magento\Catalog\Model\Product\Attribute\Frontend;
1314

14-
class Image extends \Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend
15+
use Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend;
16+
use Magento\Framework\UrlInterface;
17+
use Magento\Store\Model\StoreManagerInterface;
18+
19+
class Image extends AbstractFrontend
1520
{
1621
/**
1722
* Store manager
1823
*
19-
* @var \Magento\Store\Model\StoreManagerInterface
24+
* @var StoreManagerInterface
2025
*/
2126
protected $_storeManager;
2227

2328
/**
2429
* Construct
2530
*
26-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
31+
* @param StoreManagerInterface $storeManager
2732
*/
28-
public function __construct(\Magento\Store\Model\StoreManagerInterface $storeManager)
33+
public function __construct(StoreManagerInterface $storeManager)
2934
{
3035
$this->_storeManager = $storeManager;
3136
}
@@ -42,9 +47,9 @@ public function getUrl($product)
4247
$image = $product->getData($this->getAttribute()->getAttributeCode());
4348
$url = false;
4449
if (!empty($image)) {
45-
$url = $this->_storeManager->getStore($product->getStore())
46-
->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA)
47-
. 'catalog/product/' . $image;
50+
$url = $this->_storeManager
51+
->getStore($product->getStore())
52+
->getBaseUrl(UrlInterface::URL_TYPE_MEDIA) . 'catalog/product/' . ltrim($image, '/');
4853
}
4954
return $url;
5055
}

app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/Frontend/ImageTest.php

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

9+
use Magento\Catalog\Model\Product;
10+
use Magento\Catalog\Model\Product\Attribute\Frontend\Image;
11+
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
812
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
13+
use Magento\Store\Model\Store;
14+
use Magento\Store\Model\StoreManagerInterface;
15+
use PHPUnit\Framework\TestCase;
916

10-
class ImageTest extends \PHPUnit\Framework\TestCase
17+
class ImageTest extends TestCase
1118
{
1219
/**
13-
* @var \Magento\Catalog\Model\Product\Attribute\Frontend\Image
20+
* @var Image
1421
*/
1522
private $model;
1623

17-
public function testGetUrl()
24+
/**
25+
* @dataProvider getUrlDataProvider
26+
* @param string $expectedImage
27+
* @param string $productImage
28+
*/
29+
public function testGetUrl(string $expectedImage, string $productImage)
30+
{
31+
$this->assertEquals($expectedImage, $this->model->getUrl($this->getMockedProduct($productImage)));
32+
}
33+
34+
/**
35+
* Data provider for testGetUrl
36+
*
37+
* @return array
38+
*/
39+
public function getUrlDataProvider(): array
1840
{
19-
$this->assertEquals('catalog/product/img.jpg', $this->model->getUrl($this->getMockedProduct()));
41+
return [
42+
['catalog/product/img.jpg', 'img.jpg'],
43+
['catalog/product/img.jpg', '/img.jpg'],
44+
];
2045
}
2146

2247
protected function setUp()
2348
{
2449
$helper = new ObjectManager($this);
2550
$this->model = $helper->getObject(
26-
\Magento\Catalog\Model\Product\Attribute\Frontend\Image::class,
51+
Image::class,
2752
['storeManager' => $this->getMockedStoreManager()]
2853
);
2954
$this->model->setAttribute($this->getMockedAttribute());
3055
}
3156

3257
/**
33-
* @return \Magento\Catalog\Model\Product
58+
* @param string $productImage
59+
* @return Product
3460
*/
35-
private function getMockedProduct()
61+
private function getMockedProduct(string $productImage): Product
3662
{
37-
$mockBuilder = $this->getMockBuilder(\Magento\Catalog\Model\Product::class);
63+
$mockBuilder = $this->getMockBuilder(Product::class);
3864
$mock = $mockBuilder->setMethods(['getData', 'getStore', '__wakeup'])
3965
->disableOriginalConstructor()
4066
->getMock();
4167

4268
$mock->expects($this->any())
4369
->method('getData')
44-
->will($this->returnValue('img.jpg'));
70+
->will($this->returnValue($productImage));
4571

4672
$mock->expects($this->any())
4773
->method('getStore');
@@ -50,13 +76,13 @@ private function getMockedProduct()
5076
}
5177

5278
/**
53-
* @return \Magento\Store\Model\StoreManagerInterface
79+
* @return StoreManagerInterface
5480
*/
55-
private function getMockedStoreManager()
81+
private function getMockedStoreManager(): StoreManagerInterface
5682
{
5783
$mockedStore = $this->getMockedStore();
5884

59-
$mockBuilder = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class);
85+
$mockBuilder = $this->getMockBuilder(StoreManagerInterface::class);
6086
$mock = $mockBuilder->setMethods(['getStore'])
6187
->disableOriginalConstructor()
6288
->getMockForAbstractClass();
@@ -69,11 +95,11 @@ private function getMockedStoreManager()
6995
}
7096

7197
/**
72-
* @return \Magento\Store\Model\Store
98+
* @return Store
7399
*/
74-
private function getMockedStore()
100+
private function getMockedStore(): Store
75101
{
76-
$mockBuilder = $this->getMockBuilder(\Magento\Store\Model\Store::class);
102+
$mockBuilder = $this->getMockBuilder(Store::class);
77103
$mock = $mockBuilder->setMethods(['getBaseUrl', '__wakeup'])
78104
->disableOriginalConstructor()
79105
->getMockForAbstractClass();
@@ -86,11 +112,11 @@ private function getMockedStore()
86112
}
87113

88114
/**
89-
* @return \Magento\Eav\Model\Entity\Attribute\AbstractAttribute
115+
* @return AbstractAttribute
90116
*/
91-
private function getMockedAttribute()
117+
private function getMockedAttribute(): AbstractAttribute
92118
{
93-
$mockBuilder = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class);
119+
$mockBuilder = $this->getMockBuilder(AbstractAttribute::class);
94120
$mockBuilder->setMethods(['getAttributeCode', '__wakeup']);
95121
$mockBuilder->disableOriginalConstructor();
96122
$mock = $mockBuilder->getMockForAbstractClass();

app/code/Magento/CatalogInventory/Observer/ProcessInventoryDataObserver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private function prepareQuantityAndStockStatus(StockItemInterface $stockItem, ar
9797
) {
9898
unset($quantityAndStockStatus['is_in_stock']);
9999
}
100-
if (isset($quantityAndStockStatus['qty'])
100+
if (array_key_exists('qty', $quantityAndStockStatus)
101101
&& $stockItem->getQty() == $quantityAndStockStatus['qty']
102102
) {
103103
unset($quantityAndStockStatus['qty']);

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"composer/composer": "1.4.1",
4343
"monolog/monolog": "^1.17",
4444
"oyejorge/less.php": "~1.7.0",
45-
"pelago/emogrifier": "1.2.0",
45+
"pelago/emogrifier": "^2.0.0",
4646
"tubalmartin/cssmin": "4.1.0",
4747
"magento/magento-composer-installer": ">=0.1.11",
4848
"braintree/braintree_php": "3.25.0",

composer.lock

Lines changed: 24 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/tests/integration/testsuite/Magento/Email/Model/Template/FilterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,9 @@ public function inlinecssDirectiveDataProvider()
352352
false,
353353
true,
354354
],
355-
'Production mode - File with compilation error results in unmodified markup' => [
355+
'Production mode - File with compilation error results in structurally unmodified markup' => [
356356
'<html><p></p> {{inlinecss file="css/file-with-error.css"}}</html>',
357-
'<html><p></p> </html>',
357+
'<p></p>',
358358
true,
359359
],
360360
'Developer mode - File with compilation error results in error message' => [

lib/internal/Magento/Framework/Css/PreProcessor/Adapter/CssInliner.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Framework\Css\PreProcessor\Adapter;
77

8+
use Magento\Framework\App\State;
89
use Pelago\Emogrifier;
910

1011
/**
@@ -17,9 +18,13 @@ class CssInliner
1718
*/
1819
private $emogrifier;
1920

20-
public function __construct()
21+
/**
22+
* @param State $appState
23+
*/
24+
public function __construct(State $appState)
2125
{
2226
$this->emogrifier = new Emogrifier();
27+
$this->emogrifier->setDebug($appState->getMode() === State::MODE_DEVELOPER);
2328
}
2429

2530
/**

0 commit comments

Comments
 (0)