/**
  * @param int $qtyResult
  * @param int|null $expectedResult
  * @dataProvider processDataProvider
  */
 public function testProcess($qtyResult, $expectedResult)
 {
     $qty = 10;
     $localCode = 'en_US';
     $this->resolver->expects($this->once())->method('getLocale')->willReturn($localCode);
     $this->filter->expects($this->once())->method('setOptions')->with(['locale' => $localCode])->willReturnSelf();
     $this->filter->expects($this->once())->method('filter')->with($qty)->willReturn($qtyResult);
     $this->assertEquals($expectedResult, $this->processor->process($qty));
 }
示例#2
0
 /**
  * Add wishlist item to shopping cart and remove from wishlist
  *
  * If Product has required options - item removed from wishlist and redirect
  * to product view page with message about needed defined required options
  *
  * @return ResponseInterface
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function execute()
 {
     $itemId = (int) $this->getRequest()->getParam('item');
     /* @var $item \Magento\Wishlist\Model\Item */
     $item = $this->itemFactory->create()->load($itemId);
     if (!$item->getId()) {
         return $this->_redirect('*/*');
     }
     $wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId());
     if (!$wishlist) {
         return $this->_redirect('*/*');
     }
     // Set qty
     $qty = $this->getRequest()->getParam('qty');
     if (is_array($qty)) {
         if (isset($qty[$itemId])) {
             $qty = $qty[$itemId];
         } else {
             $qty = 1;
         }
     }
     $qty = $this->quantityProcessor->process($qty);
     if ($qty) {
         $item->setQty($qty);
     }
     $redirectUrl = $this->_url->getUrl('*/*');
     $configureUrl = $this->_url->getUrl('*/*/configure/', ['id' => $item->getId(), 'product_id' => $item->getProductId()]);
     try {
         /** @var \Magento\Wishlist\Model\Resource\Item\Option\Collection $options */
         $options = $this->optionFactory->create()->getCollection()->addItemFilter([$itemId]);
         $item->setOptions($options->getOptionsByItem($itemId));
         $buyRequest = $this->productHelper->addParamsToBuyRequest($this->getRequest()->getParams(), ['current_config' => $item->getBuyRequest()]);
         $item->mergeBuyRequest($buyRequest);
         $item->addToCart($this->cart, true);
         $this->cart->save()->getQuote()->collectTotals();
         $wishlist->save();
         if (!$this->cart->getQuote()->getHasError()) {
             $message = __('You added %1 to your shopping cart.', $this->escaper->escapeHtml($item->getProduct()->getName()));
             $this->messageManager->addSuccess($message);
         }
         if ($this->cart->getShouldRedirectToCart()) {
             $redirectUrl = $this->cart->getCartUrl();
         } else {
             $refererUrl = $this->_redirect->getRefererUrl();
             if ($refererUrl && $refererUrl != $configureUrl) {
                 $redirectUrl = $refererUrl;
             }
         }
     } catch (ProductException $e) {
         $this->messageManager->addError(__('This product(s) is out of stock.'));
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->messageManager->addNotice($e->getMessage());
         $redirectUrl = $configureUrl;
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('Cannot add item to shopping cart'));
     }
     $this->helper->calculate();
     return $this->getResponse()->setRedirect($redirectUrl);
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecuteWithoutQuantityArrayAndConfigurable()
 {
     $itemId = 2;
     $wishlistId = 1;
     $qty = [];
     $productId = 4;
     $indexUrl = 'index_url';
     $configureUrl = 'configure_url';
     $options = [5 => 'option'];
     $params = ['item' => $itemId, 'qty' => $qty];
     $this->formKeyValidator->expects($this->once())->method('validate')->with($this->requestMock)->willReturn(true);
     $itemMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item')->disableOriginalConstructor()->setMethods(['load', 'getId', 'getWishlistId', 'setQty', 'setOptions', 'getBuyRequest', 'mergeBuyRequest', 'addToCart', 'getProduct', 'getProductId'])->getMock();
     $this->requestMock->expects($this->at(0))->method('getParam')->with('item', null)->willReturn($itemId);
     $this->itemFactoryMock->expects($this->once())->method('create')->willReturn($itemMock);
     $itemMock->expects($this->once())->method('load')->with($itemId, null)->willReturnSelf();
     $itemMock->expects($this->exactly(2))->method('getId')->willReturn($itemId);
     $itemMock->expects($this->once())->method('getWishlistId')->willReturn($wishlistId);
     $wishlistMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist')->disableOriginalConstructor()->getMock();
     $this->wishlistProviderMock->expects($this->once())->method('getWishlist')->with($wishlistId)->willReturn($wishlistMock);
     $this->requestMock->expects($this->at(1))->method('getParam')->with('qty', null)->willReturn($qty);
     $this->quantityProcessorMock->expects($this->once())->method('process')->with(1)->willReturnArgument(0);
     $itemMock->expects($this->once())->method('setQty')->with(1)->willReturnSelf();
     $this->urlMock->expects($this->at(0))->method('getUrl')->with('*/*', null)->willReturn($indexUrl);
     $itemMock->expects($this->once())->method('getProductId')->willReturn($productId);
     $this->urlMock->expects($this->at(1))->method('getUrl')->with('*/*/configure/', ['id' => $itemId, 'product_id' => $productId])->willReturn($configureUrl);
     $optionMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item\\Option')->disableOriginalConstructor()->getMock();
     $this->optionFactoryMock->expects($this->once())->method('create')->willReturn($optionMock);
     $optionsMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\ResourceModel\\Item\\Option\\Collection')->disableOriginalConstructor()->getMock();
     $optionMock->expects($this->once())->method('getCollection')->willReturn($optionsMock);
     $optionsMock->expects($this->once())->method('addItemFilter')->with([$itemId])->willReturnSelf();
     $optionsMock->expects($this->once())->method('getOptionsByItem')->with($itemId)->willReturn($options);
     $itemMock->expects($this->once())->method('setOptions')->with($options)->willReturnSelf();
     $this->requestMock->expects($this->once())->method('getParams')->willReturn($params);
     $buyRequestMock = $this->getMockBuilder('Magento\\Framework\\DataObject')->disableOriginalConstructor()->getMock();
     $itemMock->expects($this->once())->method('getBuyRequest')->willReturn($buyRequestMock);
     $this->productHelperMock->expects($this->once())->method('addParamsToBuyRequest')->with($params, ['current_config' => $buyRequestMock])->willReturn($buyRequestMock);
     $itemMock->expects($this->once())->method('mergeBuyRequest')->with($buyRequestMock)->willReturnSelf();
     $itemMock->expects($this->once())->method('addToCart')->with($this->checkoutCartMock, true)->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('message')));
     $this->messageManagerMock->expects($this->once())->method('addNotice')->with('message', null)->willReturnSelf();
     $this->helperMock->expects($this->once())->method('calculate')->willReturnSelf();
     $this->resultRedirectMock->expects($this->once())->method('setUrl')->with($configureUrl)->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->model->execute());
 }
示例#4
0
 /**
  * Update wishlist item comments
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  * @throws NotFoundException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
     if (!$this->_formKeyValidator->validate($this->getRequest())) {
         $resultRedirect->setPath('*/*/');
         return $resultRedirect;
     }
     $wishlist = $this->wishlistProvider->getWishlist();
     if (!$wishlist) {
         throw new NotFoundException(__('Page not found.'));
     }
     $post = $this->getRequest()->getPostValue();
     if ($post && isset($post['description']) && is_array($post['description'])) {
         $updatedItems = 0;
         foreach ($post['description'] as $itemId => $description) {
             $item = $this->_objectManager->create('Magento\\Wishlist\\Model\\Item')->load($itemId);
             if ($item->getWishlistId() != $wishlist->getId()) {
                 continue;
             }
             // Extract new values
             $description = (string) $description;
             if ($description == $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->defaultCommentString()) {
                 $description = '';
             } elseif (!strlen($description)) {
                 $description = $item->getDescription();
             }
             $qty = null;
             if (isset($post['qty'][$itemId])) {
                 $qty = $this->quantityProcessor->process($post['qty'][$itemId]);
             }
             if ($qty === null) {
                 $qty = $item->getQty();
                 if (!$qty) {
                     $qty = 1;
                 }
             } elseif (0 == $qty) {
                 try {
                     $item->delete();
                 } catch (\Exception $e) {
                     $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
                     $this->messageManager->addError(__('Can\'t delete item from wishlist'));
                 }
             }
             // Check that we need to save
             if ($item->getDescription() == $description && $item->getQty() == $qty) {
                 continue;
             }
             try {
                 $item->setDescription($description)->setQty($qty)->save();
                 $updatedItems++;
             } catch (\Exception $e) {
                 $this->messageManager->addError(__('Can\'t save description %1', $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($description)));
             }
         }
         // save wishlist model for setting date of last update
         if ($updatedItems) {
             try {
                 $wishlist->save();
                 $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate();
             } catch (\Exception $e) {
                 $this->messageManager->addError(__('Can\'t update wish list'));
             }
         }
         if (isset($post['save_and_share'])) {
             $resultRedirect->setPath('*/*/share', ['wishlist_id' => $wishlist->getId()]);
             return $resultRedirect;
         }
     }
     $resultRedirect->setPath('*', ['wishlist_id' => $wishlist->getId()]);
     return $resultRedirect;
 }
示例#5
0
 /**
  * Move all wishlist item to cart
  *
  * @param Wishlist $wishlist
  * @param array $qtys
  * @return string
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function moveAllToCart(Wishlist $wishlist, $qtys)
 {
     $isOwner = $wishlist->isOwner($this->customerSession->getCustomerId());
     $messages = [];
     $addedItems = [];
     $notSalable = [];
     $hasOptions = [];
     $cart = $this->cart;
     $collection = $wishlist->getItemCollection()->setVisibilityFilter();
     foreach ($collection as $item) {
         /** @var \Magento\Wishlist\Model\Item */
         try {
             $disableAddToCart = $item->getProduct()->getDisableAddToCart();
             $item->unsProduct();
             // Set qty
             if (isset($qtys[$item->getId()])) {
                 $qty = $this->quantityProcessor->process($qtys[$item->getId()]);
                 if ($qty) {
                     $item->setQty($qty);
                 }
             }
             $item->getProduct()->setDisableAddToCart($disableAddToCart);
             // Add to cart
             if ($item->addToCart($cart, $isOwner)) {
                 $addedItems[] = $item->getProduct();
             }
         } catch (\Magento\Framework\Exception\LocalizedException $e) {
             if ($e->getCode() == \Magento\Wishlist\Model\Item::EXCEPTION_CODE_NOT_SALABLE) {
                 $notSalable[] = $item;
             } elseif ($e->getCode() == \Magento\Wishlist\Model\Item::EXCEPTION_CODE_HAS_REQUIRED_OPTIONS) {
                 $hasOptions[] = $item;
             } else {
                 $messages[] = __('%1 for "%2".', trim($e->getMessage(), '.'), $item->getProduct()->getName());
             }
             $cartItem = $cart->getQuote()->getItemByProduct($item->getProduct());
             if ($cartItem) {
                 $cart->getQuote()->deleteItem($cartItem);
             }
         } catch (\Exception $e) {
             $this->logger->critical($e);
             $messages[] = __('We cannot add this item to your shopping cart.');
         }
     }
     if ($isOwner) {
         $indexUrl = $this->helper->getListUrl($wishlist->getId());
     } else {
         $indexUrl = $this->urlBuilder->getUrl('wishlist/shared', ['code' => $wishlist->getSharingCode()]);
     }
     if ($this->cartHelper->getShouldRedirectToCart()) {
         $redirectUrl = $this->cartHelper->getCartUrl();
     } elseif ($this->redirector->getRefererUrl()) {
         $redirectUrl = $this->redirector->getRefererUrl();
     } else {
         $redirectUrl = $indexUrl;
     }
     if ($notSalable) {
         $products = [];
         foreach ($notSalable as $item) {
             $products[] = '"' . $item->getProduct()->getName() . '"';
         }
         $messages[] = __('We couldn\'t add the following product(s) to the shopping cart: %1.', join(', ', $products));
     }
     if ($hasOptions) {
         $products = [];
         foreach ($hasOptions as $item) {
             $products[] = '"' . $item->getProduct()->getName() . '"';
         }
         $messages[] = __('Product(s) %1 have required options. Each product can only be added individually.', join(', ', $products));
     }
     if ($messages) {
         $isMessageSole = count($messages) == 1;
         if ($isMessageSole && count($hasOptions) == 1) {
             $item = $hasOptions[0];
             if ($isOwner) {
                 $item->delete();
             }
             $redirectUrl = $item->getProductUrl();
         } else {
             foreach ($messages as $message) {
                 $this->messageManager->addError($message);
             }
             $redirectUrl = $indexUrl;
         }
     }
     if ($addedItems) {
         // save wishlist model for setting date of last update
         try {
             $wishlist->save();
         } catch (\Exception $e) {
             $this->messageManager->addError(__('We can\'t update wish list.'));
             $redirectUrl = $indexUrl;
         }
         $products = [];
         foreach ($addedItems as $product) {
             $products[] = '"' . $product->getName() . '"';
         }
         $this->messageManager->addSuccess(__('%1 product(s) have been added to shopping cart: %2.', count($addedItems), join(', ', $products)));
         // save cart and collect totals
         $cart->save()->getQuote()->collectTotals();
     }
     $this->helper->calculate();
     return $redirectUrl;
 }
 /**
  * Move all wishlist item to cart
  *
  * @param Wishlist $wishlist
  * @param array $qtys
  * @return string
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function moveAllToCart(Wishlist $wishlist, $qtys)
 {
     $isOwner = $wishlist->isOwner($this->customerSession->getCustomerId());
     $messages = [];
     $addedProducts = [];
     $notSalable = [];
     $cart = $this->cart;
     $collection = $wishlist->getItemCollection()->setVisibilityFilter();
     foreach ($collection as $item) {
         /** @var $item \Magento\Wishlist\Model\Item */
         try {
             $disableAddToCart = $item->getProduct()->getDisableAddToCart();
             $item->unsProduct();
             // Set qty
             if (isset($qtys[$item->getId()])) {
                 $qty = $this->quantityProcessor->process($qtys[$item->getId()]);
                 if ($qty) {
                     $item->setQty($qty);
                 }
             }
             $item->getProduct()->setDisableAddToCart($disableAddToCart);
             // Add to cart
             if ($item->addToCart($cart, $isOwner)) {
                 $addedProducts[] = $item->getProduct();
             }
         } catch (LocalizedException $e) {
             if ($e instanceof ProductException) {
                 $notSalable[] = $item;
             } else {
                 $messages[] = __('%1 for "%2".', trim($e->getMessage(), '.'), $item->getProduct()->getName());
             }
             $cartItem = $cart->getQuote()->getItemByProduct($item->getProduct());
             if ($cartItem) {
                 $cart->getQuote()->deleteItem($cartItem);
             }
         } catch (\Exception $e) {
             $this->logger->critical($e);
             $messages[] = __('We can\'t add this item to your shopping cart right now.');
         }
     }
     if ($isOwner) {
         $indexUrl = $this->helper->getListUrl($wishlist->getId());
     } else {
         $indexUrl = $this->urlBuilder->getUrl('wishlist/shared', ['code' => $wishlist->getSharingCode()]);
     }
     if ($this->cartHelper->getShouldRedirectToCart()) {
         $redirectUrl = $this->cartHelper->getCartUrl();
     } elseif ($this->redirector->getRefererUrl()) {
         $redirectUrl = $this->redirector->getRefererUrl();
     } else {
         $redirectUrl = $indexUrl;
     }
     if ($notSalable) {
         $products = [];
         foreach ($notSalable as $item) {
             $products[] = '"' . $item->getProduct()->getName() . '"';
         }
         $messages[] = __('We couldn\'t add the following product(s) to the shopping cart: %1.', join(', ', $products));
     }
     if ($messages) {
         foreach ($messages as $message) {
             $this->messageManager->addError($message);
         }
         $redirectUrl = $indexUrl;
     }
     if ($addedProducts) {
         // save wishlist model for setting date of last update
         try {
             $wishlist->save();
         } catch (\Exception $e) {
             $this->messageManager->addError(__('We can\'t update the Wish List right now.'));
             $redirectUrl = $indexUrl;
         }
         $products = [];
         foreach ($addedProducts as $product) {
             /** @var $product \Magento\Catalog\Model\Product */
             $products[] = '"' . $product->getName() . '"';
         }
         $this->messageManager->addSuccess(__('%1 product(s) have been added to shopping cart: %2.', count($addedProducts), join(', ', $products)));
         // save cart and collect totals
         $cart->save()->getQuote()->collectTotals();
     }
     $this->helper->calculate();
     return $redirectUrl;
 }
示例#7
0
文件: Cart.php 项目: aiesh/magento2
 /**
  * Add wishlist item to shopping cart and remove from wishlist
  *
  * If Product has required options - item removed from wishlist and redirect
  * to product view page with message about needed defined required options
  *
  * @return ResponseInterface
  */
 public function execute()
 {
     $itemId = (int) $this->getRequest()->getParam('item');
     /* @var $item \Magento\Wishlist\Model\Item */
     $item = $this->_objectManager->create('Magento\\Wishlist\\Model\\Item')->load($itemId);
     if (!$item->getId()) {
         return $this->_redirect('*/*');
     }
     $wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId());
     if (!$wishlist) {
         return $this->_redirect('*/*');
     }
     // Set qty
     $qty = $this->getRequest()->getParam('qty');
     if (is_array($qty)) {
         if (isset($qty[$itemId])) {
             $qty = $qty[$itemId];
         } else {
             $qty = 1;
         }
     }
     $qty = $this->quantityProcessor->process($qty);
     if ($qty) {
         $item->setQty($qty);
     }
     /* @var $session \Magento\Framework\Session\Generic */
     $session = $this->_objectManager->get('Magento\\Wishlist\\Model\\Session');
     $cart = $this->_objectManager->get('Magento\\Checkout\\Model\\Cart');
     $redirectUrl = $this->_url->getUrl('*/*');
     try {
         $options = $this->_objectManager->create('Magento\\Wishlist\\Model\\Item\\Option')->getCollection()->addItemFilter(array($itemId));
         $item->setOptions($options->getOptionsByItem($itemId));
         $buyRequest = $this->_objectManager->get('Magento\\Catalog\\Helper\\Product')->addParamsToBuyRequest($this->getRequest()->getParams(), array('current_config' => $item->getBuyRequest()));
         $item->mergeBuyRequest($buyRequest);
         $item->addToCart($cart, true);
         $cart->save()->getQuote()->collectTotals();
         $wishlist->save();
         if (!$cart->getQuote()->getHasError()) {
             $message = __('You added %1 to your shopping cart.', $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($item->getProduct()->getName()));
             $this->messageManager->addSuccess($message);
         }
         $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate();
         if ($this->_objectManager->get('Magento\\Checkout\\Helper\\Cart')->getShouldRedirectToCart()) {
             $redirectUrl = $this->_objectManager->get('Magento\\Checkout\\Helper\\Cart')->getCartUrl();
         } else {
             $refererUrl = $this->_redirect->getRefererUrl();
             if ($refererUrl && $refererUrl != $this->_objectManager->get('Magento\\Framework\\UrlInterface')->getUrl('*/*/configure/', array('id' => $item->getId()))) {
                 $redirectUrl = $refererUrl;
             }
         }
         $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate();
     } catch (\Magento\Framework\Model\Exception $e) {
         if ($e->getCode() == \Magento\Wishlist\Model\Item::EXCEPTION_CODE_NOT_SALABLE) {
             $this->messageManager->addError(__('This product(s) is out of stock.'));
         } elseif ($e->getCode() == \Magento\Wishlist\Model\Item::EXCEPTION_CODE_HAS_REQUIRED_OPTIONS) {
             $this->messageManager->addNotice($e->getMessage());
             $redirectUrl = $this->_url->getUrl('*/*/configure/', array('id' => $item->getId()));
         } else {
             $this->messageManager->addNotice($e->getMessage());
             $redirectUrl = $this->_url->getUrl('*/*/configure/', array('id' => $item->getId()));
         }
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('Cannot add item to shopping cart'));
     }
     $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate();
     return $this->getResponse()->setRedirect($redirectUrl);
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testMoveAllToCartWithException()
 {
     $wishlistId = 7;
     $sessionCustomerId = 23;
     $itemOneId = 14;
     $itemTwoId = 17;
     $productOneName = 'product one';
     $productTwoName = 'product two';
     $qtys = [14 => 21];
     $isOwner = true;
     $indexUrl = 'index_url';
     /** @var \Magento\Wishlist\Model\Item|\PHPUnit_Framework_MockObject_MockObject $itemOneMock */
     $itemOneMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item')->setMethods(['getProduct', 'unsProduct', 'getId', 'setQty', 'addToCart', 'delete', 'getProductUrl'])->disableOriginalConstructor()->getMock();
     /** @var \Magento\Wishlist\Model\Item|\PHPUnit_Framework_MockObject_MockObject $itemTwoMock */
     $itemTwoMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item')->setMethods(['getProduct', 'unsProduct', 'getId', 'setQty', 'addToCart', 'delete', 'getProductUrl'])->disableOriginalConstructor()->getMock();
     /** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $productOneMock */
     $productOneMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->setMethods(['getDisableAddToCart', 'setDisableAddToCart', 'getName'])->disableOriginalConstructor()->getMock();
     /** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $productTwoMock */
     $productTwoMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->setMethods(['getDisableAddToCart', 'setDisableAddToCart', 'getName'])->disableOriginalConstructor()->getMock();
     $itemOneMock->expects($this->any())->method('getProduct')->willReturn($productOneMock);
     $itemTwoMock->expects($this->any())->method('getProduct')->willReturn($productTwoMock);
     $collection = [$itemOneMock, $itemTwoMock];
     /** @var \Magento\Wishlist\Model\Wishlist|\PHPUnit_Framework_MockObject_MockObject $wishlistMock */
     $wishlistMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist')->disableOriginalConstructor()->getMock();
     $this->sessionMock->expects($this->once())->method('getCustomerId')->willReturn($sessionCustomerId);
     $wishlistMock->expects($this->once())->method('isOwner')->with($sessionCustomerId)->willReturn($isOwner);
     $wishlistMock->expects($this->once())->method('getId')->willReturn($wishlistId);
     /** @var Collection|\PHPUnit_Framework_MockObject_MockObject $collectionMock */
     $collectionMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\ResourceModel\\Item\\Collection')->disableOriginalConstructor()->getMock();
     $wishlistMock->expects($this->once())->method('getItemCollection')->willReturn($collectionMock);
     $collectionMock->expects($this->once())->method('setVisibilityFilter')->with(true)->willReturn($collection);
     $productOneMock->expects($this->once())->method('getDisableAddToCart')->willReturn(true);
     $productOneMock->expects($this->once())->method('setDisableAddToCart')->with(true);
     $productTwoMock->expects($this->once())->method('getDisableAddToCart')->willReturn(false);
     $productTwoMock->expects($this->once())->method('setDisableAddToCart')->with(false);
     $itemOneMock->expects($this->once())->method('unsProduct');
     $itemTwoMock->expects($this->once())->method('unsProduct');
     $itemOneMock->expects($this->exactly(2))->method('getId')->willReturn($itemOneId);
     $itemTwoMock->expects($this->once())->method('getId')->willReturn($itemTwoId);
     $this->quantityProcessorMock->expects($this->once())->method('process')->with($qtys[$itemOneId])->willReturnArgument(0);
     $itemOneMock->expects($this->once())->method('setQty')->with($qtys[$itemOneId])->willReturnSelf();
     $itemTwoMock->expects($this->never())->method('setQty');
     $itemOneMock->expects($this->once())->method('addToCart')->with($this->cartMock, $isOwner)->willReturn(true);
     $exception = new \Exception('Exception.');
     $itemTwoMock->expects($this->once())->method('addToCart')->with($this->cartMock, $isOwner)->willThrowException($exception);
     $this->loggerMock->expects($this->once())->method('critical')->with($exception, []);
     $this->managerMock->expects($this->at(0))->method('addError')->with(__('We can\'t add this item to your shopping cart right now.'), null)->willReturnSelf();
     $this->wishlistHelperMock->expects($this->once())->method('getListUrl')->with($wishlistId)->willReturn($indexUrl);
     $this->cartHelperMock->expects($this->once())->method('getShouldRedirectToCart')->with(null)->willReturn(false);
     $this->redirectMock->expects($this->once())->method('getRefererUrl')->willReturn('');
     $wishlistMock->expects($this->once())->method('save')->willThrowException(new \Exception());
     $this->managerMock->expects($this->at(1))->method('addError')->with(__('We can\'t update the Wish List right now.'), null)->willReturnSelf();
     $productOneMock->expects($this->any())->method('getName')->willReturn($productOneName);
     $productTwoMock->expects($this->any())->method('getName')->willReturn($productTwoName);
     $this->managerMock->expects($this->once())->method('addSuccess')->with(__('%1 product(s) have been added to shopping cart: %2.', 1, '"' . $productOneName . '"'), null)->willReturnSelf();
     $this->cartMock->expects($this->once())->method('save')->willReturnSelf();
     /** @var \Magento\Quote\Model\Quote|\PHPUnit_Framework_MockObject_MockObject $collectionMock */
     $quoteMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->getMock();
     $this->cartMock->expects($this->once())->method('getQuote')->willReturn($quoteMock);
     $quoteMock->expects($this->once())->method('collectTotals')->willReturnSelf();
     $this->wishlistHelperMock->expects($this->once())->method('calculate')->willReturnSelf();
     $this->assertEquals($indexUrl, $this->model->moveAllToCart($wishlistMock, $qtys));
 }