Skip to content

Commit c15c7c7

Browse files
committed
MC-37954: PLP sort by name is case-sensitive with ElasticSearch
1 parent 3aa86ee commit c15c7c7

File tree

3 files changed

+200
-0
lines changed

3 files changed

+200
-0
lines changed

dev/tests/integration/testsuite/Magento/Elasticsearch/Model/Indexer/ReindexAllTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,45 @@ public function testSort()
130130
$this->assertEquals($productSimpleId, $firstInSearchResults);
131131
}
132132

133+
/**
134+
* Test sorting of products with lower and upper case names after full reindex
135+
*
136+
* @magentoDbIsolation enabled
137+
* @magentoConfigFixture current_store catalog/search/elasticsearch_index_prefix indexerhandlertest
138+
* @magentoDataFixture Magento/Elasticsearch/_files/case_sensitive.php
139+
*/
140+
public function testSortCaseSensitive(): void
141+
{
142+
$productFirst = $this->productRepository->get('fulltext-1');
143+
$productSecond = $this->productRepository->get('fulltext-2');
144+
$productThird = $this->productRepository->get('fulltext-3');
145+
$productFourth = $this->productRepository->get('fulltext-4');
146+
$productFifth = $this->productRepository->get('fulltext-5');
147+
$correctSortedIds = [
148+
$productFirst->getId(),
149+
$productFourth->getId(),
150+
$productSecond->getId(),
151+
$productFifth->getId(),
152+
$productThird->getId(),
153+
];
154+
$this->reindexAll();
155+
$result = $this->sortByName();
156+
$firstInSearchResults = (int) $result[0]['_id'];
157+
$secondInSearchResults = (int) $result[1]['_id'];
158+
$thirdInSearchResults = (int) $result[2]['_id'];
159+
$fourthInSearchResults = (int) $result[3]['_id'];
160+
$fifthInSearchResults = (int) $result[4]['_id'];
161+
$actualSortedIds = [
162+
$firstInSearchResults,
163+
$secondInSearchResults,
164+
$thirdInSearchResults,
165+
$fourthInSearchResults,
166+
$fifthInSearchResults
167+
];
168+
$this->assertCount(5, $result);
169+
$this->assertEquals($correctSortedIds, $actualSortedIds);
170+
}
171+
133172
/**
134173
* Test search of specific product after full reindex
135174
*
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Catalog\Api\ProductRepositoryInterface;
8+
use Magento\Catalog\Model\Product;
9+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
10+
use Magento\Catalog\Model\Product\Visibility;
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
14+
15+
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_boolean_attribute.php');
16+
17+
/** @var $objectManager \Magento\Framework\ObjectManagerInterface */
18+
$objectManager = Bootstrap::getObjectManager();
19+
20+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
21+
try {
22+
$productRepository->get('fulltext-1');
23+
} catch (NoSuchEntityException $e) {
24+
/** @var $productFirst Product */
25+
$productFirst = $objectManager->create(Product::class);
26+
$productFirst->setTypeId('simple')
27+
->setAttributeSetId(4)
28+
->setWebsiteIds([1])
29+
->setName('A')
30+
->setSku('fulltext-1')
31+
->setPrice(10)
32+
->setMetaTitle('first meta title')
33+
->setMetaKeyword('first meta keyword')
34+
->setMetaDescription('first meta description')
35+
->setVisibility(Visibility::VISIBILITY_BOTH)
36+
->setStatus(Status::STATUS_ENABLED)
37+
->setStockData(['use_config_manage_stock' => 0])
38+
->setBooleanAttribute(1)
39+
->save();
40+
}
41+
42+
try {
43+
$productRepository->get('fulltext-2');
44+
} catch (NoSuchEntityException $e) {
45+
/** @var $productSecond Product */
46+
$productSecond = $objectManager->create(Product::class);
47+
$productSecond->setTypeId('simple')
48+
->setAttributeSetId(4)
49+
->setWebsiteIds([1])
50+
->setName('B')
51+
->setSku('fulltext-2')
52+
->setPrice(20)
53+
->setMetaTitle('second meta title')
54+
->setMetaKeyword('second meta keyword')
55+
->setMetaDescription('second meta description')
56+
->setVisibility(Visibility::VISIBILITY_BOTH)
57+
->setStatus(Status::STATUS_ENABLED)
58+
->setStockData(['use_config_manage_stock' => 0])
59+
->setBooleanAttribute(1)
60+
->save();
61+
}
62+
63+
try {
64+
$productRepository->get('fulltext-3');
65+
} catch (NoSuchEntityException $e) {
66+
/** @var $productThird Product */
67+
$productThird = $objectManager->create(Product::class);
68+
$productThird->setTypeId('simple')
69+
->setAttributeSetId(4)
70+
->setWebsiteIds([1])
71+
->setName('C')
72+
->setSku('fulltext-3')
73+
->setPrice(20)
74+
->setMetaTitle('third meta title')
75+
->setMetaKeyword('third meta keyword')
76+
->setMetaDescription('third meta description')
77+
->setVisibility(Visibility::VISIBILITY_BOTH)
78+
->setStatus(Status::STATUS_ENABLED)
79+
->setStockData(['use_config_manage_stock' => 0])
80+
->setBooleanAttribute(1)
81+
->save();
82+
}
83+
84+
try {
85+
$productRepository->get('fulltext-4');
86+
} catch (NoSuchEntityException $e) {
87+
/** @var $productFourth Product */
88+
$productFourth = $objectManager->create(Product::class);
89+
$productFourth->setTypeId('simple')
90+
->setAttributeSetId(4)
91+
->setWebsiteIds([1])
92+
->setName('a')
93+
->setSku('fulltext-4')
94+
->setPrice(20)
95+
->setMetaTitle('fourth meta title')
96+
->setMetaKeyword('fourth meta keyword')
97+
->setMetaDescription('fourth meta description')
98+
->setUrlKey('aa')
99+
->setVisibility(Visibility::VISIBILITY_BOTH)
100+
->setStatus(Status::STATUS_ENABLED)
101+
->setStockData(['use_config_manage_stock' => 0])
102+
->setBooleanAttribute(0)
103+
->save();
104+
}
105+
106+
try {
107+
$productRepository->get('fulltext-5');
108+
} catch (NoSuchEntityException $e) {
109+
/** @var $productFifth Product */
110+
$productFifth = $objectManager->create(Product::class);
111+
$productFifth->setTypeId('simple')
112+
->setAttributeSetId(4)
113+
->setWebsiteIds([1])
114+
->setName('b')
115+
->setSku('fulltext-5')
116+
->setPrice(20)
117+
->setMetaTitle('fifth meta title')
118+
->setMetaKeyword('fifth meta keyword')
119+
->setMetaDescription('fifth meta description')
120+
->setUrlKey('bb')
121+
->setVisibility(Visibility::VISIBILITY_BOTH)
122+
->setStatus(Status::STATUS_ENABLED)
123+
->setStockData(['use_config_manage_stock' => 0])
124+
->setBooleanAttribute(0)
125+
->save();
126+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
8+
9+
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_boolean_attribute_rollback.php');
10+
11+
/** @var $objectManager \Magento\Framework\ObjectManagerInterface */
12+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
13+
14+
/** @var \Magento\Framework\Registry $registry */
15+
$registry = $objectManager->get(\Magento\Framework\Registry::class);
16+
$registry->unregister('isSecureArea');
17+
$registry->register('isSecureArea', true);
18+
19+
/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection */
20+
$collection = $objectManager->create(\Magento\Catalog\Model\ResourceModel\Product\Collection::class);
21+
$collection->addAttributeToSelect('id')->load();
22+
if ($collection->count() > 0) {
23+
$collection->delete();
24+
}
25+
26+
/** @var \Magento\Store\Model\Store $store */
27+
$store = $objectManager->create(\Magento\Store\Model\Store::class);
28+
$storeCode = 'secondary';
29+
$store->load($storeCode);
30+
if ($store->getId()) {
31+
$store->delete();
32+
}
33+
34+
$registry->unregister('isSecureArea');
35+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)