8 use \Magento\Framework\Mview\View;
10 class ViewTest extends \PHPUnit\Framework\TestCase
44 $this->configMock = $this->getMockForAbstractClass(
45 \
Magento\Framework\Mview\ConfigInterface::class,
53 $this->actionFactoryMock = $this->createPartialMock(\
Magento\Framework\Mview\ActionFactory::class, [
'get']);
54 $this->stateMock = $this->createPartialMock(\
Magento\Indexer\Model\Mview\
View\State::class, [
'getViewId',
66 $this->changelogMock = $this->createPartialMock(
68 [
'getViewId',
'setViewId',
'create',
'drop',
'getVersion',
'getList',
'clear']
70 $this->subscriptionFactoryMock = $this->createPartialMock(
71 \
Magento\Framework\Mview\
View\SubscriptionFactory::class,
74 $this->model =
new View(
76 $this->actionFactoryMock,
79 $this->subscriptionFactoryMock
85 $this->model->setData(
'action_class',
'actionClass');
86 $this->assertEquals(
'actionClass', $this->model->getActionClass());
91 $this->model->setData(
'group',
'some_group');
92 $this->assertEquals(
'some_group', $this->model->getGroup());
97 $this->model->setData(
'subscriptions', [
'subscription']);
98 $this->assertEquals([
'subscription'], $this->model->getSubscriptions());
103 $viewId =
'view_test';
104 $this->configMock->expects(
113 $this->assertInstanceOf(\
Magento\Framework\Mview\View::class, $this->model->load($viewId));
123 $this->configMock->expects(
132 $this->model->load($viewId);
137 $this->stateMock->expects($this->once())
140 $this->stateMock->expects($this->once())
143 ->will($this->returnSelf());
144 $this->changelogMock->expects($this->once())
146 $subscriptionMock = $this->createPartialMock(\
Magento\Framework\Mview\
View\Subscription::class, [
'create']);
147 $subscriptionMock->expects($this->exactly(1))->method(
'create');
148 $this->subscriptionFactoryMock->expects(
153 $this->returnValue($subscriptionMock)
156 $this->model->subscribe();
161 $this->stateMock->expects($this->once())
164 $this->stateMock->expects($this->never())
166 $this->changelogMock->expects($this->never())
168 $this->subscriptionFactoryMock->expects($this->never())
171 $this->model->subscribe();
179 $this->stateMock->expects($this->once())
183 $this->changelogMock->expects($this->once())
185 ->will($this->returnCallback(
187 throw new \Exception();
192 $this->model->subscribe();
197 $this->stateMock->expects($this->once())
200 $this->stateMock->expects($this->once())
203 ->will($this->returnSelf());
204 $this->changelogMock->expects($this->never())
206 $subscriptionMock = $this->createPartialMock(\
Magento\Framework\Mview\
View\Subscription::class, [
'remove']);
207 $subscriptionMock->expects($this->exactly(1))->method(
'remove');
208 $this->subscriptionFactoryMock->expects(
213 $this->returnValue($subscriptionMock)
216 $this->model->unsubscribe();
221 $this->stateMock->expects($this->once())
224 $this->stateMock->expects($this->never())
225 ->method(
'setVersionId');
226 $this->stateMock->expects($this->never())
228 $this->changelogMock->expects($this->never())
230 $this->subscriptionFactoryMock->expects($this->never())
233 $this->model->unsubscribe();
241 $this->stateMock->expects($this->once())
245 $subscriptionMock = $this->createPartialMock(\
Magento\Framework\Mview\
View\Subscription::class, [
'remove']);
246 $subscriptionMock->expects($this->exactly(1))
248 ->will($this->returnCallback(
250 throw new \Exception();
253 $this->subscriptionFactoryMock->expects($this->exactly(1))
255 ->will($this->returnValue($subscriptionMock));
258 $this->model->unsubscribe();
263 $currentVersionId = 3;
267 $this->stateMock->expects($this->any())
268 ->method(
'getViewId')
269 ->will($this->returnValue(1));
270 $this->stateMock->expects($this->once())
271 ->method(
'getVersionId')
272 ->will($this->returnValue($lastVersionId));
273 $this->stateMock->expects($this->once())
274 ->method(
'setVersionId')
275 ->will($this->returnSelf());
276 $this->stateMock->expects($this->exactly(2))
277 ->method(
'getStatus')
279 $this->stateMock->expects($this->exactly(2))
280 ->method(
'setStatus')
281 ->will($this->returnSelf());
282 $this->stateMock->expects($this->exactly(2))
284 ->will($this->returnSelf());
286 $this->changelogMock->expects(
291 $this->returnValue($currentVersionId)
293 $this->changelogMock->expects(
301 $this->returnValue($listId)
304 $actionMock = $this->createMock(\
Magento\Framework\Mview\ActionInterface::class);
305 $actionMock->expects($this->once())->method(
'execute')->with($listId)->will($this->returnSelf());
306 $this->actionFactoryMock->expects(
313 $this->returnValue($actionMock)
317 $this->model->update();
326 $currentVersionId = 3;
330 $this->stateMock->expects($this->any())
331 ->method(
'getViewId')
332 ->will($this->returnValue(1));
333 $this->stateMock->expects($this->once())
334 ->method(
'getVersionId')
335 ->will($this->returnValue($lastVersionId));
336 $this->stateMock->expects($this->never())
337 ->method(
'setVersionId');
338 $this->stateMock->expects($this->exactly(2))
339 ->method(
'getStatus')
341 $this->stateMock->expects($this->exactly(2))
342 ->method(
'setStatus')
343 ->will($this->returnSelf());
344 $this->stateMock->expects($this->exactly(2))
346 ->will($this->returnSelf());
348 $this->changelogMock->expects(
353 $this->returnValue($currentVersionId)
355 $this->changelogMock->expects(
363 $this->returnValue($listId)
366 $actionMock = $this->createPartialMock(\
Magento\Framework\Mview\ActionInterface::class, [
'execute']);
367 $actionMock->expects($this->once())->method(
'execute')->with($listId)->will(
368 $this->returnCallback(
370 throw new \Exception(
'Test exception');
374 $this->actionFactoryMock->expects(
381 $this->returnValue($actionMock)
385 $this->model->update();
390 $this->stateMock->expects($this->once())
393 $this->stateMock->expects($this->once())
394 ->method(
'setVersionId')
396 ->will($this->returnSelf());
397 $this->stateMock->expects($this->once())
398 ->method(
'setStatus')
400 ->will($this->returnSelf());
401 $this->stateMock->expects($this->once())
403 ->will($this->returnSelf());
405 $this->changelogMock->expects($this->once())
406 ->method(
'getVersion')
407 ->will($this->returnValue(11));
410 $this->model->suspend();
415 $this->stateMock->expects($this->once())
418 $this->stateMock->expects($this->never())
419 ->method(
'setVersionId');
420 $this->stateMock->expects($this->never())
421 ->method(
'setStatus');
422 $this->stateMock->expects($this->never())
425 $this->changelogMock->expects($this->never())
426 ->method(
'getVersion');
429 $this->model->suspend();
434 $this->stateMock->expects($this->once())
435 ->method(
'getStatus')
437 $this->stateMock->expects($this->once())
438 ->method(
'setStatus')
440 ->will($this->returnSelf());
441 $this->stateMock->expects($this->once())
443 ->will($this->returnSelf());
446 $this->model->resume();
455 $this->stateMock->expects($this->once())
456 ->method(
'getStatus')
457 ->will($this->returnValue(
$status));
458 $this->stateMock->expects($this->never())
459 ->method(
'setStatus');
460 $this->stateMock->expects($this->never())
464 $this->model->resume();
473 [\Magento\Framework\Mview\View\StateInterface::STATUS_IDLE],
474 [\Magento\Framework\Mview\View\StateInterface::STATUS_WORKING],
480 $this->stateMock->expects($this->once())
483 $this->stateMock->expects($this->once())
484 ->method(
'getVersionId')
485 ->will($this->returnValue(11));
486 $this->changelogMock->expects($this->once())
489 ->will($this->returnValue(
true));
491 $this->model->clearChangelog();
496 $this->stateMock->expects($this->once())
499 $this->stateMock->expects($this->never())
500 ->method(
'getVersionId');
501 $this->changelogMock->expects($this->never())
504 $this->model->clearChangelog();
509 $this->model->setState($this->stateMock);
510 $this->assertEquals($this->stateMock, $this->model->getState());
520 $this->stateMock->expects($this->once())
522 ->will($this->returnValue(
$mode));
523 $this->assertEquals(
$result, $this->model->isEnabled());
532 [\Magento\Framework\Mview\View\StateInterface::MODE_ENABLED,
true],
533 [\Magento\Framework\Mview\View\StateInterface::MODE_DISABLED,
false],
544 $this->stateMock->expects($this->once())
545 ->method(
'getStatus')
546 ->will($this->returnValue(
$status));
547 $this->assertEquals(
$result, $this->model->isIdle());
556 [\Magento\Framework\Mview\View\StateInterface::STATUS_IDLE,
true],
557 [\Magento\Framework\Mview\View\StateInterface::STATUS_WORKING,
false],
558 [\Magento\Framework\Mview\View\StateInterface::STATUS_SUSPENDED,
false],
569 $this->stateMock->expects($this->once())
570 ->method(
'getStatus')
571 ->will($this->returnValue(
$status));
572 $this->assertEquals(
$result, $this->model->isWorking());
581 [\Magento\Framework\Mview\View\StateInterface::STATUS_IDLE,
false],
582 [\Magento\Framework\Mview\View\StateInterface::STATUS_WORKING,
true],
583 [\Magento\Framework\Mview\View\StateInterface::STATUS_SUSPENDED,
false],
594 $this->stateMock->expects($this->once())
595 ->method(
'getStatus')
596 ->will($this->returnValue(
$status));
597 $this->assertEquals(
$result, $this->model->isSuspended());
606 [\Magento\Framework\Mview\View\StateInterface::STATUS_IDLE,
false],
607 [\Magento\Framework\Mview\View\StateInterface::STATUS_WORKING,
false],
608 [\Magento\Framework\Mview\View\StateInterface::STATUS_SUSPENDED,
true],
614 $this->stateMock->expects($this->once())
615 ->method(
'getUpdated')
616 ->will($this->returnValue(
'some datetime'));
617 $this->assertEquals(
'some datetime', $this->model->getUpdated());
622 $viewId =
'view_test';
623 $this->configMock->expects(
632 $this->model->load($viewId);
641 'view_id' =>
'view_test',
642 'action_class' =>
'Some\Class\Name',
643 'group' =>
'some_group',
644 'subscriptions' => [
'some_entity' => [
'name' =>
'some_entity',
'column' =>
'entity_id']]
dataProviderIsSuspended()
dataProviderResumeNotSuspended()
testIsWorking($status, $result)
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
testUnsubscribeDisabled()
testUnsubscribeWithException()
testIsIdle($status, $result)
testIsSuspended($status, $result)
testClearChangelogDisabled()
testResumeNotSuspended($status)
testIsEnabled($mode, $result)
testSubscribeWithException()
testUpdateWithException()