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
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 ([
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments