Skip to content

Commit

Permalink
ENGCOM-5337: Get review entity id by code instead hard-coded. #23353
Browse files Browse the repository at this point in the history
  • Loading branch information
sidolov authored Jun 26, 2019
2 parents 7fc1cf4 + 7bd47cd commit 4aeadb5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 4aeadb5

Please sign in to comment.