Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Product media_gallery_entries / types only present if image, thumbnai… #718

Merged
merged 4 commits into from
Jun 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

use Magento\TestFramework\TestCase\GraphQlAbstract;

/**
* Test cases for product media gallery data retrieval.
*/
class MediaGalleryTest extends GraphQlAbstract
{
/**
Expand Down Expand Up @@ -45,19 +48,48 @@ public function testProductSmallImageUrlWithExistingImage()
self::assertTrue($this->checkImageExists($response['products']['items'][0]['small_image']['url']));
}

/**
* @magentoApiDataFixture Magento/Catalog/_files/product_with_image.php
*/
public function testProductMediaGalleryEntries()
{
$this->markTestSkipped('https://github.com/magento/graphql-ce/issues/738');
$productSku = 'simple';
$query = <<<QUERY
{
products(filter: {sku: {eq: "{$productSku}"}}) {
items {
name
sku
media_gallery_entries {
id
file
types
}
}
}
}
QUERY;
$response = $this->graphQlQuery($query);

self::assertArrayHasKey('file', $response['products']['items'][0]['media_gallery_entries'][0]);
self::assertContains('magento_image.jpg', $response['products']['items'][0]['media_gallery_entries'][0]['url']);
}

/**
* @param string $url
* @return bool
*/
private function checkImageExists(string $url): bool
{
// phpcs:disable Magento2.Functions.DiscouragedFunction
$connection = curl_init($url);
curl_setopt($connection, CURLOPT_HEADER, true);
curl_setopt($connection, CURLOPT_NOBODY, true);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
curl_exec($connection);
$responseStatus = curl_getinfo($connection, CURLINFO_HTTP_CODE);

// phpcs:enable Magento2.Functions.DiscouragedFunction
return $responseStatus === 200 ? true : false;
}
}