Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/code/Magento/Review/Controller/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ protected function loadProduct($productId)

try {
$product = $this->productRepository->getById($productId);

if (!in_array($this->storeManager->getStore()->getWebsiteId(), $product->getWebsiteIds())) {
throw new NoSuchEntityException();
}

if (!$product->isVisibleInCatalog() || !$product->isVisibleInSiteVisibility()) {
throw new NoSuchEntityException();
}
Expand Down
16 changes: 14 additions & 2 deletions app/code/Magento/Review/Test/Unit/Controller/Product/PostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,13 @@ protected function setUp()
$ratingFactory->expects($this->once())->method('create')->willReturn($this->rating);
$this->messageManager = $this->getMock('\Magento\Framework\Message\ManagerInterface');

$this->store = $this->getMock('\Magento\Store\Model\Store', ['getId'], [], '', false);
$this->store = $this->getMock(
'\Magento\Store\Model\Store',
['getId', 'getWebsiteId'],
[],
'',
false
);
$storeManager = $this->getMockForAbstractClass('\Magento\Store\Model\StoreManagerInterface');
$storeManager->expects($this->any())->method('getStore')->willReturn($this->store);

Expand Down Expand Up @@ -242,7 +248,7 @@ public function testExecute()
->willReturn(1);
$product = $this->getMock(
'Magento\Catalog\Model\Product',
['__wakeup', 'isVisibleInCatalog', 'isVisibleInSiteVisibility', 'getId'],
['__wakeup', 'isVisibleInCatalog', 'isVisibleInSiteVisibility', 'getId', 'getWebsiteIds'],
[],
'',
false
Expand All @@ -253,6 +259,10 @@ public function testExecute()
$product->expects($this->once())
->method('isVisibleInSiteVisibility')
->willReturn(true);
$product->expects($this->once())
->method('getWebsiteIds')
->willReturn([1]);

$this->productRepository->expects($this->any())->method('getById')
->with(1)
->willReturn($product);
Expand Down Expand Up @@ -288,6 +298,8 @@ public function testExecute()
$this->review->expects($this->once())->method('setCustomerId')->with($customerId)->willReturnSelf();
$this->store->expects($this->exactly(2))->method('getId')
->willReturn($storeId);
$this->store->expects($this->once())->method('getWebsiteId')
->willReturn(1);
$this->review->expects($this->once())->method('setStoreId')
->with($storeId)
->willReturnSelf();
Expand Down