Skip to content

Commit 1040096

Browse files
committed
MC-31551: Category images are broken after migrating to 2.3.4
- refactor resolver
1 parent 2891b2a commit 1040096

File tree

3 files changed

+68
-3
lines changed

3 files changed

+68
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\GraphQl\Catalog;
99

10+
use Magento\Catalog\Model\ResourceModel\Category\Collection as CategoryCollection;
1011
use Magento\Framework\ObjectManagerInterface;
1112
use Magento\Store\Model\StoreManagerInterface;
1213
use Magento\TestFramework\Helper\Bootstrap;
@@ -383,13 +384,21 @@ public function testMinimumMatchQueryLength()
383384
/**
384385
* Test category image full name is returned
385386
*
386-
* @magentoApiDataFixture Magento/Catalog/_files/category.php
387+
* @magentoApiDataFixture Magento/Catalog/_files/catalog_category_with_long_image_name.php
387388
*/
388389
public function testCategoryImageName()
389390
{
391+
/** @var CategoryCollection $categoryCollection */
392+
$categoryCollection = $this->objectManager->get(CategoryCollection::class);
393+
$categoryModel = $categoryCollection
394+
->addAttributeToSelect('image')
395+
->addAttributeToFilter('name', ['eq' => 'Parent Image Category'])
396+
->getFirstItem();
397+
$categoryId = $categoryModel->getId();
398+
390399
$query = <<<QUERY
391400
{
392-
categoryList(filters: {ids: {in: ["333"]}}) {
401+
categoryList(filters: {ids: {in: ["$categoryId"]}}) {
393402
id
394403
name
395404
image
@@ -406,7 +415,7 @@ public function testCategoryImageName()
406415
$categoryList = $response['categoryList'];
407416
$this->assertArrayNotHasKey('errors', $response);
408417
$this->assertNotEmpty($response['categoryList']);
409-
$this->assertEquals('Category 1', $categoryList[0]['name']);
418+
$this->assertEquals('Parent Image Category', $categoryList[0]['name']);
410419
$this->assertEquals($expectedImageUrl, $categoryList[0]['image']);
411420
}
412421

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
require 'catalog_category_image.php';
8+
9+
/** @var $category \Magento\Catalog\Model\Category */
10+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
11+
12+
$categoryParent = $objectManager->create(\Magento\Catalog\Model\Category::class);
13+
$categoryParent->setName('Parent Image Category')
14+
->setPath('1/2')
15+
->setLevel(2)
16+
->setImage($filePathLong)
17+
->setAvailableSortBy('name')
18+
->setDefaultSortBy('name')
19+
->setIsActive(true)
20+
->setPosition(1)
21+
->save();
22+
23+
$categoryChild = $objectManager->create(\Magento\Catalog\Model\Category::class);
24+
$categoryChild->setName('Child Image Category')
25+
->setPath($categoryParent->getPath())
26+
->setLevel(3)
27+
->setImage($fileNameLong)
28+
->setAvailableSortBy('name')
29+
->setDefaultSortBy('name')
30+
->setIsActive(true)
31+
->setPosition(2)
32+
->save();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/** @var \Magento\Framework\ObjectManagerInterface $objectManager */
8+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
9+
10+
/** @var \Magento\Framework\Registry $registry */
11+
$registry = $objectManager->get(\Magento\Framework\Registry::class);
12+
13+
$registry->unregister('isSecureArea');
14+
$registry->register('isSecureArea', true);
15+
16+
/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection */
17+
$collection = $objectManager->create(\Magento\Catalog\Model\ResourceModel\Category\Collection::class);
18+
$collection
19+
->addAttributeToFilter('name', ['in' => ['Parent Image Category', 'Child Image Category']])
20+
->load()
21+
->delete();
22+
23+
$registry->unregister('isSecureArea');
24+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)