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()); }
/** * @magentoDataFixture Magento/Customer/_files/customer.php * @magentoDataFixture Magento/Wishlist/_files/wishlist_with_product_qty_increments.php * @magentoAppArea frontend */ public function testGetWishlistByCustomerId() { /** @var \Magento\Wishlist\Model\Wishlist $wishlist */ $wishlist = $this->_objectManager->create('Magento\\Wishlist\\Model\\Wishlist')->loadByCustomerId($this->_fixtureCustomerId); /** @var \Magento\Framework\App\Request\Http $request */ $request = $this->_contextHelper->getRequest(); $request->setParam('wishlist_id', ''); $this->assertEquals($wishlist, $this->_wishlistHelper->getWishlist()); }