Skip to content

Commit 412fe3c

Browse files
authored
Merge pull request #4871 from magento-borg/borg-2.2.11
[borg] Bug fixes
2 parents 830768c + f04a653 commit 412fe3c

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

app/code/Magento/User/Controller/Adminhtml/User/Delete.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
@@ -9,9 +8,14 @@
98
use Magento\User\Block\User\Edit\Tab\Main as UserEdit;
109
use Magento\Framework\Exception\AuthenticationException;
1110

11+
/**
12+
* Delete admin user.
13+
*/
1214
class Delete extends \Magento\User\Controller\Adminhtml\User
1315
{
1416
/**
17+
* Execute delete action.
18+
*
1519
* @return void
1620
*/
1721
public function execute()
@@ -34,7 +38,7 @@ public function execute()
3438
$currentUser->performIdentityCheck($currentUserPassword);
3539
/** @var \Magento\User\Model\User $model */
3640
$model = $this->_userFactory->create();
37-
$model->setId($userId);
41+
$model->load($userId);
3842
$model->delete();
3943
$this->messageManager->addSuccess(__('You deleted the user.'));
4044
$this->_redirect('adminhtml/*/');

app/code/Magento/User/Model/ResourceModel/User.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ protected function _afterLoad(\Magento\Framework\Model\AbstractModel $user)
255255
*/
256256
public function delete(\Magento\Framework\Model\AbstractModel $user)
257257
{
258+
$user->beforeDelete();
258259
$this->_beforeDelete($user);
259260
$connection = $this->getConnection();
260261

@@ -272,7 +273,9 @@ public function delete(\Magento\Framework\Model\AbstractModel $user)
272273
$connection->rollBack();
273274
return false;
274275
}
276+
$user->afterDelete();
275277
$connection->commit();
278+
$user->afterDeleteCommit();
276279
$this->_afterDelete($user);
277280
return true;
278281
}

app/code/Magento/User/Test/Unit/Controller/Adminhtml/User/DeleteTest.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected function setUp()
8181

8282
$this->userMock = $this->getMockBuilder(\Magento\User\Model\User::class)
8383
->disableOriginalConstructor()
84-
->setMethods(['getId', 'performIdentityCheck', 'delete'])
84+
->setMethods(['getId', 'performIdentityCheck', 'delete', 'load'])
8585
->getMock();
8686

8787
$this->userFactoryMock = $this->getMockBuilder(\Magento\User\Model\UserFactory::class)
@@ -134,15 +134,18 @@ public function testExecute($currentUserPassword, $userId, $currentUserId, $resu
134134

135135
$this->requestMock->expects($this->any())
136136
->method('getPost')
137-
->willReturnMap([
138-
['user_id', $userId],
139-
[\Magento\User\Block\User\Edit\Tab\Main::CURRENT_USER_PASSWORD_FIELD, $currentUserPassword],
140-
]);
137+
->willReturnMap(
138+
[
139+
['user_id', $userId],
140+
[\Magento\User\Block\User\Edit\Tab\Main::CURRENT_USER_PASSWORD_FIELD, $currentUserPassword],
141+
]
142+
);
141143

142144
$userMock = clone $currentUserMock;
143145

144146
$this->userFactoryMock->expects($this->any())->method('create')->will($this->returnValue($userMock));
145147
$this->responseMock->expects($this->any())->method('setRedirect')->willReturnSelf();
148+
$this->userMock->expects($this->any())->method('load')->with($userId)->willReturn($this->userFactoryMock);
146149
$this->userMock->expects($this->any())->method('delete')->willReturnSelf();
147150
$this->messageManagerMock->expects($this->once())->method($resultMethod);
148151

@@ -172,10 +175,12 @@ public function testEmptyPassword()
172175

173176
$this->requestMock->expects($this->any())
174177
->method('getPost')
175-
->willReturnMap([
176-
['user_id', $userId],
177-
[\Magento\User\Block\User\Edit\Tab\Main::CURRENT_USER_PASSWORD_FIELD, ''],
178-
]);
178+
->willReturnMap(
179+
[
180+
['user_id', $userId],
181+
[\Magento\User\Block\User\Edit\Tab\Main::CURRENT_USER_PASSWORD_FIELD, ''],
182+
]
183+
);
179184

180185
$result = $this->controller->execute();
181186
$this->assertNull($result);
@@ -191,8 +196,8 @@ public function executeDataProvider()
191196
return [
192197
[
193198
'currentUserPassword' => '123123q',
194-
'userId' => 1,
195-
'currentUserId' => 2,
199+
'userId' => 2,
200+
'currentUserId' => 1,
196201
'resultMethod' => 'addSuccess',
197202
],
198203
[

dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/User/DeleteTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function testDeleteActionWithError()
2222
$messageManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
2323
->get(\Magento\Framework\Message\ManagerInterface::class);
2424
$user->load(1);
25+
$this->getRequest()->setMethod('POST');
2526
$this->getRequest()->setPostValue('user_id', $user->getId() . '_suffix_ignored_in_mysql_casting_to_int');
2627

2728
$this->dispatch('backend/admin/user/delete');

0 commit comments

Comments
 (0)