public function setUp() { $this->helper = $this->getMockBuilder('Magento\\Wishlist\\Helper\\Data')->disableOriginalConstructor()->getMock(); $this->wishlistFactory = $this->getMockBuilder('Magento\\Wishlist\\Model\\WishlistFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->wishlist = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist')->disableOriginalConstructor()->getMock(); $this->wishlistFactory->expects($this->any())->method('create')->willReturn($this->wishlist); $this->observer = new Observer($this->helper, $this->wishlistFactory); }
protected function setUp() { $this->checkoutSession = $this->getMockBuilder('Magento\\Checkout\\Model\\Session')->setMethods(['getSharedWishlist', 'getWishlistPendingMessages', 'getWishlistPendingUrls', 'getWishlistIds', 'getSingleWishlistId', 'setSingleWishlistId', 'setWishlistIds', 'setWishlistPendingUrls', 'setWishlistPendingMessages', 'setNoCartRedirect'])->disableOriginalConstructor()->getMock(); $this->customerSession = $this->getMockBuilder('Magento\\Customer\\Model\\Session')->disableOriginalConstructor()->setMethods(['setWishlistItemCount', 'isLoggedIn', 'getCustomerId'])->getMock(); $this->wishlistFactory = $this->getMockBuilder('Magento\\Wishlist\\Model\\WishlistFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->wishlist = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist')->disableOriginalConstructor()->getMock(); $this->messageManager = $this->getMockBuilder('Magento\\Framework\\Message\\ManagerInterface')->getMock(); $this->wishlistFactory->expects($this->any())->method('create')->willReturn($this->wishlist); $this->observer = new Observer($this->checkoutSession, $this->customerSession, $this->wishlistFactory, $this->messageManager); }
public function testGetWishlistWithIdWithoutCustomer() { $wishlist = $this->getMock('\\Magento\\Wishlist\\Model\\Wishlist', ['loadByCustomerId', 'load', 'getId', 'getCustomerId', '__wakeup'], [], '', false); $wishlist->expects($this->once())->method('load')->will($this->returnSelf()); $wishlist->expects($this->any())->method('getId')->will($this->returnValue(1)); $wishlist->expects($this->once())->method('getCustomerId')->will($this->returnValue(1)); $this->wishlistFactory->expects($this->once())->method('create')->will($this->returnValue($wishlist)); $this->request->expects($this->once())->method('getParam')->will($this->returnValue(1)); $this->assertEquals(false, $this->wishlistProvider->getWishlist()); }
public function testGetWishlistWithCustomerId() { $customerId = 1; $data = $customerId . ',2'; $wishlist = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist')->disableOriginalConstructor()->getMock(); $this->wishlistFactoryMock->expects($this->once())->method('create')->willReturn($wishlist); $this->requestMock->expects($this->at(0))->method('getParam')->with('wishlist_id', null)->willReturn(''); $this->urlDecoderMock->expects($this->any())->method('decode')->willReturnArgument(0); $this->requestMock->expects($this->at(1))->method('getParam')->with('data', null)->willReturn($data); $this->customerSessionMock->expects($this->once())->method('getCustomerId')->willReturn(0); $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock(); $this->customerFactoryMock->expects($this->once())->method('create')->willReturn($customer); $this->customerRepositoryMock->expects($this->never())->method('getById'); $customer->expects($this->exactly(2))->method('getId')->willReturn($customerId); $wishlist->expects($this->once())->method('loadByCustomerId')->with($customerId, false)->willReturnSelf(); $this->assertEquals($wishlist, $this->model->getWishlist()); }