本文整理匯總了PHP中Observer::processAddToCart方法的典型用法代碼示例。如果您正苦於以下問題:PHP Observer::processAddToCart方法的具體用法?PHP Observer::processAddToCart怎麽用?PHP Observer::processAddToCart使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Observer
的用法示例。
在下文中一共展示了Observer::processAddToCart方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testProcessAddToCart
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);
}