diff --git a/lib/GroupBackend.php b/lib/GroupBackend.php index ce5431c98..e2a6d0b21 100644 --- a/lib/GroupBackend.php +++ b/lib/GroupBackend.php @@ -543,10 +543,10 @@ public function setupSearchQuery(string $search, IQueryBuilder $query, bool $inc #[\Override] public function searchInGroup(string $gid, string $search = '', int $limit = -1, int $offset = 0): array { $query = $this->dbc->getQueryBuilder(); - $query->select('g.uid', 'dn.value AS displayname') - ->from(self::TABLE_MEMBERS, 'g') - ->where($query->expr()->eq('gid', $query->createNamedParameter($gid))) - ->orderBy('g.uid', 'ASC'); + $query->select('m.uid', 'dn.value AS displayname') + ->from(self::TABLE_MEMBERS, 'm') + ->where($query->expr()->eq('m.gid', $query->createNamedParameter($gid))) + ->orderBy('m.uid', 'ASC'); $this->setupSearchQuery($search, $query, includeMetadata: true); diff --git a/tests/unit/GroupBackendTest.php b/tests/unit/GroupBackendTest.php index d14691edf..245687626 100644 --- a/tests/unit/GroupBackendTest.php +++ b/tests/unit/GroupBackendTest.php @@ -162,6 +162,29 @@ public function testCountUsersInGroupMatchesDisplayNameAndEmail(): void { $this->assertSame(1, $this->groupBackend->countUsersInGroup($groupId, $this->users[0]['uid'])); } + public function testSearchInGroup(): void { + foreach ($this->groups as $group) { + $users = $this->groupBackend->searchInGroup($group['gid']); + $this->assertCount(count($group['members']), $users, 'Should retrieve all group members'); + foreach (array_keys($users) as $uid) { + $this->assertContains($uid, $group['members'], sprintf('User %s should be member of group %s', $uid, $group['gid'])); + } + } + } + + public function testSearchInGroupMatchesDisplayNameAndEmail(): void { + $groupId = $this->groups[0]['gid']; + + $byDisplayName = $this->groupBackend->searchInGroup($groupId, $this->users[0]['displayname']); + $this->assertArrayHasKey($this->users[0]['uid'], $byDisplayName, 'Display name search should return the matching user'); + + $byEmail = $this->groupBackend->searchInGroup($groupId, $this->users[1]['email']); + $this->assertArrayHasKey($this->users[1]['uid'], $byEmail, 'Email search should return the matching user'); + + $byUid = $this->groupBackend->searchInGroup($groupId, $this->users[0]['uid']); + $this->assertArrayHasKey($this->users[0]['uid'], $byUid, 'UID search should still work'); + } + private function resetAccountData(): void { foreach ($this->users as $user) { $qb = $this->connection->getQueryBuilder();