Skip to content

Commit 34e6d2a

Browse files
committed
MC-18332: Remove MySQL Search Engine
- restore some tests - remove di references - remove constant references
1 parent dd43754 commit 34e6d2a

File tree

8 files changed

+670
-31
lines changed

8 files changed

+670
-31
lines changed

app/code/Magento/AdvancedSearch/Model/Indexer/Fulltext/Plugin/CustomerGroup.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ public function aroundSave(
5656
\Closure $proceed,
5757
AbstractModel $group
5858
) {
59-
$needInvalidation =
60-
($this->engineResolver->getCurrentSearchEngine() != EngineResolver::CATALOG_SEARCH_MYSQL_ENGINE)
61-
&& ($group->isObjectNew() || $group->dataHasChangedFor('tax_class_id'));
59+
$needInvalidation = $group->isObjectNew() || $group->dataHasChangedFor('tax_class_id');
6260
$result = $proceed($group);
6361
if ($needInvalidation) {
6462
$this->indexerRegistry->get(Fulltext::INDEXER_ID)->invalidate();

app/code/Magento/CatalogSearch/Model/ResourceModel/Advanced/Collection.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,6 @@ public function _loadEntities($printQuery = false, $logQuery = false)
360360
{
361361
$this->getEntity();
362362

363-
$currentSearchEngine = $this->_scopeConfig->getValue(self::SEARCH_ENGINE_VALUE_PATH);
364-
if ($this->_pageSize && $currentSearchEngine === EngineResolver::CATALOG_SEARCH_MYSQL_ENGINE) {
365-
$this->getSelect()->limitPage($this->getCurPage(), $this->_pageSize);
366-
}
367-
368363
$this->printLogQuery($printQuery, $logQuery);
369364

370365
try {

app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,6 @@ public function _loadEntities($printQuery = false, $logQuery = false)
399399
{
400400
$this->getEntity();
401401

402-
$currentSearchEngine = $this->_scopeConfig->getValue(self::SEARCH_ENGINE_VALUE_PATH);
403-
if ($this->_pageSize && $currentSearchEngine === EngineResolver::CATALOG_SEARCH_MYSQL_ENGINE) {
404-
$this->getSelect()->limitPage($this->getCurPage(), $this->_pageSize);
405-
}
406-
407402
$this->printLogQuery($printQuery, $logQuery);
408403

409404
try {
Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogSearch\Test\Unit\Model\ResourceModel\Advanced;
9+
10+
use Magento\Catalog\Model\Product;
11+
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
12+
use Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitation;
13+
use Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitationFactory;
14+
use Magento\CatalogSearch\Model\ResourceModel\Advanced\Collection;
15+
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchCriteriaResolverFactory;
16+
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchCriteriaResolverInterface;
17+
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplierFactory;
18+
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplierInterface;
19+
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\TotalRecordsResolverFactory;
20+
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\TotalRecordsResolverInterface;
21+
use Magento\CatalogSearch\Test\Unit\Model\ResourceModel\BaseCollection;
22+
use Magento\Eav\Model\Config;
23+
use Magento\Framework\Api\Filter;
24+
use Magento\Framework\Api\FilterBuilder;
25+
use Magento\Framework\Api\Search\SearchCriteriaBuilder;
26+
use Magento\Framework\Api\Search\SearchResultInterface;
27+
use Magento\Framework\Search\Adapter\Mysql\TemporaryStorageFactory;
28+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
29+
use Magento\Search\Api\SearchInterface;
30+
use PHPUnit\Framework\MockObject\MockObject;
31+
32+
/**
33+
* Tests Magento\CatalogSearch\Model\ResourceModel\Advanced\Collection
34+
*
35+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
36+
* @deprecated Implementation class was replaced
37+
* @see \Magento\ElasticSearch
38+
*/
39+
class CollectionTest extends BaseCollection
40+
{
41+
/**
42+
* @var ObjectManager
43+
*/
44+
private $objectManager;
45+
46+
/**
47+
* @var Collection
48+
*/
49+
private $advancedCollection;
50+
51+
/**
52+
* @var FilterBuilder|MockObject
53+
*/
54+
private $filterBuilder;
55+
56+
/**
57+
* @var SearchCriteriaBuilder|MockObject
58+
*/
59+
private $criteriaBuilder;
60+
61+
/**
62+
* @var TemporaryStorageFactory|MockObject
63+
*/
64+
private $temporaryStorageFactory;
65+
66+
/**
67+
* @var SearchInterface|MockObject
68+
*/
69+
private $search;
70+
71+
/**
72+
* @var Config|MockObject
73+
*/
74+
private $eavConfig;
75+
76+
/**
77+
* @var SearchResultApplierFactory|MockObject
78+
*/
79+
private $searchResultApplierFactory;
80+
81+
/**
82+
* @inheritdoc
83+
*/
84+
protected function setUp(): void
85+
{
86+
$this->objectManager = new ObjectManager($this);
87+
$this->eavConfig = $this->createMock(Config::class);
88+
$storeManager = $this->getStoreManager();
89+
$universalFactory = $this->getUniversalFactory();
90+
$this->criteriaBuilder = $this->getCriteriaBuilder();
91+
$this->filterBuilder = $this->createMock(FilterBuilder::class);
92+
$this->temporaryStorageFactory = $this->createMock(
93+
TemporaryStorageFactory::class
94+
);
95+
$this->search = $this->getMockForAbstractClass(SearchInterface::class);
96+
97+
$productLimitationMock = $this->createMock(
98+
ProductLimitation::class
99+
);
100+
$productLimitationFactoryMock = $this->getMockBuilder(ProductLimitationFactory::class)
101+
->disableOriginalConstructor()
102+
->setMethods(['create'])
103+
->getMock();
104+
$productLimitationFactoryMock->method('create')
105+
->willReturn($productLimitationMock);
106+
107+
$searchCriteriaResolver = $this->getMockBuilder(SearchCriteriaResolverInterface::class)
108+
->disableOriginalConstructor()
109+
->setMethods(['resolve'])
110+
->getMockForAbstractClass();
111+
$searchCriteriaResolverFactory = $this->getMockBuilder(SearchCriteriaResolverFactory::class)
112+
->disableOriginalConstructor()
113+
->setMethods(['create'])
114+
->getMock();
115+
$searchCriteriaResolverFactory->expects($this->any())
116+
->method('create')
117+
->willReturn($searchCriteriaResolver);
118+
119+
$this->searchResultApplierFactory = $this->getMockBuilder(SearchResultApplierFactory::class)
120+
->disableOriginalConstructor()
121+
->setMethods(['create'])
122+
->getMock();
123+
124+
$totalRecordsResolver = $this->getMockBuilder(TotalRecordsResolverInterface::class)
125+
->disableOriginalConstructor()
126+
->setMethods(['resolve'])
127+
->getMockForAbstractClass();
128+
$totalRecordsResolverFactory = $this->getMockBuilder(TotalRecordsResolverFactory::class)
129+
->disableOriginalConstructor()
130+
->setMethods(['create'])
131+
->getMock();
132+
$totalRecordsResolverFactory->expects($this->any())
133+
->method('create')
134+
->willReturn($totalRecordsResolver);
135+
136+
$this->advancedCollection = $this->objectManager->getObject(
137+
Collection::class,
138+
[
139+
'eavConfig' => $this->eavConfig,
140+
'storeManager' => $storeManager,
141+
'universalFactory' => $universalFactory,
142+
'searchCriteriaBuilder' => $this->criteriaBuilder,
143+
'filterBuilder' => $this->filterBuilder,
144+
'temporaryStorageFactory' => $this->temporaryStorageFactory,
145+
'search' => $this->search,
146+
'productLimitationFactory' => $productLimitationFactoryMock,
147+
'collectionProvider' => null,
148+
'searchCriteriaResolverFactory' => $searchCriteriaResolverFactory,
149+
'searchResultApplierFactory' => $this->searchResultApplierFactory,
150+
'totalRecordsResolverFactory' => $totalRecordsResolverFactory
151+
]
152+
);
153+
}
154+
155+
/**
156+
* Test to Load data with filter in place
157+
*/
158+
public function testLoadWithFilterNoFilters()
159+
{
160+
$this->advancedCollection->loadWithFilter();
161+
}
162+
163+
/**
164+
* Test a search using 'like' condition
165+
*/
166+
public function testLike()
167+
{
168+
$pageSize = 10;
169+
$attributeCode = 'description';
170+
$attributeCodeId = 42;
171+
$attribute = $this->createMock(Attribute::class);
172+
$attribute->expects($this->once())->method('getAttributeCode')->willReturn($attributeCode);
173+
$this->eavConfig->expects($this->once())->method('getAttribute')->with(Product::ENTITY, $attributeCodeId)
174+
->willReturn($attribute);
175+
$filtersData = ['catalog_product_entity_text' => [$attributeCodeId => ['like' => 'search text']]];
176+
$this->filterBuilder->expects($this->once())->method('setField')->with($attributeCode)
177+
->willReturn($this->filterBuilder);
178+
$this->filterBuilder->expects($this->once())->method('setValue')->with('search text')
179+
->willReturn($this->filterBuilder);
180+
181+
$filter = $this->createMock(Filter::class);
182+
$this->filterBuilder->expects($this->any())->method('create')->willReturn($filter);
183+
184+
$searchResult = $this->getMockForAbstractClass(SearchResultInterface::class);
185+
$this->search->expects($this->once())->method('search')->willReturn($searchResult);
186+
187+
$this->advancedCollection->setPageSize($pageSize);
188+
$this->advancedCollection->setCurPage(0);
189+
190+
$searchResultApplier = $this->getMockForAbstractClass(SearchResultApplierInterface::class);
191+
$this->searchResultApplierFactory->expects($this->once())
192+
->method('create')
193+
->with(
194+
[
195+
'collection' => $this->advancedCollection,
196+
'searchResult' => $searchResult,
197+
'orders' => [],
198+
'size' => $pageSize,
199+
'currentPage' => 0,
200+
]
201+
)
202+
->willReturn($searchResultApplier);
203+
204+
// addFieldsToFilter will load filters,
205+
// then loadWithFilter will trigger _renderFiltersBefore code in Advanced/Collection
206+
$this->assertSame(
207+
$this->advancedCollection,
208+
$this->advancedCollection->addFieldsToFilter($filtersData)->loadWithFilter()
209+
);
210+
}
211+
212+
/**
213+
* @return MockObject
214+
*/
215+
protected function getCriteriaBuilder()
216+
{
217+
$criteriaBuilder = $this->getMockBuilder(SearchCriteriaBuilder::class)
218+
->setMethods(['addFilter', 'create', 'setRequestName'])
219+
->disableOriginalConstructor()
220+
->getMock();
221+
222+
return $criteriaBuilder;
223+
}
224+
}

app/code/Magento/CatalogSearch/etc/di.xml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
99
<preference for="Magento\Framework\Search\Adapter\OptionsInterface" type="Magento\CatalogSearch\Model\Adapter\Options" />
10-
<preference for="Magento\CatalogSearch\Model\Search\FilterMapper\FilterStrategyInterface" type="Magento\CatalogSearch\Model\Search\FilterMapper\FilterContext"/>
1110
<preference for="Magento\CatalogSearch\Model\Indexer\IndexSwitcherInterface" type="Magento\CatalogSearch\Model\Indexer\IndexSwitcherProxy"/>
1211
<preference for="Magento\CatalogSearch\Model\Adapter\Aggregation\RequestCheckerInterface" type="Magento\CatalogSearch\Model\Adapter\Aggregation\RequestCheckerComposite"/>
1312
<preference for="Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchCriteriaResolverInterface" type="Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchCriteriaResolver"/>
@@ -200,30 +199,13 @@
200199
<argument name="name" xsi:type="string">catalog_view_container</argument>
201200
</arguments>
202201
</type>
203-
<type name="Magento\CatalogSearch\Model\Search\FilterMapper\TermDropdownStrategy">
204-
<arguments>
205-
<!-- @deprecated parameter storeManager has been deprecated and not in used now -->
206-
<argument name="storeManager" xsi:type="null"/>
207-
<!-- @deprecated parameter resourceConnection has been deprecated and not in used now -->
208-
<argument name="resourceConnection" xsi:type="null"/>
209-
<!-- @deprecated parameter scopeConfig has been deprecated and not in used now -->
210-
<argument name="scopeConfig" xsi:type="null"/>
211-
</arguments>
212-
</type>
213202
<type name="Magento\CatalogSearch\Model\Indexer\Fulltext">
214203
<arguments>
215204
<argument name="dimensionProvider" xsi:type="object" shared="false">
216205
Magento\Store\Model\StoreDimensionProvider
217206
</argument>
218207
</arguments>
219208
</type>
220-
<type name="Magento\CatalogSearch\Model\Search\FilterMapper\ExclusionStrategy">
221-
<arguments>
222-
<argument name="priceTableResolver" xsi:type="object">
223-
Magento\Catalog\Model\Indexer\Product\Price\PriceTableResolver
224-
</argument>
225-
</arguments>
226-
</type>
227209
<type name="Magento\Eav\Model\Entity\Setup\PropertyMapper\Composite">
228210
<arguments>
229211
<argument name="propertyMappers" xsi:type="array">
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Search\Test\Unit\Adapter\Aggregation;
7+
8+
use Magento\Framework\Search\Adapter\Aggregation\AggregationResolver;
9+
use Magento\Framework\Search\Adapter\Aggregation\AggregationResolverInterface;
10+
use Magento\Framework\Search\RequestInterface;
11+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
12+
13+
class AggregationResolverTest extends \PHPUnit\Framework\TestCase
14+
{
15+
/**
16+
* @var RequestInterface|\PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
private $request;
19+
20+
/**
21+
* @var AggregationResolverInterface|\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
private $specificAggregationResolver;
24+
25+
/**
26+
* @var AggregationResolver
27+
*/
28+
private $aggregationResolver;
29+
30+
protected function setUp()
31+
{
32+
$this->request = $this->createMock(RequestInterface::class);
33+
$this->specificAggregationResolver = $this->createMock(AggregationResolverInterface::class);
34+
35+
$this->aggregationResolver = (new ObjectManager($this))->getObject(
36+
AggregationResolver::class,
37+
[
38+
'resolvers' => [
39+
'specific_resolver' => $this->specificAggregationResolver,
40+
],
41+
]
42+
);
43+
}
44+
45+
public function testResolve()
46+
{
47+
$documentIds = ['document_1', 'document_2'];
48+
$resolvedAggregations = ['aggregation_1'];
49+
50+
$this->request->expects($this->atLeastOnce())->method('getIndex')->willReturn('specific_resolver');
51+
$this->specificAggregationResolver->expects($this->once())
52+
->method('resolve')
53+
->with($this->request, $documentIds)
54+
->willReturn($resolvedAggregations);
55+
56+
$this->assertEquals($resolvedAggregations, $this->aggregationResolver->resolve($this->request, $documentIds));
57+
}
58+
59+
public function testResolveWithoutSpecificResolver()
60+
{
61+
$aggregations = ['aggregation_1'];
62+
63+
$this->request->expects($this->atLeastOnce())->method('getIndex')->willReturn('index_1');
64+
$this->request->expects($this->once())->method('getAggregation')->willReturn($aggregations);
65+
66+
$this->assertEquals($aggregations, $this->aggregationResolver->resolve($this->request, []));
67+
}
68+
}

0 commit comments

Comments
 (0)