Skip to content

Commit 29d8607

Browse files
committed
ACP2E-948: Product listing GraphQL query limited to total_count 10,000 products only
1 parent aa8aff4 commit 29d8607

File tree

4 files changed

+42
-231
lines changed

4 files changed

+42
-231
lines changed

app/code/Magento/CatalogGraphQl/Test/Unit/DataProvider/Product/SearchCriteriaBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function testBuild(): void
131131
->method('getAttribute')
132132
->with(Product::ENTITY, 'price')
133133
->willReturn($attributeInterface);
134-
$sortOrderList = ['relevance', '_id'];
134+
$sortOrderList = ['relevance', 'entity_id'];
135135

136136
$this->sortOrderBuilder->expects($this->exactly(2))
137137
->method('setField')

app/code/Magento/Elasticsearch/Test/Unit/SearchAdapter/Query/Builder/Sort/PositionTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,13 @@ public function testBuildWithMultipleCategoryId(): void
114114
$matchQueryMock->method('getValue')
115115
->willReturn([7, 8]);
116116
$attributeMock = $this->createMock(AttributeAdapter::class);
117-
$this->fieldNameResolverMock->expects(self::exactly(2))
117+
$matcher = self::exactly(2);
118+
$this->fieldNameResolverMock->expects($matcher)
118119
->method('getFieldName')
119-
->withConsecutive([$attributeMock, ['categoryId' => 7]], [$attributeMock, ['categoryId' => 8]])
120-
->willReturnOnConsecutiveCalls('position_category_7', 'position_category_8');
120+
->willReturnCallback(fn ($attribute, $context) => match ([$attribute, $context]) {
121+
[$attributeMock, ['categoryId' => 7]] => 'position_category_7',
122+
[$attributeMock, ['categoryId' => 8]] => 'position_category_8',
123+
});
121124

122125
$result = $this->position->build($attributeMock, 'desc', $requestMock);
123126
self::assertArrayHasKey('_script', $result);

app/code/Magento/Elasticsearch/Test/Unit/SearchAdapter/Query/Builder/SortTest.php

Lines changed: 31 additions & 225 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,23 @@
99

1010
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeAdapter;
1111
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeProvider;
12-
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldName\ResolverInterface
13-
as FieldNameResolver;
1412
use Magento\Elasticsearch\SearchAdapter\Query\Builder\Sort;
15-
use Magento\Framework\Search\RequestInterface;
16-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
13+
use Magento\Elasticsearch\SearchAdapter\Query\Builder\Sort\ExpressionBuilderInterface as SortExpressionBuilder;
14+
use Magento\Framework\Search\Request;
1715
use PHPUnit\Framework\MockObject\MockObject;
1816
use PHPUnit\Framework\TestCase;
1917

2018
class SortTest extends TestCase
2119
{
2220
/**
23-
* @var AttributeProvider
21+
* @var AttributeProvider|MockObject
2422
*/
25-
private $attributeAdapterProvider;
23+
private $attributeAdapterProviderMock;
2624

2725
/**
28-
* @var FieldNameResolver
26+
* @var SortExpressionBuilder|MockObject
2927
*/
30-
private $fieldNameResolver;
28+
private $sortExpressionBuilderMock;
3129

3230
/**
3331
* @var Sort
@@ -39,232 +37,40 @@ class SortTest extends TestCase
3937
*/
4038
protected function setUp(): void
4139
{
42-
$this->attributeAdapterProvider = $this->getMockBuilder(AttributeProvider::class)
43-
->disableOriginalConstructor()
44-
->onlyMethods(['getByAttributeCode'])
45-
->getMock();
46-
$this->fieldNameResolver = $this->getMockBuilder(FieldNameResolver::class)
47-
->disableOriginalConstructor()
48-
->onlyMethods(['getFieldName'])
49-
->getMock();
50-
51-
$this->sortBuilder = (new ObjectManager($this))->getObject(
52-
Sort::class,
53-
[
54-
'attributeAdapterProvider' => $this->attributeAdapterProvider,
55-
'fieldNameResolver' => $this->fieldNameResolver,
56-
]
57-
);
40+
$this->attributeAdapterProviderMock = $this->createMock(AttributeProvider::class);
41+
$this->sortExpressionBuilderMock = $this->createMock(SortExpressionBuilder::class);
42+
$this->sortBuilder = new Sort($this->attributeAdapterProviderMock, $this->sortExpressionBuilderMock);
5843
}
5944

6045
/**
61-
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
62-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
63-
* @dataProvider getSortProvider
64-
* @param array $sortItems
65-
* @param $isSortable
66-
* @param $isFloatType
67-
* @param $isIntegerType
68-
* @param $fieldName
69-
* @param array $expected
46+
* @return void
7047
*/
71-
public function testGetSort(
72-
array $sortItems,
73-
$isSortable,
74-
$isFloatType,
75-
$isIntegerType,
76-
$isComplexType,
77-
$fieldName,
78-
array $expected
79-
) {
80-
/** @var MockObject|RequestInterface $request */
81-
$request = $this->getMockBuilder(RequestInterface::class)
82-
->disableOriginalConstructor()
83-
->addMethods(['getSort'])
84-
->getMockForAbstractClass();
85-
$request->expects($this->any())
48+
public function testGetSort(): void
49+
{
50+
$request = $this->createMock(Request::class);
51+
$sortItems = [
52+
[
53+
'field' => 'some_attribute',
54+
'direction' => 'DESC',
55+
]
56+
];
57+
$request->expects(self::once())
8658
->method('getSort')
8759
->willReturn($sortItems);
88-
$attributeMock = $this->getMockBuilder(AttributeAdapter::class)
89-
->disableOriginalConstructor()
90-
->onlyMethods(['isSortable', 'isFloatType', 'isIntegerType', 'isComplexType'])
91-
->getMock();
92-
$attributeMock->expects($this->any())
93-
->method('isSortable')
94-
->willReturn($isSortable);
95-
$attributeMock->expects($this->any())
96-
->method('isFloatType')
97-
->willReturn($isFloatType);
98-
$attributeMock->expects($this->any())
99-
->method('isIntegerType')
100-
->willReturn($isIntegerType);
101-
$attributeMock->expects($this->any())
102-
->method('isComplexType')
103-
->willReturn($isComplexType);
104-
$this->attributeAdapterProvider->expects($this->any())
60+
$attributeAdapterMock = $this->createMock(AttributeAdapter::class);
61+
$this->attributeAdapterProviderMock->expects(self::once())
10562
->method('getByAttributeCode')
106-
->with($this->anything())
107-
->willReturn($attributeMock);
108-
$this->fieldNameResolver->expects($this->any())
109-
->method('getFieldName')
110-
->with($this->anything())
111-
->willReturnCallback(
112-
function ($attribute, $context) use ($fieldName) {
113-
if (empty($context)) {
114-
return $fieldName;
115-
} elseif ($context['type'] === 'sort') {
116-
return 'sort_' . $fieldName;
117-
}
118-
}
119-
);
63+
->with('some_attribute')
64+
->willReturn($attributeAdapterMock);
65+
$sortExpression = ['some_attribute' => ['order' => 'desc']];
66+
$this->sortExpressionBuilderMock->expects(self::once())
67+
->method('build')
68+
->with($attributeAdapterMock, 'desc', $request)
69+
->willReturn($sortExpression);
12070

121-
$this->assertEquals(
122-
$expected,
71+
self::assertEquals(
72+
[$sortExpression],
12373
$this->sortBuilder->getSort($request)
12474
);
12575
}
126-
127-
/**
128-
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
129-
* @return array
130-
*/
131-
public function getSortProvider()
132-
{
133-
return [
134-
[
135-
[
136-
[
137-
'field' => 'entity_id',
138-
'direction' => 'DESC'
139-
]
140-
],
141-
false,
142-
false,
143-
false,
144-
false,
145-
null,
146-
[]
147-
],
148-
[
149-
[
150-
[
151-
'field' => 'entity_id',
152-
'direction' => 'DESC'
153-
],
154-
[
155-
'field' => 'price',
156-
'direction' => 'DESC'
157-
],
158-
],
159-
false,
160-
false,
161-
false,
162-
false,
163-
'price',
164-
[
165-
[
166-
'price' => [
167-
'order' => 'desc'
168-
]
169-
]
170-
]
171-
],
172-
[
173-
[
174-
[
175-
'field' => 'entity_id',
176-
'direction' => 'DESC'
177-
],
178-
[
179-
'field' => 'price',
180-
'direction' => 'DESC'
181-
],
182-
],
183-
true,
184-
true,
185-
true,
186-
false,
187-
'price',
188-
[
189-
[
190-
'price' => [
191-
'order' => 'desc'
192-
]
193-
]
194-
]
195-
],
196-
[
197-
[
198-
[
199-
'field' => 'entity_id',
200-
'direction' => 'DESC'
201-
],
202-
[
203-
'field' => 'name',
204-
'direction' => 'DESC'
205-
],
206-
],
207-
true,
208-
false,
209-
false,
210-
false,
211-
'name',
212-
[
213-
[
214-
'name.sort_name' => [
215-
'order' => 'desc'
216-
]
217-
]
218-
]
219-
],
220-
[
221-
[
222-
[
223-
'field' => 'entity_id',
224-
'direction' => 'DESC'
225-
],
226-
[
227-
'field' => 'not_eav_attribute',
228-
'direction' => 'DESC'
229-
],
230-
],
231-
false,
232-
false,
233-
false,
234-
false,
235-
'not_eav_attribute',
236-
[
237-
[
238-
'not_eav_attribute' => [
239-
'order' => 'desc'
240-
]
241-
]
242-
]
243-
],
244-
[
245-
[
246-
[
247-
'field' => 'entity_id',
248-
'direction' => 'DESC'
249-
],
250-
[
251-
'field' => 'color',
252-
'direction' => 'DESC'
253-
],
254-
],
255-
true,
256-
false,
257-
false,
258-
true,
259-
'color',
260-
[
261-
[
262-
'color_value.sort_color' => [
263-
'order' => 'desc'
264-
]
265-
]
266-
]
267-
]
268-
];
269-
}
27076
}

app/code/Magento/Elasticsearch7/Test/Unit/SearchAdapter/AdapterTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,10 @@ public function testQueryExceedingPageSizeLimit(int $from, int $size): void
257257
];
258258
$this->connectionMock->expects($this->exactly(2))
259259
->method('query')
260-
->withConsecutive([$firstQuery], [$finalQuery])
261-
->willReturnOnConsecutiveCalls($firstResponse, $finalResponse);
260+
->willReturnCallback(fn ($query) => match($query) {
261+
$firstQuery => $firstResponse,
262+
$finalQuery => $finalResponse,
263+
});
262264
$this->connectionMock->expects($this->once())->method('closePointInTime')->with(['body' => $pit]);
263265

264266
$queryResponseMock = $this->mockQueryResponse($requestMock, $finalQuery, $finalResponse);

0 commit comments

Comments
 (0)