/** * @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) ->willReturn(true); $this->reviewSession->expects($this->any())->method('getFormData') ->with(true) ->willReturn($ratingsData); $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($ratingsData) ->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(); $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->executeInternal()); }