Skip to content

Commit 32c698c

Browse files
committed
ACP2E-1214: [Magento Cloud] - Mass Delete Product Review doesnt work when logged in as limited user role
1 parent cb8a09f commit 32c698c

File tree

2 files changed

+109
-1
lines changed

2 files changed

+109
-1
lines changed

app/code/Magento/Review/Controller/Adminhtml/Product/MassDelete.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ public function execute()
7171
} catch (LocalizedException $e) {
7272
$this->messageManager->addErrorMessage($e->getMessage());
7373
} catch (\Exception $e) {
74-
$this->messageManager->addExceptionMessage($e, __('Something went wrong while deleting these records.'));
74+
$this->messageManager->addExceptionMessage(
75+
$e,
76+
__('Something went wrong while deleting these records.')
77+
);
7578
}
7679
}
7780
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Review\Test\Unit\Controller\Adminhtml\Product;
9+
10+
use Magento\Backend\App\Action\Context;
11+
use Magento\Framework\App\RequestInterface;
12+
use Magento\Framework\Controller\Result\Redirect;
13+
use Magento\Framework\Controller\ResultFactory;
14+
use Magento\Framework\Message\ManagerInterface;
15+
use Magento\Framework\Registry;
16+
use Magento\Review\Controller\Adminhtml\Product\MassDelete;
17+
use Magento\Review\Model\RatingFactory;
18+
use Magento\Review\Model\ResourceModel\Review as ReviewResourceModel;
19+
use Magento\Review\Model\ResourceModel\Review\Collection as ReviewCollection;
20+
use Magento\Review\Model\ResourceModel\Review\CollectionFactory as ReviewCollectionFactory;
21+
use Magento\Review\Model\ReviewFactory;
22+
use PHPUnit\Framework\MockObject\MockObject;
23+
use PHPUnit\Framework\TestCase;
24+
25+
class MassDeleteTest extends TestCase
26+
{
27+
/**
28+
* @var MassDelete
29+
*/
30+
private $massDelete;
31+
32+
/**
33+
* @var RequestInterface|MockObject
34+
*/
35+
private $requestMock;
36+
37+
/**
38+
* @var ReviewCollectionFactory|MockObject
39+
*/
40+
private $collectionFactoryMock;
41+
42+
/**
43+
* @inheritdoc
44+
*/
45+
protected function setUp(): void
46+
{
47+
$contextMock = $this->createMock(Context::class);
48+
$this->requestMock = $this->createMock(RequestInterface::class);
49+
$contextMock->method('getRequest')
50+
->willReturn($this->requestMock);
51+
$messageManagerMock = $this->createMock(ManagerInterface::class);
52+
$contextMock->method('getMessageManager')
53+
->willReturn($messageManagerMock);
54+
$resultFactoryMock = $this->createMock(ResultFactory::class);
55+
$contextMock->method('getResultFactory')
56+
->willReturn($resultFactoryMock);
57+
$resultMock = $this->createMock(Redirect::class);
58+
$resultFactoryMock->method('create')
59+
->willReturn($resultMock);
60+
61+
$coreRegistryMock = $this->createMock(Registry::class);
62+
$reviewFactoryMock = $this->createMock(ReviewFactory::class);
63+
$ratingFactoryMock = $this->createMock(RatingFactory::class);
64+
$this->collectionFactoryMock = $this->createMock(ReviewCollectionFactory::class);
65+
66+
$this->massDelete = new MassDelete(
67+
$contextMock,
68+
$coreRegistryMock,
69+
$reviewFactoryMock,
70+
$ratingFactoryMock,
71+
$this->collectionFactoryMock
72+
);
73+
}
74+
75+
public function testExecute(): void
76+
{
77+
$this->requestMock->expects(self::atLeastOnce())
78+
->method('getParam')
79+
->willReturnMap(
80+
[
81+
['reviews', null, [10, 20]],
82+
['ret', 'index', 'index'],
83+
]
84+
);
85+
86+
$collectionMock = $this->createMock(ReviewCollection::class);
87+
$this->collectionFactoryMock->expects(self::once())
88+
->method('create')
89+
->willReturn($collectionMock);
90+
$resource = $this->createMock(ReviewResourceModel::class);
91+
$collectionMock->method('getResource')
92+
->willReturn($resource);
93+
$resource->method('getIdFieldName')
94+
->willReturn('id');
95+
$collectionMock->expects(self::once())
96+
->method('addFieldToFilter')
97+
->with('main_table.id', [10, 20])
98+
->willReturnSelf();
99+
$collectionMock->expects(self::once())
100+
->method('addStoreData')
101+
->willReturnSelf();
102+
103+
$this->massDelete->execute();
104+
}
105+
}

0 commit comments

Comments
 (0)