Skip to content

Commit

Permalink
🔃 [EngCom] Public Pull Requests - 2.2-develop
Browse files Browse the repository at this point in the history
Accepted Public Pull Requests:
 - #13498: issue #13497 - Method getUrl in Magento\Catalog\Model\Product\Attribu� (by @igortregub)
 - #13494: Fixing of Problem with updating stock item qty and stock status (by @nuzil)
 - #13132: Update the Emogrifier dependency to ^2.0.0 (by @oliverklee)
  • Loading branch information
magento-engcom-team authored Feb 6, 2018
2 parents 5c2b4a1 + 62304f4 commit f18377b
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,28 @@
*
* @author Magento Core Team <core@magentocommerce.com>
*/

namespace Magento\Catalog\Model\Product\Attribute\Frontend;

class Image extends \Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend
use Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\StoreManagerInterface;

class Image extends AbstractFrontend
{
/**
* Store manager
*
* @var \Magento\Store\Model\StoreManagerInterface
* @var StoreManagerInterface
*/
protected $_storeManager;

/**
* Construct
*
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param StoreManagerInterface $storeManager
*/
public function __construct(\Magento\Store\Model\StoreManagerInterface $storeManager)
public function __construct(StoreManagerInterface $storeManager)
{
$this->_storeManager = $storeManager;
}
Expand All @@ -42,9 +47,9 @@ public function getUrl($product)
$image = $product->getData($this->getAttribute()->getAttributeCode());
$url = false;
if (!empty($image)) {
$url = $this->_storeManager->getStore($product->getStore())
->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA)
. 'catalog/product/' . $image;
$url = $this->_storeManager
->getStore($product->getStore())
->getBaseUrl(UrlInterface::URL_TYPE_MEDIA) . 'catalog/product/' . ltrim($image, '/');
}
return $url;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,71 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Catalog\Test\Unit\Model\Product\Attribute\Frontend;

use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Attribute\Frontend\Image;
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;
use PHPUnit\Framework\TestCase;

class ImageTest extends \PHPUnit\Framework\TestCase
class ImageTest extends TestCase
{
/**
* @var \Magento\Catalog\Model\Product\Attribute\Frontend\Image
* @var Image
*/
private $model;

public function testGetUrl()
/**
* @dataProvider getUrlDataProvider
* @param string $expectedImage
* @param string $productImage
*/
public function testGetUrl(string $expectedImage, string $productImage)
{
$this->assertEquals($expectedImage, $this->model->getUrl($this->getMockedProduct($productImage)));
}

/**
* Data provider for testGetUrl
*
* @return array
*/
public function getUrlDataProvider(): array
{
$this->assertEquals('catalog/product/img.jpg', $this->model->getUrl($this->getMockedProduct()));
return [
['catalog/product/img.jpg', 'img.jpg'],
['catalog/product/img.jpg', '/img.jpg'],
];
}

protected function setUp()
{
$helper = new ObjectManager($this);
$this->model = $helper->getObject(
\Magento\Catalog\Model\Product\Attribute\Frontend\Image::class,
Image::class,
['storeManager' => $this->getMockedStoreManager()]
);
$this->model->setAttribute($this->getMockedAttribute());
}

/**
* @return \Magento\Catalog\Model\Product
* @param string $productImage
* @return Product
*/
private function getMockedProduct()
private function getMockedProduct(string $productImage): Product
{
$mockBuilder = $this->getMockBuilder(\Magento\Catalog\Model\Product::class);
$mockBuilder = $this->getMockBuilder(Product::class);
$mock = $mockBuilder->setMethods(['getData', 'getStore', '__wakeup'])
->disableOriginalConstructor()
->getMock();

$mock->expects($this->any())
->method('getData')
->will($this->returnValue('img.jpg'));
->will($this->returnValue($productImage));

$mock->expects($this->any())
->method('getStore');
Expand All @@ -50,13 +76,13 @@ private function getMockedProduct()
}

/**
* @return \Magento\Store\Model\StoreManagerInterface
* @return StoreManagerInterface
*/
private function getMockedStoreManager()
private function getMockedStoreManager(): StoreManagerInterface
{
$mockedStore = $this->getMockedStore();

$mockBuilder = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class);
$mockBuilder = $this->getMockBuilder(StoreManagerInterface::class);
$mock = $mockBuilder->setMethods(['getStore'])
->disableOriginalConstructor()
->getMockForAbstractClass();
Expand All @@ -69,11 +95,11 @@ private function getMockedStoreManager()
}

/**
* @return \Magento\Store\Model\Store
* @return Store
*/
private function getMockedStore()
private function getMockedStore(): Store
{
$mockBuilder = $this->getMockBuilder(\Magento\Store\Model\Store::class);
$mockBuilder = $this->getMockBuilder(Store::class);
$mock = $mockBuilder->setMethods(['getBaseUrl', '__wakeup'])
->disableOriginalConstructor()
->getMockForAbstractClass();
Expand All @@ -86,11 +112,11 @@ private function getMockedStore()
}

/**
* @return \Magento\Eav\Model\Entity\Attribute\AbstractAttribute
* @return AbstractAttribute
*/
private function getMockedAttribute()
private function getMockedAttribute(): AbstractAttribute
{
$mockBuilder = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class);
$mockBuilder = $this->getMockBuilder(AbstractAttribute::class);
$mockBuilder->setMethods(['getAttributeCode', '__wakeup']);
$mockBuilder->disableOriginalConstructor();
$mock = $mockBuilder->getMockForAbstractClass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private function prepareQuantityAndStockStatus(StockItemInterface $stockItem, ar
) {
unset($quantityAndStockStatus['is_in_stock']);
}
if (isset($quantityAndStockStatus['qty'])
if (array_key_exists('qty', $quantityAndStockStatus)
&& $stockItem->getQty() == $quantityAndStockStatus['qty']
) {
unset($quantityAndStockStatus['qty']);
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"composer/composer": "1.4.1",
"monolog/monolog": "^1.17",
"oyejorge/less.php": "~1.7.0",
"pelago/emogrifier": "1.2.0",
"pelago/emogrifier": "^2.0.0",
"tubalmartin/cssmin": "4.1.0",
"magento/magento-composer-installer": ">=0.1.11",
"braintree/braintree_php": "3.25.0",
Expand Down
39 changes: 24 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ public function inlinecssDirectiveDataProvider()
false,
true,
],
'Production mode - File with compilation error results in unmodified markup' => [
'Production mode - File with compilation error results in structurally unmodified markup' => [
'<html><p></p> {{inlinecss file="css/file-with-error.css"}}</html>',
'<html><p></p> </html>',
'<p></p>',
true,
],
'Developer mode - File with compilation error results in error message' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\Framework\Css\PreProcessor\Adapter;

use Magento\Framework\App\State;
use Pelago\Emogrifier;

/**
Expand All @@ -17,9 +18,13 @@ class CssInliner
*/
private $emogrifier;

public function __construct()
/**
* @param State $appState
*/
public function __construct(State $appState)
{
$this->emogrifier = new Emogrifier();
$this->emogrifier->setDebug($appState->getMode() === State::MODE_DEVELOPER);
}

/**
Expand Down

0 comments on commit f18377b

Please sign in to comment.