aboutsummaryrefslogtreecommitdiffstats
path: root/apps/provisioning_api
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2024-10-17 15:43:57 +0200
committerCôme Chilliet <come.chilliet@nextcloud.com>2024-10-17 15:43:57 +0200
commit0353134a45665b0a79ffd84ad49250b315df78eb (patch)
tree32776b522fbea53d7eb564f9b9fc8916f5f44dbc /apps/provisioning_api
parent4100f583f03464978e622f5765bbef33e363c97f (diff)
downloadnextcloud-server-0353134a45665b0a79ffd84ad49250b315df78eb.tar.gz
nextcloud-server-0353134a45665b0a79ffd84ad49250b315df78eb.zip
chore(provisioning_api): Add tests for getDisabledUserDetails
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps/provisioning_api')
-rw-r--r--apps/provisioning_api/tests/Controller/UsersControllerTest.php125
1 files changed, 125 insertions, 0 deletions
diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
index 2d339205fae..d5931ef0eba 100644
--- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
@@ -219,6 +219,131 @@ class UsersControllerTest extends TestCase {
$this->assertEquals($expected, $this->api->getUsers('MyCustomSearch')->getData());
}
+ private function createUserMock(string $uid, bool $enabled): MockObject&IUser {
+ $mockUser = $this->getMockBuilder(IUser::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $mockUser
+ ->method('getUID')
+ ->willReturn($uid);
+ $mockUser
+ ->method('isEnabled')
+ ->willReturn($enabled);
+ return $mockUser;
+ }
+
+ public function testGetDisabledUsersAsAdmin(): void {
+ $loggedInUser = $this->getMockBuilder(IUser::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $loggedInUser
+ ->expects($this->once())
+ ->method('getUID')
+ ->willReturn('admin');
+ $this->userSession
+ ->expects($this->atLeastOnce())
+ ->method('getUser')
+ ->willReturn($loggedInUser);
+ $this->groupManager
+ ->expects($this->once())
+ ->method('isAdmin')
+ ->willReturn(true);
+ $this->userManager
+ ->expects($this->once())
+ ->method('getDisabledUsers')
+ ->with(3, 0, 'MyCustomSearch')
+ ->willReturn([
+ $this->createUserMock('admin', false),
+ $this->createUserMock('foo', false),
+ $this->createUserMock('bar', false),
+ ]);
+
+ $expected = [
+ 'users' => [
+ 'admin' => ['id' => 'admin'],
+ 'foo' => ['id' => 'foo'],
+ 'bar' => ['id' => 'bar'],
+ ],
+ ];
+ $this->assertEquals($expected, $this->api->getDisabledUsersDetails('MyCustomSearch', 3)->getData());
+ }
+
+ public function testGetDisabledUsersAsSubAdmin(): void {
+ $loggedInUser = $this->getMockBuilder(IUser::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $loggedInUser
+ ->expects($this->once())
+ ->method('getUID')
+ ->willReturn('subadmin');
+ $this->userSession
+ ->expects($this->atLeastOnce())
+ ->method('getUser')
+ ->willReturn($loggedInUser);
+ $this->groupManager
+ ->expects($this->once())
+ ->method('isAdmin')
+ ->willReturn(false);
+ $firstGroup = $this->getMockBuilder('OCP\IGroup')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $secondGroup = $this->getMockBuilder('OCP\IGroup')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $subAdminManager = $this->getMockBuilder('OC\SubAdmin')
+ ->disableOriginalConstructor()->getMock();
+ $subAdminManager
+ ->expects($this->once())
+ ->method('isSubAdmin')
+ ->with($loggedInUser)
+ ->willReturn(true);
+ $subAdminManager
+ ->expects($this->once())
+ ->method('getSubAdminsGroups')
+ ->with($loggedInUser)
+ ->willReturn([$firstGroup, $secondGroup]);
+ $this->groupManager
+ ->expects($this->once())
+ ->method('getSubAdmin')
+ ->willReturn($subAdminManager);
+ $this->groupManager
+ ->expects($this->never())
+ ->method('displayNamesInGroup');
+
+ $firstGroup
+ ->expects($this->once())
+ ->method('searchUsers')
+ ->with('MyCustomSearch')
+ ->willReturn([
+ $this->createUserMock('user1', false),
+ $this->createUserMock('bob', true),
+ $this->createUserMock('user2', false),
+ $this->createUserMock('alice', true),
+ ]);
+
+ $secondGroup
+ ->expects($this->once())
+ ->method('searchUsers')
+ ->with('MyCustomSearch')
+ ->willReturn([
+ $this->createUserMock('user2', false),
+ $this->createUserMock('joe', true),
+ $this->createUserMock('user3', false),
+ $this->createUserMock('jim', true),
+ $this->createUserMock('john', true),
+ ]);
+
+
+ $expected = [
+ 'users' => [
+ 'user1' => ['id' => 'user1'],
+ 'user2' => ['id' => 'user2'],
+ 'user3' => ['id' => 'user3'],
+ ],
+ ];
+ $this->assertEquals($expected, $this->api->getDisabledUsersDetails('MyCustomSearch', 3)->getData());
+ }
+
public function testAddUserAlreadyExisting(): void {
$this->expectException(OCSException::class);