summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorblizzz <blizzz@arthur-schiwon.de>2020-04-09 00:08:34 +0200
committerGitHub <noreply@github.com>2020-04-09 00:08:34 +0200
commite9795d01f12bdc5aec96350cb428b95814963c43 (patch)
treec56700cd19926aab2d0eb7786a891e880c61ba33 /tests
parent22edb626b6b97a19bbe08ee8f036c5116d6bf214 (diff)
parent01c147a4a5016f0672d3ad9069df66421a6a6067 (diff)
downloadnextcloud-server-e9795d01f12bdc5aec96350cb428b95814963c43.tar.gz
nextcloud-server-e9795d01f12bdc5aec96350cb428b95814963c43.zip
Merge pull request #16035 from nextcloud/share-search-hide-on-match
dont show remote and email options if we have an exact match for local user email
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Collaboration/Collaborators/UserPluginTest.php139
1 files changed, 77 insertions, 62 deletions
diff --git a/tests/lib/Collaboration/Collaborators/UserPluginTest.php b/tests/lib/Collaboration/Collaborators/UserPluginTest.php
index ff916d63b38..f279ada254b 100644
--- a/tests/lib/Collaboration/Collaborators/UserPluginTest.php
+++ b/tests/lib/Collaboration/Collaborators/UserPluginTest.php
@@ -27,6 +27,7 @@ use OC\Collaboration\Collaborators\SearchResult;
use OC\Collaboration\Collaborators\UserPlugin;
use OCP\Collaboration\Collaborators\ISearchResult;
use OCP\IConfig;
+use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserManager;
@@ -93,9 +94,8 @@ class UserPluginTest extends TestCase {
$this->config->expects($this->any())
->method('getAppValue')
->willReturnCallback(
- function($appName, $key, $default)
- use ($shareWithGroupOnly, $shareeEnumeration, $shareeEnumerationLimitToGroup)
- {
+ function ($appName, $key, $default)
+ use ($shareWithGroupOnly, $shareeEnumeration, $shareeEnumerationLimitToGroup) {
if ($appName === 'core' && $key === 'shareapi_only_share_with_group_members') {
return $shareWithGroupOnly ? 'yes' : 'no';
} else if ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') {
@@ -127,6 +127,16 @@ class UserPluginTest extends TestCase {
return $user;
}
+ public function getGroupMock($gid) {
+ $group = $this->createMock(IGroup::class);
+
+ $group->expects($this->any())
+ ->method('getGID')
+ ->willReturn($gid);
+
+ return $group;
+ }
+
public function dataGetUsers() {
return [
['test', false, true, [], [], [], [], true, false],
@@ -137,33 +147,33 @@ class UserPluginTest extends TestCase {
'test', false, true, [], [],
[
['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test']],
- ], [], true, $this->getUserMock('test', 'Test')
+ ], [], true, $this->getUserMock('test', 'Test'),
],
[
'test', false, false, [], [],
[
['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test']],
- ], [], true, $this->getUserMock('test', 'Test')
+ ], [], true, $this->getUserMock('test', 'Test'),
],
[
'test', true, true, [], [],
- [], [], true, $this->getUserMock('test', 'Test')
+ [], [], true, $this->getUserMock('test', 'Test'),
],
[
'test', true, false, [], [],
- [], [], true, $this->getUserMock('test', 'Test')
+ [], [], true, $this->getUserMock('test', 'Test'),
],
[
'test', true, true, ['test-group'], [['test-group', 'test', 2, 0, []]],
[
['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test']],
- ], [], true, $this->getUserMock('test', 'Test')
+ ], [], true, $this->getUserMock('test', 'Test'),
],
[
'test', true, false, ['test-group'], [['test-group', 'test', 2, 0, []]],
[
['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test']],
- ], [], true, $this->getUserMock('test', 'Test')
+ ], [], true, $this->getUserMock('test', 'Test'),
],
[
'test',
@@ -267,7 +277,7 @@ class UserPluginTest extends TestCase {
true,
['abc', 'xyz'],
[
- ['abc', 'test', 2, 0, ['test1' => 'Test One']],
+ ['abc', 'test', 2, 0, [$this->getUserMock('test1', 'Test One')]],
['xyz', 'test', 2, 0, []],
],
[],
@@ -283,7 +293,7 @@ class UserPluginTest extends TestCase {
false,
['abc', 'xyz'],
[
- ['abc', 'test', 2, 0, ['test1' => 'Test One']],
+ ['abc', 'test', 2, 0, [$this->getUserMock('test1', 'Test One')]],
['xyz', 'test', 2, 0, []],
],
[],
@@ -298,12 +308,12 @@ class UserPluginTest extends TestCase {
['abc', 'xyz'],
[
['abc', 'test', 2, 0, [
- 'test1' => 'Test One',
- 'test2' => 'Test Two',
+ $this->getUserMock('test1', 'Test One'),
+ $this->getUserMock('test2', 'Test Two'),
]],
['xyz', 'test', 2, 0, [
- 'test1' => 'Test One',
- 'test2' => 'Test Two',
+ $this->getUserMock('test1', 'Test One'),
+ $this->getUserMock('test2', 'Test Two'),
]],
],
[],
@@ -321,12 +331,12 @@ class UserPluginTest extends TestCase {
['abc', 'xyz'],
[
['abc', 'test', 2, 0, [
- 'test1' => 'Test One',
- 'test2' => 'Test Two',
+ $this->getUserMock('test1', 'Test One'),
+ $this->getUserMock('test2', 'Test Two'),
]],
['xyz', 'test', 2, 0, [
- 'test1' => 'Test One',
- 'test2' => 'Test Two',
+ $this->getUserMock('test1', 'Test One'),
+ $this->getUserMock('test2', 'Test Two'),
]],
],
[],
@@ -341,10 +351,10 @@ class UserPluginTest extends TestCase {
['abc', 'xyz'],
[
['abc', 'test', 2, 0, [
- 'test' => 'Test One',
+ $this->getUserMock('test', 'Test One'),
]],
['xyz', 'test', 2, 0, [
- 'test2' => 'Test Two',
+ $this->getUserMock('test2', 'Test Two'),
]],
],
[
@@ -363,10 +373,10 @@ class UserPluginTest extends TestCase {
['abc', 'xyz'],
[
['abc', 'test', 2, 0, [
- 'test' => 'Test One',
+ $this->getUserMock('test', 'Test One'),
]],
['xyz', 'test', 2, 0, [
- 'test2' => 'Test Two',
+ $this->getUserMock('test2', 'Test Two'),
]],
],
[
@@ -410,31 +420,36 @@ class UserPluginTest extends TestCase {
->method('getUser')
->willReturn($this->user);
- if(!$shareWithGroupOnly) {
+ if (!$shareWithGroupOnly) {
$this->userManager->expects($this->once())
->method('searchDisplayName')
->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->expects($this->exactly(2))
- ->method('getUserGroupIds')
- ->withConsecutive(
- [$this->user],
- [$singleUser]
- )
+ $this->groupManager->method('getUserGroups')
+ ->with($this->user)
+ ->willReturn($groups);
+
+ $this->groupManager->method('getUserGroupIds')
+ ->with($singleUser)
->willReturn($groupResponse);
} else {
$this->groupManager->expects($this->once())
- ->method('getUserGroupIds')
+ ->method('getUserGroups')
->with($this->user)
- ->willReturn($groupResponse);
+ ->willReturn($groups);
}
- $this->groupManager->expects($this->exactly(sizeof($groupResponse)))
- ->method('displayNamesInGroup')
- ->with($this->anything(), $searchTerm, $this->limit, $this->offset)
- ->willReturnMap($userResponse);
+ foreach ($userResponse as $groupDefinition) {
+ [$gid, $search, $limit, $offset, $users] = $groupDefinition;
+ $groups[$gid]->method('searchDisplayName')
+ ->with($search, $limit, $offset)
+ ->willReturn($users);
+ }
}
if ($singleUser !== false) {
@@ -457,24 +472,24 @@ class UserPluginTest extends TestCase {
$inputUsers = [
'alice' => 'Alice',
'bob' => 'Bob',
- 'carol' => 'Carol'
+ 'carol' => 'Carol',
];
return [
[
$inputUsers,
['alice', 'carol'],
- 'bob'
+ 'bob',
],
[
$inputUsers,
['alice', 'bob', 'carol'],
- 'dave'
+ 'dave',
],
[
$inputUsers,
['alice', 'bob', 'carol'],
- null
- ]
+ null,
+ ],
];
}
@@ -489,8 +504,8 @@ class UserPluginTest extends TestCase {
$this->session->expects($this->once())
->method('getUser')
- ->willReturnCallback(function() use ($currentUserId) {
- if($currentUserId !== null) {
+ ->willReturnCallback(function () use ($currentUserId) {
+ if ($currentUserId !== null) {
return $this->getUserMock($currentUserId, $currentUserId);
}
return null;
@@ -506,55 +521,55 @@ class UserPluginTest extends TestCase {
'test',
['groupA'],
[
- [ 'uid' => 'test1', 'groups' => ['groupA'] ],
- [ 'uid' => 'test2', 'groups' => ['groupB'] ]
+ ['uid' => 'test1', 'groups' => ['groupA']],
+ ['uid' => 'test2', 'groups' => ['groupB']],
],
- ['test1']
+ ['test1'],
],
[
'test',
['groupA'],
[
- [ 'uid' => 'test1', 'groups' => ['groupA'] ],
- [ 'uid' => 'test2', 'groups' => ['groupB', 'groupA'] ]
+ ['uid' => 'test1', 'groups' => ['groupA']],
+ ['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
],
- ['test1', 'test2']
+ ['test1', 'test2'],
],
[
'test',
['groupA'],
[
- [ 'uid' => 'test1', 'groups' => ['groupA', 'groupC'] ],
- [ 'uid' => 'test2', 'groups' => ['groupB', 'groupA'] ]
+ ['uid' => 'test1', 'groups' => ['groupA', 'groupC']],
+ ['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
],
- ['test1', 'test2']
+ ['test1', 'test2'],
],
[
'test',
['groupC', 'groupB'],
[
- [ 'uid' => 'test1', 'groups' => ['groupA', 'groupC'] ],
- [ 'uid' => 'test2', 'groups' => ['groupB', 'groupA'] ]
+ ['uid' => 'test1', 'groups' => ['groupA', 'groupC']],
+ ['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
],
- ['test1', 'test2']
+ ['test1', 'test2'],
],
[
'test',
[],
[
- [ 'uid' => 'test1', 'groups' => ['groupA'] ],
- [ 'uid' => 'test2', 'groups' => ['groupB', 'groupA'] ]
+ ['uid' => 'test1', 'groups' => ['groupA']],
+ ['uid' => 'test2', 'groups' => ['groupB', 'groupA']],
],
- []
+ [],
],
[
'test',
['groupC', 'groupB'],
[
- [ 'uid' => 'test1', 'groups' => [] ],
- [ 'uid' => 'test2', 'groups' => [] ]
+ ['uid' => 'test1', 'groups' => []],
+ ['uid' => 'test2', 'groups' => []],
],
- []
+ [],
],
];
}
@@ -570,7 +585,7 @@ class UserPluginTest extends TestCase {
}, $matchingUsers);
$mappedResult = array_map(function ($user) {
- return ['label' => $user, 'value' => [ 'shareType' => 0, 'shareWith' => $user ]];
+ return ['label' => $user, 'value' => ['shareType' => 0, 'shareWith' => $user]];
}, $result);
$this->userManager->expects($this->once())