File tree Expand file tree Collapse file tree 2 files changed +19
-6
lines changed
app/code/Magento/CatalogSearch
Test/Unit/Model/Autocomplete Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -21,11 +21,9 @@ class DataProvider implements DataProviderInterface
21
21
/**
22
22
* Autocomplete limit
23
23
*/
24
- const CONFIG_AUTOCOMPLETE_LIMIT = 'catalog/search/autocomplete_limit ' ;
24
+ public const CONFIG_AUTOCOMPLETE_LIMIT = 'catalog/search/autocomplete_limit ' ;
25
25
26
26
/**
27
- * Query factory
28
- *
29
27
* @var QueryFactory
30
28
*/
31
29
protected $ queryFactory ;
@@ -38,8 +36,6 @@ class DataProvider implements DataProviderInterface
38
36
protected $ itemFactory ;
39
37
40
38
/**
41
- * Limit
42
- *
43
39
* @var int
44
40
*/
45
41
protected $ limit ;
@@ -68,8 +64,12 @@ public function __construct(
68
64
*/
69
65
public function getItems ()
70
66
{
71
- $ collection = $ this ->getSuggestCollection ();
72
67
$ query = $ this ->queryFactory ->get ()->getQueryText ();
68
+ if (!$ query ) {
69
+ return [];
70
+ }
71
+
72
+ $ collection = $ this ->getSuggestCollection ();
73
73
$ result = [];
74
74
foreach ($ collection as $ item ) {
75
75
$ resultItem = $ this ->itemFactory ->create ([
Original file line number Diff line number Diff line change @@ -147,4 +147,17 @@ private function buildCollection(array $data)
147
147
->method ('getIterator ' )
148
148
->willReturn (new \ArrayIterator ($ collectionData ));
149
149
}
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
+ }
150
163
}
You can’t perform that action at this time.
0 commit comments