Skip to content

Commit

Permalink
MAGETWO-8709: [GITHUB] Child product image should be shown in Wishist…
Browse files Browse the repository at this point in the history
… if options are selected for configurable product #8168

- fixing formatting
  • Loading branch information
cpartica committed Jul 11, 2018
1 parent 838182a commit dc703f4
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class Configurable extends Renderer implements IdentityInterface
{
/**
* Path in config to the setting which defines if parent or child product should be used to generate a thumbnail.
* @deprecated moved to model because of class refactoring
* @see \Magento\ConfigurableProduct\Model\Product\Configuration\Item\ItemProductResolver::CONFIG_THUMBNAIL_SOURCE
*/
const CONFIG_THUMBNAIL_SOURCE = 'checkout/cart/configurable_product_image';

Expand Down Expand Up @@ -57,7 +59,7 @@ public function getOptionList()

/**
* {@inheritdoc}
* @deprecated because parent can handle the logic for images of all product types
* @deprecated because now parent handles the logic for images of all product types
* @see \Magento\Checkout\Block\Cart\Item\Renderer::getProductForThumbnail
*/
public function getProductForThumbnail()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
*/
class ItemProductResolver implements ItemResolverInterface
{
/**
* Path in config to the setting which defines if parent or child product should be used to generate a thumbnail.
*/
const CONFIG_THUMBNAIL_SOURCE = 'checkout/cart/configurable_product_image';

/**
Expand All @@ -43,7 +46,7 @@ public function getFinalProduct(ItemInterface $item) : ProductInterface
*/
$parentItem = $item->getProduct();
$config = $this->scopeConfig->getValue(
\Magento\ConfigurableProduct\Block\Cart\Item\Renderer\Configurable::CONFIG_THUMBNAIL_SOURCE,
self::CONFIG_THUMBNAIL_SOURCE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,102 +11,48 @@
class ConfigurableTest extends \PHPUnit\Framework\TestCase
{
/** @var \Magento\Framework\View\ConfigInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $_configManager;
private $configManager;

/** @var \Magento\Catalog\Helper\Image|\PHPUnit_Framework_MockObject_MockObject */
protected $_imageHelper;
private $imageHelper;

/** @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $_scopeConfig;
private $scopeConfig;

/** @var \PHPUnit_Framework_MockObject_MockObject */
protected $productConfigMock;
private $productConfigMock;

/** @var Renderer */
protected $_renderer;
private $renderer;

protected function setUp()
{
parent::setUp();
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->_configManager = $this->createMock(\Magento\Framework\View\ConfigInterface::class);
$this->_imageHelper = $this->createPartialMock(
$this->configManager = $this->createMock(\Magento\Framework\View\ConfigInterface::class);
$this->imageHelper = $this->createPartialMock(
\Magento\Catalog\Helper\Image::class,
['init', 'resize', '__toString']
);
$this->_scopeConfig = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
$this->scopeConfig = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
$this->productConfigMock = $this->createMock(\Magento\Catalog\Helper\Product\Configuration::class);
$this->_renderer = $objectManagerHelper->getObject(
$this->renderer = $objectManagerHelper->getObject(
\Magento\ConfigurableProduct\Block\Cart\Item\Renderer\Configurable::class,
[
'viewConfig' => $this->_configManager,
'imageHelper' => $this->_imageHelper,
'scopeConfig' => $this->_scopeConfig,
'viewConfig' => $this->configManager,
'imageHelper' => $this->imageHelper,
'scopeConfig' => $this->scopeConfig,
'productConfig' => $this->productConfigMock
]
);
}

/**
* Initialize parent configurable product and child product.
*
* @param bool $childHasThumbnail
* @param bool $useParentThumbnail
* @return \Magento\Catalog\Model\Product[]|\PHPUnit_Framework_MockObject_MockObject[]
*/
protected function _initProducts($childHasThumbnail = true, $useParentThumbnail = false)
{
/** Set option which can force usage of parent product thumbnail when configurable product is displayed */
$thumbnailToBeUsed = $useParentThumbnail
? ThumbnailSource::OPTION_USE_PARENT_IMAGE
: ThumbnailSource::OPTION_USE_OWN_IMAGE;
$this->_scopeConfig->expects(
$this->any()
)->method(
'getValue'
)->with(
Renderer::CONFIG_THUMBNAIL_SOURCE
)->will(
$this->returnValue($thumbnailToBeUsed)
);

/** Initialized parent product */
/** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $parentProduct */
$parentProduct = $this->createMock(\Magento\Catalog\Model\Product::class);

/** Initialize child product */
/** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $childProduct */
$childProduct = $this->createPartialMock(\Magento\Catalog\Model\Product::class, ['getThumbnail', '__wakeup']);
$childThumbnail = $childHasThumbnail ? 'thumbnail.jpg' : 'no_selection';
$childProduct->expects($this->any())->method('getThumbnail')->will($this->returnValue($childThumbnail));

/** Mock methods which return parent and child products */
/** @var \Magento\Quote\Model\Quote\Item\Option|\PHPUnit_Framework_MockObject_MockObject $itemOption */
$itemOption = $this->createMock(\Magento\Quote\Model\Quote\Item\Option::class);
$itemOption->expects($this->any())->method('getProduct')->will($this->returnValue($childProduct));
/** @var \Magento\Quote\Model\Quote\Item|\PHPUnit_Framework_MockObject_MockObject $item */
$item = $this->createMock(\Magento\Quote\Model\Quote\Item::class);
$item->expects($this->any())->method('getProduct')->will($this->returnValue($parentProduct));
$item->expects(
$this->any()
)->method(
'getOptionByCode'
)->with(
'simple_product'
)->will(
$this->returnValue($itemOption)
);
$this->_renderer->setItem($item);

return ['parentProduct' => $parentProduct, 'childProduct' => $childProduct];
}

public function testGetOptionList()
{
$itemMock = $this->createMock(\Magento\Quote\Model\Quote\Item::class);
$this->_renderer->setItem($itemMock);
$this->renderer->setItem($itemMock);
$this->productConfigMock->expects($this->once())->method('getOptions')->with($itemMock);
$this->_renderer->getOptionList();
$this->renderer->getOptionList();
}

public function testGetIdentities()
Expand All @@ -116,7 +62,7 @@ public function testGetIdentities()
$product->expects($this->exactly(2))->method('getIdentities')->will($this->returnValue($productTags));
$item = $this->createMock(\Magento\Quote\Model\Quote\Item::class);
$item->expects($this->exactly(2))->method('getProduct')->will($this->returnValue($product));
$this->_renderer->setItem($item);
$this->assertEquals(array_merge($productTags, $productTags), $this->_renderer->getIdentities());
$this->renderer->setItem($item);
$this->assertEquals(array_merge($productTags, $productTags), $this->renderer->getIdentities());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class Grouped extends Renderer implements IdentityInterface
{
/**
* Path in config to the setting which defines if parent or child product should be used to generate a thumbnail.
* @deprecated moved to model because of class refactoring
* @see \Magento\GroupedProduct\Model\Product\Configuration\Item\ItemProductResolver::CONFIG_THUMBNAIL_SOURCE
*/
const CONFIG_THUMBNAIL_SOURCE = 'checkout/cart/grouped_product_image';

Expand All @@ -38,7 +40,7 @@ public function getGroupedProduct()

/**
* {@inheritdoc}
* @deprecated because parent can handle the logic for images of all product types
* @deprecated because now parent handles the logic for images of all product types
* @see \Magento\Checkout\Block\Cart\Item\Renderer::getProductForThumbnail
*/
public function getProductForThumbnail()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function getFinalProduct(ItemInterface $item) : ProductInterface
* or if child product thumbnail is not available
*/
$config = $this->scopeConfig->getValue(
\Magento\GroupedProduct\Block\Cart\Item\Renderer\Grouped::CONFIG_THUMBNAIL_SOURCE,
self::CONFIG_THUMBNAIL_SOURCE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
$childProduct = $item->getProduct();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,84 +11,30 @@
class GroupedTest extends \PHPUnit\Framework\TestCase
{
/** @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $_scopeConfig;
private $scopeConfig;

/** @var Renderer */
protected $_renderer;
private $renderer;

protected function setUp()
{
parent::setUp();
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->_scopeConfig = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
$this->_renderer = $objectManagerHelper->getObject(
$this->scopeConfig = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
$this->renderer = $objectManagerHelper->getObject(
\Magento\GroupedProduct\Block\Cart\Item\Renderer\Grouped::class,
['scopeConfig' => $this->_scopeConfig]
['scopeConfig' => $this->scopeConfig]
);
}

/**
* Initialize parent grouped product and child product.
*
* @param bool $childHasThumbnail
* @param bool $useParentThumbnail
* @return \Magento\Catalog\Model\Product[]|\PHPUnit_Framework_MockObject_MockObject[]
*/
protected function _initProducts($childHasThumbnail = true, $useParentThumbnail = false)
{
/** Set option which can force usage of parent product thumbnail when grouped product is displayed */
$thumbnailToBeUsed = $useParentThumbnail
? ThumbnailSource::OPTION_USE_PARENT_IMAGE
: ThumbnailSource::OPTION_USE_OWN_IMAGE;
$this->_scopeConfig->expects(
$this->any()
)->method(
'getValue'
)->with(
Renderer::CONFIG_THUMBNAIL_SOURCE
)->will(
$this->returnValue($thumbnailToBeUsed)
);

/** Initialized parent product */
/** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $parentProduct */
$parentProduct = $this->createMock(\Magento\Catalog\Model\Product::class);

/** Initialize child product */
/** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $childProduct */
$childProduct = $this->createPartialMock(\Magento\Catalog\Model\Product::class, ['getThumbnail', '__wakeup']);
$childThumbnail = $childHasThumbnail ? 'thumbnail.jpg' : 'no_selection';
$childProduct->expects($this->any())->method('getThumbnail')->will($this->returnValue($childThumbnail));

/** Mock methods which return parent and child products */
/** @var \Magento\Quote\Model\Quote\Item\Option|\PHPUnit_Framework_MockObject_MockObject $itemOption */
$itemOption = $this->createMock(\Magento\Quote\Model\Quote\Item\Option::class);
$itemOption->expects($this->any())->method('getProduct')->will($this->returnValue($parentProduct));
/** @var \Magento\Quote\Model\Quote\Item|\PHPUnit_Framework_MockObject_MockObject $item */
$item = $this->createMock(\Magento\Quote\Model\Quote\Item::class);
$item->expects($this->any())->method('getProduct')->will($this->returnValue($childProduct));
$item->expects(
$this->any()
)->method(
'getOptionByCode'
)->with(
'product_type'
)->will(
$this->returnValue($itemOption)
);
$this->_renderer->setItem($item);

return ['parentProduct' => $parentProduct, 'childProduct' => $childProduct];
}

public function testGetIdentities()
{
$productTags = ['catalog_product_1'];
$product = $this->createMock(\Magento\Catalog\Model\Product::class);
$product->expects($this->exactly(2))->method('getIdentities')->will($this->returnValue($productTags));
$item = $this->createMock(\Magento\Quote\Model\Quote\Item::class);
$item->expects($this->exactly(2))->method('getProduct')->will($this->returnValue($product));
$this->_renderer->setItem($item);
$this->assertEquals(array_merge($productTags, $productTags), $this->_renderer->getIdentities());
$this->renderer->setItem($item);
$this->assertEquals(array_merge($productTags, $productTags), $this->renderer->getIdentities());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

/**
* Wishlist block customer item cart column
*
* @author Magento Core Team <core@magentocommerce.com>
*/
namespace Magento\Wishlist\Block\Customer\Wishlist\Item\Column;

Expand Down

0 comments on commit dc703f4

Please sign in to comment.