Skip to content

Commit 8f49229

Browse files
committed
MC-15941: Product media_gallery_entries / types only present if image, thumbnail, small_image is requested
- add api-functional test
1 parent 92e848e commit 8f49229

File tree

4 files changed

+95
-4
lines changed

4 files changed

+95
-4
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/MediaGalleryTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
use Magento\TestFramework\TestCase\GraphQlAbstract;
1111

12+
/**
13+
* Test media gallery queries
14+
*/
1215
class MediaGalleryTest extends GraphQlAbstract
1316
{
1417
/**
@@ -45,6 +48,43 @@ public function testProductSmallImageUrlWithExistingImage()
4548
self::assertTrue($this->checkImageExists($response['products']['items'][0]['small_image']['url']));
4649
}
4750

51+
/**
52+
* @magentoApiDataFixture Magento/Catalog/_files/product_with_multiple_images.php
53+
*/
54+
public function testMediaGalleryTypesAreCorrect()
55+
{
56+
$productSku = 'simple';
57+
$query = <<<QUERY
58+
{
59+
products(filter: {sku: {eq: "{$productSku}"}}) {
60+
items {
61+
media_gallery_entries {
62+
label
63+
media_type
64+
file
65+
types
66+
}
67+
}
68+
}
69+
}
70+
QUERY;
71+
$response = $this->graphQlQuery($query);
72+
73+
$this->assertNotEmpty($response['products']['items'][0]['media_gallery_entries']);
74+
$mediaGallery = $response['products']['items'][0]['media_gallery_entries'];
75+
$this->assertCount(2, $mediaGallery);
76+
77+
$this->assertEquals('Image Alt Text', $mediaGallery[0]['label']);
78+
$this->assertEquals('image', $mediaGallery[0]['media_type']);
79+
$this->assertContains('magento_image', $mediaGallery[0]['file']);
80+
$this->assertEquals(['image', 'small_image'], $mediaGallery[0]['types']);
81+
82+
$this->assertEquals('Thumbnail Image', $mediaGallery[1]['label']);
83+
$this->assertEquals('image', $mediaGallery[1]['media_type']);
84+
$this->assertContains('magento_thumbnail', $mediaGallery[1]['file']);
85+
$this->assertEquals(['thumbnail', 'swatch_image'], $mediaGallery[1]['types']);
86+
}
87+
4888
/**
4989
* @param string $url
5090
* @return bool

dev/tests/integration/testsuite/Magento/Catalog/_files/product_image.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@
1818
$mediaDirectory->create($targetDirPath);
1919
$mediaDirectory->create($targetTmpDirPath);
2020

21-
$targetTmpFilePath = $mediaDirectory->getAbsolutePath() . DIRECTORY_SEPARATOR . $targetTmpDirPath
22-
. DIRECTORY_SEPARATOR . 'magento_image.jpg';
23-
copy(__DIR__ . '/magento_image.jpg', $targetTmpFilePath);
24-
// Copying the image to target dir is not necessary because during product save, it will be moved there from tmp dir
21+
$images = ['magento_image.jpg', 'magento_small_image.jpg', 'magento_thumbnail.jpg'];
22+
23+
foreach ($images as $image) {
24+
$targetTmpFilePath = $mediaDirectory->getAbsolutePath() . DIRECTORY_SEPARATOR . $targetTmpDirPath
25+
. DIRECTORY_SEPARATOR . $image;
26+
27+
$sourceFilePath = __DIR__ . DIRECTORY_SEPARATOR . $image;
28+
29+
copy($sourceFilePath, $targetTmpFilePath);
30+
// Copying the image to target dir is not necessary because during product save, it will be moved there from tmp dir
31+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
require __DIR__ . '/product_image.php';
8+
require __DIR__ . '/product_simple.php';
9+
10+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
11+
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
12+
$product = $productRepository->get('simple');
13+
14+
/** @var $product \Magento\Catalog\Model\Product */
15+
$product->setStoreId(0)
16+
->setImage('/m/a/magento_image.jpg')
17+
->setSmallImage('/m/a/magento_image.jpg')
18+
->setThumbnail('/m/a/magento_thumbnail.jpg')
19+
->setSwatchImage('/m/a/magento_thumbnail.jpg')
20+
->setData('media_gallery', ['images' => [
21+
[
22+
'file' => '/m/a/magento_image.jpg',
23+
'position' => 1,
24+
'label' => 'Image Alt Text',
25+
'disabled' => 0,
26+
'media_type' => 'image'
27+
],
28+
[
29+
'file' => '/m/a/magento_thumbnail.jpg',
30+
'position' => 2,
31+
'label' => 'Thumbnail Image',
32+
'disabled' => 0,
33+
'media_type' => 'image'
34+
],
35+
]])
36+
->setCanSaveCustomOptions(true)
37+
->save();
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
require __DIR__ . '/product_with_image_rollback.php';

0 commit comments

Comments
 (0)