Skip to content

Commit

Permalink
MAGETWO-70606: [Backport] - [GITHUB] Simple product videos display th…
Browse files Browse the repository at this point in the history
…e thumbnail image rather than the embedded video player. #6360 - for 2.1
  • Loading branch information
VladimirZaets committed Sep 15, 2017
1 parent 8ddb2af commit dcde436
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@

use Magento\Swatches\Block\Product\Renderer\Configurable;
use Magento\Swatches\Model\Swatch;
use Magento\Swatches\Model\SwatchAttributesProvider;
use Magento\Framework\Locale\Format;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyFields)
*/
class ConfigurableTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -58,6 +61,12 @@ class ConfigurableTest extends \PHPUnit_Framework_TestCase
/** @var \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject */
private $urlBuilder;

/** @var \Magento\Framework\Locale\Format|\PHPUnit_Framework_MockObject_MockObject */
private $localeFormat;

/** @var \Magento\Swatches\Model\SwatchAttributesProvider |\PHPUnit_Framework_MockObject_MockObject */
private $swatchAttributesProvider;

protected function setUp()
{
$this->arrayUtils = $this->getMock('\Magento\Framework\Stdlib\ArrayUtils', [], [], '', false);
Expand All @@ -68,6 +77,8 @@ protected function setUp()
$this->catalogProduct = $this->getMock('\Magento\Catalog\Helper\Product', [], [], '', false);
$this->currentCustomer = $this->getMock('\Magento\Customer\Helper\Session\CurrentCustomer', [], [], '', false);
$this->priceCurrency = $this->getMock('\Magento\Framework\Pricing\PriceCurrencyInterface', [], [], '', false);
$this->swatchAttributesProvider = $this->getMock(SwatchAttributesProvider::class, [], [], '', false);
$this->localeFormat = $this->getMock(Format::class, [], [], '', false);
$this->configurableAttributeData = $this->getMock(
'Magento\ConfigurableProduct\Model\ConfigurableAttributeData',
[],
Expand Down Expand Up @@ -98,6 +109,8 @@ protected function setUp()
'priceCurrency' => $this->priceCurrency,
'configurableAttributeData' => $this->configurableAttributeData,
'data' => [],
'swatchAttributesProvider' => $this->swatchAttributesProvider,
'format' => $this->localeFormat
]
);
}
Expand Down Expand Up @@ -154,9 +167,11 @@ public function testSetIsProductListingContext()
private function prepareGetJsonSwatchConfig()
{
$product1 = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false);
$product1->expects($this->atLeastOnce())->method('isSaleable')->willReturn(true);
$product1->expects($this->atLeastOnce())->method('getData')->with('code')->willReturn(1);

$product2 = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false);
$product2->expects($this->atLeastOnce())->method('isSaleable')->willReturn(true);
$product2->expects($this->atLeastOnce())->method('getData')->with('code')->willReturn(3);

$simpleProducts = [$product1, $product2];
Expand All @@ -167,7 +182,7 @@ private function prepareGetJsonSwatchConfig()
'',
false
);
$configurableType->expects($this->atLeastOnce())->method('getSalableUsedProducts')->with($this->product, null)
$configurableType->expects($this->atLeastOnce())->method('getUsedProducts')->with($this->product, null)
->willReturn($simpleProducts);
$this->product->expects($this->any())->method('getTypeInstance')->willReturn($configurableType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ public function setUp()
'',
false
);
$this->product = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false);
$this->product = self::getMockBuilder(\Magento\Catalog\Model\Product::class)
->setMethods(['getTypeInstance', 'getUsedProducts', 'isSaleable'])
->disableOriginalConstructor()
->getMock();
$this->typeInstance = $this->getMock(
\Magento\Catalog\Model\Product\Type\AbstractType::class,
[],
Expand Down Expand Up @@ -203,7 +206,7 @@ public function setUp()
}

/**
* @covers Magento\Swatches\Block\Product\Renderer\Listing\Configurable::getSwatchAttributesData
* @covers \Magento\Swatches\Block\Product\Renderer\Listing\Configurable::getSwatchAttributesData
*/
public function testGetJsonSwatchConfigWithoutSwatches()
{
Expand All @@ -219,7 +222,7 @@ public function testGetJsonSwatchConfigWithoutSwatches()
}

/**
* @covers Magento\Swatches\Block\Product\Renderer\Listing\Configurable::getSwatchAttributesData
* @covers \Magento\Swatches\Block\Product\Renderer\Listing\Configurable::getSwatchAttributesData
*/
public function testGetJsonSwatchNotUsedInProductListing()
{
Expand All @@ -242,7 +245,7 @@ public function testGetJsonSwatchNotUsedInProductListing()
}

/**
* @covers Magento\Swatches\Block\Product\Renderer\Listing\Configurable::getSwatchAttributesData
* @covers \Magento\Swatches\Block\Product\Renderer\Listing\Configurable::getSwatchAttributesData
*/
public function testGetJsonSwatchUsedInProductListing()
{
Expand Down Expand Up @@ -277,15 +280,14 @@ public function testGetJsonSwatchUsedInProductListing()
$this->configurable->getJsonSwatchConfig();
}

/**
* @return void
*/
private function prepareGetJsonSwatchConfig()
{
$product1 = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false);
$product1->expects($this->atLeastOnce())->method('isSaleable')->willReturn(true);
$product1->expects($this->any())->method('getData')->with('code')->willReturn(1);

$product2 = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false);
$product2->expects($this->atLeastOnce())->method('isSaleable')->willReturn(true);
$product2->expects($this->any())->method('getData')->with('code')->willReturn(3);

$simpleProducts = [$product1, $product2];
Expand All @@ -296,10 +298,23 @@ private function prepareGetJsonSwatchConfig()
'',
false
);
$configurableType->expects($this->atLeastOnce())->method('getSalableUsedProducts')
$configurableType->expects($this->any())->method('getSalableUsedProducts')
->with($this->product, null)
->willReturn($simpleProducts);
$this->product->expects($this->any())->method('getTypeInstance')->willReturn($configurableType);
$productCollection = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Collection::class)
->disableOriginalConstructor()
->setMethods(['getIterator'])
->getMock();

$configurableType->expects($this->any())->method('getUsedProducts')
->with($this->product, null)
->willReturn($productCollection);

$productCollection->expects($this->once())->method('getIterator')
->willReturn(new \ArrayIterator($simpleProducts));

$this->product->expects($this->any())->method('getTypeInstance')
->willReturn($configurableType);

$productAttribute1 = $this->getMock(
\Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class,
Expand Down

0 comments on commit dcde436

Please sign in to comment.