Skip to content

Commit 9d66ee8

Browse files
committed
Merge remote-tracking branch 'origin/MC-31405' into MC-31551
2 parents d04dae2 + b9f0d39 commit 9d66ee8

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Category/Image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function resolve(
5656
$mediaPath = $this->directoryList->getUrlPath('media');
5757
$pos = strpos($imagePath, $mediaPath);
5858
if ($pos !== false) {
59-
$imagePath = substr($imagePath, $pos + strlen($mediaPath), strlen($baseUrl));
59+
$imagePath = substr($imagePath, $pos + strlen($mediaPath));
6060
}
6161
$imageUrl = rtrim($baseUrl, '/') . '/' . ltrim($imagePath, '/');
6262

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryListTest.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\GraphQl\Catalog;
99

10+
use Magento\Framework\ObjectManagerInterface;
1011
use Magento\Store\Model\StoreManagerInterface;
1112
use Magento\TestFramework\Helper\Bootstrap;
1213
use Magento\TestFramework\TestCase\GraphQlAbstract;
@@ -16,6 +17,16 @@
1617
*/
1718
class CategoryListTest extends GraphQlAbstract
1819
{
20+
/**
21+
* @var ObjectManagerInterface
22+
*/
23+
private $objectManager;
24+
25+
protected function setUp()
26+
{
27+
$this->objectManager = Bootstrap::getObjectManager();
28+
}
29+
1930
/**
2031
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
2132
* @dataProvider filterSingleCategoryDataProvider
@@ -333,7 +344,7 @@ public function testEmptyFiltersReturnRootCategory()
333344
}
334345
}
335346
QUERY;
336-
$storeManager = Bootstrap::getObjectManager()->get(StoreManagerInterface::class);
347+
$storeManager = $this->objectManager->get(StoreManagerInterface::class);
337348
$storeRootCategoryId = $storeManager->getStore()->getRootCategoryId();
338349

339350
$result = $this->graphQlQuery($query);
@@ -369,6 +380,36 @@ public function testMinimumMatchQueryLength()
369380
$this->assertEquals([], $result['categoryList']);
370381
}
371382

383+
/**
384+
* Test category image full name is returned
385+
*
386+
* @magentoApiDataFixture Magento/Catalog/_files/category.php
387+
*/
388+
public function testCategoryImageName()
389+
{
390+
$query = <<<QUERY
391+
{
392+
categoryList(filters: {ids: {in: ["333"]}}) {
393+
id
394+
name
395+
image
396+
}
397+
}
398+
QUERY;
399+
$storeManager = $this->objectManager->get(StoreManagerInterface::class);
400+
$storeBaseUrl = $storeManager->getStore()->getBaseUrl('media');
401+
402+
$expected = "catalog/category/magento_long_image_name_magento_long_image_name_magento_long_image_name.jpg";
403+
$expectedImageUrl = rtrim($storeBaseUrl, '/') . '/' . $expected;
404+
405+
$response = $this->graphQlQuery($query);
406+
$categoryList = $response['categoryList'];
407+
$this->assertArrayNotHasKey('errors', $response);
408+
$this->assertNotEmpty($response['categoryList']);
409+
$this->assertEquals('Category 1', $categoryList[0]['name']);
410+
$this->assertEquals($expectedImageUrl, $categoryList[0]['image']);
411+
}
412+
372413
/**
373414
* @return array
374415
*/

dev/tests/integration/testsuite/Magento/Catalog/_files/catalog_category_image.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
$mediaDirectory = $objectManager->get(\Magento\Framework\Filesystem::class)
1414
->getDirectoryWrite(DirectoryList::MEDIA);
1515
$fileName = 'magento_small_image.jpg';
16+
$fileNameLong = 'magento_long_image_name_magento_long_image_name_magento_long_image_name.jpg';
1617
$filePath = 'catalog/category/' . $fileName;
18+
$filePathLong = 'catalog/category/' . $fileNameLong;
1719
$mediaDirectory->create('catalog/category');
1820

1921
copy(__DIR__ . DIRECTORY_SEPARATOR . $fileName, $mediaDirectory->getAbsolutePath($filePath));
22+
copy(__DIR__ . DIRECTORY_SEPARATOR . $fileNameLong, $mediaDirectory->getAbsolutePath($filePathLong));

dev/tests/integration/testsuite/Magento/Catalog/_files/category.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
require 'catalog_category_image.php';
8+
79
$category = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Category::class);
810
$category->isObjectNew(true);
911
$category->setId(
@@ -18,6 +20,8 @@
1820
'1/2/333'
1921
)->setLevel(
2022
2
23+
)->setImage(
24+
$filePathLong
2125
)->setAvailableSortBy(
2226
['position', 'name']
2327
)->setDefaultSortBy(

0 commit comments

Comments
 (0)