Skip to content

Commit c8225a4

Browse files
committed
Merge remote-tracking branch 'origin/MC-39836' into issue-29302-graphql-schema-change
2 parents a2c5e93 + 70ecd37 commit c8225a4

File tree

8 files changed

+151
-67
lines changed

8 files changed

+151
-67
lines changed

app/code/Magento/AwsS3/Model/HttpLoggerHandler.php

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogGraphQl\Model\Category;
9+
10+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
11+
use Magento\Framework\GraphQl\Query\Uid;
12+
use Magento\Framework\GraphQl\Query\Resolver\ArgumentsProcessorInterface;
13+
14+
/**
15+
* Parent Category UID processor class for category uid and category id arguments
16+
*/
17+
class ParentCategoryUidsArgsProcessor implements ArgumentsProcessorInterface
18+
{
19+
private const ID = 'parent_id';
20+
21+
private const UID = 'parent_category_uid';
22+
23+
/** @var Uid */
24+
private $uidEncoder;
25+
26+
/**
27+
* @param Uid $uidEncoder
28+
*/
29+
public function __construct(Uid $uidEncoder)
30+
{
31+
$this->uidEncoder = $uidEncoder;
32+
}
33+
34+
/**
35+
* Composite processor that loops through available processors for arguments that come from graphql input
36+
*
37+
* @param string $fieldName,
38+
* @param array $args
39+
* @return array
40+
* @throws GraphQlInputException
41+
*/
42+
public function process(
43+
string $fieldName,
44+
array $args
45+
): array {
46+
$filterKey = 'filters';
47+
$parentUidFilter = $args[$filterKey][self::UID] ?? [];
48+
$parentIdFilter = $args[$filterKey][self::ID] ?? [];
49+
if (!empty($parentIdFilter)
50+
&& !empty($parentUidFilter)
51+
&& ($fieldName === 'categories' || $fieldName === 'categoryList')) {
52+
throw new GraphQlInputException(
53+
__('`%1` and `%2` can\'t be used at the same time.', [self::ID, self::UID])
54+
);
55+
} elseif (!empty($parentUidFilter)) {
56+
if (isset($parentUidFilter['eq'])) {
57+
$args[$filterKey][self::ID]['eq'] = $this->uidEncoder->decode(
58+
$parentUidFilter['eq']
59+
);
60+
} elseif (!empty($parentUidFilter['in'])) {
61+
foreach ($parentUidFilter['in'] as $parentUids) {
62+
$args[$filterKey][self::ID]['in'][] = $this->uidEncoder->decode($parentUids);
63+
}
64+
}
65+
unset($args[$filterKey][self::UID]);
66+
}
67+
return $args;
68+
}
69+
}

app/code/Magento/CatalogGraphQl/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
<argument name="processors" xsi:type="array">
7373
<item name="category_uid" xsi:type="object">Magento\CatalogGraphQl\Model\Resolver\Products\Query\CategoryUidArgsProcessor</item>
7474
<item name="category_uids" xsi:type="object">Magento\CatalogGraphQl\Model\Category\CategoryUidsArgsProcessor</item>
75+
<item name="parent_category_uids" xsi:type="object">Magento\CatalogGraphQl\Model\Category\ParentCategoryUidsArgsProcessor</item>
7576
</argument>
7677
</arguments>
7778
</type>

app/code/Magento/CatalogGraphQl/etc/schema.graphqls

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ input CategoryFilterInput @doc(description: "CategoryFilterInput defines the fi
332332
{
333333
ids: FilterEqualTypeInput @deprecated(reason: "Use the `category_uid` argument instead.") @doc(description: "Deprecated: use 'category_uid' to filter uniquely identifiers of categories.")
334334
category_uid: FilterEqualTypeInput @doc(description: "Filter by the unique category ID for a `CategoryInterface` object.")
335-
parent_id: FilterEqualTypeInput @doc(description: "Filter by the unique parent category ID for a `CategoryInterface` object.")
335+
parent_id: FilterEqualTypeInput @deprecated @doc(description: "Filter by the unique parent category ID for a `CategoryInterface` object.")
336+
parent_category_uid: FilterEqualTypeInput @doc(description: "Filter by the unique parent category ID for a `CategoryInterface` object.")
336337
url_key: FilterEqualTypeInput @doc(description: "Filter by the part of the URL that identifies the category.")
337338
name: FilterMatchTypeInput @doc(description: "Filter by the display name of the category.")
338339
url_path: FilterEqualTypeInput @doc(description: "Filter by the URL path for the category.")

app/code/Magento/ImportExport/Controller/Adminhtml/Export/File/Download.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ public function execute()
6161
$resultRedirect = $this->resultRedirectFactory->create();
6262
$resultRedirect->setPath('adminhtml/export/index');
6363
$fileName = $this->getRequest()->getParam('filename');
64-
$exportDirectory = $this->filesystem->getDirectoryRead(DirectoryList::VAR_EXPORT);
64+
$exportDirectory = $this->filesystem->getDirectoryRead(DirectoryList::VAR_IMPORT_EXPORT);
6565

6666
try {
67-
$fileExist = $exportDirectory->isExist($fileName);
67+
$fileExist = $exportDirectory->isExist('export/' . $fileName);
6868
} catch (Throwable $e) {
6969
$fileExist = false;
7070
}

app/code/Magento/ProductVideo/Controller/Adminhtml/Product/Gallery/RetrieveImage.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ protected function appendResultSaveRemoteImage($fileName)
180180
$result['name'] = $fileInfo['basename'];
181181
$result['type'] = $this->imageAdapter->getMimeType();
182182
$result['error'] = 0;
183-
$result['size'] = filesize($this->appendAbsoluteFileSystemPath($fileName));
183+
$result['size'] = $this->fileSystem->getDirectoryWrite(DirectoryList::MEDIA)
184+
->getDriver()->stat(($this->appendAbsoluteFileSystemPath($fileName)))['size'];
184185
$result['url'] = $this->mediaConfig->getTmpMediaUrl($tmpFileName);
185186
$result['file'] = $tmpFileName;
186187
return $result;

app/code/Magento/ProductVideo/Test/Unit/Controller/Adminhtml/Product/Gallery/RetrieveImageTest.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Backend\App\Action\Context;
1111
use Magento\Catalog\Model\Product\Media\Config;
1212
use Magento\Framework\App\RequestInterface;
13+
use Magento\Framework\Controller\Result\Raw;
1314
use Magento\Framework\Controller\Result\RawFactory;
1415
use Magento\Framework\DataObject;
1516
use Magento\Framework\Filesystem;
@@ -99,6 +100,11 @@ class RetrieveImageTest extends TestCase
99100
*/
100101
private $fileDriverMock;
101102

103+
/**
104+
* @var Raw|MockObject
105+
*/
106+
private $responseMock;
107+
102108
private function setupObjectManagerForCheckImageExist($return)
103109
{
104110
$objectManagerMock = $this->getMockForAbstractClass(ObjectManagerInterface::class);
@@ -119,8 +125,8 @@ protected function setUp(): void
119125
->createMock(NotProtectedExtension::class);
120126
$this->rawFactoryMock =
121127
$this->createPartialMock(RawFactory::class, ['create']);
122-
$response = new DataObject();
123-
$this->rawFactoryMock->expects($this->once())->method('create')->willReturn($response);
128+
$this->responseMock = $this->createMock(Raw::class);
129+
$this->rawFactoryMock->expects($this->once())->method('create')->willReturn($this->responseMock);
124130
$this->configMock = $this->createMock(Config::class);
125131
$this->filesystemMock = $this->createMock(Filesystem::class);
126132
$this->adapterMock =
@@ -140,6 +146,8 @@ protected function setUp(): void
140146
->getMockForAbstractClass();
141147
$this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->request);
142148
$this->contextMock->expects($this->any())->method('getObjectManager')->willReturn($managerMock);
149+
$this->fileDriverMock->method('stat')
150+
->willReturn(['size' => 200]);
143151

144152
$this->image = $objectManager->getObject(
145153
RetrieveImage::class,
@@ -172,12 +180,24 @@ public function testExecute()
172180
$writeInterface = $this->createMock(
173181
WriteInterface::class
174182
);
183+
$writeInterface->method('getDriver')
184+
->willReturn($this->fileDriverMock);
175185
$this->filesystemMock->expects($this->any())->method('getDirectoryRead')->willReturn($readInterface);
176186
$readInterface->expects($this->any())->method('getAbsolutePath')->willReturn('');
177187
$this->abstractAdapter->expects($this->any())->method('validateUploadFile')->willReturn('true');
178188
$this->validatorMock->expects($this->once())->method('isValid')->with('jpg')->willReturn('true');
179189
$this->filesystemMock->expects($this->once())->method('getDirectoryWrite')->willReturn($writeInterface);
180190
$this->curlMock->expects($this->once())->method('read')->willReturn('testimage');
191+
$this->responseMock->expects(self::once())
192+
->method('setContents')
193+
->with(json_encode([
194+
'name' => 'test.jpg',
195+
'type' => null,
196+
'error' => 0,
197+
'size' => 200,
198+
'url' => null,
199+
'file' => '/t/e/test.jpg'
200+
], JSON_THROW_ON_ERROR));
181201

182202
$this->image->execute();
183203
}
@@ -192,6 +212,8 @@ public function testExecuteInvalidFileImage()
192212
);
193213
$readInterface = $this->createMock(ReadInterface::class);
194214
$writeInterface = $this->createMock(WriteInterface::class);
215+
$writeInterface->method('getDriver')
216+
->willReturn($this->fileDriverMock);
195217
$this->filesystemMock->expects($this->any())->method('getDirectoryRead')->willReturn($readInterface);
196218
$readInterface->expects($this->any())->method('getAbsolutePath')->willReturn('');
197219
$this->abstractAdapter->expects($this->any())
@@ -216,6 +238,8 @@ public function testExecuteInvalidFileType()
216238
);
217239
$readInterface = $this->createMock(ReadInterface::class);
218240
$writeInterface = $this->createMock(WriteInterface::class);
241+
$writeInterface->method('getDriver')
242+
->willReturn($this->fileDriverMock);
219243
$this->filesystemMock->expects($this->any())->method('getDirectoryRead')->willReturn($readInterface);
220244
$readInterface->expects($this->any())->method('getAbsolutePath')->willReturn('');
221245
$this->abstractAdapter->expects($this->never())->method('validateUploadFile');

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,20 @@ public function filterSingleCategoryDataProvider(): array
613613
'position' => '1'
614614
]
615615
],
616+
[
617+
'parent_category_uid',
618+
'eq',
619+
'NA==',
620+
[
621+
'id' => '5',
622+
'name' => 'Category 1.1.1',
623+
'url_key' => 'category-1-1-1',
624+
'url_path' => 'category-1/category-1-1/category-1-1-1',
625+
'children_count' => '0',
626+
'path' => '1/2/3/4/5',
627+
'position' => '1'
628+
]
629+
],
616630
[
617631
'name',
618632
'match',
@@ -761,6 +775,41 @@ public function filterMultipleCategoriesDataProvider(): array
761775
]
762776
]
763777
],
778+
// Filter by multiple parent UIDs
779+
[
780+
'parent_category_uid',
781+
'in',
782+
'["Mw==", "NA=="]',
783+
[
784+
[
785+
'id' => '4',
786+
'name' => 'Category 1.1',
787+
'url_key' => 'category-1-1',
788+
'url_path' => 'category-1/category-1-1',
789+
'children_count' => '0',
790+
'path' => '1/2/3/4',
791+
'position' => '1'
792+
],
793+
[
794+
'id' => '5',
795+
'name' => 'Category 1.1.1',
796+
'url_key' => 'category-1-1-1',
797+
'url_path' => 'category-1/category-1-1/category-1-1-1',
798+
'children_count' => '0',
799+
'path' => '1/2/3/4/5',
800+
'position' => '1'
801+
],
802+
[
803+
'id' => '13',
804+
'name' => 'Category 1.2',
805+
'url_key' => 'category-1-2',
806+
'url_path' => 'category-1/category-1-2',
807+
'children_count' => '0',
808+
'path' => '1/2/3/13',
809+
'position' => '2'
810+
]
811+
]
812+
],
764813
//Filter by multiple url keys
765814
[
766815
'url_key',

0 commit comments

Comments
 (0)