Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Fix unit tests
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen authored and backportbot[bot] committed Jun 23, 2020
commit d1df66f7af7c46e12ccb78a60ec0e85ea0678ede
2 changes: 1 addition & 1 deletion lib/private/Collaboration/Collaborators/UserPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {

if ($this->shareWithGroupOnly) {
// Only add, if we have a common group
$commonGroups = array_intersect($userGroupIds, $this->groupManager->getUserGroupIds($user));
$commonGroups = array_intersect($currentUserGroups, $this->groupManager->getUserGroupIds($user));
$addUser = !empty($commonGroups);
}

Expand Down
84 changes: 47 additions & 37 deletions tests/lib/Collaboration/Collaborators/UserPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public function dataGetUsers() {
true,
['abc', 'xyz'],
[
['abc', 'test', 2, 0, [$this->getUserMock('test1', 'Test One')]],
['abc', 'test', 2, 0, ['test1' => 'Test One']],
['xyz', 'test', 2, 0, []],
],
[],
Expand All @@ -284,20 +284,22 @@ public function dataGetUsers() {
],
true,
false,
[['test1', $this->getUserMock('test1', 'Test One')]],
],
[
'test',
true,
false,
['abc', 'xyz'],
[
['abc', 'test', 2, 0, [$this->getUserMock('test1', 'Test One')]],
['abc', 'test', 2, 0, ['test1' => 'Test One']],
['xyz', 'test', 2, 0, []],
],
[],
[],
true,
false,
[['test1', $this->getUserMock('test1', 'Test One')]],
],
[
'test',
Expand All @@ -306,12 +308,12 @@ public function dataGetUsers() {
['abc', 'xyz'],
[
['abc', 'test', 2, 0, [
$this->getUserMock('test1', 'Test One'),
$this->getUserMock('test2', 'Test Two'),
'test1' => 'Test One',
'test2' => 'Test Two',
]],
['xyz', 'test', 2, 0, [
$this->getUserMock('test1', 'Test One'),
$this->getUserMock('test2', 'Test Two'),
'test1' => 'Test One',
'test2' => 'Test Two',
]],
],
[],
Expand All @@ -321,6 +323,10 @@ public function dataGetUsers() {
],
false,
false,
[
['test1', $this->getUserMock('test1', 'Test One')],
['test2', $this->getUserMock('test2', 'Test Two')],
],
],
[
'test',
Expand All @@ -329,18 +335,22 @@ public function dataGetUsers() {
['abc', 'xyz'],
[
['abc', 'test', 2, 0, [
$this->getUserMock('test1', 'Test One'),
$this->getUserMock('test2', 'Test Two'),
'test1' => 'Test One',
'test2' => 'Test Two',
]],
['xyz', 'test', 2, 0, [
$this->getUserMock('test1', 'Test One'),
$this->getUserMock('test2', 'Test Two'),
'test1' => 'Test One',
'test2' => 'Test Two',
]],
],
[],
[],
true,
false,
[
['test1', $this->getUserMock('test1', 'Test One')],
['test2', $this->getUserMock('test2', 'Test Two')],
],
],
[
'test',
Expand All @@ -349,10 +359,10 @@ public function dataGetUsers() {
['abc', 'xyz'],
[
['abc', 'test', 2, 0, [
$this->getUserMock('test', 'Test One'),
'test' => 'Test One',
]],
['xyz', 'test', 2, 0, [
$this->getUserMock('test2', 'Test Two'),
'test2' => 'Test Two',
]],
],
[
Expand All @@ -363,6 +373,10 @@ public function dataGetUsers() {
],
false,
false,
[
['test', $this->getUserMock('test', 'Test One')],
['test2', $this->getUserMock('test2', 'Test Two')],
],
],
[
'test',
Expand All @@ -371,10 +385,10 @@ public function dataGetUsers() {
['abc', 'xyz'],
[
['abc', 'test', 2, 0, [
$this->getUserMock('test', 'Test One'),
'test' => 'Test One',
]],
['xyz', 'test', 2, 0, [
$this->getUserMock('test2', 'Test Two'),
'test2' => 'Test Two',
]],
],
[
Expand All @@ -383,6 +397,10 @@ public function dataGetUsers() {
[],
true,
false,
[
['test', $this->getUserMock('test', 'Test One')],
['test2', $this->getUserMock('test2', 'Test Two')],
],
],
];
}
Expand All @@ -399,6 +417,7 @@ public function dataGetUsers() {
* @param array $expected
* @param bool $reachedEnd
* @param bool|IUser $singleUser
* @param array $users
*/
public function testSearch(
$searchTerm,
Expand All @@ -409,7 +428,8 @@ public function testSearch(
array $exactExpected,
array $expected,
$reachedEnd,
$singleUser
$singleUser,
array $users = []
) {
$this->mockConfig($shareWithGroupOnly, $shareeEnumeration, false);
$this->instantiatePlugin();
Expand All @@ -424,39 +444,29 @@ public function testSearch(
->with($searchTerm, $this->limit, $this->offset)
->willReturn($userResponse);
} else {
$groups = array_combine($groupResponse, array_map(function ($gid) {
return $this->getGroupMock($gid);
}, $groupResponse));
if ($singleUser !== false) {
$this->groupManager->method('getUserGroups')
->with($this->user)
->willReturn($groups);
$this->groupManager->method('getUserGroupIds')
->with($this->user)
->willReturn($groupResponse);

if ($singleUser !== false) {
$this->groupManager->method('getUserGroupIds')
->with($singleUser)
->willReturn($groupResponse);
} else {
$this->groupManager->expects($this->once())
->method('getUserGroups')
->with($this->user)
->willReturn($groups);
}

foreach ($userResponse as $groupDefinition) {
[$gid, $search, $limit, $offset, $users] = $groupDefinition;
$groups[$gid]->method('searchDisplayName')
->with($search, $limit, $offset)
->willReturn($users);
}
$this->groupManager->method('displayNamesInGroup')
->willReturnMap($userResponse);
}

if ($singleUser !== false) {
$this->userManager->expects($this->once())
->method('get')
->with($searchTerm)
->willReturn($singleUser);
$users[] = [$searchTerm, $singleUser];
}

if (!empty($users)) {
$this->userManager->expects($this->atLeastOnce())
->method('get')
->willReturnMap($users);
}

$moreResults = $this->plugin->search($searchTerm, $this->limit, $this->offset, $this->searchResult);
$result = $this->searchResult->asArray();
Expand Down