Example #1
0
 /**
  * Add all items from wishlist to shopping cart
  *
  * @return void
  */
 public function execute()
 {
     $wishlist = $this->wishlistProvider->getWishlist();
     if (!$wishlist) {
         $this->_forward('noroute');
         return;
     }
     $redirectUrl = $this->itemCarrier->moveAllToCart($wishlist, $this->getRequest()->getParam('qty'));
     $this->getResponse()->setRedirect($redirectUrl);
 }
 public function testExecuteWithWishlist()
 {
     $url = 'http://redirect-url.com';
     $quantity = 2;
     $this->wishlistProviderMock->expects($this->once())->method('getWishlist')->willReturn($this->wishlistMock);
     $this->requestMock->expects($this->any())->method('getParam')->with('qty')->willReturn($quantity);
     $this->itemCarrierMock->expects($this->once())->method('moveAllToCart')->with($this->wishlistMock, 2)->willReturn($url);
     $this->resultRedirectMock->expects($this->once())->method('setUrl')->with($url)->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->allcartController->execute());
 }
Example #3
0
 public function testExecuteWithWishlist()
 {
     $wishlist = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist')->disableOriginalConstructor()->getMock();
     $this->wishlistProvider->expects($this->once())->method('getWishlist')->willReturn($wishlist);
     $this->request->expects($this->once())->method('getParam')->with('qty')->will($this->returnValue(2));
     $this->itemCarrier->expects($this->once())->method('moveAllToCart')->with($wishlist, 2)->will($this->returnValue('http://redirect-url.com'));
     $this->response->expects($this->once())->method('setRedirect')->will($this->returnValue('http://redirect-url.com'));
     $controller = $this->getController();
     $controller->execute();
 }
Example #4
0
 /**
  * Add all items from wishlist to shopping cart
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     $wishlist = $this->wishlistProvider->getWishlist();
     if (!$wishlist) {
         /** @var \Magento\Framework\Controller\Result\Forward $resultForward */
         $resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD);
         $resultForward->forward('noroute');
         return $resultForward;
     }
     $redirectUrl = $this->itemCarrier->moveAllToCart($wishlist, $this->getRequest()->getParam('qty'));
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
     $resultRedirect->setUrl($redirectUrl);
     return $resultRedirect;
 }
Example #5
0
    public function testExecutePassed()
    {
        $url = 'http://redirect-url.com';
        $wishlist = $this->getMock('Magento\Wishlist\Model\Wishlist', [], [], '', false);
        
        $this->formKeyValidator->expects($this->once())
            ->method('validate')
            ->with($this->request)
            ->will($this->returnValue(true));
        $this->request->expects($this->once())
            ->method('getParam')
            ->with('qty')
            ->will($this->returnValue(2));
        $this->wishlistProvider->expects($this->once())
            ->method('getWishlist')
            ->will($this->returnValue($wishlist));
        $this->itemCarrier->expects($this->once())
            ->method('moveAllToCart')
            ->with($wishlist, 2)
            ->willReturn($url);
        $this->resultRedirectMock->expects($this->once())
            ->method('setUrl')
            ->with($url)
            ->willReturnSelf();

        $this->assertSame($this->resultRedirectMock, $this->getController()->executeInternal());
    }
Example #6
0
 public function testExecutePassed()
 {
     $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false);
     $this->formKeyValidator->expects($this->once())->method('validate')->with($this->request)->will($this->returnValue(true));
     $this->request->expects($this->once())->method('getParam')->with('qty')->will($this->returnValue(2));
     $this->response->expects($this->once())->method('setRedirect')->will($this->returnValue('http://redirect-url.com'));
     $this->wishlistProvider->expects($this->once())->method('getWishlist')->will($this->returnValue($wishlist));
     $this->itemCarrier->expects($this->once())->method('moveAllToCart')->with($wishlist, 2)->will($this->returnValue('http://redirect-url.com'));
     $this->getController()->execute();
 }
 /**
  * @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));
 }