Skip to content

Commit 3420575

Browse files
committed
MC-37477: Advanced Search on Elasticsearch returns Configurable Product Children as Individual Search Results
1 parent d4f121e commit 3420575

File tree

1 file changed

+47
-12
lines changed
  • dev/tests/integration/testsuite/Magento/Elasticsearch/Model/CatalogSearch

1 file changed

+47
-12
lines changed

dev/tests/integration/testsuite/Magento/Elasticsearch/Model/CatalogSearch/AdvancedTest.php

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77

88
namespace Magento\Elasticsearch\Model\CatalogSearch;
99

10+
use Magento\Catalog\Api\ProductRepositoryInterface;
1011
use Magento\CatalogSearch\Model\Advanced;
1112
use Magento\Catalog\Model\Product\Visibility;
1213
use Magento\Catalog\Api\Data\ProductInterface;
14+
use Magento\Framework\ObjectManagerInterface;
15+
use Magento\Framework\Registry;
1316
use Magento\TestFramework\Helper\Bootstrap;
1417
use PHPUnit\Framework\TestCase;
1518

@@ -18,15 +21,25 @@
1821
*/
1922
class AdvancedTest extends TestCase
2023
{
24+
/**
25+
* @var ObjectManagerInterface
26+
*/
27+
private $objectManager;
28+
29+
/**
30+
* @var Registry
31+
*/
32+
private $registry;
33+
2134
/**
2235
* @var Visibility
2336
*/
2437
private $productVisibility;
2538

2639
/**
27-
* @var Advanced
40+
* @var ProductRepositoryInterface
2841
*/
29-
private $advancedSearch;
42+
private $productRepository;
3043

3144
/**
3245
* @inheritDoc
@@ -35,9 +48,10 @@ protected function setUp(): void
3548
{
3649
parent::setUp();
3750

38-
$objectManager = Bootstrap::getObjectManager();
39-
$this->productVisibility = $objectManager->get(Visibility::class);
40-
$this->advancedSearch = $objectManager->get(Advanced::class);
51+
$this->objectManager = Bootstrap::getObjectManager();
52+
$this->registry = $this->objectManager->get(Registry::class);
53+
$this->productVisibility = $this->objectManager->get(Visibility::class);
54+
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
4155
}
4256

4357
/**
@@ -50,17 +64,38 @@ protected function setUp(): void
5064
*/
5165
public function testAddFilters(): void
5266
{
53-
$searchName = 'Configurable';
67+
$this->assertResultsAfterRequest(1);
68+
69+
/** @var ProductInterface $configurableProductOption */
70+
$configurableProductOption = $this->productRepository->get('Simple option 1');
71+
$configurableProductOption->setVisibility(Visibility::VISIBILITY_IN_SEARCH);
72+
$this->productRepository->save($configurableProductOption);
73+
74+
$this->registry->unregister('advanced_search_conditions');
75+
$this->assertResultsAfterRequest(2);
76+
}
77+
78+
/**
79+
* Do Elasticsearch query and assert results.
80+
*
81+
* @param int $count
82+
* @return void
83+
*/
84+
private function assertResultsAfterRequest(int $count): void
85+
{
86+
/** @var Advanced $advancedSearch */
87+
$advancedSearch = $this->objectManager->create(Advanced::class);
88+
$advancedSearch->addFilters(['name' => 'Configurable']);
5489

55-
$this->advancedSearch->addFilters(['name' => $searchName]);
5690
/** @var ProductInterface[] $itemsResult */
57-
$itemsResult = $this->advancedSearch->getProductCollection()
91+
$itemsResult = $advancedSearch->getProductCollection()
5892
->addAttributeToSelect(ProductInterface::VISIBILITY)
5993
->getItems();
60-
$this->assertCount(1, $itemsResult);
6194

62-
$product = array_shift($itemsResult);
63-
$this->assertStringContainsString($searchName, $product->getName());
64-
$this->assertContains((int)$product->getVisibility(), $this->productVisibility->getVisibleInSearchIds());
95+
$this->assertCount($count, $itemsResult);
96+
foreach ($itemsResult as $product) {
97+
$this->assertStringContainsString('Configurable', $product->getName());
98+
$this->assertContains((int)$product->getVisibility(), $this->productVisibility->getVisibleInSearchIds());
99+
}
65100
}
66101
}

0 commit comments

Comments
 (0)