Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/private/User/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ public function searchDisplayName($pattern, $limit = null, $offset = null) {
$backendUsers = $backend->getDisplayNames($pattern, $limit, $offset);
if (is_array($backendUsers)) {
foreach ($backendUsers as $uid => $displayName) {
$users[] = new LazyUser($uid, $this, $displayName, $backend);
// A user known to several backends is served by the first one, as in get()
$users[$uid] ??= new LazyUser($uid, $this, $displayName, $backend);
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions tests/lib/User/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,31 @@ public function testSearchTwoBackendLimitOffset(): void {
$this->assertEquals('foo3', array_shift($result)->getUID());
}

public function testSearchDisplayNameTwoBackendsSameUser(): void {
$backend1 = $this->createMock(\Test\Util\User\Dummy::class);
$backend1->expects($this->once())
->method('getDisplayNames')
->with($this->equalTo(''), $this->equalTo(3), $this->equalTo(0))
->willReturn(['foo1' => 'Foo One', 'foo2' => 'Foo Two']);

$backend2 = $this->createMock(\Test\Util\User\Dummy::class);
$backend2->expects($this->once())
->method('getDisplayNames')
->with($this->equalTo(''), $this->equalTo(3), $this->equalTo(0))
->willReturn(['foo2' => 'Foo Two (other)', 'foo3' => 'Foo Three']);

$this->manager->registerBackend($backend1);
$this->manager->registerBackend($backend2);

$result = $this->manager->searchDisplayName('', 3, 0);
$this->assertCount(3, $result);
$this->assertEquals('foo1', $result[0]->getUID());
$this->assertEquals('foo3', $result[1]->getUID());
$this->assertEquals('foo2', $result[2]->getUID());
$this->assertEquals('Foo Two', $result[2]->getDisplayName());
$this->assertSame($backend1, $result[2]->getBackend());
}

public static function dataCreateUserInvalid(): array {
return [
['te?st', 'foo', 'Only the following characters are allowed in a username:'
Expand Down
Loading