Skip to content
Snippets Groups Projects
Commit b241a65c authored by Volodymyr Zaets's avatar Volodymyr Zaets Committed by GitHub
Browse files

Merge pull request #616 from magento-falcons/MAGETWO-61201

Bugs
- MAGETWO-60908 Image role can't be updated
- MAGETWO-60299 Sample Data Test Failure: NavigateProductEntityTest
parents d40ab324 f84bd659
No related merge requests found
......@@ -94,13 +94,16 @@ class GalleryManagement implements \Magento\Catalog\Api\ProductAttributeMediaGal
}
$found = false;
foreach ($existingMediaGalleryEntries as $key => $existingEntry) {
$entryTypes = (array)$entry->getTypes();
$existingEntryTypes = (array)$existingMediaGalleryEntries[$key]->getTypes();
$existingMediaGalleryEntries[$key]->setTypes(array_diff($existingEntryTypes, $entryTypes));
if ($existingEntry->getId() == $entry->getId()) {
$found = true;
if ($entry->getFile()) {
$entry->setId(null);
}
$existingMediaGalleryEntries[$key] = $entry;
break;
}
}
if (!$found) {
......
......@@ -298,11 +298,11 @@ class Processor
if (is_array($mediaAttribute)) {
foreach ($mediaAttribute as $attribute) {
if (in_array($attribute, $mediaAttributeCodes)) {
$product->setData($attribute, null);
$product->setData($attribute, 'no_selection');
}
}
} elseif (in_array($mediaAttribute, $mediaAttributeCodes)) {
$product->setData($mediaAttribute, null);
$product->setData($mediaAttribute, 'no_selection');
}
return $this;
......
......@@ -191,20 +191,33 @@ class GalleryManagementTest extends \PHPUnit_Framework_TestCase
$productSku = 'testProduct';
$entryMock = $this->getMock(\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface::class);
$entryId = 42;
$entrySecondId = 43;
$this->productRepositoryMock->expects($this->once())->method('get')->with($productSku)
->willReturn($this->productMock);
$existingEntryMock = $this->getMock(
\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface::class
);
$existingSecondEntryMock = $this->getMock(
\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface::class
);
$existingEntryMock->expects($this->once())->method('getId')->willReturn($entryId);
$existingEntryMock->expects($this->once())->method('getTypes')->willReturn(['small_image']);
$existingEntryMock->expects($this->once())->method('setTypes')->with(['small_image']);
$existingSecondEntryMock->expects($this->once())->method('getId')->willReturn($entrySecondId);
$existingSecondEntryMock->expects($this->once())->method('getTypes')->willReturn(['image']);
$existingSecondEntryMock->expects($this->once())->method('setTypes')->with([]);
$this->productMock->expects($this->once())->method('getMediaGalleryEntries')
->willReturn([$existingEntryMock]);
$entryMock->expects($this->once())->method('getId')->willReturn($entryId);
->willReturn([$existingEntryMock, $existingSecondEntryMock]);
$entryMock->expects($this->exactly(2))->method('getId')->willReturn($entryId);
$entryMock->expects($this->once())->method('getFile')->willReturn("base64");
$entryMock->expects($this->once())->method('setId')->with(null);
$entryMock->expects($this->exactly(2))->method('getTypes')->willReturn(['image']);
$this->productMock->expects($this->once())->method('setMediaGalleryEntries')
->willReturn([$entryMock]);
->with([$entryMock, $existingSecondEntryMock])
->willReturnSelf();
$this->productRepositoryMock->expects($this->once())->method('save')->with($this->productMock);
$this->assertTrue($this->model->update($productSku, $entryMock));
}
......
......@@ -197,4 +197,56 @@ class ProcessorTest extends \PHPUnit_Framework_TestCase
[false]
];
}
/**
* @param int $setDataExpectsCalls
* @param string|null $setDataArgument
* @param array|string $mediaAttribute
* @dataProvider clearMediaAttributeDataProvider
*/
public function testClearMediaAttribute($setDataExpectsCalls, $setDataArgument, $mediaAttribute)
{
$productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
->disableOriginalConstructor()
->getMock();
$productMock->expects($this->exactly($setDataExpectsCalls))
->method('setData')
->with($setDataArgument, 'no_selection');
$this->mediaConfig->expects($this->once())
->method('getMediaAttributeCodes')
->willReturn(['image', 'small_image']);
$this->assertSame($this->model, $this->model->clearMediaAttribute($productMock, $mediaAttribute));
}
/**
* @return array
*/
public function clearMediaAttributeDataProvider()
{
return [
[
'setDataExpectsCalls' => 1,
'setDataArgument' => 'image',
'mediaAttribute' => 'image',
],
[
'setDataExpectsCalls' => 1,
'setDataArgument' => 'image',
'mediaAttribute' => ['image'],
],
[
'setDataExpectsCalls' => 0,
'setDataArgument' => null,
'mediaAttribute' => 'some_image',
],
[
'setDataExpectsCalls' => 0,
'setDataArgument' => null,
'mediaAttribute' => ['some_image'],
],
];
}
}
......@@ -237,8 +237,8 @@ class ProductAttributeMediaGalleryManagementInterfaceTest extends \Magento\TestF
$targetProduct = $this->getTargetSimpleProduct();
$this->assertEquals('/m/a/magento_image.jpg', $targetProduct->getData('thumbnail'));
$this->assertNull($targetProduct->getData('image'));
$this->assertNull($targetProduct->getData('small_image'));
$this->assertEquals('no_selection', $targetProduct->getData('image'));
$this->assertEquals('no_selection', $targetProduct->getData('small_image'));
$mediaGallery = $targetProduct->getData('media_gallery');
$this->assertCount(1, $mediaGallery['images']);
$updatedImage = array_shift($mediaGallery['images']);
......
......@@ -522,14 +522,16 @@ class View extends AbstractConfigureBlock
}
/**
* Check id media gallery is visible for the product.
* Check if media gallery is visible for the product.
*
* @return bool
*/
public function isGalleryVisible()
{
$this->waitForElementNotVisible($this->galleryLoader);
return $this->_rootElement->find($this->mediaGallery)->isVisible();
$this->waitForElementVisible($this->mediaGallery);
return true;
}
/**
......
......@@ -146,15 +146,15 @@ class ProcessorTest extends \PHPUnit_Framework_TestCase
);
$product->setData(['image' => 'test1', 'small_image' => 'test2', 'thumbnail' => 'test3']);
$this->assertNotEmpty($product->getData('image'));
$this->assertNotEquals('no_selection', $product->getData('image'));
$this->_model->clearMediaAttribute($product, 'image');
$this->assertNull($product->getData('image'));
$this->assertEquals('no_selection', $product->getData('image'));
$this->assertNotEmpty($product->getData('small_image'));
$this->assertNotEmpty($product->getData('thumbnail'));
$this->assertNotEquals('no_selection', $product->getData('small_image'));
$this->assertNotEquals('no_selection', $product->getData('thumbnail'));
$this->_model->clearMediaAttribute($product, ['small_image', 'thumbnail']);
$this->assertNull($product->getData('small_image'));
$this->assertNull($product->getData('thumbnail'));
$this->assertEquals('no_selection', $product->getData('small_image'));
$this->assertEquals('no_selection', $product->getData('thumbnail'));
}
public function testSetMediaAttribute()
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment