Skip to content

Commit 477cead

Browse files
author
Oleksandr Iegorov
committed
MC-42811: Missing Bundled Products on Category Pages
1 parent 0d5567b commit 477cead

File tree

2 files changed

+64
-17
lines changed

2 files changed

+64
-17
lines changed

app/code/Magento/Elasticsearch/Model/Indexer/IndexerHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Catalog\Model\Category;
99
use Magento\CatalogSearch\Model\Indexer\Fulltext;
10+
use Magento\CatalogSearch\Model\Indexer\Fulltext\Processor;
1011
use Magento\Elasticsearch\Model\Adapter\Elasticsearch as ElasticsearchAdapter;
1112
use Magento\Elasticsearch\Model\Adapter\Index\IndexNameResolver;
1213
use Magento\Framework\App\DeploymentConfig;
@@ -17,7 +18,6 @@
1718
use Magento\Framework\Indexer\SaveHandler\IndexerInterface;
1819
use Magento\Framework\Search\Request\Dimension;
1920
use Magento\Framework\Indexer\CacheContext;
20-
use Magento\CatalogSearch\Model\Indexer\Fulltext\Processor;
2121

2222
/**
2323
* Indexer Handler for Elasticsearch engine.

app/code/Magento/Elasticsearch/Test/Unit/Model/Indexer/IndexerHandlerTest.php

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,22 @@
77

88
namespace Magento\Elasticsearch\Test\Unit\Model\Indexer;
99

10+
use Magento\CatalogSearch\Model\Indexer\Fulltext\Processor;
1011
use Magento\AdvancedSearch\Model\Client\ClientInterface;
1112
use Magento\Elasticsearch\Model\Adapter\Elasticsearch;
1213
use Magento\Elasticsearch\Model\Adapter\Index\IndexNameResolver;
1314
use Magento\Elasticsearch\Model\Indexer\IndexerHandler;
1415
use Magento\Framework\App\ScopeInterface;
1516
use Magento\Framework\App\ScopeResolverInterface;
17+
use Magento\Framework\Indexer\IndexerInterface;
1618
use Magento\Framework\Indexer\IndexStructureInterface;
1719
use Magento\Framework\Indexer\SaveHandler\Batch;
1820
use Magento\Framework\Search\Request\Dimension;
1921
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
2022
use PHPUnit\Framework\MockObject\MockObject;
2123
use PHPUnit\Framework\TestCase;
24+
use Magento\Framework\App\DeploymentConfig;
25+
use Magento\Framework\Indexer\CacheContext;
2226

2327
/**
2428
* Test for \Magento\Elasticsearch\Model\Indexer\IndexerHandler
@@ -71,6 +75,26 @@ class IndexerHandlerTest extends TestCase
7175
*/
7276
private $scopeInterface;
7377

78+
/**
79+
* @var Processor|MockObject
80+
*/
81+
private $processor;
82+
83+
/**
84+
* @var IndexerInterface|MockObject
85+
*/
86+
private $indexer;
87+
88+
/**
89+
* @var CacheContext|MockObject
90+
*/
91+
private $cacheContext;
92+
93+
/**
94+
* @var DeploymentConfig|MockObject
95+
*/
96+
private $deploymentConfig;
97+
7498
/**
7599
* Set up test environment.
76100
*
@@ -117,26 +141,42 @@ protected function setUp(): void
117141
false
118142
);
119143

144+
$this->processor = $this->getMockBuilder(Processor::class)
145+
->disableOriginalConstructor()
146+
->getMock();
147+
$this->indexer = $this->getMockBuilder(IndexerInterface::class)
148+
->disableOriginalConstructor()
149+
->getMockForAbstractClass();
150+
$this->processor->expects($this->any())
151+
->method('getIndexer')
152+
->willReturn($this->indexer);
153+
154+
$this->deploymentConfig = $this->getMockBuilder(DeploymentConfig::class)
155+
->disableOriginalConstructor()
156+
->getMock();
157+
158+
$this->cacheContext = $this->getMockBuilder(CacheContext::class)
159+
->disableOriginalConstructor()
160+
->getMock();
161+
120162
$this->scopeInterface = $this->getMockForAbstractClass(
121163
ScopeInterface::class,
122164
[],
123165
'',
124166
false
125167
);
126168

127-
$objectManager = new ObjectManagerHelper($this);
128-
129-
$this->model = $objectManager->getObject(
130-
IndexerHandler::class,
131-
[
132-
'indexStructure' => $this->indexStructure,
133-
'adapter' => $this->adapter,
134-
'indexNameResolver' => $this->indexNameResolver,
135-
'batch' => $this->batch,
136-
'data' => ['indexer_id' => 'catalogsearch_fulltext'],
137-
500,
138-
'scopeResolver' => $this->scopeResolver
139-
]
169+
$this->model = new IndexerHandler(
170+
$this->indexStructure,
171+
$this->adapter,
172+
$this->indexNameResolver,
173+
$this->batch,
174+
$this->scopeResolver,
175+
['indexer_id' => 'catalogsearch_fulltext'],
176+
500,
177+
$this->deploymentConfig,
178+
$this->cacheContext,
179+
$this->processor
140180
);
141181
}
142182

@@ -182,7 +222,8 @@ public function testSaveIndex()
182222
{
183223
$dimensionValue = 3;
184224
$documentId = 123;
185-
$documents = new \ArrayIterator([$documentId]);
225+
$document = ['entity_id' => $documentId, 'category_ids' => [1, 2]];
226+
$documents = new \ArrayIterator([$document]);
186227

187228
$dimension = $this->getMockBuilder(Dimension::class)
188229
->disableOriginalConstructor()
@@ -199,17 +240,23 @@ public function testSaveIndex()
199240
$this->adapter->expects($this->once())
200241
->method('prepareDocsPerStore')
201242
->with([], $dimensionValue)
202-
->willReturn([$documentId]);
243+
->willReturn([$document]);
203244
$this->adapter->expects($this->once())
204245
->method('addDocs')
205-
->with([$documentId]);
246+
->with([$document]);
206247
$this->scopeResolver->expects($this->once())
207248
->method('getScope')
208249
->willReturn($this->scopeInterface);
209250
$this->scopeInterface->expects($this->once())
210251
->method('getId')
211252
->willReturn($dimensionValue);
212253

254+
$this->indexer->expects($this->once())
255+
->method('isScheduled')
256+
->willReturn(true);
257+
$this->cacheContext->expects($this->once())
258+
->method('registerEntities');
259+
213260
$result = $this->model->saveIndex([$dimension], $documents);
214261

215262
$this->assertEquals($this->model, $result);

0 commit comments

Comments
 (0)