Skip to content

Commit c252c18

Browse files
committed
Merge branch 'MC-31010-product-image' into honey-235-bug-pr
2 parents 8ead858 + b896511 commit c252c18

File tree

3 files changed

+48
-60
lines changed

3 files changed

+48
-60
lines changed

app/code/Magento/CatalogGraphQl/etc/schema.graphqls

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,17 @@ type CustomizableFileValue @doc(description: "CustomizableFileValue defines the
199199
interface MediaGalleryInterface @doc(description: "Contains basic information about a product image or video.") @typeResolver(class: "Magento\\CatalogGraphQl\\Model\\MediaGalleryTypeResolver") {
200200
url: String @doc(description: "The URL of the product image or video.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\MediaGallery\\Url")
201201
label: String @doc(description: "The label of the product image or video.")
202+
position: Int @doc(description: "The media item's position after it has been sorted.")
203+
disabled: Boolean @doc(description: "Whether the image is hidden from view.")
202204
}
203205

204206
type ProductImage implements MediaGalleryInterface @doc(description: "Product image information. Contains the image URL and label.") {
205207
}
206208

209+
type ProductVideo implements MediaGalleryInterface @doc(description: "Contains information about a product video.") {
210+
video_content: ProductMediaGalleryEntriesVideoContent @doc(description: "Contains a ProductMediaGalleryEntriesVideoContent object.")
211+
}
212+
207213
interface CustomizableOptionInterface @typeResolver(class: "Magento\\CatalogGraphQl\\Model\\CustomizableOptionTypeResolver") @doc(description: "The CustomizableOptionInterface contains basic information about a customizable option. It can be implemented by several types of configurable options.") {
208214
title: String @doc(description: "The display name for this option.")
209215
required: Boolean @doc(description: "Indicates whether the option is required.")
@@ -403,7 +409,7 @@ type MediaGalleryEntry @doc(description: "MediaGalleryEntry defines characterist
403409
media_type: String @doc(description: "image or video.")
404410
label: String @doc(description: "The alt text displayed on the UI when the user points to the image.")
405411
position: Int @doc(description: "The media item's position after it has been sorted.")
406-
disabled: Boolean @doc(description: "Whether the image is hidden from vie.")
412+
disabled: Boolean @doc(description: "Whether the image is hidden from view.")
407413
types: [String] @doc(description: "Array of image types. It can have the following values: image, small_image, thumbnail.")
408414
file: String @doc(description: "The path of the image on the server.")
409415
content: ProductMediaGalleryEntriesContent @doc(description: "Contains a ProductMediaGalleryEntriesContent object.")
@@ -466,7 +472,3 @@ type StoreConfig @doc(description: "The type contains information about a store
466472
catalog_default_sort_by : String @doc(description: "Default Sort By.")
467473
root_category_id: Int @doc(description: "The ID of the root category") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\RootCategoryId")
468474
}
469-
470-
type ProductVideo @doc(description: "Contains information about a product video.") implements MediaGalleryInterface {
471-
video_content: ProductMediaGalleryEntriesVideoContent @doc(description: "Contains a ProductMediaGalleryEntriesVideoContent object.")
472-
}

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@
1414
*/
1515
class MediaGalleryTest extends GraphQlAbstract
1616
{
17-
/**
18-
* @var \Magento\TestFramework\ObjectManager
19-
*/
20-
private $objectManager;
21-
22-
protected function setUp()
23-
{
24-
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
25-
}
26-
2717
/**
2818
* @magentoApiDataFixture Magento/Catalog/_files/product_with_image.php
2919
*/
@@ -38,7 +28,7 @@ public function testProductSmallImageUrlWithExistingImage()
3828
url
3929
}
4030
}
41-
}
31+
}
4232
}
4333
QUERY;
4434
$response = $this->graphQlQuery($query);
@@ -57,15 +47,15 @@ public function testMediaGalleryTypesAreCorrect()
5747
$query = <<<QUERY
5848
{
5949
products(filter: {sku: {eq: "{$productSku}"}}) {
60-
items {
50+
items {
6151
media_gallery_entries {
6252
label
6353
media_type
6454
file
6555
types
6656
}
6757
}
68-
}
58+
}
6959
}
7060
QUERY;
7161
$response = $this->graphQlQuery($query);
@@ -91,23 +81,29 @@ public function testMediaGallery()
9181
$query = <<<QUERY
9282
{
9383
products(filter: {sku: {eq: "{$productSku}"}}) {
94-
items {
84+
items {
9585
media_gallery {
9686
label
9787
url
88+
position
89+
disabled
9890
}
9991
}
100-
}
92+
}
10193
}
10294
QUERY;
10395
$response = $this->graphQlQuery($query);
10496
$this->assertNotEmpty($response['products']['items'][0]['media_gallery']);
10597
$mediaGallery = $response['products']['items'][0]['media_gallery'];
10698
$this->assertCount(2, $mediaGallery);
10799
$this->assertEquals('Image Alt Text', $mediaGallery[0]['label']);
108-
self::assertTrue($this->checkImageExists($mediaGallery[0]['url']));
100+
$this->assertEquals(1, $mediaGallery[0]['position']);
101+
$this->assertFalse($mediaGallery[0]['disabled']);
102+
$this->assertTrue($this->checkImageExists($mediaGallery[0]['url']));
109103
$this->assertEquals('Thumbnail Image', $mediaGallery[1]['label']);
110-
self::assertTrue($this->checkImageExists($mediaGallery[1]['url']));
104+
$this->assertEquals(2, $mediaGallery[1]['position']);
105+
$this->assertFalse($mediaGallery[1]['disabled']);
106+
$this->assertTrue($this->checkImageExists($mediaGallery[1]['url']));
111107
}
112108

113109
/**
@@ -119,10 +115,12 @@ public function testMediaGalleryForProductVideos()
119115
$query = <<<QUERY
120116
{
121117
products(filter: {sku: {eq: "{$productSku}"}}) {
122-
items {
118+
items {
123119
media_gallery {
124120
label
125121
url
122+
position
123+
disabled
126124
... on ProductVideo {
127125
video_content {
128126
media_type
@@ -135,15 +133,17 @@ public function testMediaGalleryForProductVideos()
135133
}
136134
}
137135
}
138-
}
136+
}
139137
}
140138
QUERY;
141139
$response = $this->graphQlQuery($query);
142140
$this->assertNotEmpty($response['products']['items'][0]['media_gallery']);
143141
$mediaGallery = $response['products']['items'][0]['media_gallery'];
144142
$this->assertCount(1, $mediaGallery);
145143
$this->assertEquals('Video Label', $mediaGallery[0]['label']);
146-
self::assertTrue($this->checkImageExists($mediaGallery[0]['url']));
144+
$this->assertTrue($this->checkImageExists($mediaGallery[0]['url']));
145+
$this->assertFalse($mediaGallery[0]['disabled']);
146+
$this->assertEquals(2, $mediaGallery[0]['position']);
147147
$this->assertNotEmpty($mediaGallery[0]['video_content']);
148148
$video_content = $mediaGallery[0]['video_content'];
149149
$this->assertEquals('external-video', $video_content['media_type']);

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

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,44 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
use Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryExtensionFactory;
8+
use Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory;
9+
use Magento\Catalog\Api\ProductAttributeMediaGalleryManagementInterface;
10+
use Magento\Framework\Api\Data\ImageContentInterfaceFactory;
11+
use Magento\Framework\Api\Data\VideoContentInterfaceFactory;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
use Magento\TestFramework\ObjectManager;
14+
715
include __DIR__ . '/product_simple_with_full_option_set.php';
816

9-
/**
10-
* @var \Magento\TestFramework\ObjectManager $objectManager
11-
*/
12-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
17+
/** @var ObjectManager $objectManager */
18+
$objectManager = Bootstrap::getObjectManager();
1319

14-
/**
15-
* @var \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory $mediaGalleryEntryFactory
16-
*/
17-
18-
$mediaGalleryEntryFactory = $objectManager->get(
19-
\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory::class
20-
);
20+
/** @var ProductAttributeMediaGalleryEntryInterfaceFactory $mediaGalleryEntryFactory */
21+
$mediaGalleryEntryFactory = $objectManager->get(ProductAttributeMediaGalleryEntryInterfaceFactory::class);
2122

22-
/**
23-
* @var \Magento\Framework\Api\Data\ImageContentInterfaceFactory $imageContentFactory
24-
*/
25-
$imageContentFactory = $objectManager->get(\Magento\Framework\Api\Data\ImageContentInterfaceFactory::class);
23+
/** @var ImageContentInterfaceFactory $imageContentFactory */
24+
$imageContentFactory = $objectManager->get(ImageContentInterfaceFactory::class);
2625
$imageContent = $imageContentFactory->create();
27-
$testImagePath = __DIR__ .'/magento_image.jpg';
26+
$testImagePath = __DIR__ . '/magento_image.jpg';
2827
$imageContent->setBase64EncodedData(base64_encode(file_get_contents($testImagePath)));
2928
$imageContent->setType("image/jpeg");
3029
$imageContent->setName("1.jpg");
3130

3231
$video = $mediaGalleryEntryFactory->create();
3332
$video->setDisabled(false);
34-
//$video->setFile('1.png');
3533
$video->setFile('1.jpg');
3634
$video->setLabel('Video Label');
3735
$video->setMediaType('external-video');
3836
$video->setPosition(2);
3937
$video->setContent($imageContent);
4038

41-
/**
42-
* @var \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryExtensionFactory $mediaGalleryEntryExtensionFactory
43-
*/
44-
$mediaGalleryEntryExtensionFactory = $objectManager->get(
45-
\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryExtensionFactory::class
46-
);
39+
/** @var ProductAttributeMediaGalleryEntryExtensionFactory $mediaGalleryEntryExtensionFactory */
40+
$mediaGalleryEntryExtensionFactory = $objectManager->get(ProductAttributeMediaGalleryEntryExtensionFactory::class);
4741
$mediaGalleryEntryExtension = $mediaGalleryEntryExtensionFactory->create();
4842

49-
/**
50-
* @var \Magento\Framework\Api\Data\VideoContentInterfaceFactory $videoContentFactory
51-
*/
52-
$videoContentFactory = $objectManager->get(
53-
\Magento\Framework\Api\Data\VideoContentInterfaceFactory::class
54-
);
43+
/** @var VideoContentInterfaceFactory $videoContentFactory */
44+
$videoContentFactory = $objectManager->get(VideoContentInterfaceFactory::class);
5545
$videoContent = $videoContentFactory->create();
5646
$videoContent->setMediaType('external-video');
5747
$videoContent->setVideoDescription('Video description');
@@ -63,10 +53,6 @@
6353
$mediaGalleryEntryExtension->setVideoContent($videoContent);
6454
$video->setExtensionAttributes($mediaGalleryEntryExtension);
6555

66-
/**
67-
* @var \Magento\Catalog\Api\ProductAttributeMediaGalleryManagementInterface $mediaGalleryManagement
68-
*/
69-
$mediaGalleryManagement = $objectManager->get(
70-
\Magento\Catalog\Api\ProductAttributeMediaGalleryManagementInterface::class
71-
);
56+
/** @var ProductAttributeMediaGalleryManagementInterface $mediaGalleryManagement */
57+
$mediaGalleryManagement = $objectManager->get(ProductAttributeMediaGalleryManagementInterface::class);
7258
$mediaGalleryManagement->create('simple', $video);

0 commit comments

Comments
 (0)