Skip to content

Commit f8a10cd

Browse files
committed
ACP2E-1299: Search in user roles not working
1 parent 5a022f6 commit f8a10cd

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

app/code/Magento/User/Block/Role/Grid/User.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,16 @@ public function getUsers($json = false)
206206
if ($json) {
207207
return $this->getJSONString($inRoleUser);
208208
}
209-
return $this->escapeJs($this->escapeHtml($inRoleUser));
209+
$escapedInRoleUser = $this->escapeHtml($inRoleUser);
210+
if (is_array($escapedInRoleUser)) {
211+
return array_map(
212+
function ($value) {
213+
return $this->escapeJs($value);
214+
},
215+
$escapedInRoleUser
216+
);
217+
}
218+
return $this->escapeJs($escapedInRoleUser);
210219
}
211220
$roleId = $this->getRoleId();
212221
$users = $this->getUsersFormData();

app/code/Magento/User/Test/Unit/Block/Role/Grid/UserTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Magento\User\Block\Role\Grid\User;
2323
use Magento\User\Controller\Adminhtml\User\Role\SaveRole;
2424
use Magento\User\Model\ResourceModel\Role\User\CollectionFactory;
25+
use Magento\Framework\Escaper;
2526
use PHPUnit\Framework\MockObject\MockObject;
2627
use PHPUnit\Framework\TestCase;
2728

@@ -82,6 +83,11 @@ class UserTest extends TestCase
8283
*/
8384
protected $filesystemMock;
8485

86+
/**
87+
* @var Escaper|MockObject
88+
*/
89+
protected $escaperMock;
90+
8591
protected function setUp(): void
8692
{
8793
$this->backendHelperMock = $this->getMockBuilder(Data::class)
@@ -123,6 +129,10 @@ protected function setUp(): void
123129
->disableOriginalConstructor()
124130
->getMock();
125131

132+
$this->escaperMock = $this->getMockBuilder(Escaper::class)
133+
->disableOriginalConstructor()
134+
->getMockForAbstractClass();
135+
126136
$objectManagerHelper = new ObjectManager($this);
127137
$this->model = $objectManagerHelper->getObject(
128138
User::class,
@@ -135,7 +145,8 @@ protected function setUp(): void
135145
'request' => $this->requestInterfaceMock,
136146
'urlBuilder' => $this->urlInterfaceMock,
137147
'layout' => $this->layoutMock,
138-
'filesystem' => $this->filesystemMock
148+
'filesystem' => $this->filesystemMock,
149+
'escaper' => $this->escaperMock
139150
]
140151
);
141152
}
@@ -302,4 +313,14 @@ public function testGetUsersIncorrectInRoleUser(): void
302313
$this->requestInterfaceMock->expects($this->once())->method('getParam')->with($param)->willReturn($paramValue);
303314
$this->assertEquals('{}', $this->model->getUsers(true));
304315
}
316+
317+
/**
318+
* @return void
319+
*/
320+
public function testGetUsers(): void
321+
{
322+
$paramValue = array("1");
323+
$this->requestInterfaceMock->expects($this->once())->method('getParam')->with('in_role_user')->willReturn($paramValue);
324+
$this->assertEquals($paramValue, $this->model->getUsers());
325+
}
305326
}

0 commit comments

Comments
 (0)