Esempio 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);
     }
 }
Esempio 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);
     }
 }
Esempio n. 3
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecute()
 {
     $ratingsData = ['ratings' => [1 => 1]];
     $productId = 1;
     $customerId = 1;
     $storeId = 1;
     $reviewId = 1;
     $redirectUrl = 'url';
     $this->formKeyValidator->expects($this->any())->method('validate')->with($this->request)->will($this->returnValue(true));
     $this->reviewSession->expects($this->any())->method('getFormData')->with(true)->will($this->returnValue($ratingsData));
     $this->eventManager->expects($this->at(0))->method('dispatch')->with('review_controller_product_init_before', ['controller_action' => $this->model])->will($this->returnSelf());
     $this->request->expects($this->at(0))->method('getParam')->with('category', false)->will($this->returnValue(false));
     $this->request->expects($this->at(1))->method('getParam')->with('id')->will($this->returnValue(1));
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', ['__wakeup', 'isVisibleInCatalog', 'isVisibleInSiteVisibility', 'getId'], [], '', false);
     $product->expects($this->once())->method('isVisibleInCatalog')->will($this->returnValue(true));
     $product->expects($this->once())->method('isVisibleInSiteVisibility')->will($this->returnValue(true));
     $this->productRepository->expects($this->any())->method('getById')->with(1)->will($this->returnValue($product));
     $this->coreRegistry->expects($this->at(0))->method('register')->with('current_product', $product)->will($this->returnSelf());
     $this->coreRegistry->expects($this->at(1))->method('register')->with('product', $product)->will($this->returnSelf());
     $this->eventManager->expects($this->at(1))->method('dispatch')->with('review_controller_product_init', ['product' => $product])->will($this->returnSelf());
     $this->eventManager->expects($this->at(2))->method('dispatch')->with('review_controller_product_init_after', ['product' => $product, 'controller_action' => $this->model])->will($this->returnSelf());
     $this->review->expects($this->once())->method('setData')->with($ratingsData)->will($this->returnSelf());
     $this->review->expects($this->once())->method('validate')->will($this->returnValue(true));
     $this->review->expects($this->once())->method('getEntityIdByCode')->with(\Magento\Review\Model\Review::ENTITY_PRODUCT_CODE)->will($this->returnValue(1));
     $this->review->expects($this->once())->method('setEntityId')->with(1)->will($this->returnSelf());
     $product->expects($this->exactly(2))->method('getId')->will($this->returnValue($productId));
     $this->review->expects($this->once())->method('setEntityPkValue')->with($productId)->will($this->returnSelf());
     $this->review->expects($this->once())->method('setStatusId')->with(\Magento\Review\Model\Review::STATUS_PENDING)->will($this->returnSelf());
     $this->customerSession->expects($this->exactly(2))->method('getCustomerId')->will($this->returnValue($customerId));
     $this->review->expects($this->once())->method('setCustomerId')->with($customerId)->will($this->returnSelf());
     $this->store->expects($this->exactly(2))->method('getId')->will($this->returnValue($storeId));
     $this->review->expects($this->once())->method('setStoreId')->with($storeId)->will($this->returnSelf());
     $this->review->expects($this->once())->method('setStores')->with([$storeId])->will($this->returnSelf());
     $this->review->expects($this->once())->method('save')->will($this->returnSelf());
     $this->rating->expects($this->once())->method('setRatingId')->with(1)->will($this->returnSelf());
     $this->review->expects($this->once())->method('getId')->will($this->returnValue($reviewId));
     $this->rating->expects($this->once())->method('setReviewId')->with($reviewId)->will($this->returnSelf());
     $this->rating->expects($this->once())->method('setCustomerId')->with($customerId)->will($this->returnSelf());
     $this->rating->expects($this->once())->method('addOptionVote')->with(1, $productId)->will($this->returnSelf());
     $this->review->expects($this->once())->method('aggregate')->will($this->returnSelf());
     $this->messageManager->expects($this->once())->method('addSuccess')->with('Your review has been accepted for moderation.')->will($this->returnSelf());
     $this->reviewSession->expects($this->once())->method('getRedirectUrl')->with(true)->will($this->returnValue($redirectUrl));
     $this->response->expects($this->once())->method('setRedirect')->with($redirectUrl)->will($this->returnSelf());
     $this->model->execute();
 }
Esempio n. 4
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecute()
 {
     $reviewData = ['ratings' => [1 => 1], 'review_id' => 2];
     $productId = 1;
     $customerId = 1;
     $storeId = 1;
     $reviewId = 1;
     $redirectUrl = 'url';
     $this->formKeyValidator->expects($this->any())->method('validate')->with($this->request)->willReturn(true);
     $this->reviewSession->expects($this->any())->method('getFormData')->with(true)->willReturn($reviewData);
     $this->request->expects($this->at(0))->method('getParam')->with('category', false)->willReturn(false);
     $this->request->expects($this->at(1))->method('getParam')->with('id')->willReturn(1);
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', ['__wakeup', 'isVisibleInCatalog', 'isVisibleInSiteVisibility', 'getId'], [], '', false);
     $product->expects($this->once())->method('isVisibleInCatalog')->willReturn(true);
     $product->expects($this->once())->method('isVisibleInSiteVisibility')->willReturn(true);
     $this->productRepository->expects($this->any())->method('getById')->with(1)->willReturn($product);
     $this->coreRegistry->expects($this->at(0))->method('register')->with('current_product', $product)->willReturnSelf();
     $this->coreRegistry->expects($this->at(1))->method('register')->with('product', $product)->willReturnSelf();
     $this->review->expects($this->once())->method('setData')->with($reviewData)->willReturnSelf();
     $this->review->expects($this->once())->method('validate')->willReturn(true);
     $this->review->expects($this->once())->method('getEntityIdByCode')->with(\Magento\Review\Model\Review::ENTITY_PRODUCT_CODE)->willReturn(1);
     $this->review->expects($this->once())->method('setEntityId')->with(1)->willReturnSelf();
     $this->review->expects($this->once())->method('unsetData')->with('review_id');
     $product->expects($this->exactly(2))->method('getId')->willReturn($productId);
     $this->review->expects($this->once())->method('setEntityPkValue')->with($productId)->willReturnSelf();
     $this->review->expects($this->once())->method('setStatusId')->with(\Magento\Review\Model\Review::STATUS_PENDING)->willReturnSelf();
     $this->customerSession->expects($this->exactly(2))->method('getCustomerId')->willReturn($customerId);
     $this->review->expects($this->once())->method('setCustomerId')->with($customerId)->willReturnSelf();
     $this->store->expects($this->exactly(2))->method('getId')->willReturn($storeId);
     $this->review->expects($this->once())->method('setStoreId')->with($storeId)->willReturnSelf();
     $this->review->expects($this->once())->method('setStores')->with([$storeId])->willReturnSelf();
     $this->review->expects($this->once())->method('save')->willReturnSelf();
     $this->rating->expects($this->once())->method('setRatingId')->with(1)->willReturnSelf();
     $this->review->expects($this->once())->method('getId')->willReturn($reviewId);
     $this->rating->expects($this->once())->method('setReviewId')->with($reviewId)->willReturnSelf();
     $this->rating->expects($this->once())->method('setCustomerId')->with($customerId)->willReturnSelf();
     $this->rating->expects($this->once())->method('addOptionVote')->with(1, $productId)->willReturnSelf();
     $this->review->expects($this->once())->method('aggregate')->willReturnSelf();
     $this->messageManager->expects($this->once())->method('addSuccess')->with(__('You submitted your review for moderation.'))->willReturnSelf();
     $this->reviewSession->expects($this->once())->method('getRedirectUrl')->with(true)->willReturn($redirectUrl);
     $this->assertSame($this->resultRedirectMock, $this->model->execute());
 }