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 dcde436 commit 4c8dbf2
Showing 1 changed file with 33 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
*/
namespace Magento\ConfigurableProduct\Block\Product\View\Type;

use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\CatalogInventory\Model\Stock\Status;
use Magento\TestFramework\Helper\Bootstrap;

/**
* Test class for \Magento\ConfigurableProduct\Block\Product\View\Type\Configurable.
*
Expand All @@ -17,14 +13,38 @@
*/
class ConfigurableTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\ConfigurableProduct\Block\Product\View\Type\Configurable
*/
protected $_block;

/**
* @var \Magento\Catalog\Model\Product
*/
protected $_product;

protected function setUp()
{
$this->_product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Catalog\Model\Product::class
);
$this->_product->load(1);
$this->_block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
)->createBlock(
\Magento\ConfigurableProduct\Block\Product\View\Type\Configurable::class
);
$this->_block->setProduct($this->_product);
}

/**
* @magentoAppIsolation enabled
*/
public function testGetAllowAttributes()
{
$attributes = $this->getSubject()->getAllowAttributes();
$attributes = $this->_block->getAllowAttributes();
$this->assertInstanceOf(
'Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute\Collection',
\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute\Collection::class,
$attributes
);
$this->assertGreaterThanOrEqual(1, $attributes->getSize());
Expand All @@ -35,74 +55,33 @@ public function testGetAllowAttributes()
*/
public function testHasOptions()
{
$this->assertTrue($this->getSubject()->hasOptions());
$this->assertTrue($this->_block->hasOptions());
}

/**
* @magentoAppIsolation enabled
* @dataProvider allowProductsDataProvider
*/
public function testGetAllowProducts($isInStock, $status, $expectedCount)
public function testGetAllowProducts()
{
/** @var ProductRepositoryInterface $productRepository */
$productRepository = Bootstrap::getObjectManager()->create(ProductRepositoryInterface::class);
$childProduct = $productRepository->get('simple_10');
$childProduct->setStatus($status);
$stockItem = $childProduct->getExtensionAttributes()->getStockItem();
$stockItem->setIsInStock($isInStock);
$productRepository->save($childProduct);

$products = $this->getSubject()->getAllowProducts();
$this->assertCount($expectedCount, $products);
$products = $this->_block->getAllowProducts();
$this->assertGreaterThanOrEqual(2, count($products));
foreach ($products as $product) {
$this->assertInstanceOf('Magento\Catalog\Model\Product', $product);
$this->assertInstanceOf(\Magento\Catalog\Model\Product::class, $product);
}
}

/**
* @return array
*/
public function allowProductsDataProvider()
{
return [
[Status::STATUS_OUT_OF_STOCK, false, 1],
[Status::STATUS_OUT_OF_STOCK, true, 1],
[Status::STATUS_IN_STOCK, false, 1],
[Status::STATUS_IN_STOCK, true, 2],
];
}

/**
* @magentoAppIsolation enabled
*/
public function testGetJsonConfig()
{
$config = json_decode($this->getSubject()->getJsonConfig(), true);
$config = json_decode($this->_block->getJsonConfig(), true);
$this->assertNotEmpty($config);
$this->assertArrayHasKey('productId', $config);
$this->assertEquals(1001, $config['productId']);
$this->assertEquals(1, $config['productId']);
$this->assertArrayHasKey('attributes', $config);
$this->assertArrayHasKey('template', $config);
$this->assertArrayHasKey('prices', $config);
$this->assertArrayHasKey('basePrice', $config['prices']);
}

/**
* @return Configurable
*/
private function getSubject()
{
/** @var ProductRepositoryInterface $productRepository */
$productRepository = Bootstrap::getObjectManager()
->create(ProductRepositoryInterface::class);
$product = $productRepository->get('configurable');
/** @var \Magento\ConfigurableProduct\Block\Product\View\Type\Configurable $block */
$block = Bootstrap::getObjectManager()->get(
'Magento\Framework\View\LayoutInterface'
)->createBlock(
'Magento\ConfigurableProduct\Block\Product\View\Type\Configurable'
);
$block->setProduct($product);
return $block;
}
}

0 comments on commit 4c8dbf2

Please sign in to comment.