@@ -14,6 +14,9 @@ class CollectionTest extends \PHPUnit\Framework\TestCase
14
14
/**
15
15
* @dataProvider filtersDataProviderSearch
16
16
* @magentoDataFixture Magento/Framework/Search/_files/products.php
17
+ * @magentoDataFixture Magento/CatalogSearch/_files/full_reindex.php
18
+ * @magentoConfigFixture default/catalog/search/engine mysql
19
+ * @magentoAppIsolation enabled
17
20
*/
18
21
public function testLoadWithFilterSearch ($ request , $ filters , $ expectedCount )
19
22
{
@@ -31,6 +34,42 @@ public function testLoadWithFilterSearch($request, $filters, $expectedCount)
31
34
$ this ->assertCount ($ expectedCount , $ items );
32
35
}
33
36
37
+ /**
38
+ * @dataProvider filtersDataProviderQuickSearch
39
+ * @magentoDataFixture Magento/Framework/Search/_files/products.php
40
+ */
41
+ public function testLoadWithFilterQuickSearch ($ filters , $ expectedCount )
42
+ {
43
+ $ objManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
44
+ $ searchLayer = $ objManager ->create (\Magento \Catalog \Model \Layer \Search::class);
45
+ /** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $fulltextCollection */
46
+ $ fulltextCollection = $ searchLayer ->getProductCollection ();
47
+ foreach ($ filters as $ field => $ value ) {
48
+ $ fulltextCollection ->addFieldToFilter ($ field , $ value );
49
+ }
50
+ $ fulltextCollection ->loadWithFilter ();
51
+ $ items = $ fulltextCollection ->getItems ();
52
+ $ this ->assertCount ($ expectedCount , $ items );
53
+ }
54
+
55
+ /**
56
+ * @dataProvider filtersDataProviderCatalogView
57
+ * @magentoDataFixture Magento/Framework/Search/_files/products.php
58
+ */
59
+ public function testLoadWithFilterCatalogView ($ filters , $ expectedCount )
60
+ {
61
+ $ objManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
62
+ $ searchLayer = $ objManager ->create (\Magento \Catalog \Model \Layer \Category::class);
63
+ /** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $fulltextCollection */
64
+ $ fulltextCollection = $ searchLayer ->getProductCollection ();
65
+ foreach ($ filters as $ field => $ value ) {
66
+ $ fulltextCollection ->addFieldToFilter ($ field , $ value );
67
+ }
68
+ $ fulltextCollection ->loadWithFilter ();
69
+ $ items = $ fulltextCollection ->getItems ();
70
+ $ this ->assertCount ($ expectedCount , $ items );
71
+ }
72
+
34
73
/**
35
74
* @magentoDataFixture Magento/Framework/Search/_files/products_with_the_same_search_score.php
36
75
*/
@@ -42,11 +81,9 @@ public function testSearchResultsAreTheSameForSameRequests()
42
81
$ objManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
43
82
44
83
foreach (range (1 , $ howManySearchRequests ) as $ i ) {
84
+ $ searchLayer = $ objManager ->create (\Magento \Catalog \Model \Layer \Search::class);
45
85
/** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $fulltextCollection */
46
- $ fulltextCollection = $ objManager ->create (
47
- \Magento \CatalogSearch \Model \ResourceModel \Fulltext \Collection::class,
48
- ['searchRequestName ' => 'quick_search_container ' ]
49
- );
86
+ $ fulltextCollection = $ searchLayer ->getProductCollection ();
50
87
51
88
$ fulltextCollection ->addFieldToFilter ('search_term ' , 'shorts ' );
52
89
$ fulltextCollection ->setOrder ('relevance ' );
@@ -81,4 +118,22 @@ public function filtersDataProviderSearch()
81
118
['catalog_view_container ' , [], 0 ],
82
119
];
83
120
}
121
+
122
+ public function filtersDataProviderQuickSearch ()
123
+ {
124
+ return [
125
+ [['search_term ' => ' shorts ' ], 2 ],
126
+ [['search_term ' => 'nonexistent ' ], 0 ],
127
+ ];
128
+ }
129
+
130
+ public function filtersDataProviderCatalogView ()
131
+ {
132
+ return [
133
+ [['category_ids ' => 2 ], 5 ],
134
+ [['category_ids ' => 100001 ], 0 ],
135
+ [['category_ids ' => []], 5 ],
136
+ [[], 5 ],
137
+ ];
138
+ }
84
139
}
0 commit comments