Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Product images not found for SF API #375

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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 @@ -13,6 +13,8 @@
use Magento\CatalogStorefrontApi\Api\Data\ProductsGetRequestInterface;
use Magento\CatalogStorefrontApi\Api\Data\SampleArrayMapper;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\TestFramework\Helper\Bootstrap;

/**
Expand Down Expand Up @@ -47,6 +49,11 @@ class SamplesTest extends StorefrontTestsAbstract
*/
private $arrayMapper;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @inheritdoc
*/
Expand All @@ -57,42 +64,56 @@ protected function setUp(): void
$this->productsGetRequestInterface = Bootstrap::getObjectManager()->create(ProductsGetRequestInterface::class);
$this->productRepository = Bootstrap::getObjectManager()->create(ProductRepositoryInterface::class);
$this->arrayMapper = Bootstrap::getObjectManager()->create(SampleArrayMapper::class);
$this->storeManager = Bootstrap::getObjectManager()->create(StoreManagerInterface::class);
}

/**
* Validate downloadable product data
*
* @magentoDataFixture Magento_CatalogStorefront::Test/Api/Product/Downloadable/_files/sf_product_downloadable_with_urls.php
* @dataProvider downloadableUrlsProvider
*
* @magentoDbIsolation disabled
*
* @param array $expected
*
* @throws NoSuchEntityException
* @dataProvider downloadableUrlsProvider
* @throws \Throwable
*/
public function testDownloadableProductsWithUrls(array $expected): void
{
$product = $this->productRepository->get(self::TEST_SKU);

$this->productsGetRequestInterface->setIds([$product->getId()]);
$this->productsGetRequestInterface->setStore(self::STORE_CODE);
$this->productsGetRequestInterface->setAttributeCodes(['samples']);
$catalogServiceItem = $this->catalogService->getProducts($this->productsGetRequestInterface);
self::assertNotEmpty($catalogServiceItem->getItems());

$actual = $this->arrayMapper->convertToArray($catalogServiceItem->getItems()[0]->getSamples()[0]);

$this->compare($expected, $actual);
$this->validateSampleData($expected);
}

/**
* Validate downloadable product data
*
* @magentoDataFixture Magento/Downloadable/_files/product_downloadable_with_files.php
* @dataProvider downloadableFilesProvider
*
* @magentoDbIsolation disabled
*
* @param array $expected
*
* @throws NoSuchEntityException
* @dataProvider downloadableFilesProvider
* @throws \Throwable
*/
public function testDownloadableProductsWithFiles(array $expected): void
{
$this->validateSampleData($expected);
}

/**
* Validate sample data
*
* @param array $dataProvider
*
* @return void
*
* @throws NoSuchEntityException
* @throws \Throwable
*/
private function validateSampleData(array $dataProvider) : void
{
$product = $this->productRepository->get(self::TEST_SKU);

Expand All @@ -104,7 +125,15 @@ public function testDownloadableProductsWithFiles(array $expected): void

$actual = $this->arrayMapper->convertToArray($catalogServiceItem->getItems()[0]->getSamples()[0]);

$this->compare($expected, $actual);
$this->compare($dataProvider, $actual);

$baseUrl = $this->storeManager->getStore(self::STORE_CODE)->getBaseUrl(UrlInterface::URL_TYPE_WEB);
$sample = $product->getExtensionAttributes()->getDownloadableProductSamples()[0];

self::assertEquals(
\sprintf('%sdownloadable/download/sample/sample_id/%s', $baseUrl, $sample->getId()),
$actual['resource']['url']
);
}

/**
Expand All @@ -118,7 +147,6 @@ public function downloadableUrlsProvider(): array
[
[
'resource' => [
'url' => 'http://example.com/downloadable.txt',
'label' => 'Downloadable Product Sample',
'roles' => [],
],
Expand All @@ -139,7 +167,6 @@ public function downloadableFilesProvider(): array
[
[
'resource' => [
'url' => '/j/e/jellyfish_1_4.jpg',
'label' => 'Downloadable Product Sample Title',
'roles' => [],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Magento\CatalogStorefrontApi\Api\Data\ProductsGetRequestInterface;
use Magento\CatalogStorefrontApi\Api\Data\ProductOptionArrayMapper;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\TestFramework\Helper\Bootstrap;

/**
Expand Down Expand Up @@ -54,6 +56,11 @@ class DownloadLinksTest extends StorefrontTestsAbstract
*/
protected $arrayMapper;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @inheritdoc
*/
Expand All @@ -64,6 +71,7 @@ protected function setUp(): void
$this->productsGetRequestInterface = Bootstrap::getObjectManager()->create(ProductsGetRequestInterface::class);
$this->productRepository = Bootstrap::getObjectManager()->create(ProductRepositoryInterface::class);
$this->arrayMapper = Bootstrap::getObjectManager()->create(ProductOptionArrayMapper::class);
$this->storeManager = Bootstrap::getObjectManager()->create(StoreManagerInterface::class);
}

/**
Expand Down Expand Up @@ -136,6 +144,14 @@ public function testDownloadableLinksFileOptionData(array $expected): void
}

$this->compare($expected, $actual);

$baseUrl = $this->storeManager->getStore(self::STORE_CODE)->getBaseUrl(UrlInterface::URL_TYPE_WEB);
$link = $product->getExtensionAttributes()->getDownloadableProductLinks()[0];

self::assertEquals(
\sprintf('%sdownloadable/download/linkSample/link_id/%s', $baseUrl, $link->getId()),
$actual[0]['values'][0]['info_url']
);
}

/**
Expand Down Expand Up @@ -200,7 +216,6 @@ public function downloadableLinkFileProvider(): array
'image_url' => '',
'qty_mutability' => false,
'qty' => 0.0,
'info_url' => '/j/e/jellyfish_1_3.jpg',
'price' => 15.0
]
]
Expand Down