Skip to content

Commit 4997123

Browse files
MC-19450: Adapt integration tests to elasticsearch
1 parent e5db71a commit 4997123

File tree

3 files changed

+64
-17
lines changed

3 files changed

+64
-17
lines changed

dev/tests/integration/testsuite/Magento/CatalogSearch/Model/Indexer/FulltextTest.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use Magento\Catalog\Model\Product;
1111
use Magento\Catalog\Model\Product\Visibility;
12-
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection;
1312
use Magento\TestFramework\Helper\Bootstrap;
1413

1514
/**
@@ -76,10 +75,6 @@ protected function setUp()
7675
);
7776
$this->indexer->load('catalogsearch_fulltext');
7877

79-
$this->engine = Bootstrap::getObjectManager()->get(
80-
\Magento\CatalogSearch\Model\ResourceModel\Engine::class
81-
);
82-
8378
$this->queryFactory = Bootstrap::getObjectManager()->get(
8479
\Magento\Search\Model\QueryFactory::class
8580
);
@@ -223,12 +218,8 @@ protected function search(string $text, $visibilityFilter = null): array
223218
$query->setQueryText($text);
224219
$query->saveIncrementalPopularity();
225220
$products = [];
226-
$collection = Bootstrap::getObjectManager()->create(
227-
Collection::class,
228-
[
229-
'searchRequestName' => 'quick_search_container'
230-
]
231-
);
221+
$searchLayer = Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Layer\Search::class);
222+
$collection = $searchLayer->getProductCollection();
232223
$collection->addSearchFilter($text);
233224

234225
if (null !== $visibilityFilter) {

dev/tests/integration/testsuite/Magento/CatalogSearch/Model/ResourceModel/Advanced/CollectionTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ class CollectionTest extends \PHPUnit\Framework\TestCase
1818

1919
protected function setUp()
2020
{
21-
$this->advancedCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
22-
->create(\Magento\CatalogSearch\Model\ResourceModel\Advanced\Collection::class);
21+
$advanced = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
22+
->create(\Magento\CatalogSearch\Model\Search\ItemCollectionProvider::class);
23+
$this->advancedCollection = $advanced->getCollection();
2324
}
2425

2526
/**

dev/tests/integration/testsuite/Magento/CatalogSearch/Model/ResourceModel/Fulltext/CollectionTest.php

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class CollectionTest extends \PHPUnit\Framework\TestCase
1414
/**
1515
* @dataProvider filtersDataProviderSearch
1616
* @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
1720
*/
1821
public function testLoadWithFilterSearch($request, $filters, $expectedCount)
1922
{
@@ -31,6 +34,42 @@ public function testLoadWithFilterSearch($request, $filters, $expectedCount)
3134
$this->assertCount($expectedCount, $items);
3235
}
3336

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+
3473
/**
3574
* @magentoDataFixture Magento/Framework/Search/_files/products_with_the_same_search_score.php
3675
*/
@@ -42,11 +81,9 @@ public function testSearchResultsAreTheSameForSameRequests()
4281
$objManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
4382

4483
foreach (range(1, $howManySearchRequests) as $i) {
84+
$searchLayer = $objManager->create(\Magento\Catalog\Model\Layer\Search::class);
4585
/** @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();
5087

5188
$fulltextCollection->addFieldToFilter('search_term', 'shorts');
5289
$fulltextCollection->setOrder('relevance');
@@ -81,4 +118,22 @@ public function filtersDataProviderSearch()
81118
['catalog_view_container', [], 0],
82119
];
83120
}
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+
}
84139
}

0 commit comments

Comments
 (0)