Example #1
0
 public function testProcessAddToCart()
 {
     $wishlistId = 1;
     $customerId = 2;
     $url = 'http://some.pending/url';
     $message = 'some error msg';
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $event = $this->getMockBuilder('Magento\\Framework\\Event')->setMethods(['getRequest', 'getResponse'])->disableOriginalConstructor()->getMock();
     $request = $this->getMockBuilder('Magento\\Framework\\App\\RequestInterface')->getMock();
     $response = $this->getMockBuilder('Magento\\Framework\\App\\ResponseInterface')->setMethods(['setRedirect'])->getMockForAbstractClass();
     $wishlists = $this->getMockBuilder('Magento\\Wishlist\\Model\\Resource\\Wishlist\\Collection')->disableOriginalConstructor()->getMock();
     $loadedWishlist = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist\\Item')->setMethods(['getId', 'delete'])->disableOriginalConstructor()->getMock();
     $eventObserver->expects($this->any())->method('getEvent')->willReturn($event);
     $request->expects($this->any())->method('getParam')->with('wishlist_next')->willReturn(true);
     $event->expects($this->once())->method('getRequest')->willReturn($request);
     $this->checkoutSession->expects($this->once())->method('getSharedWishlist');
     $this->checkoutSession->expects($this->once())->method('getWishlistPendingMessages')->willReturn([$message]);
     $this->checkoutSession->expects($this->once())->method('getWishlistPendingUrls')->willReturn([$url]);
     $this->checkoutSession->expects($this->once())->method('getWishlistIds');
     $this->checkoutSession->expects($this->once())->method('getSingleWishlistId')->willReturn($wishlistId);
     $this->customerSession->expects($this->once())->method('isLoggedIn')->willReturn(true);
     $this->customerSession->expects($this->once())->method('getCustomerId')->willReturn($customerId);
     $this->wishlist->expects($this->once())->method('loadByCustomerId')->with($this->logicalOr($customerId, true))->willReturnSelf();
     $this->wishlist->expects($this->once())->method('getItemCollection')->willReturn($wishlists);
     $loadedWishlist->expects($this->once())->method('getId')->willReturn($wishlistId);
     $loadedWishlist->expects($this->once())->method('delete');
     $wishlists->expects($this->once())->method('load')->willReturn([$loadedWishlist]);
     $this->checkoutSession->expects($this->once())->method('setWishlistIds')->with([])->willReturnSelf();
     $this->checkoutSession->expects($this->once())->method('setSingleWishlistId')->with(null)->willReturnSelf();
     $this->checkoutSession->expects($this->once())->method('setWishlistPendingUrls')->with([])->willReturnSelf();
     $this->checkoutSession->expects($this->once())->method('setWishlistPendingMessages')->with([])->willReturnSelf();
     $this->messageManager->expects($this->once())->method('addError')->with($message)->willReturnSelf();
     $event->expects($this->once())->method('getResponse')->willReturn($response);
     $response->expects($this->once())->method('setRedirect')->with($url);
     $this->checkoutSession->expects($this->once())->method('setNoCartRedirect')->with(true);
     /** @var $eventObserver \Magento\Framework\Event\Observer */
     $this->observer->processAddToCart($eventObserver);
 }