/**
  * @dataProvider urlAddresses
  * @param string $baseUrl
  * @param string $successUrl
  */
 public function testSuccessUrl($baseUrl, $successUrl)
 {
     $testStoreMock = $this->getMock('\\Magento\\Store\\Model\\Store', [], [], '', false);
     $testStoreMock->expects($this->any())->method('getBaseUrl')->will($this->returnValue($baseUrl));
     $this->_requestMock->expects($this->any())->method('getParam')->will($this->returnValue(null));
     $this->_storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($testStoreMock));
     $this->assertEquals($baseUrl, $this->_model->success($successUrl));
 }
 /**
  * Test execute add success critical exception
  *
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecuteAddSuccessCriticalException()
 {
     $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false);
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
     $item = $this->getMock('Magento\\Wishlist\\Model\\Item', [], [], '', false);
     $helper = $this->getMock('Magento\\Wishlist\\Helper\\Data', [], [], '', false);
     $logger = $this->getMock('Magento\\Framework\\Logger\\Monolog', [], [], '', false);
     $exception = new \Exception();
     $logger->expects($this->once())->method('critical')->with($exception)->willReturn(true);
     $helper->expects($this->exactly(2))->method('calculate')->willReturn(true);
     $wishlist->expects($this->once())->method('getItem')->with(3)->willReturn($item);
     $wishlist->expects($this->once())->method('updateItem')->with(3, new \Magento\Framework\Object([]))->willReturnSelf();
     $wishlist->expects($this->once())->method('save')->willReturn(null);
     $wishlist->expects($this->once())->method('getId')->willReturn(56);
     $product->expects($this->once())->method('isVisibleInCatalog')->willReturn(true);
     $product->expects($this->once())->method('getName')->willReturn('Test name');
     $this->request->expects($this->at(0))->method('getParam')->with('product', null)->willReturn(2);
     $this->request->expects($this->at(1))->method('getParam')->with('id', null)->willReturn(3);
     $this->productRepository->expects($this->once())->method('getById')->with(2)->willReturn($product);
     $item->expects($this->once())->method('load')->with(3)->willReturnSelf();
     $item->expects($this->once())->method('__call')->with('getWishlistId')->willReturn(12);
     $this->wishlistProvider->expects($this->once())->method('getWishlist')->with(12)->willReturn($wishlist);
     $this->om->expects($this->once())->method('create')->with('Magento\\Wishlist\\Model\\Item')->willReturn($item);
     $this->request->expects($this->once())->method('getParams')->willReturn([]);
     $this->om->expects($this->at(1))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->willReturn($helper);
     $this->om->expects($this->at(2))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->willReturn($helper);
     $this->om->expects($this->at(3))->method('get')->with('Psr\\Log\\LoggerInterface')->willReturn($logger);
     $this->eventManager->expects($this->once())->method('dispatch')->with('wishlist_update_item', ['wishlist' => $wishlist, 'product' => $product, 'item' => $item])->willReturn(true);
     $this->messageManager->expects($this->once())->method('addSuccess')->with('Test name has been updated in your wish list.', null)->willThrowException($exception);
     $this->messageManager->expects($this->once())->method('addError')->with('An error occurred while updating wish list.', null)->willReturn(true);
     $this->redirect->expects($this->once())->method('redirect')->with($this->response, '*/*', ['wishlist_id' => 56])->willReturn(true);
     $this->getController()->execute();
 }
Example #3
0
 public function testExecuteCanNotSaveWishlistAndWithRedirect()
 {
     $referer = 'http://referer-url.com';
     $exception = new \Exception('Message');
     $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false);
     $wishlist->expects($this->once())->method('save')->willThrowException($exception);
     $this->wishlistProvider->expects($this->once())->method('getWishlist')->with(2)->willReturn($wishlist);
     $this->messageManager->expects($this->once())->method('addError')->with('An error occurred while deleting the item from wish list.')->willReturn(true);
     $wishlistHelper = $this->getMock('Magento\\Wishlist\\Helper\\Data', [], [], '', false);
     $wishlistHelper->expects($this->once())->method('calculate')->willReturnSelf();
     $this->om->expects($this->once())->method('get')->with('Magento\\Wishlist\\Helper\\Data')->will($this->returnValue($wishlistHelper));
     $item = $this->getMock('Magento\\Wishlist\\Model\\Item', [], [], '', false);
     $item->expects($this->once())->method('load')->with(1)->willReturnSelf();
     $item->expects($this->once())->method('getId')->willReturn(1);
     $item->expects($this->once())->method('__call')->with('getWishlistId')->willReturn(2);
     $item->expects($this->once())->method('delete')->willReturn(true);
     $this->om->expects($this->once())->method('create')->with('Magento\\Wishlist\\Model\\Item')->willReturn($item);
     $this->request->expects($this->once())->method('getServer')->with('HTTP_REFERER')->willReturn($referer);
     $this->request->expects($this->exactly(3))->method('getParam')->willReturnMap([['item', null, 1], ['referer_url', null, $referer], ['uenc', null, false]]);
     $this->url->expects($this->once())->method('getUrl')->with('*/*')->willReturn('http:/test.com/frontname/module/controller/action');
     $this->redirect->expects($this->once())->method('getRedirectUrl')->willReturn('http:/test.com/frontname/module/controller/action');
     $this->response->expects($this->once())->method('setRedirect')->with('http:/test.com/frontname/module/controller/action')->willReturn(true);
     $this->getController()->execute();
 }