diff --git a/lib/private/Group/Manager.php b/lib/private/Group/Manager.php index e58a1fe65856f..c1741a8188a63 100644 --- a/lib/private/Group/Manager.php +++ b/lib/private/Group/Manager.php @@ -301,18 +301,8 @@ public function getUserGroups(?IUser $user = null) { * @return \OC\Group\Group[] */ public function getUserIdGroups(string $uid): array { - $groups = []; - - foreach ($this->getUserIdGroupIds($uid) as $groupId) { - $aGroup = $this->get($groupId); - if ($aGroup instanceof IGroup) { - $groups[$groupId] = $aGroup; - } else { - $this->logger->debug('User "' . $uid . '" belongs to deleted group: "' . $groupId . '"', ['app' => 'core']); - } - } - - return $groups; + $groupIds = $this->getUserIdGroupIds($uid); + return $this->getGroupsObjects($groupIds); } /** diff --git a/tests/lib/Group/ManagerTest.php b/tests/lib/Group/ManagerTest.php index 8515ef0e3e807..a1ab9268b34d8 100644 --- a/tests/lib/Group/ManagerTest.php +++ b/tests/lib/Group/ManagerTest.php @@ -427,9 +427,9 @@ public function testGetUserGroups(): void { ->with('user1') ->willReturn(['group1']); $backend->expects($this->any()) - ->method('groupExists') + ->method('getGroupDetails') ->with('group1') - ->willReturn(true); + ->willReturn(['displayName' => 'group1']); $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress); $manager->addBackend($backend); @@ -475,9 +475,9 @@ public function testGetUserGroupsWithDeletedGroup(): void { ->with('user1') ->willReturn(['group1']); $backend->expects($this->any()) - ->method('groupExists') - ->with('group1') - ->willReturn(false); + ->method('getGroupsDetails') + ->with(['group1']) + ->willReturn(['group1' => []]); $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress); $manager->addBackend($backend); @@ -559,8 +559,8 @@ public function testGetUserGroupsMultipleBackends(): void { ->with('user1') ->willReturn(['group1']); $backend1->expects($this->any()) - ->method('groupExists') - ->willReturn(true); + ->method('getGroupDetails') + ->willReturnCallback(fn ($gid) => $gid === 'group1' ? ['displayName' => 'group1'] : []); /** * @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend2 @@ -570,9 +570,9 @@ public function testGetUserGroupsMultipleBackends(): void { ->method('getUserGroups') ->with('user1') ->willReturn(['group1', 'group2']); - $backend1->expects($this->any()) - ->method('groupExists') - ->willReturn(true); + $backend2->expects($this->any()) + ->method('getGroupDetails') + ->willReturnCallback(fn ($gid) => ['displayName' => $gid]); $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress); $manager->addBackend($backend1); @@ -869,6 +869,10 @@ public function testGetUserGroupsWithAddUser(): void { ->method('groupExists') ->with('group1') ->willReturn(true); + $backend->expects($this->any()) + ->method('getGroupDetails') + ->with('group1') + ->willReturn(['displayName' => 'group1']); $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress); $manager->addBackend($backend); @@ -903,9 +907,9 @@ public function testGetUserGroupsWithRemoveUser(): void { return $expectedGroups; }); $backend->expects($this->any()) - ->method('groupExists') + ->method('getGroupDetails') ->with('group1') - ->willReturn(true); + ->willReturn(['displayName' => 'group1']); $backend->expects($this->once()) ->method('inGroup') ->willReturn(true);