From 4e96d8d8d4764e7a64505a2a726e0be4e3bd9dc1 Mon Sep 17 00:00:00 2001 From: Aleksejs Baranovs Date: Fri, 9 Oct 2020 15:15:08 +0300 Subject: [PATCH 1/2] Product images not found for SF API - Sample url change --- .../Api/Product/Downloadable/SamplesTest.php | 49 +++++++++++++------ .../ProductOptions/DownloadLinksTest.php | 7 ++- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/app/code/Magento/CatalogStorefront/Test/Api/Product/Downloadable/SamplesTest.php b/app/code/Magento/CatalogStorefront/Test/Api/Product/Downloadable/SamplesTest.php index 79f129ae7..1ca5aaea2 100644 --- a/app/code/Magento/CatalogStorefront/Test/Api/Product/Downloadable/SamplesTest.php +++ b/app/code/Magento/CatalogStorefront/Test/Api/Product/Downloadable/SamplesTest.php @@ -63,36 +63,49 @@ protected function setUp(): void * 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); @@ -104,7 +117,13 @@ public function testDownloadableProductsWithFiles(array $expected): void $actual = $this->arrayMapper->convertToArray($catalogServiceItem->getItems()[0]->getSamples()[0]); - $this->compare($expected, $actual); + $this->compare($dataProvider, $actual); + + $sample = $product->getExtensionAttributes()->getDownloadableProductSamples()[0]; + self::assertStringEndsWith( + \sprintf('/downloadable/download/sample/sample_id/%s', $sample->getId()), + $actual['resource']['url'] + ); } /** @@ -118,7 +137,6 @@ public function downloadableUrlsProvider(): array [ [ 'resource' => [ - 'url' => 'http://example.com/downloadable.txt', 'label' => 'Downloadable Product Sample', 'roles' => [], ], @@ -139,7 +157,6 @@ public function downloadableFilesProvider(): array [ [ 'resource' => [ - 'url' => '/j/e/jellyfish_1_4.jpg', 'label' => 'Downloadable Product Sample Title', 'roles' => [], ], diff --git a/app/code/Magento/CatalogStorefront/Test/Api/Product/ProductOptions/DownloadLinksTest.php b/app/code/Magento/CatalogStorefront/Test/Api/Product/ProductOptions/DownloadLinksTest.php index cfd956b83..ad6505de9 100644 --- a/app/code/Magento/CatalogStorefront/Test/Api/Product/ProductOptions/DownloadLinksTest.php +++ b/app/code/Magento/CatalogStorefront/Test/Api/Product/ProductOptions/DownloadLinksTest.php @@ -136,6 +136,12 @@ public function testDownloadableLinksFileOptionData(array $expected): void } $this->compare($expected, $actual); + + $link = $product->getExtensionAttributes()->getDownloadableProductLinks()[0]; + self::assertStringEndsWith( + \sprintf('/downloadable/download/linkSample/link_id/%s', $link->getId()), + $actual[0]['values'][0]['info_url'] + ); } /** @@ -200,7 +206,6 @@ public function downloadableLinkFileProvider(): array 'image_url' => '', 'qty_mutability' => false, 'qty' => 0.0, - 'info_url' => '/j/e/jellyfish_1_3.jpg', 'price' => 15.0 ] ] From 7ed9bc82fb25d538ed1be3bc53b5d1c13b65981f Mon Sep 17 00:00:00 2001 From: Aleksejs Baranovs Date: Mon, 12 Oct 2020 13:41:04 +0300 Subject: [PATCH 2/2] Product images not found for SF API - Sample url change --- .../Test/Api/Product/Downloadable/SamplesTest.php | 14 ++++++++++++-- .../Product/ProductOptions/DownloadLinksTest.php | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/CatalogStorefront/Test/Api/Product/Downloadable/SamplesTest.php b/app/code/Magento/CatalogStorefront/Test/Api/Product/Downloadable/SamplesTest.php index 1ca5aaea2..1f438d935 100644 --- a/app/code/Magento/CatalogStorefront/Test/Api/Product/Downloadable/SamplesTest.php +++ b/app/code/Magento/CatalogStorefront/Test/Api/Product/Downloadable/SamplesTest.php @@ -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; /** @@ -47,6 +49,11 @@ class SamplesTest extends StorefrontTestsAbstract */ private $arrayMapper; + /** + * @var StoreManagerInterface + */ + private $storeManager; + /** * @inheritdoc */ @@ -57,6 +64,7 @@ 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); } /** @@ -119,9 +127,11 @@ private function validateSampleData(array $dataProvider) : void $this->compare($dataProvider, $actual); + $baseUrl = $this->storeManager->getStore(self::STORE_CODE)->getBaseUrl(UrlInterface::URL_TYPE_WEB); $sample = $product->getExtensionAttributes()->getDownloadableProductSamples()[0]; - self::assertStringEndsWith( - \sprintf('/downloadable/download/sample/sample_id/%s', $sample->getId()), + + self::assertEquals( + \sprintf('%sdownloadable/download/sample/sample_id/%s', $baseUrl, $sample->getId()), $actual['resource']['url'] ); } diff --git a/app/code/Magento/CatalogStorefront/Test/Api/Product/ProductOptions/DownloadLinksTest.php b/app/code/Magento/CatalogStorefront/Test/Api/Product/ProductOptions/DownloadLinksTest.php index ad6505de9..fd11af355 100644 --- a/app/code/Magento/CatalogStorefront/Test/Api/Product/ProductOptions/DownloadLinksTest.php +++ b/app/code/Magento/CatalogStorefront/Test/Api/Product/ProductOptions/DownloadLinksTest.php @@ -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; /** @@ -54,6 +56,11 @@ class DownloadLinksTest extends StorefrontTestsAbstract */ protected $arrayMapper; + /** + * @var StoreManagerInterface + */ + private $storeManager; + /** * @inheritdoc */ @@ -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); } /** @@ -137,9 +145,11 @@ 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::assertStringEndsWith( - \sprintf('/downloadable/download/linkSample/link_id/%s', $link->getId()), + + self::assertEquals( + \sprintf('%sdownloadable/download/linkSample/link_id/%s', $baseUrl, $link->getId()), $actual[0]['values'][0]['info_url'] ); }