Skip to content

Commit 1f83e2d

Browse files
committed
Merge branch 'ACP2E-1787' of https://github.com/magento-l3/magento2ce into PR-2023-04-27
2 parents 6884f3a + 42973d0 commit 1f83e2d

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

app/code/Magento/CatalogSearch/Model/Autocomplete/DataProvider.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ class DataProvider implements DataProviderInterface
2121
/**
2222
* Autocomplete limit
2323
*/
24-
const CONFIG_AUTOCOMPLETE_LIMIT = 'catalog/search/autocomplete_limit';
24+
public const CONFIG_AUTOCOMPLETE_LIMIT = 'catalog/search/autocomplete_limit';
2525

2626
/**
27-
* Query factory
28-
*
2927
* @var QueryFactory
3028
*/
3129
protected $queryFactory;
@@ -38,8 +36,6 @@ class DataProvider implements DataProviderInterface
3836
protected $itemFactory;
3937

4038
/**
41-
* Limit
42-
*
4339
* @var int
4440
*/
4541
protected $limit;
@@ -68,8 +64,12 @@ public function __construct(
6864
*/
6965
public function getItems()
7066
{
71-
$collection = $this->getSuggestCollection();
7267
$query = $this->queryFactory->get()->getQueryText();
68+
if (!$query) {
69+
return [];
70+
}
71+
72+
$collection = $this->getSuggestCollection();
7373
$result = [];
7474
foreach ($collection as $item) {
7575
$resultItem = $this->itemFactory->create([

app/code/Magento/CatalogSearch/Test/Unit/Model/Autocomplete/DataProviderTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,17 @@ private function buildCollection(array $data)
147147
->method('getIterator')
148148
->willReturn(new \ArrayIterator($collectionData));
149149
}
150+
151+
public function testGetItemsWithEmptyQueryText()
152+
{
153+
$this->query->expects($this->once())
154+
->method('getQueryText')
155+
->willReturn('');
156+
$this->query->expects($this->never())
157+
->method('getSuggestCollection');
158+
$this->itemFactory->expects($this->never())
159+
->method('create');
160+
$result = $this->model->getItems();
161+
$this->assertEmpty($result);
162+
}
150163
}

0 commit comments

Comments
 (0)