Skip to content

Commit 50c27bf

Browse files
author
Joan He
authored
Merge pull request #4812 from magento-arcticfoxes/2.3-develop-pr
[arcticfoxes] Bug Fixes
2 parents d6ef3ef + f53b9ca commit 50c27bf

File tree

19 files changed

+234
-184
lines changed

19 files changed

+234
-184
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ private function getSearchResultApplier(SearchResultInterface $searchResult): Se
393393
/** This variable sets by serOrder method, but doesn't have a getter method. */
394394
'orders' => $this->_orders,
395395
'size' => $this->getPageSize(),
396+
'currentPage' => (int)$this->_curPage,
396397
]
397398
);
398399
}

app/code/Magento/CatalogSearch/Test/Unit/Model/ResourceModel/Advanced/CollectionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ public function testLike()
183183
'searchResult' => $searchResult,
184184
'orders' => [],
185185
'size' => $pageSize,
186+
'currentPage' => 0,
186187
]
187188
)
188189
->willReturn($searchResultApplier);

app/code/Magento/Elasticsearch/Model/Adapter/Elasticsearch.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,11 @@ public function cleanIndex($storeId, $mappedIndexerId)
195195
{
196196
$this->checkIndex($storeId, $mappedIndexerId, true);
197197
$indexName = $this->indexNameResolver->getIndexName($storeId, $mappedIndexerId, $this->preparedIndex);
198-
if ($this->client->isEmptyIndex($indexName)) {
199-
// use existing index if empty
200-
return $this;
201-
}
202198

203199
// prepare new index name and increase version
204200
$indexPattern = $this->indexNameResolver->getIndexPattern($storeId, $mappedIndexerId);
205201
$version = (int)(str_replace($indexPattern, '', $indexName));
206-
$newIndexName = $indexPattern . ++$version;
202+
$newIndexName = $indexPattern . (++$version);
207203

208204
// remove index if already exists
209205
if ($this->client->indexExists($newIndexName)) {
@@ -354,12 +350,14 @@ protected function prepareIndex($storeId, $indexName, $mappedIndexerId)
354350
{
355351
$this->indexBuilder->setStoreId($storeId);
356352
$settings = $this->indexBuilder->build();
357-
$allAttributeTypes = $this->fieldMapper->getAllAttributesTypes([
358-
'entityType' => $mappedIndexerId,
359-
// Use store id instead of website id from context for save existing fields mapping.
360-
// In future websiteId will be eliminated due to index stored per store
361-
'websiteId' => $storeId
362-
]);
353+
$allAttributeTypes = $this->fieldMapper->getAllAttributesTypes(
354+
[
355+
'entityType' => $mappedIndexerId,
356+
// Use store id instead of website id from context for save existing fields mapping.
357+
// In future websiteId will be eliminated due to index stored per store
358+
'websiteId' => $storeId
359+
]
360+
);
363361
$settings['index']['mapping']['total_fields']['limit'] = $this->getMappingTotalFieldsLimit($allAttributeTypes);
364362
$this->client->createIndex($indexName, ['settings' => $settings]);
365363
$this->client->addFieldsMapping(

app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/ElasticsearchTest.php

Lines changed: 56 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class ElasticsearchTest extends \PHPUnit\Framework\TestCase
7777
* Setup
7878
*
7979
* @return void
80+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
8081
*/
8182
protected function setUp()
8283
{
@@ -93,55 +94,65 @@ protected function setUp()
9394
->getMock();
9495
$this->clientConfig = $this->getMockBuilder(\Magento\Elasticsearch\Model\Config::class)
9596
->disableOriginalConstructor()
96-
->setMethods([
97-
'getIndexPrefix',
98-
'getEntityType',
99-
])->getMock();
97+
->setMethods(
98+
[
99+
'getIndexPrefix',
100+
'getEntityType',
101+
]
102+
)->getMock();
100103
$this->indexBuilder = $this->getMockBuilder(\Magento\Elasticsearch\Model\Adapter\Index\BuilderInterface::class)
101104
->disableOriginalConstructor()
102105
->getMock();
103106
$this->logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)
104107
->disableOriginalConstructor()
105108
->getMock();
106109
$elasticsearchClientMock = $this->getMockBuilder(\Elasticsearch\Client::class)
107-
->setMethods([
108-
'indices',
109-
'ping',
110-
'bulk',
111-
'search',
112-
])
110+
->setMethods(
111+
[
112+
'indices',
113+
'ping',
114+
'bulk',
115+
'search',
116+
]
117+
)
113118
->disableOriginalConstructor()
114119
->getMock();
115120
$indicesMock = $this->getMockBuilder(\Elasticsearch\Namespaces\IndicesNamespace::class)
116-
->setMethods([
117-
'exists',
118-
'getSettings',
119-
'create',
120-
'putMapping',
121-
'deleteMapping',
122-
'existsAlias',
123-
'updateAliases',
124-
'stats'
125-
])
121+
->setMethods(
122+
[
123+
'exists',
124+
'getSettings',
125+
'create',
126+
'putMapping',
127+
'deleteMapping',
128+
'existsAlias',
129+
'updateAliases',
130+
'stats'
131+
]
132+
)
126133
->disableOriginalConstructor()
127134
->getMock();
128135
$elasticsearchClientMock->expects($this->any())
129136
->method('indices')
130137
->willReturn($indicesMock);
131138
$this->client = $this->getMockBuilder(\Magento\Elasticsearch\Model\Client\Elasticsearch::class)
132-
->setConstructorArgs([
133-
'options' => $this->getClientOptions(),
134-
'elasticsearchClient' => $elasticsearchClientMock
135-
])
139+
->setConstructorArgs(
140+
[
141+
'options' => $this->getClientOptions(),
142+
'elasticsearchClient' => $elasticsearchClientMock
143+
]
144+
)
136145
->getMock();
137146
$this->connectionManager->expects($this->any())
138147
->method('getConnection')
139148
->willReturn($this->client);
140149
$this->fieldMapper->expects($this->any())
141150
->method('getAllAttributesTypes')
142-
->willReturn([
143-
'name' => 'string',
144-
]);
151+
->willReturn(
152+
[
153+
'name' => 'string',
154+
]
155+
);
145156
$this->clientConfig->expects($this->any())
146157
->method('getIndexPrefix')
147158
->willReturn('indexName');
@@ -151,12 +162,14 @@ protected function setUp()
151162
$this->indexNameResolver = $this->getMockBuilder(
152163
\Magento\Elasticsearch\Model\Adapter\Index\IndexNameResolver::class
153164
)
154-
->setMethods([
155-
'getIndexName',
156-
'getIndexNamespace',
157-
'getIndexFromAlias',
158-
'getIndexNameForAlias',
159-
])
165+
->setMethods(
166+
[
167+
'getIndexName',
168+
'getIndexNamespace',
169+
'getIndexFromAlias',
170+
'getIndexNameForAlias',
171+
]
172+
)
160173
->disableOriginalConstructor()
161174
->getMock();
162175
$this->batchDocumentDataMapper = $this->getMockBuilder(
@@ -216,9 +229,11 @@ public function testPrepareDocsPerStore()
216229
{
217230
$this->batchDocumentDataMapper->expects($this->once())
218231
->method('map')
219-
->willReturn([
220-
'name' => 'Product Name',
221-
]);
232+
->willReturn(
233+
[
234+
'name' => 'Product Name',
235+
]
236+
);
222237
$this->assertInternalType(
223238
'array',
224239
$this->model->prepareDocsPerStore(
@@ -283,10 +298,6 @@ public function testCleanIndex()
283298
->with(1, 'product', [])
284299
->willReturn('indexName_product_1_v');
285300

286-
$this->client->expects($this->once())
287-
->method('isEmptyIndex')
288-
->with('indexName_product_1_v')
289-
->willReturn(false);
290301
$this->client->expects($this->atLeastOnce())
291302
->method('indexExists')
292303
->willReturn(true);
@@ -299,26 +310,6 @@ public function testCleanIndex()
299310
);
300311
}
301312

302-
/**
303-
* Test cleanIndex() method isEmptyIndex is true
304-
*/
305-
public function testCleanIndexTrue()
306-
{
307-
$this->indexNameResolver->expects($this->any())
308-
->method('getIndexName')
309-
->willReturn('indexName_product_1_v');
310-
311-
$this->client->expects($this->once())
312-
->method('isEmptyIndex')
313-
->with('indexName_product_1_v')
314-
->willReturn(true);
315-
316-
$this->assertSame(
317-
$this->model,
318-
$this->model->cleanIndex(1, 'product')
319-
);
320-
}
321-
322313
/**
323314
* Test deleteDocs() method
324315
*/
@@ -376,9 +367,11 @@ public function testConnectException()
376367
{
377368
$connectionManager = $this->getMockBuilder(\Magento\Elasticsearch\SearchAdapter\ConnectionManager::class)
378369
->disableOriginalConstructor()
379-
->setMethods([
380-
'getConnection',
381-
])
370+
->setMethods(
371+
[
372+
'getConnection',
373+
]
374+
)
382375
->getMock();
383376

384377
$connectionManager->expects($this->any())

dev/tests/integration/testsuite/Magento/Bundle/Model/Product/TypeTest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,20 @@ protected function setUp()
4949

5050
/**
5151
* @magentoDataFixture Magento/Bundle/_files/product.php
52-
* @covers \Magento\Indexer\Model\Indexer::reindexAll
5352
* @covers \Magento\Bundle\Model\Product\Type::getSearchableData
5453
* @magentoDbIsolation disabled
5554
*/
56-
public function testPrepareProductIndexForBundleProduct()
55+
public function testGetSearchableData()
5756
{
58-
$this->indexer->reindexAll();
59-
60-
$select = $this->connectionMock->select()->from($this->resource->getTableName('catalogsearch_fulltext_scope1'))
61-
->where('`data_index` LIKE ?', '%' . 'Bundle Product Items' . '%');
57+
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
58+
/** @var \Magento\Catalog\Model\Product $bundleProduct */
59+
$bundleProduct = $productRepository->get('bundle-product');
60+
$bundleType = $bundleProduct->getTypeInstance();
61+
/** @var \Magento\Bundle\Model\Product\Type $bundleType */
62+
$searchableData = $bundleType->getSearchableData($bundleProduct);
6263

63-
$result = $this->connectionMock->fetchAll($select);
64-
$this->assertCount(1, $result);
64+
$this->assertCount(1, $searchableData);
65+
$this->assertEquals('Bundle Product Items', $searchableData[0]);
6566
}
6667

6768
/**

dev/tests/integration/testsuite/Magento/Catalog/Model/Indexer/FlatTest.php

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ public function testDeleteCategory()
246246
*
247247
* @magentoConfigFixture current_store catalog/frontend/flat_catalog_category true
248248
* @magentoAppArea frontend
249+
* @magentoDbIsolation disabled
249250
*/
250251
public function testFlatAfterDeleted()
251252
{
@@ -348,19 +349,21 @@ private function instantiateCategoryModel()
348349
*/
349350
private function createSubCategoriesInDefaultCategory()
350351
{
351-
$this->executeWithFlatEnabledInAdminArea(function () {
352-
$category = $this->getLoadedDefaultCategory();
353-
354-
$categoryOne = $this->instantiateCategoryModel();
355-
$categoryOne->setName('Category One')->setPath($category->getPath())->setIsActive(true);
356-
$category->getResource()->save($categoryOne);
357-
self::$categoryOne = $categoryOne->getId();
358-
359-
$categoryTwo = $this->instantiateCategoryModel();
360-
$categoryTwo->setName('Category Two')->setPath($categoryOne->getPath())->setIsActive(true);
361-
$category->getResource()->save($categoryTwo);
362-
self::$categoryTwo = $categoryTwo->getId();
363-
});
352+
$this->executeWithFlatEnabledInAdminArea(
353+
function () {
354+
$category = $this->getLoadedDefaultCategory();
355+
356+
$categoryOne = $this->instantiateCategoryModel();
357+
$categoryOne->setName('Category One')->setPath($category->getPath())->setIsActive(true);
358+
$category->getResource()->save($categoryOne);
359+
self::$categoryOne = $categoryOne->getId();
360+
361+
$categoryTwo = $this->instantiateCategoryModel();
362+
$categoryTwo->setName('Category Two')->setPath($categoryOne->getPath())->setIsActive(true);
363+
$category->getResource()->save($categoryTwo);
364+
self::$categoryTwo = $categoryTwo->getId();
365+
}
366+
);
364367
}
365368

366369
/**
@@ -371,11 +374,13 @@ private function createSubCategoriesInDefaultCategory()
371374
*/
372375
private function moveSubCategoriesInDefaultCategory()
373376
{
374-
$this->executeWithFlatEnabledInAdminArea(function () {
375-
$this->createSubCategoriesInDefaultCategory();
376-
$categoryTwo = $this->getLoadedCategory(self::$categoryTwo);
377-
$categoryTwo->move(self::$defaultCategoryId, self::$categoryOne);
378-
});
377+
$this->executeWithFlatEnabledInAdminArea(
378+
function () {
379+
$this->createSubCategoriesInDefaultCategory();
380+
$categoryTwo = $this->getLoadedCategory(self::$categoryTwo);
381+
$categoryTwo->move(self::$defaultCategoryId, self::$categoryOne);
382+
}
383+
);
379384
}
380385

381386
/**
@@ -386,10 +391,12 @@ private function moveSubCategoriesInDefaultCategory()
386391
*/
387392
private function deleteSubCategoriesInDefaultCategory()
388393
{
389-
$this->executeWithFlatEnabledInAdminArea(function () {
390-
$this->createSubCategoriesInDefaultCategory();
391-
$this->removeSubCategoriesInDefaultCategory();
392-
});
394+
$this->executeWithFlatEnabledInAdminArea(
395+
function () {
396+
$this->createSubCategoriesInDefaultCategory();
397+
$this->removeSubCategoriesInDefaultCategory();
398+
}
399+
);
393400
}
394401

395402
/**
@@ -398,13 +405,15 @@ private function deleteSubCategoriesInDefaultCategory()
398405
*/
399406
private function removeSubCategoriesInDefaultCategory()
400407
{
401-
$this->executeWithFlatEnabledInAdminArea(function () {
402-
$category = $this->instantiateCategoryModel();
403-
$category->load(self::$categoryTwo);
404-
$category->delete();
405-
$category->load(self::$categoryOne);
406-
$category->delete();
407-
});
408+
$this->executeWithFlatEnabledInAdminArea(
409+
function () {
410+
$category = $this->instantiateCategoryModel();
411+
$category->load(self::$categoryTwo);
412+
$category->delete();
413+
$category->load(self::$categoryOne);
414+
$category->delete();
415+
}
416+
);
408417
}
409418

410419
/**
@@ -468,12 +477,4 @@ private function getActiveConfigInstance()
468477
\Magento\Framework\App\Config\MutableScopeConfigInterface::class
469478
);
470479
}
471-
472-
/**
473-
* teardown
474-
*/
475-
public function tearDown()
476-
{
477-
parent::tearDown();
478-
}
479480
}

0 commit comments

Comments
 (0)