]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix unit tests 21452/head
authorJoas Schilling <coding@schilljs.com>
Thu, 18 Jun 2020 09:33:43 +0000 (11:33 +0200)
committerJoas Schilling <coding@schilljs.com>
Thu, 18 Jun 2020 09:33:43 +0000 (11:33 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/private/Collaboration/Collaborators/UserPlugin.php
tests/lib/Collaboration/Collaborators/UserPluginTest.php

index 946baf687c59305c143a3e6835c3a8a47b163fea..123fa7314455fc1b3068143bb6237f7fc0588486 100644 (file)
@@ -153,7 +153,7 @@ class UserPlugin implements ISearchPlugin {
 
                                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);
                                }
 
index 0256c1eb157c7f5b03f3474b85710f4d298cd2bb..40813c82850d96da5e161c54728f537b9293f368 100644 (file)
@@ -275,7 +275,7 @@ class UserPluginTest extends TestCase {
                                true,
                                ['abc', 'xyz'],
                                [
-                                       ['abc', 'test', 2, 0, [$this->getUserMock('test1', 'Test One')]],
+                                       ['abc', 'test', 2, 0, ['test1' => 'Test One']],
                                        ['xyz', 'test', 2, 0, []],
                                ],
                                [],
@@ -284,6 +284,7 @@ class UserPluginTest extends TestCase {
                                ],
                                true,
                                false,
+                               [['test1', $this->getUserMock('test1', 'Test One')]],
                        ],
                        [
                                'test',
@@ -291,13 +292,14 @@ class UserPluginTest extends TestCase {
                                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',
@@ -306,12 +308,12 @@ class UserPluginTest extends TestCase {
                                ['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',
                                        ]],
                                ],
                                [],
@@ -321,6 +323,10 @@ class UserPluginTest extends TestCase {
                                ],
                                false,
                                false,
+                               [
+                                       ['test1', $this->getUserMock('test1', 'Test One')],
+                                       ['test2', $this->getUserMock('test2', 'Test Two')],
+                               ],
                        ],
                        [
                                'test',
@@ -329,18 +335,22 @@ class UserPluginTest extends TestCase {
                                ['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',
@@ -349,10 +359,10 @@ class UserPluginTest extends TestCase {
                                ['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',
                                        ]],
                                ],
                                [
@@ -363,6 +373,10 @@ class UserPluginTest extends TestCase {
                                ],
                                false,
                                false,
+                               [
+                                       ['test', $this->getUserMock('test', 'Test One')],
+                                       ['test2', $this->getUserMock('test2', 'Test Two')],
+                               ],
                        ],
                        [
                                'test',
@@ -371,10 +385,10 @@ class UserPluginTest extends TestCase {
                                ['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',
                                        ]],
                                ],
                                [
@@ -383,6 +397,10 @@ class UserPluginTest extends TestCase {
                                [],
                                true,
                                false,
+                               [
+                                       ['test', $this->getUserMock('test', 'Test One')],
+                                       ['test2', $this->getUserMock('test2', 'Test Two')],
+                               ],
                        ],
                ];
        }
@@ -399,6 +417,7 @@ class UserPluginTest extends TestCase {
         * @param array $expected
         * @param bool $reachedEnd
         * @param bool|IUser $singleUser
+        * @param array $users
         */
        public function testSearch(
                $searchTerm,
@@ -409,7 +428,8 @@ class UserPluginTest extends TestCase {
                array $exactExpected,
                array $expected,
                $reachedEnd,
-               $singleUser
+               $singleUser,
+               array $users = []
        ) {
                $this->mockConfig($shareWithGroupOnly, $shareeEnumeration, false);
                $this->instantiatePlugin();
@@ -424,39 +444,29 @@ class UserPluginTest extends TestCase {
                                ->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();