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 13, 2017
1 parent cd6c087 commit ed1c05c
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 213 deletions.
Original file line number Diff line number Diff line change
@@ -1,33 +1,18 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\ConfigurableProduct\Block\Plugin\Product\Media;

use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
use Magento\Catalog\Model\Product;
use Magento\Framework\Serialize\Serializer\Json;

/**
* Provides a serialized media gallery data for configurable product options.
*/
class Gallery
{
/**
* @var Json
*/
private $json;

/**
* @param Json $json
*/
public function __construct(
Json $json
) {
$this->json = $json;
}

/**
* @param \Magento\Catalog\Block\Product\View\Gallery $subject
* @param string $result
Expand All @@ -37,7 +22,7 @@ public function afterGetOptionsMediaGalleryDataJson(
\Magento\Catalog\Block\Product\View\Gallery $subject,
$result
) {
$result = $this->json->unserialize($result);
$result = json_decode($result, true);
$parentProduct = $subject->getProduct();
if ($parentProduct->getTypeId() == Configurable::TYPE_CODE) {
/** @var Configurable $productType */
Expand All @@ -49,7 +34,7 @@ public function afterGetOptionsMediaGalleryDataJson(
$result[$key] = $this->getProductGallery($product);
}
}
return $this->json->serialize($result);
return json_encode($result);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\ConfigurableProduct\Test\Unit\Block\Plugin\Product\Media;

use Magento\ConfigurableProduct\Block\Plugin\Product\Media\Gallery;
use Magento\Catalog\Model\Product;

/**
* Class GalleryTest
*/
class GalleryTest extends \PHPUnit_Framework_TestCase
{

public function testAfterGetOptions()
{
$jsonMock = $this->createJsonMock();
$productMock = $this->createProductMock();
$galleryMock = $this->createGalleryMock();
$variationProductMock = $this->createProductMock();
$configurableTypeMock = $this->createConfigurableTypeMock();

$resultJson = '[]';
$variationProductId = 1;
$expectedGalleryJson = [
$variationProductId => [
[
'mediaType' => 'type',
'videoUrl' => 'url',
'isBase' => true
]
]
];
$image = new \Magento\Framework\DataObject(
['media_type' => 'type', 'video_url' => 'url', 'file' => 'image.jpg']
);

$galleryMock->expects(($this->any()))->method('getProduct')->willReturn($productMock);
$productMock->expects($this->once())->method('getTypeId')->willReturn('configurable');
$productMock->expects($this->once())->method('getTypeInstance')->willReturn($configurableTypeMock);
$configurableTypeMock->expects($this->once())->method('getUsedProducts')->with($productMock)
->willReturn([$variationProductMock]);
$variationProductMock->expects($this->once())->method('getId')->willReturn($variationProductId);
$variationProductMock->expects($this->once())->method('getMediaGalleryImages')->willReturn([$image]);
$variationProductMock->expects($this->once())->method('getImage')->willReturn('image.jpg');

$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$plugin = $helper->getObject(Gallery::class);
$result = $plugin->afterGetOptionsMediaGalleryDataJson($galleryMock, $resultJson);
$this->assertEquals(json_encode($expectedGalleryJson), $result);
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject
*/
private function createJsonMock()
{
return $this->getMockBuilder(Json::class)
->disableOriginalConstructor()
->getMock();
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject
*/
private function createProductMock()
{
return $this->getMockBuilder(Product::class)
->disableOriginalConstructor()
->getMock();
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject
*/
private function createGalleryMock()
{
return $this->getMockBuilder(\Magento\Catalog\Block\Product\View\Gallery::class)
->disableOriginalConstructor()
->getMock();
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject
*/
private function createConfigurableTypeMock()
{
return $this->getMockBuilder(\Magento\ConfigurableProduct\Model\Product\Type\Configurable::class)
->disableOriginalConstructor()
->getMock();
}
}
29 changes: 0 additions & 29 deletions lib/internal/Magento/Framework/Serialize/JsonValidator.php

This file was deleted.

8 changes: 0 additions & 8 deletions lib/internal/Magento/Framework/Serialize/README.md

This file was deleted.

40 changes: 0 additions & 40 deletions lib/internal/Magento/Framework/Serialize/Serializer/Base64Json.php

This file was deleted.

40 changes: 0 additions & 40 deletions lib/internal/Magento/Framework/Serialize/Serializer/Json.php

This file was deleted.

46 changes: 0 additions & 46 deletions lib/internal/Magento/Framework/Serialize/Serializer/Serialize.php

This file was deleted.

32 changes: 0 additions & 32 deletions lib/internal/Magento/Framework/Serialize/SerializerInterface.php

This file was deleted.

0 comments on commit ed1c05c

Please sign in to comment.