diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/Post.php b/app/code/Magento/Review/Controller/Adminhtml/Product/Post.php index b62fcc7326eec..b42dd3b3063f6 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/Post.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/Post.php @@ -10,10 +10,16 @@ use Magento\Framework\Controller\ResultFactory; use Magento\Store\Model\Store; use Magento\Framework\Exception\LocalizedException; +use Magento\Review\Model\Review; +/** + * Review admin controller for POST request. + */ class Post extends ProductController implements HttpPostActionInterface { /** + * Create a product review. + * * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() @@ -33,7 +39,7 @@ public function execute() } $review = $this->reviewFactory->create()->setData($data); try { - $review->setEntityId(1) // product + $review->setEntityId($review->getEntityIdByCode(Review::ENTITY_PRODUCT_CODE)) ->setEntityPkValue($productId) ->setStoreId(Store::DEFAULT_STORE_ID) ->setStatusId($data['status_id']) diff --git a/app/code/Magento/Review/Test/Unit/Controller/Adminhtml/Product/PostTest.php b/app/code/Magento/Review/Test/Unit/Controller/Adminhtml/Product/PostTest.php index 7d22524895ae7..6592ff977a069 100644 --- a/app/code/Magento/Review/Test/Unit/Controller/Adminhtml/Product/PostTest.php +++ b/app/code/Magento/Review/Test/Unit/Controller/Adminhtml/Product/PostTest.php @@ -6,6 +6,7 @@ namespace Magento\Review\Test\Unit\Controller\Adminhtml\Product; use Magento\Framework\Controller\ResultFactory; +use Magento\Review\Model\Review; /** * @SuppressWarnings(PHPMD.TooManyFields) @@ -109,7 +110,7 @@ protected function _prepareMockObjects() $this->storeModelMock = $this->createPartialMock(\Magento\Store\Model\Store::class, ['__wakeup', 'getId']); $this->reviewMock = $this->createPartialMock( \Magento\Review\Model\Review::class, - ['__wakeup', 'create', 'save', 'getId', 'getResource', 'aggregate'] + ['__wakeup', 'create', 'save', 'getId', 'getResource', 'aggregate', 'getEntityIdByCode'] ); $this->reviewFactoryMock = $this->createPartialMock(\Magento\Review\Model\ReviewFactory::class, ['create']); $this->ratingMock = $this->createPartialMock( @@ -174,6 +175,10 @@ public function testPostAction() $this->reviewMock->expects($this->once()) ->method('aggregate') ->willReturn($this->reviewMock); + $this->reviewMock->expects($this->once()) + ->method('getEntityIdByCode') + ->with(Review::ENTITY_PRODUCT_CODE) + ->willReturn(1); $this->ratingMock->expects($this->once()) ->method('setRatingId') ->willReturnSelf();