$users = [];
foreach ($this->backends as $backend) {
if ($backend instanceof ISearchableGroupBackend) {
- $users = array_merge($users, array_values($backend->searchInGroup($this->gid, $search, $limit ?? -1, $offset ?? 0)));
+ $users += $backend->searchInGroup($this->gid, $search, $limit ?? -1, $offset ?? 0);
} else {
$userIds = $backend->usersInGroup($this->gid, $search, $limit ?? -1, $offset ?? 0);
$userManager = \OCP\Server::get(IUserManager::class);
- $userObjects = array_map(
- fn (string $userId): IUser => new LazyUser($userId, $userManager),
- $userIds
- );
- $users = array_merge($users, $userObjects);
+ foreach ($userIds as $userId) {
+ if (!isset($users[$userId])) {
+ $users[$userId] = new LazyUser($userId, $userManager);
+ }
+ }
}
if (!is_null($limit) and $limit <= 0) {
return $users;
* @param string[] $userIds an array containing user IDs
* @return \OC\User\User[] an Array with the userId as Key and \OC\User\User as value
*/
- private function getVerifiedUsers($userIds) {
- if (!is_array($userIds)) {
- return [];
- }
+ private function getVerifiedUsers(array $userIds): array {
$users = [];
foreach ($userIds as $userId) {
$user = $this->userManager->get($userId);
$users = $group->searchUsers('2');
$this->assertEquals(1, count($users));
- $user2 = $users['user2'];
+ $user2 = reset($users);
$this->assertEquals('user2', $user2->getUID());
}
$users = $group->searchUsers('2');
$this->assertEquals(1, count($users));
- $user2 = $users['user2'];
+ $user2 = reset($users);
$this->assertEquals('user2', $user2->getUID());
}
$users = $group->searchUsers('user', 1, 1);
$this->assertEquals(1, count($users));
- $user2 = $users['user2'];
+ $user2 = reset($users);
$this->assertEquals('user2', $user2->getUID());
}
$users = $group->searchUsers('user', 2, 1);
$this->assertEquals(2, count($users));
- $user2 = $users['user2'];
- $user1 = $users['user1'];
+ $user2 = reset($users);
+ $user1 = next($users);
$this->assertEquals('user2', $user2->getUID());
$this->assertEquals('user1', $user1->getUID());
}
use OC\User\User;
use OC\User\Manager;
use OCP\GroupInterface;
+use OCP\Group\Backend\ISearchableGroupBackend;
use OCP\ICacheFactory;
use OCP\IUser;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
+interface ISearchableGroupInterface extends ISearchableGroupBackend, GroupInterface {
+}
+
class ManagerTest extends TestCase {
/** @var Manager|MockObject */
protected $userManager;
}
// need to declare it this way due to optional methods
// thanks to the implementsActions logic
- $backend = $this->getMockBuilder(GroupInterface::class)
+ $backend = $this->getMockBuilder(ISearchableGroupInterface::class)
->disableOriginalConstructor()
->setMethods([
'getGroupDetails',