Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function getResponse()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getResponse');
     if (!$pluginInfo) {
         return parent::getResponse();
     } else {
         return $this->___callPlugins('getResponse', func_get_args(), $pluginInfo);
     }
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function dispatch(\Magento\Framework\App\RequestInterface $request)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'dispatch');
     if (!$pluginInfo) {
         return parent::dispatch($request);
     } else {
         return $this->___callPlugins('dispatch', func_get_args(), $pluginInfo);
     }
 }
Exemplo n.º 3
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();
 }