42 protected function setUp()
44 $this->configMock = $this->getMockForAbstractClass(
45 \
Magento\Framework\Indexer\ConfigInterface::class,
53 $this->actionFactoryMock = $this->createPartialMock(
54 \
Magento\Framework\Indexer\ActionFactory::class,
57 $this->viewMock = $this->getMockForAbstractClass(
58 \
Magento\Framework\Mview\ViewInterface::class,
64 [
'load',
'isEnabled',
'getUpdated',
'getStatus',
'__wakeup',
'getId',
'suspend',
'resume']
66 $this->stateFactoryMock = $this->createPartialMock(
67 \
Magento\Indexer\Model\Indexer\StateFactory::class,
70 $this->indexFactoryMock = $this->createPartialMock(
71 \
Magento\Indexer\Model\Indexer\CollectionFactory::class,
74 $structureFactory = $this->getMockBuilder(\
Magento\Framework\Indexer\StructureFactory::class)
75 ->disableOriginalConstructor()
76 ->setMethods([
'create'])
80 $this->model = new \Magento\Indexer\Model\Indexer(
82 $this->actionFactoryMock,
85 $this->stateFactoryMock,
86 $this->indexFactoryMock
96 $indexId =
'indexer_id';
97 $this->configMock->expects(
106 $this->model->load($indexId);
111 $indexId =
'indexer_internal_name';
112 $this->viewMock->expects($this->once())->method(
'load')->with(
'view_test')->will($this->returnSelf());
115 $this->assertEquals($this->viewMock, $this->model->getView());
120 $indexId =
'indexer_internal_name';
121 $stateMock = $this->createPartialMock(
122 \
Magento\Indexer\Model\Indexer\State::class,
123 [
'loadByIndexer',
'getId',
'__wakeup']
125 $stateMock->expects($this->once())->method(
'loadByIndexer')->with($indexId)->will($this->returnSelf());
126 $this->stateFactoryMock->expects($this->once())->method(
'create')->will($this->returnValue($stateMock));
130 $this->assertInstanceOf(\
Magento\Indexer\Model\Indexer\State::class, $this->model->getState());
141 $indexId =
'indexer_internal_name';
144 $this->viewMock->expects($this->any())->method(
'getId')->will($this->returnValue(1));
145 $this->viewMock->expects($this->once())->method(
'isEnabled')->will($this->returnValue($getViewIsEnabled));
146 $this->viewMock->expects($this->any())->method(
'getUpdated')->will($this->returnValue($getViewGetUpdated));
148 $stateMock = $this->createPartialMock(
149 \
Magento\Indexer\Model\Indexer\State::class,
150 [
'load',
'getId',
'setIndexerId',
'__wakeup',
'getUpdated']
153 $stateMock->expects($this->any())->method(
'getUpdated')->will($this->returnValue($getStateGetUpdated));
154 $this->stateFactoryMock->expects($this->once())->method(
'create')->will($this->returnValue($stateMock));
156 if ($getViewIsEnabled && $getViewGetUpdated) {
157 if (!$getStateGetUpdated) {
158 $this->assertEquals($getViewGetUpdated, $this->model->getLatestUpdated());
160 if ($getViewGetUpdated == $getStateGetUpdated) {
161 $this->assertEquals($getViewGetUpdated, $this->model->getLatestUpdated());
163 $this->assertEquals($getViewGetUpdated, $this->model->getLatestUpdated());
167 $this->assertEquals($getStateGetUpdated, $this->model->getLatestUpdated());
177 [
false,
'06-Jan-1944',
'06-Jan-1944'],
178 [
false,
'',
'06-Jan-1944'],
179 [
false,
'06-Jan-1944',
''],
181 [
true,
'06-Jan-1944',
'06-Jan-1944'],
182 [
true,
'',
'06-Jan-1944'],
183 [
true,
'06-Jan-1944',
''],
185 [
true,
'06-Jan-1944',
'05-Jan-1944']
191 $indexId =
'indexer_internal_name';
194 $stateMock = $this->createPartialMock(
195 \
Magento\Indexer\Model\Indexer\State::class,
196 [
'load',
'getId',
'setIndexerId',
'__wakeup',
'getStatus',
'setStatus',
'save']
198 $stateMock->expects($this->once())->method(
'load')->with($indexId,
'indexer_id')->will($this->returnSelf());
199 $stateMock->expects($this->never())->method(
'setIndexerId');
200 $stateMock->expects($this->once())->method(
'getId')->will($this->returnValue(1));
201 $stateMock->expects($this->exactly(2))->method(
'setStatus')->will($this->returnSelf());
202 $stateMock->expects($this->once())->method(
'getStatus')->will($this->returnValue(
'idle'));
203 $stateMock->expects($this->exactly(2))->method(
'save')->will($this->returnSelf());
204 $this->stateFactoryMock->expects($this->once())->method(
'create')->will($this->returnValue($stateMock));
206 $this->viewMock->expects($this->once())->method(
'isEnabled')->will($this->returnValue(
true));
207 $this->viewMock->expects($this->once())->method(
'suspend');
208 $this->viewMock->expects($this->once())->method(
'resume');
210 $actionMock = $this->createPartialMock(
211 \
Magento\Framework\Indexer\ActionInterface::class,
212 [
'executeFull',
'executeList',
'executeRow']
214 $this->actionFactoryMock->expects(
221 $this->returnValue($actionMock)
224 $this->model->reindexAll();
233 $indexId =
'indexer_internal_name';
236 $stateMock = $this->createPartialMock(
237 \
Magento\Indexer\Model\Indexer\State::class,
238 [
'load',
'getId',
'setIndexerId',
'__wakeup',
'getStatus',
'setStatus',
'save']
240 $stateMock->expects($this->once())->method(
'load')->with($indexId,
'indexer_id')->will($this->returnSelf());
241 $stateMock->expects($this->never())->method(
'setIndexerId');
242 $stateMock->expects($this->once())->method(
'getId')->will($this->returnValue(1));
243 $stateMock->expects($this->exactly(2))->method(
'setStatus')->will($this->returnSelf());
244 $stateMock->expects($this->once())->method(
'getStatus')->will($this->returnValue(
'idle'));
245 $stateMock->expects($this->exactly(2))->method(
'save')->will($this->returnSelf());
246 $this->stateFactoryMock->expects($this->once())->method(
'create')->will($this->returnValue($stateMock));
248 $this->viewMock->expects($this->once())->method(
'isEnabled')->will($this->returnValue(
false));
249 $this->viewMock->expects($this->never())->method(
'suspend');
250 $this->viewMock->expects($this->once())->method(
'resume');
252 $actionMock = $this->createPartialMock(
253 \
Magento\Framework\Indexer\ActionInterface::class,
254 [
'executeFull',
'executeList',
'executeRow']
256 $actionMock->expects($this->once())->method(
'executeFull')->will(
257 $this->returnCallback(
259 throw new \Exception(
'Test exception');
263 $this->actionFactoryMock->expects(
270 $this->returnValue($actionMock)
273 $this->model->reindexAll();
283 $indexId =
'indexer_internal_name';
286 $stateMock = $this->createPartialMock(
287 \
Magento\Indexer\Model\Indexer\State::class,
288 [
'load',
'getId',
'setIndexerId',
'__wakeup',
'getStatus',
'setStatus',
'save']
290 $stateMock->expects($this->once())->method(
'load')->with($indexId,
'indexer_id')->will($this->returnSelf());
291 $stateMock->expects($this->never())->method(
'setIndexerId');
292 $stateMock->expects($this->once())->method(
'getId')->will($this->returnValue(1));
293 $stateMock->expects($this->exactly(2))->method(
'setStatus')->will($this->returnSelf());
294 $stateMock->expects($this->once())->method(
'getStatus')->will($this->returnValue(
'idle'));
295 $stateMock->expects($this->exactly(2))->method(
'save')->will($this->returnSelf());
296 $this->stateFactoryMock->expects($this->once())->method(
'create')->will($this->returnValue($stateMock));
298 $this->viewMock->expects($this->once())->method(
'isEnabled')->will($this->returnValue(
false));
299 $this->viewMock->expects($this->never())->method(
'suspend');
300 $this->viewMock->expects($this->once())->method(
'resume');
302 $actionMock = $this->createPartialMock(
303 \
Magento\Framework\Indexer\ActionInterface::class,
304 [
'executeFull',
'executeList',
'executeRow']
306 $actionMock->expects($this->once())->method(
'executeFull')->will(
307 $this->returnCallback(
309 throw new \Error(
'Test Engine Error');
313 $this->actionFactoryMock->expects(
320 $this->returnValue($actionMock)
323 $this->model->reindexAll();
332 'indexer_id' =>
'indexer_internal_name',
333 'view_id' =>
'view_test',
334 'action_class' =>
'Some\Class\Name',
335 'title' =>
'Indexer public name',
336 'description' =>
'Indexer public description' 345 $this->configMock->expects(
354 $this->model->load($indexId);
360 $this->model->setTitle(
$result);
361 $this->assertEquals(
$result, $this->model->getTitle());
367 $this->model->setDescription(
$result);
368 $this->assertEquals(
$result, $this->model->getDescription());
373 $stateMock = $this->createPartialMock(
374 \
Magento\Indexer\Model\Indexer\State::class,
375 [
'loadByIndexer',
'getId',
'__wakeup']
378 $this->model->setState($stateMock);
379 $this->assertInstanceOf(\
Magento\Indexer\Model\Indexer\State::class, $this->model->getState());
385 $this->viewMock->expects($this->once())->method(
'load')->will($this->returnSelf());
386 $this->viewMock->expects($this->once())->method(
'isEnabled')->will($this->returnValue(
$result));
387 $this->assertEquals(
$result, $this->model->isScheduled());
397 $stateMock = $this->createPartialMock(\
Magento\Indexer\Model\Indexer\State::class, [
'load',
'save']);
399 $this->stateFactoryMock->expects($this->once())->method(
'create')->will($this->returnValue($stateMock));
400 $this->viewMock->expects($this->once())->method(
'load')->will($this->returnSelf());
401 $this->viewMock->expects($this->once())->method(
$method)->will($this->returnValue(
true));
402 $stateMock->expects($this->once())->method(
'save')->will($this->returnSelf());
403 $this->model->setScheduled($scheduled);
413 [
false,
'unsubscribe']
420 $stateMock = $this->createPartialMock(\
Magento\Indexer\Model\Indexer\State::class, [
'load',
'getStatus']);
422 $this->stateFactoryMock->expects($this->once())->method(
'create')->will($this->returnValue($stateMock));
423 $stateMock->expects($this->once())->method(
'getStatus')->will($this->returnValue(
$status));
424 $this->assertEquals(
$status, $this->model->getStatus());
434 $stateMock = $this->createPartialMock(\
Magento\Indexer\Model\Indexer\State::class, [
'load',
'getStatus']);
436 $this->stateFactoryMock->expects($this->once())->method(
'create')->will($this->returnValue($stateMock));
437 $stateMock->expects($this->once())->method(
'getStatus')->will($this->returnValue(
$status));
438 $this->assertEquals(
true, $this->model->$method());
455 $stateMock = $this->createPartialMock(
456 \
Magento\Indexer\Model\Indexer\State::class,
457 [
'load',
'setStatus',
'save']
460 $this->stateFactoryMock->expects($this->once())->method(
'create')->will($this->returnValue($stateMock));
464 $stateMock->expects($this->once())->method(
'save')->will($this->returnSelf());
465 $this->model->invalidate();
472 $stateMock = $this->createPartialMock(\
Magento\Indexer\Model\Indexer\State::class, [
'load',
'save']);
473 $actionMock = $this->createPartialMock(
474 \
Magento\Framework\Indexer\ActionInterface::class,
475 [
'executeFull',
'executeList',
'executeRow']
478 $this->actionFactoryMock->expects(
483 $this->returnValue($actionMock)
486 $this->stateFactoryMock->expects($this->once())->method(
'create')->will($this->returnValue($stateMock));
487 $stateMock->expects($this->once())->method(
'save')->will($this->returnSelf());
488 $actionMock->expects($this->once())->method(
'executeRow')->with(
$id)->will($this->returnSelf());
489 $this->model->reindexRow(
$id);
496 $stateMock = $this->createPartialMock(\
Magento\Indexer\Model\Indexer\State::class, [
'load',
'save']);
497 $actionMock = $this->createPartialMock(
498 \
Magento\Framework\Indexer\ActionInterface::class,
499 [
'executeFull',
'executeList',
'executeRow']
502 $this->actionFactoryMock->expects(
507 $this->returnValue($actionMock)
510 $this->stateFactoryMock->expects($this->once())->method(
'create')->will($this->returnValue($stateMock));
511 $stateMock->expects($this->once())->method(
'save')->will($this->returnSelf());
512 $actionMock->expects($this->once())->method(
'executeList')->with($ids)->will($this->returnSelf());
513 $this->model->reindexList($ids);
testGetLatestUpdated($getViewIsEnabled, $getViewGetUpdated, $getStateGetUpdated)
testReindexAllWithException()
getLatestUpdatedDataProvider()
testReindexAllWithError()
setScheduledDataProvider()
testSetScheduled($scheduled, $method)
testStatus($method, $status)