|
9 | 9 |
|
10 | 10 | use Magento\TestFramework\TestCase\GraphQlAbstract;
|
11 | 11 |
|
| 12 | +/** |
| 13 | + * Test cases for product media gallery data retrieval. |
| 14 | + */ |
12 | 15 | class MediaGalleryTest extends GraphQlAbstract
|
13 | 16 | {
|
14 | 17 | /**
|
@@ -45,19 +48,48 @@ public function testProductSmallImageUrlWithExistingImage()
|
45 | 48 | self::assertTrue($this->checkImageExists($response['products']['items'][0]['small_image']['url']));
|
46 | 49 | }
|
47 | 50 |
|
| 51 | + /** |
| 52 | + * @magentoApiDataFixture Magento/Catalog/_files/product_with_image.php |
| 53 | + */ |
| 54 | + public function testProductMediaGalleryEntries() |
| 55 | + { |
| 56 | + $this->markTestSkipped('https://github.com/magento/graphql-ce/issues/738'); |
| 57 | + $productSku = 'simple'; |
| 58 | + $query = <<<QUERY |
| 59 | +{ |
| 60 | + products(filter: {sku: {eq: "{$productSku}"}}) { |
| 61 | + items { |
| 62 | + name |
| 63 | + sku |
| 64 | + media_gallery_entries { |
| 65 | + id |
| 66 | + file |
| 67 | + types |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | +} |
| 72 | +QUERY; |
| 73 | + $response = $this->graphQlQuery($query); |
| 74 | + |
| 75 | + self::assertArrayHasKey('file', $response['products']['items'][0]['media_gallery_entries'][0]); |
| 76 | + self::assertContains('magento_image.jpg', $response['products']['items'][0]['media_gallery_entries'][0]['url']); |
| 77 | + } |
| 78 | + |
48 | 79 | /**
|
49 | 80 | * @param string $url
|
50 | 81 | * @return bool
|
51 | 82 | */
|
52 | 83 | private function checkImageExists(string $url): bool
|
53 | 84 | {
|
| 85 | + // phpcs:disable Magento2.Functions.DiscouragedFunction |
54 | 86 | $connection = curl_init($url);
|
55 | 87 | curl_setopt($connection, CURLOPT_HEADER, true);
|
56 | 88 | curl_setopt($connection, CURLOPT_NOBODY, true);
|
57 | 89 | curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
|
58 | 90 | curl_exec($connection);
|
59 | 91 | $responseStatus = curl_getinfo($connection, CURLINFO_HTTP_CODE);
|
60 |
| - |
| 92 | + // phpcs:enable Magento2.Functions.DiscouragedFunction |
61 | 93 | return $responseStatus === 200 ? true : false;
|
62 | 94 | }
|
63 | 95 | }
|
0 commit comments