Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use IUserManager::find() when searching for members #106

Merged
merged 1 commit into from
Sep 12, 2017
Merged
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
11 changes: 4 additions & 7 deletions lib/Service/MembershipHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,10 @@ public function isTheOnlyAdmin($groupId, $userId) {
* Return the user ids of the members in the given group matching the given pattern
*
* @param int $groupId numeric group id
* @param string $pattern pattern
* @return array array of user ids as keys and true as value
*/
private function getGroupMemberUserIds($groupId, $pattern) {
$search = new Search($pattern);

$foundMembers = $this->groupsHandler->getGroupMembers($groupId, $search);
private function getGroupMemberUserIds($groupId) {
$foundMembers = $this->groupsHandler->getGroupMembers($groupId);
$existingMembers = [];
foreach ($foundMembers as $foundMember) {
$existingMembers[$foundMember['user_id']] = true;
Expand All @@ -248,7 +245,7 @@ private function getGroupMemberUserIds($groupId, $pattern) {
* @return IUser[] results
*/
public function searchForNewMembers($groupId, $pattern, $limit = 200) {
$existingMembers = $this->getGroupMemberUserIds($groupId, $pattern);
$existingMembers = $this->getGroupMemberUserIds($groupId);

$totalResults = [];
$totalResultCount = 0;
Expand All @@ -257,7 +254,7 @@ public function searchForNewMembers($groupId, $pattern, $limit = 200) {
$internalOffset = 0;
// loop until the $totalResults reaches $limit size or no more results exist
do {
$results = $this->userManager->searchDisplayName($pattern, $internalLimit, $internalOffset);
$results = $this->userManager->find($pattern, $internalLimit, $internalOffset);
foreach ($results as $result) {
if ($totalResultCount >= $limit) {
break;
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/Service/MembershipHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public function testSearchForNewMembers() {

$this->handler->expects($this->once())
->method('getGroupMembers')
->with(1, $search)
->with(1)
->willReturn([
['user_id' => 'user1'],
['user_id' => 'user2'],
Expand All @@ -286,7 +286,7 @@ public function testSearchForNewMembers() {
$user4->method('getDisplayName')->willReturn('User Four');

$this->userManager->expects($this->once())
->method('searchDisplayName')
->method('find')
->with('us', 150, 0)
->willReturn([$user1, $user2, $user3, $user4]);
$results = $this->helper->searchForNewMembers(1, 'us', 150);
Expand All @@ -310,7 +310,7 @@ public function testSearchForNewMembersBigPage() {

$this->handler->expects($this->once())
->method('getGroupMembers')
->with(1, $search)
->with(1)
->willReturn([
['user_id' => 'user15'],
['user_id' => 'user16'],
Expand All @@ -320,11 +320,11 @@ public function testSearchForNewMembersBigPage() {
$usersChunk = array_chunk($users, 20);

$this->userManager->expects($this->at(0))
->method('searchDisplayName')
->method('find')
->with('us', 20, 0)
->willReturn($usersChunk[0]);
$this->userManager->expects($this->at(1))
->method('searchDisplayName')
->method('find')
->with('us', 20, 20)
->willReturn($usersChunk[1]);

Expand Down Expand Up @@ -355,7 +355,7 @@ public function testSearchForNewMembersSmallLastPage() {

$this->handler->expects($this->once())
->method('getGroupMembers')
->with(1, $search)
->with(1)
->willReturn([
['user_id' => 'user15'],
['user_id' => 'user16'],
Expand All @@ -365,11 +365,11 @@ public function testSearchForNewMembersSmallLastPage() {
$usersChunk = array_chunk($users, 20);

$this->userManager->expects($this->at(0))
->method('searchDisplayName')
->method('find')
->with('us', 20, 0)
->willReturn($usersChunk[0]);
$this->userManager->expects($this->at(1))
->method('searchDisplayName')
->method('find')
->with('us', 20, 20)
->willReturn($usersChunk[1]);

Expand Down