Skip to content

Commit

Permalink
ENGCOM-5272: Product media_gallery_entries / types only present if im…
Browse files Browse the repository at this point in the history
…age, thumbnai… #718

 - Merge Pull Request magento/graphql-ce#718 from XxXgeoXxX/graphql-ce:2.3-develop##612
 - Merged commits:
   1. bb5ae76
   2. b776ec3
   3. f01d084
   4. 44d7ff4
  • Loading branch information
magento-engcom-team committed Jun 12, 2019
2 parents fdfaed6 + 44d7ff4 commit 1faa43b
Showing 1 changed file with 33 additions and 1 deletion.
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;
}
}

0 comments on commit 1faa43b

Please sign in to comment.