From 78af5b8a06033a5d969cb820de7b54006fc9bd38 Mon Sep 17 00:00:00 2001 From: Danilo Argentiero Date: Fri, 21 Jun 2019 11:57:24 +0200 Subject: [PATCH 1/2] Get review entity id by code instead hard-coded. --- app/code/Magento/Review/Controller/Adminhtml/Product/Post.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/Post.php b/app/code/Magento/Review/Controller/Adminhtml/Product/Post.php index b62fcc7326eec..ae4babb056798 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/Post.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/Post.php @@ -10,6 +10,7 @@ use Magento\Framework\Controller\ResultFactory; use Magento\Store\Model\Store; use Magento\Framework\Exception\LocalizedException; +use Magento\Review\Model\Review; class Post extends ProductController implements HttpPostActionInterface { @@ -33,7 +34,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']) From a3016bc9f7db98404c1d6d4b9429c02c77aff6dc Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Mon, 24 Jun 2019 16:10:50 +0300 Subject: [PATCH 2/2] magentomagento2#23353: Unit and static tests fix. --- .../Magento/Review/Controller/Adminhtml/Product/Post.php | 5 +++++ .../Test/Unit/Controller/Adminhtml/Product/PostTest.php | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/Post.php b/app/code/Magento/Review/Controller/Adminhtml/Product/Post.php index ae4babb056798..b42dd3b3063f6 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/Post.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/Post.php @@ -12,9 +12,14 @@ 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() 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();