diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2021-03-17 15:22:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-17 15:22:03 +0100 |
commit | 0d46fafd41a739c74a500d6149af23deb9d70155 (patch) | |
tree | fc14e854db1f5850d4dcdd389c4768b806c96d16 /tests | |
parent | d011df6aa7a38fdfafe6bc0acddebe9e156918d8 (diff) | |
parent | cf434d5107acc95d8a6afad15707e3e4fc33bbc9 (diff) | |
download | nextcloud-server-0d46fafd41a739c74a500d6149af23deb9d70155.tar.gz nextcloud-server-0d46fafd41a739c74a500d6149af23deb9d70155.zip |
Merge pull request #26161 from nextcloud/bugfix/noid/improve-matching-of-phonebook-searches
Improve search results when only phonebook-matches can we autocompleted
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Collaboration/Collaborators/UserPluginTest.php | 76 |
1 files changed, 63 insertions, 13 deletions
diff --git a/tests/lib/Collaboration/Collaborators/UserPluginTest.php b/tests/lib/Collaboration/Collaborators/UserPluginTest.php index f2e0e7e274b..acbcd42f04f 100644 --- a/tests/lib/Collaboration/Collaborators/UserPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/UserPluginTest.php @@ -104,17 +104,19 @@ class UserPluginTest extends TestCase { ); } - public function mockConfig($shareWithGroupOnly, $shareeEnumeration, $shareeEnumerationLimitToGroup) { + public function mockConfig($shareWithGroupOnly, $shareeEnumeration, $shareeEnumerationLimitToGroup, $shareeEnumerationPhone = false) { $this->config->expects($this->any()) ->method('getAppValue') ->willReturnCallback( - function ($appName, $key, $default) use ($shareWithGroupOnly, $shareeEnumeration, $shareeEnumerationLimitToGroup) { + function ($appName, $key, $default) use ($shareWithGroupOnly, $shareeEnumeration, $shareeEnumerationLimitToGroup, $shareeEnumerationPhone) { if ($appName === 'core' && $key === 'shareapi_only_share_with_group_members') { return $shareWithGroupOnly ? 'yes' : 'no'; } elseif ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') { return $shareeEnumeration ? 'yes' : 'no'; } elseif ($appName === 'core' && $key === 'shareapi_restrict_user_enumeration_to_group') { return $shareeEnumerationLimitToGroup ? 'yes' : 'no'; + } elseif ($appName === 'core' && $key === 'shareapi_restrict_user_enumeration_to_phone') { + return $shareeEnumerationPhone ? 'yes' : 'no'; } return $default; } @@ -269,6 +271,28 @@ class UserPluginTest extends TestCase { [ 'test', false, + true, + [], + [ + $this->getUserMock('test0', 'Test'), + $this->getUserMock('test1', 'Test One'), + $this->getUserMock('test2', 'Test Two'), + ], + [ + ['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test0'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test0'], + ], + [ + ['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test1'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test1'], + ['label' => 'Test Two', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test2'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test2'], + ], + false, + false, + [], + true, + ], + [ + 'test', + false, false, [], [ @@ -443,9 +467,10 @@ class UserPluginTest extends TestCase { array $expected, $reachedEnd, $singleUser, - array $users = [] + array $users = [], + $shareeEnumerationPhone = false ) { - $this->mockConfig($shareWithGroupOnly, $shareeEnumeration, false); + $this->mockConfig($shareWithGroupOnly, $shareeEnumeration, false, $shareeEnumerationPhone); $this->instantiatePlugin(); $this->session->expects($this->any()) @@ -453,10 +478,24 @@ class UserPluginTest extends TestCase { ->willReturn($this->user); if (!$shareWithGroupOnly) { - $this->userManager->expects($this->once()) - ->method('searchDisplayName') - ->with($searchTerm, $this->limit, $this->offset) - ->willReturn($userResponse); + if ($shareeEnumerationPhone) { + $this->userManager->expects($this->once()) + ->method('searchKnownUsersByDisplayName') + ->with($this->user->getUID(), $searchTerm, $this->limit, $this->offset) + ->willReturn($userResponse); + + $this->knownUserService->method('isKnownToUser') + ->willReturnMap([ + [$this->user->getUID(), 'test0', true], + [$this->user->getUID(), 'test1', true], + [$this->user->getUID(), 'test2', true], + ]); + } else { + $this->userManager->expects($this->once()) + ->method('searchDisplayName') + ->with($searchTerm, $this->limit, $this->offset) + ->willReturn($userResponse); + } } else { $this->groupManager->method('getUserGroupIds') ->with($this->user) @@ -620,9 +659,10 @@ class UserPluginTest extends TestCase { public function testSearchEnumerationLimit($search, $userGroups, $matchingUsers, $result) { $this->mockConfig(false, true, true); - $userResults = array_map(function ($user) { - return $this->getUserMock($user['uid'], $user['uid']); - }, $matchingUsers); + $userResults = []; + foreach ($matchingUsers as $user) { + $userResults[$user['uid']] = $user['uid']; + } $mappedResultExact = array_map(function ($user) { return ['label' => $user, 'value' => ['shareType' => 0, 'shareWith' => $user], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => $user]; @@ -631,9 +671,19 @@ class UserPluginTest extends TestCase { return ['label' => $user, 'value' => ['shareType' => 0, 'shareWith' => $user], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => $user]; }, $result['wide']); - $this->userManager->expects($this->once()) - ->method('searchDisplayName') + $this->userManager + ->method('get') + ->willReturnCallback(function ($userId) use ($userResults) { + if (isset($userResults[$userId])) { + return $this->getUserMock($userId, $userId); + } + return null; + }); + + $this->groupManager->method('displayNamesInGroup') ->willReturn($userResults); + + $this->session->expects($this->any()) ->method('getUser') ->willReturn($this->getUserMock('test', 'foo')); |