Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:magento/magento2ce into MAGETWO-…
Browse files Browse the repository at this point in the history
…54677
  • Loading branch information
valdislav committed Aug 23, 2016
2 parents 6e305b4 + 3ef1e28 commit df9ac67
Show file tree
Hide file tree
Showing 24 changed files with 822 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function execute()
$attributesData[$attributeCode] = $value;
} elseif ($attribute->getFrontendInput() == 'multiselect') {
// Check if 'Change' checkbox has been checked by admin for this attribute
$isChanged = (bool)$this->getRequest()->getPost($attributeCode . '_checkbox');
$isChanged = (bool)$this->getRequest()->getPost('toggle_' . $attributeCode);
if (!$isChanged) {
unset($attributesData[$attributeCode]);
continue;
Expand Down
5 changes: 4 additions & 1 deletion app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,10 @@ public function getMediaGalleryImages()
if (!$this->hasData('media_gallery_images') && is_array($this->getMediaGallery('images'))) {
$images = $this->_collectionFactory->create();
foreach ($this->getMediaGallery('images') as $image) {
if ((isset($image['disabled']) && $image['disabled']) || empty($image['value_id'])) {
if ((isset($image['disabled']) && $image['disabled'])
|| empty($image['value_id'])
|| $images->getItemById($image['value_id']) != null
) {
continue;
}
$image['url'] = $this->getMediaConfig()->getMediaUrl($image['file']);
Expand Down
84 changes: 84 additions & 0 deletions app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ class ProductTest extends \PHPUnit_Framework_TestCase
*/
private $extensionAttributesFactory;

/**
* @var \Magento\Framework\Filesystem
*/
private $filesystemMock;

/**
* @var \Magento\Framework\Data\CollectionFactory
*/
private $collectionFactoryMock;

/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
Expand Down Expand Up @@ -374,6 +384,13 @@ protected function setUp()
$this->extensionAttributesFactory = $this->getMockBuilder(ExtensionAttributesFactory::class)
->disableOriginalConstructor()
->getMock();
$this->filesystemMock = $this->getMockBuilder(\Magento\Framework\Filesystem::class)
->disableOriginalConstructor()
->getMock();
$this->collectionFactoryMock = $this->getMockBuilder(\Magento\Framework\Data\CollectionFactory::class)
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();
$this->mediaConfig = $this->getMock(\Magento\Catalog\Model\Product\Media\Config::class, [], [], '', false);
$this->objectManagerHelper = new ObjectManagerHelper($this);

Expand Down Expand Up @@ -402,6 +419,8 @@ protected function setUp()
'mediaGalleryEntryConverterPool' => $this->mediaGalleryEntryConverterPoolMock,
'linkRepository' => $this->productLinkRepositoryMock,
'catalogProductMediaConfig' => $this->mediaConfig,
'_filesystem' => $this->filesystemMock,
'_collectionFactory' => $this->collectionFactoryMock,
'data' => ['id' => 1]
]
);
Expand Down Expand Up @@ -1230,6 +1249,71 @@ public function testSetMediaGalleryEntries()
$this->assertEquals($expectedResult, $this->model->getMediaGallery());
}

public function testGetMediaGalleryImagesMerging()
{
$mediaEntries = [
'images' => [
[
'value_id' => 1,
'file' => 'imageFile.jpg',
'media_type' => 'image',
],
[
'value_id' => 1,
'file' => 'imageFile.jpg',
],
[
'value_id' => 2,
'file' => 'smallImageFile.jpg',
'media_type' => 'image',
],
]
];
$expectedImageDataObject = new \Magento\Framework\DataObject([
'value_id' => 1,
'file' => 'imageFile.jpg',
'media_type' => 'image',
'url' => 'http://magento.dev/pub/imageFile.jpg',
'id' => 1,
'path' => '/var/www/html/pub/imageFile.jpg',
]);
$expectedSmallImageDataObject = new \Magento\Framework\DataObject([
'value_id' => 2,
'file' => 'smallImageFile.jpg',
'media_type' => 'image',
'url' => 'http://magento.dev/pub/smallImageFile.jpg',
'id' => 2,
'path' => '/var/www/html/pub/smallImageFile.jpg',
]);

$directoryMock = $this->getMockBuilder(\Magento\Framework\Filesystem\Directory\ReadInterface::class)
->disableOriginalConstructor()
->getMock();
$this->filesystemMock->expects($this->once())->method('getDirectoryRead')->willReturn($directoryMock);
$this->model->setData('media_gallery', $mediaEntries);
$imagesCollectionMock = $this->getMockBuilder(\Magento\Framework\Data\Collection::class)
->disableOriginalConstructor()
->getMock();
$this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($imagesCollectionMock);
$imagesCollectionMock->expects($this->at(2))->method('getItemById')->with(1)->willReturn($expectedImageDataObject);
$this->mediaConfig->expects($this->at(0))
->method('getMediaUrl')
->willReturn('http://magento.dev/pub/imageFile.jpg');
$directoryMock->expects($this->at(0))
->method('getAbsolutePath')
->willReturn('/var/www/html/pub/imageFile.jpg');
$this->mediaConfig->expects($this->at(2))
->method('getMediaUrl')
->willReturn('http://magento.dev/pub/smallImageFile.jpg');
$directoryMock->expects($this->at(1))
->method('getAbsolutePath')
->willReturn('/var/www/html/pub/smallImageFile.jpg');
$imagesCollectionMock->expects($this->at(1))->method('addItem')->with($expectedImageDataObject);
$imagesCollectionMock->expects($this->at(4))->method('addItem')->with($expectedSmallImageDataObject);

$this->model->getMediaGalleryImages();
}

public function testGetCustomAttributes()
{
$priceCode = 'price';
Expand Down
Loading

0 comments on commit df9ac67

Please sign in to comment.