Skip to content

Commit fd90885

Browse files
Merge MAGETWO-92724 into 2.1.16-bugfixes-261018
2 parents f6bbab8 + a33ab18 commit fd90885

File tree

3 files changed

+48
-4
lines changed
  • app/code/Magento/Customer
  • dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml

3 files changed

+48
-4
lines changed

app/code/Magento/Customer/Block/Adminhtml/Group/Edit.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public function __construct(
5757
* Update Save and Delete buttons. Remove Delete button if group can't be deleted.
5858
*
5959
* @return void
60+
* @throws \Magento\Framework\Exception\LocalizedException
61+
* @throws \Magento\Framework\Exception\NoSuchEntityException
6062
*/
6163
protected function _construct()
6264
{
@@ -68,6 +70,23 @@ protected function _construct()
6870

6971
$this->buttonList->update('save', 'label', __('Save Customer Group'));
7072
$this->buttonList->update('delete', 'label', __('Delete Customer Group'));
73+
$this->buttonList->update(
74+
'delete',
75+
'onclick',
76+
sprintf(
77+
"deleteConfirm('%s','%s', %s)",
78+
'Are you sure?',
79+
$this->getDeleteUrl(),
80+
json_encode(
81+
[
82+
'action' => '',
83+
'data' => [
84+
'form_key' => $this->getFormKey()
85+
]
86+
]
87+
)
88+
)
89+
);
7190

7291
$groupId = $this->coreRegistry->registry(RegistryConstants::CURRENT_GROUP_ID);
7392
if (!$groupId || $this->groupManagement->isReadonly($groupId)) {

app/code/Magento/Customer/Controller/Adminhtml/Group/Delete.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,22 @@
77
namespace Magento\Customer\Controller\Adminhtml\Group;
88

99
use Magento\Framework\Exception\NoSuchEntityException;
10+
use Magento\Framework\Exception\NotFoundException;
1011

1112
class Delete extends \Magento\Customer\Controller\Adminhtml\Group
1213
{
1314
/**
1415
* Delete customer group.
1516
*
1617
* @return \Magento\Backend\Model\View\Result\Redirect
18+
* @throws NotFoundException
1719
*/
1820
public function execute()
1921
{
22+
if (!$this->getRequest()->isPost()) {
23+
throw new NotFoundException(__('Page not found'));
24+
}
25+
2026
$id = $this->getRequest()->getParam('id');
2127
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
2228
$resultRedirect = $this->resultRedirectFactory->create();

dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/GroupTest.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Framework\Message\MessageInterface;
99
use Magento\TestFramework\Helper\Bootstrap;
10+
use Magento\Framework\Data\Form\FormKey;
1011

1112
/**
1213
* @magentoAppArea adminhtml
@@ -80,6 +81,10 @@ public function testNewActionWithCustomerGroupDataInSession()
8081
*/
8182
public function testDeleteActionNoGroupId()
8283
{
84+
/** @var FormKey $formKey */
85+
$formKey = $this->_objectManager->get(FormKey::class);
86+
$this->getRequest()->setMethod('POST');
87+
$this->getRequest()->setParam('form_key', $formKey->getFormKey());
8388
$this->dispatch('backend/customer/group/delete');
8489
$this->assertRedirect($this->stringStartsWith(self::BASE_CONTROLLER_URL));
8590
}
@@ -90,9 +95,16 @@ public function testDeleteActionNoGroupId()
9095
public function testDeleteActionExistingGroup()
9196
{
9297
$groupId = $this->findGroupIdWithCode(self::CUSTOMER_GROUP_CODE);
93-
$this->getRequest()->setParam('id', $groupId);
98+
/** @var FormKey $formKey */
99+
$formKey = $this->_objectManager->get(FormKey::class);
100+
$this->getRequest()->setMethod('POST');
101+
$this->getRequest()->setParams(
102+
[
103+
'id' => $groupId,
104+
'form_key' => $formKey->getFormKey()
105+
]
106+
);
94107
$this->dispatch('backend/customer/group/delete');
95-
96108
/**
97109
* Check that success message is set
98110
*/
@@ -108,9 +120,16 @@ public function testDeleteActionExistingGroup()
108120
*/
109121
public function testDeleteActionNonExistingGroupId()
110122
{
111-
$this->getRequest()->setParam('id', 10000);
123+
/** @var FormKey $formKey */
124+
$formKey = $this->_objectManager->get(FormKey::class);
125+
$this->getRequest()->setMethod('POST');
126+
$this->getRequest()->setParams(
127+
[
128+
'id' => 10000,
129+
'form_key' => $formKey->getFormKey()
130+
]
131+
);
112132
$this->dispatch('backend/customer/group/delete');
113-
114133
/**
115134
* Check that error message is set
116135
*/

0 commit comments

Comments
 (0)