Esempio n. 1
0
 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());
 }
Esempio n. 2
0
 public function testExecutePassed()
 {
     $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false);
     $layout = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false);
     $layout->expects($this->once())->method('initMessages')->willReturn(true);
     $this->wishlistProvider->expects($this->once())->method('getWishlist')->willReturn($wishlist);
     $this->view->expects($this->once())->method('loadLayout')->willReturn(true);
     $this->view->expects($this->once())->method('getLayout')->willReturn($layout);
     $this->view->expects($this->once())->method('renderLayout')->willReturn(true);
     $this->getController()->execute();
 }
 /**
  * Test execute add success critical exception
  *
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecuteAddSuccessCriticalException()
 {
     $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false);
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
     $item = $this->getMock('Magento\\Wishlist\\Model\\Item', [], [], '', false);
     $helper = $this->getMock('Magento\\Wishlist\\Helper\\Data', [], [], '', false);
     $logger = $this->getMock('Magento\\Framework\\Logger\\Monolog', [], [], '', false);
     $exception = new \Exception();
     $logger->expects($this->once())->method('critical')->with($exception)->willReturn(true);
     $helper->expects($this->exactly(2))->method('calculate')->willReturn(true);
     $wishlist->expects($this->once())->method('getItem')->with(3)->willReturn($item);
     $wishlist->expects($this->once())->method('updateItem')->with(3, new \Magento\Framework\DataObject([]))->willReturnSelf();
     $wishlist->expects($this->once())->method('save')->willReturn(null);
     $wishlist->expects($this->once())->method('getId')->willReturn(56);
     $product->expects($this->once())->method('isVisibleInCatalog')->willReturn(true);
     $product->expects($this->once())->method('getName')->willReturn('Test name');
     $this->request->expects($this->at(0))->method('getParam')->with('product', null)->willReturn(2);
     $this->request->expects($this->at(1))->method('getParam')->with('id', null)->willReturn(3);
     $this->productRepository->expects($this->once())->method('getById')->with(2)->willReturn($product);
     $item->expects($this->once())->method('load')->with(3)->willReturnSelf();
     $item->expects($this->once())->method('__call')->with('getWishlistId')->willReturn(12);
     $this->wishlistProvider->expects($this->once())->method('getWishlist')->with(12)->willReturn($wishlist);
     $this->om->expects($this->once())->method('create')->with('Magento\\Wishlist\\Model\\Item')->willReturn($item);
     $this->request->expects($this->once())->method('getParams')->willReturn([]);
     $this->om->expects($this->at(1))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->willReturn($helper);
     $this->om->expects($this->at(2))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->willReturn($helper);
     $this->om->expects($this->at(3))->method('get')->with('Psr\\Log\\LoggerInterface')->willReturn($logger);
     $this->eventManager->expects($this->once())->method('dispatch')->with('wishlist_update_item', ['wishlist' => $wishlist, 'product' => $product, 'item' => $item])->willReturn(true);
     $this->messageManager->expects($this->once())->method('addSuccess')->with('Test name has been updated in your Wish List.', null)->willThrowException($exception);
     $this->messageManager->expects($this->once())->method('addError')->with('We can\'t update your Wish List right now.', null)->willReturn(true);
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*', ['wishlist_id' => 56])->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->getController()->execute());
 }
Esempio n. 4
0
    public function testExecutePassed()
    {
        $wishlist = $this->getMock('Magento\Wishlist\Model\Wishlist', [], [], '', false);

        $this->wishlistProvider->expects($this->once())
            ->method('getWishlist')
            ->willReturn($wishlist);

        $this->assertSame($this->resultPageMock, $this->getController()->executeInternal());
    }
Esempio n. 5
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecuteProductAddedToWishlistAfterObjectManagerThrowException()
 {
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', ['isVisibleInCatalog', 'getName'], [], '', false);
     $product->expects($this->once())->method('isVisibleInCatalog')->will($this->returnValue(true));
     $product->expects($this->once())->method('getName')->will($this->returnValue('Product test name'));
     $this->productRepository->expects($this->once())->method('getById')->with(2)->will($this->returnValue($product));
     $exception = new \Exception('Exception');
     $wishListItem = new \stdClass();
     $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', ['addNewItem', 'save', 'getId'], [], '', false);
     $wishlist->expects($this->once())->method('addNewItem')->will($this->returnValue($wishListItem));
     $wishlist->expects($this->once())->method('getId')->will($this->returnValue(2));
     $wishlist->expects($this->once())->method('save')->will($this->returnValue(true));
     $this->wishlistProvider->expects($this->once())->method('getWishlist')->will($this->returnValue($wishlist));
     $request = $this->getMock('Magento\\Framework\\App\\Request\\Http', ['getParams'], [], '', false);
     $request->expects($this->once())->method('getParams')->will($this->returnValue(['product' => 2]));
     $wishlistHelper = $this->getMock('Magento\\Wishlist\\Helper\\Data', ['calculate'], [], '', false);
     $wishlistHelper->expects($this->once())->method('calculate')->will($this->returnSelf());
     $escaper = $this->getMock('Magento\\Framework\\Escaper', ['escapeHtml', 'escapeUrl'], [], '', false);
     $escaper->expects($this->once())->method('escapeHtml')->with('Product test name')->will($this->returnValue('Product test name'));
     $escaper->expects($this->once())->method('escapeUrl')->with('http://test-url.com')->will($this->returnValue('http://test-url.com'));
     $logger = $this->getMock('Magento\\Framework\\Logger\\Monolog', ['critical'], [], '', false);
     $logger->expects($this->once())->method('critical')->with($exception)->will($this->returnValue(true));
     $om = $this->getMock('Magento\\Framework\\App\\ObjectManager', ['get'], [], '', false);
     $om->expects($this->at(0))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->will($this->returnValue($wishlistHelper));
     $om->expects($this->at(1))->method('get')->with('Magento\\Framework\\Escaper')->will($this->returnValue($escaper));
     $om->expects($this->at(2))->method('get')->with('Magento\\Framework\\Escaper')->will($this->returnValue($escaper));
     $om->expects($this->at(3))->method('get')->with('Psr\\Log\\LoggerInterface')->will($this->returnValue($logger));
     $response = $this->getMock('Magento\\Framework\\App\\Response\\Http', null, [], '', false);
     $eventManager = $this->getMock('Magento\\Framework\\Event\\Manager', ['dispatch'], [], '', false);
     $eventManager->expects($this->once())->method('dispatch')->with('wishlist_add_product', ['wishlist' => $wishlist, 'product' => $product, 'item' => $wishListItem])->will($this->returnValue(true));
     $url = $this->getMock('Magento\\Framework\\Url', null, [], '', false);
     $actionFlag = $this->getMock('Magento\\Framework\\App\\ActionFlag', null, [], '', false);
     $redirect = $this->getMock('\\Magento\\Store\\App\\Response\\Redirect', ['redirect'], [], '', false);
     $redirect->expects($this->once())->method('redirect')->with($response, '*', ['wishlist_id' => 2])->will($this->returnValue(null));
     $view = $this->getMock('Magento\\Framework\\App\\View', null, [], '', false);
     $messageManager = $this->getMock('Magento\\Framework\\Message\\Manager', ['addError', 'addSuccess'], [], '', false);
     $messageManager->expects($this->once())->method('addError')->with('An error occurred while adding item to wish list.')->will($this->returnValue(null));
     $messageManager->expects($this->once())->method('addSuccess')->will($this->throwException($exception));
     $this->context->expects($this->any())->method('getObjectManager')->will($this->returnValue($om));
     $this->context->expects($this->any())->method('getRequest')->will($this->returnValue($request));
     $this->context->expects($this->any())->method('getResponse')->will($this->returnValue($response));
     $this->context->expects($this->any())->method('getEventManager')->will($this->returnValue($eventManager));
     $this->context->expects($this->any())->method('getUrl')->will($this->returnValue($url));
     $this->context->expects($this->any())->method('getActionFlag')->will($this->returnValue($actionFlag));
     $this->context->expects($this->any())->method('getRedirect')->will($this->returnValue($redirect));
     $this->context->expects($this->any())->method('getView')->will($this->returnValue($view));
     $this->context->expects($this->any())->method('getMessageManager')->will($this->returnValue($messageManager));
     $this->customerSession->expects($this->exactly(1))->method('getBeforeWishlistRequest')->will($this->returnValue(false));
     $this->customerSession->expects($this->never())->method('unsBeforeWishlistRequest')->will($this->returnValue(null));
     $this->customerSession->expects($this->once())->method('getBeforeWishlistUrl')->will($this->returnValue('http://test-url.com'));
     $this->customerSession->expects($this->once())->method('setBeforeWishlistUrl')->with(null)->will($this->returnValue(null));
     $this->createController();
     $this->controller->execute();
 }
Esempio n. 6
0
 public function testExecuteCanNotSaveWishlistAndWithRedirect()
 {
     $referer = 'http://referer-url.com';
     $exception = new \Exception('Message');
     $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false);
     $wishlist->expects($this->once())->method('save')->willThrowException($exception);
     $this->wishlistProvider->expects($this->once())->method('getWishlist')->with(2)->willReturn($wishlist);
     $this->messageManager->expects($this->once())->method('addError')->with('An error occurred while deleting the item from wish list.')->willReturn(true);
     $wishlistHelper = $this->getMock('Magento\\Wishlist\\Helper\\Data', [], [], '', false);
     $wishlistHelper->expects($this->once())->method('calculate')->willReturnSelf();
     $this->om->expects($this->once())->method('get')->with('Magento\\Wishlist\\Helper\\Data')->will($this->returnValue($wishlistHelper));
     $item = $this->getMock('Magento\\Wishlist\\Model\\Item', [], [], '', false);
     $item->expects($this->once())->method('load')->with(1)->willReturnSelf();
     $item->expects($this->once())->method('getId')->willReturn(1);
     $item->expects($this->once())->method('__call')->with('getWishlistId')->willReturn(2);
     $item->expects($this->once())->method('delete')->willReturn(true);
     $this->om->expects($this->once())->method('create')->with('Magento\\Wishlist\\Model\\Item')->willReturn($item);
     $this->request->expects($this->once())->method('getServer')->with('HTTP_REFERER')->willReturn($referer);
     $this->request->expects($this->exactly(3))->method('getParam')->willReturnMap([['item', null, 1], ['referer_url', null, $referer], ['uenc', null, false]]);
     $this->url->expects($this->once())->method('getUrl')->with('*/*')->willReturn('http:/test.com/frontname/module/controller/action');
     $this->redirect->expects($this->once())->method('getRedirectUrl')->willReturn('http:/test.com/frontname/module/controller/action');
     $this->response->expects($this->once())->method('setRedirect')->with('http:/test.com/frontname/module/controller/action')->willReturn(true);
     $this->getController()->execute();
 }