82 $this->productRepository = $this->createMock(\
Magento\Catalog\Model\ProductRepository::class);
83 $this->context = $this->createMock(\
Magento\Framework\
App\Action\Context::class);
84 $this->request = $this->createMock(\
Magento\Framework\
App\Request\Http::class);
85 $this->wishlistProvider = $this->createMock(\
Magento\
Wishlist\Controller\WishlistProvider::class);
86 $this->om = $this->createMock(\
Magento\Framework\
App\ObjectManager::class);
87 $this->messageManager = $this->createMock(\
Magento\Framework\Message\Manager::class);
88 $this->url = $this->createMock(\
Magento\Framework\Url::class);
89 $this->customerSession = $this->createMock(\
Magento\Customer\Model\Session::class);
90 $this->eventManager = $this->createMock(\
Magento\Framework\
Event\Manager::class);
91 $this->resultFactoryMock = $this->getMockBuilder(\
Magento\Framework\Controller\ResultFactory::class)
92 ->disableOriginalConstructor()
94 $this->resultRedirectMock = $this->getMockBuilder(\
Magento\Framework\Controller\Result\Redirect::class)
95 ->disableOriginalConstructor()
98 $this->resultFactoryMock->expects($this->any())
101 ->willReturn($this->resultRedirectMock);
103 $this->formKeyValidator = $this->getMockBuilder(\
Magento\Framework\
Data\Form\FormKey\Validator::class)
104 ->disableOriginalConstructor()
116 $this->productRepository,
119 $this->wishlistProvider,
121 $this->messageManager,
134 $actionFlag = $this->createMock(\
Magento\Framework\
App\ActionFlag::class);
137 ->expects($this->any())
138 ->method(
'getObjectManager')
139 ->willReturn($this->om);
141 ->expects($this->any())
142 ->method(
'getRequest')
143 ->willReturn($this->request);
145 ->expects($this->any())
146 ->method(
'getEventManager')
147 ->willReturn($this->eventManager);
149 ->expects($this->any())
151 ->willReturn($this->url);
153 ->expects($this->any())
154 ->method(
'getActionFlag')
155 ->willReturn($actionFlag);
157 ->expects($this->any())
158 ->method(
'getMessageManager')
159 ->willReturn($this->messageManager);
160 $this->context->expects($this->any())
161 ->method(
'getResultFactory')
162 ->willReturn($this->resultFactoryMock);
174 $this->formKeyValidator->expects($this->once())
176 ->with($this->request)
179 return new \Magento\Wishlist\Controller\Index\UpdateItemOptions(
181 $this->customerSession,
182 $this->wishlistProvider,
183 $this->productRepository,
184 $this->formKeyValidator
192 $this->formKeyValidator->expects($this->once())
194 ->with($this->request)
197 $this->resultRedirectMock->expects($this->once())
202 $controller = new \Magento\Wishlist\Controller\Index\Remove(
204 $this->wishlistProvider,
205 $this->formKeyValidator
208 $this->assertSame($this->resultRedirectMock,
$controller->execute());
219 ->expects($this->once())
223 $this->resultRedirectMock->expects($this->once())
228 $this->assertSame($this->resultRedirectMock, $this->
getController()->execute());
239 ->expects($this->once())
244 $this->productRepository
245 ->expects($this->once())
248 ->willThrowException(
new \
Magento\Framework\Exception\NoSuchEntityException());
250 $this->messageManager
251 ->expects($this->once())
253 ->with(
'We can\'t specify a product.')
255 $this->resultRedirectMock->expects($this->once())
260 $this->assertSame($this->resultRedirectMock, $this->
getController()->execute());
274 ->expects($this->once())
275 ->method(
'isVisibleInCatalog')
279 ->expects($this->at(0))
281 ->with(
'product',
null)
284 ->expects($this->at(1))
289 $this->productRepository
290 ->expects($this->once())
295 $this->messageManager
296 ->expects($this->never())
298 ->with(
'We can\'t specify a product.')
302 ->expects($this->once())
307 ->expects($this->once())
309 ->with(
'getWishlistId')
312 $this->wishlistProvider
313 ->expects($this->once())
314 ->method(
'getWishlist')
319 ->expects($this->once())
323 $this->resultRedirectMock->expects($this->once())
328 $this->assertSame($this->resultRedirectMock, $this->
getController()->execute());
345 ->expects($this->exactly(2))
346 ->method(
'calculate')
350 ->expects($this->once())
355 ->expects($this->once())
356 ->method(
'updateItem')
360 ->expects($this->once())
364 ->expects($this->once())
369 ->expects($this->once())
370 ->method(
'isVisibleInCatalog')
373 ->expects($this->once())
375 ->willReturn(
'Test name');
378 ->expects($this->at(0))
380 ->with(
'product',
null)
383 ->expects($this->at(1))
388 $this->productRepository
389 ->expects($this->once())
395 ->expects($this->once())
400 ->expects($this->once())
402 ->with(
'getWishlistId')
405 $this->wishlistProvider
406 ->expects($this->once())
407 ->method(
'getWishlist')
412 ->expects($this->once())
418 ->expects($this->once())
419 ->method(
'getParams')
423 ->expects($this->exactly(2))
429 ->expects($this->once())
434 $this->messageManager
435 ->expects($this->once())
436 ->method(
'addSuccess')
437 ->with(
'Test name has been updated in your Wish List.',
null)
439 $this->messageManager
440 ->expects($this->once())
442 ->with(
'error-message',
null)
444 $this->resultRedirectMock->expects($this->once())
446 ->with(
'*/*', [
'wishlist_id' => 56])
449 $this->assertSame($this->resultRedirectMock, $this->
getController()->execute());
464 $logger = $this->createMock(\
Magento\Framework\Logger\Monolog::class);
465 $exception = new \Exception();
468 ->expects($this->once())
474 ->expects($this->exactly(2))
475 ->method(
'calculate')
479 ->expects($this->once())
484 ->expects($this->once())
485 ->method(
'updateItem')
489 ->expects($this->once())
493 ->expects($this->once())
498 ->expects($this->once())
499 ->method(
'isVisibleInCatalog')
502 ->expects($this->once())
504 ->willReturn(
'Test name');
507 ->expects($this->at(0))
509 ->with(
'product',
null)
512 ->expects($this->at(1))
517 $this->productRepository
518 ->expects($this->once())
524 ->expects($this->once())
529 ->expects($this->once())
531 ->with(
'getWishlistId')
534 $this->wishlistProvider
535 ->expects($this->once())
536 ->method(
'getWishlist')
541 ->expects($this->once())
547 ->expects($this->once())
548 ->method(
'getParams')
552 ->expects($this->at(1))
557 ->expects($this->at(2))
562 ->expects($this->at(3))
564 ->with(\Psr\
Log\LoggerInterface::class)
568 ->expects($this->once())
573 $this->messageManager
574 ->expects($this->once())
575 ->method(
'addSuccess')
576 ->with(
'Test name has been updated in your Wish List.',
null)
577 ->willThrowException($exception);
578 $this->messageManager
579 ->expects($this->once())
581 ->with(
'We can\'t update your Wish List right now.',
null)
583 $this->resultRedirectMock->expects($this->once())
585 ->with(
'*/*', [
'wishlist_id' => 56])
588 $this->assertSame($this->resultRedirectMock, $this->
getController()->execute());
testExecuteAddSuccessException()
testExecuteWithoutProduct()
testExecuteWithoutWishList()
testExecuteWithoutProductId()
testExecuteAddSuccessCriticalException()
testExecuteWithInvalidFormKey()