diff options
Diffstat (limited to 'tests/lib/Collaboration/Collaborators/GroupPluginTest.php')
-rw-r--r-- | tests/lib/Collaboration/Collaborators/GroupPluginTest.php | 145 |
1 files changed, 72 insertions, 73 deletions
diff --git a/tests/lib/Collaboration/Collaborators/GroupPluginTest.php b/tests/lib/Collaboration/Collaborators/GroupPluginTest.php index 2f7cd1061e9..a4ecd598562 100644 --- a/tests/lib/Collaboration/Collaborators/GroupPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/GroupPluginTest.php @@ -1,24 +1,8 @@ <?php + /** - * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace Test\Collaboration\Collaborators; @@ -35,19 +19,19 @@ use OCP\Share\IShare; use Test\TestCase; class GroupPluginTest extends TestCase { - /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ protected $config; - /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ protected $groupManager; - /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */ protected $session; - /** @var ISearchResult */ + /** @var ISearchResult */ protected $searchResult; - /** @var GroupPlugin */ + /** @var GroupPlugin */ protected $plugin; /** @var int */ @@ -56,7 +40,7 @@ class GroupPluginTest extends TestCase { /** @var int */ protected $offset = 0; - /** @var IUser|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IUser|\PHPUnit\Framework\MockObject\MockObject */ protected $user; protected function setUp(): void { @@ -125,13 +109,15 @@ class GroupPluginTest extends TestCase { return $group; } - public function dataGetGroups() { + public function dataGetGroups(): array { return [ - ['test', false, true, [], [], [], [], true, false], - ['test', false, false, [], [], [], [], true, false], + ['test', false, true, false, [], [], [], [], true, false], + ['test', false, false, false, [], [], [], [], true, false], + // group sharing disabled + ['test', false, true, true, [], [], [], [], false, false], // group without display name [ - 'test', false, true, + 'test', false, true, false, [$this->getGroupMock('test1')], [], [], @@ -141,7 +127,7 @@ class GroupPluginTest extends TestCase { ], // group with display name, search by id [ - 'test', false, true, + 'test', false, true, false, [$this->getGroupMock('test1', 'Test One')], [], [], @@ -151,7 +137,7 @@ class GroupPluginTest extends TestCase { ], // group with display name, search by display name [ - 'one', false, true, + 'one', false, true, false, [$this->getGroupMock('test1', 'Test One')], [], [], @@ -161,7 +147,7 @@ class GroupPluginTest extends TestCase { ], // group with display name, search by display name, exact expected [ - 'Test One', false, true, + 'Test One', false, true, false, [$this->getGroupMock('test1', 'Test One')], [], [['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_GROUP, 'shareWith' => 'test1']]], @@ -170,7 +156,7 @@ class GroupPluginTest extends TestCase { false, ], [ - 'test', false, false, + 'test', false, false, false, [$this->getGroupMock('test1')], [], [], @@ -179,7 +165,7 @@ class GroupPluginTest extends TestCase { false, ], [ - 'test', false, true, + 'test', false, true, false, [ $this->getGroupMock('test'), $this->getGroupMock('test1'), @@ -191,7 +177,7 @@ class GroupPluginTest extends TestCase { false, ], [ - 'test', false, false, + 'test', false, false, false, [ $this->getGroupMock('test'), $this->getGroupMock('test1'), @@ -203,7 +189,7 @@ class GroupPluginTest extends TestCase { false, ], [ - 'test', false, true, + 'test', false, true, false, [ $this->getGroupMock('test0'), $this->getGroupMock('test1'), @@ -218,7 +204,7 @@ class GroupPluginTest extends TestCase { null, ], [ - 'test', false, false, + 'test', false, false, false, [ $this->getGroupMock('test0'), $this->getGroupMock('test1'), @@ -230,7 +216,7 @@ class GroupPluginTest extends TestCase { null, ], [ - 'test', false, true, + 'test', false, true, false, [ $this->getGroupMock('test0'), $this->getGroupMock('test1'), @@ -247,7 +233,7 @@ class GroupPluginTest extends TestCase { $this->getGroupMock('test'), ], [ - 'test', false, false, + 'test', false, false, false, [ $this->getGroupMock('test0'), $this->getGroupMock('test1'), @@ -260,10 +246,10 @@ class GroupPluginTest extends TestCase { true, $this->getGroupMock('test'), ], - ['test', true, true, [], [], [], [], true, false], - ['test', true, false, [], [], [], [], true, false], + ['test', true, true, false, [], [], [], [], true, false], + ['test', true, false, false, [], [], [], [], true, false], [ - 'test', true, true, + 'test', true, true, false, [ $this->getGroupMock('test1'), $this->getGroupMock('test2'), @@ -275,7 +261,7 @@ class GroupPluginTest extends TestCase { false, ], [ - 'test', true, false, + 'test', true, false, false, [ $this->getGroupMock('test1'), $this->getGroupMock('test2'), @@ -287,7 +273,7 @@ class GroupPluginTest extends TestCase { false, ], [ - 'test', true, true, + 'test', true, true, false, [ $this->getGroupMock('test'), $this->getGroupMock('test1'), @@ -299,7 +285,7 @@ class GroupPluginTest extends TestCase { false, ], [ - 'test', true, false, + 'test', true, false, false, [ $this->getGroupMock('test'), $this->getGroupMock('test1'), @@ -311,7 +297,7 @@ class GroupPluginTest extends TestCase { false, ], [ - 'test', true, true, + 'test', true, true, false, [ $this->getGroupMock('test'), $this->getGroupMock('test1'), @@ -323,7 +309,7 @@ class GroupPluginTest extends TestCase { false, ], [ - 'test', true, false, + 'test', true, false, false, [ $this->getGroupMock('test'), $this->getGroupMock('test1'), @@ -335,7 +321,7 @@ class GroupPluginTest extends TestCase { false, ], [ - 'test', true, true, + 'test', true, true, false, [ $this->getGroupMock('test'), $this->getGroupMock('test1'), @@ -347,7 +333,7 @@ class GroupPluginTest extends TestCase { false, ], [ - 'test', true, false, + 'test', true, false, false, [ $this->getGroupMock('test'), $this->getGroupMock('test1'), @@ -359,7 +345,7 @@ class GroupPluginTest extends TestCase { false, ], [ - 'test', true, true, + 'test', true, true, false, [ $this->getGroupMock('test0'), $this->getGroupMock('test1'), @@ -374,7 +360,7 @@ class GroupPluginTest extends TestCase { null, ], [ - 'test', true, false, + 'test', true, false, false, [ $this->getGroupMock('test0'), $this->getGroupMock('test1'), @@ -386,7 +372,7 @@ class GroupPluginTest extends TestCase { null, ], [ - 'test', true, true, + 'test', true, true, false, [ $this->getGroupMock('test0'), $this->getGroupMock('test1'), @@ -403,7 +389,7 @@ class GroupPluginTest extends TestCase { $this->getGroupMock('test'), ], [ - 'test', true, false, + 'test', true, false, false, [ $this->getGroupMock('test0'), $this->getGroupMock('test1'), @@ -417,7 +403,7 @@ class GroupPluginTest extends TestCase { $this->getGroupMock('test'), ], [ - 'test', false, false, + 'test', false, false, false, [ $this->getGroupMock('test', null, true), $this->getGroupMock('test1'), @@ -432,11 +418,11 @@ class GroupPluginTest extends TestCase { } /** - * @dataProvider dataGetGroups * * @param string $searchTerm * @param bool $shareWithGroupOnly * @param bool $shareeEnumeration + * @param bool $groupSharingDisabled * @param array $groupResponse * @param array $userGroupsResponse * @param array $exactExpected @@ -444,36 +430,47 @@ class GroupPluginTest extends TestCase { * @param bool $reachedEnd * @param bool|IGroup $singleGroup */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetGroups')] public function testSearch( - $searchTerm, - $shareWithGroupOnly, - $shareeEnumeration, + string $searchTerm, + bool $shareWithGroupOnly, + bool $shareeEnumeration, + bool $groupSharingDisabled, array $groupResponse, array $userGroupsResponse, array $exactExpected, array $expected, - $reachedEnd, - $singleGroup - ) { + bool $reachedEnd, + $singleGroup, + ): void { $this->config->expects($this->any()) ->method('getAppValue') ->willReturnCallback( - function ($appName, $key, $default) use ($shareWithGroupOnly, $shareeEnumeration) { - 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'; + function ($appName, $key, $default) use ($shareWithGroupOnly, $shareeEnumeration, $groupSharingDisabled) { + if ($appName !== 'core') { + return $default; + } + switch ($key) { + case 'shareapi_only_share_with_group_members': + return $shareWithGroupOnly ? 'yes' : 'no'; + case 'shareapi_allow_share_dialog_user_enumeration': + return $shareeEnumeration ? 'yes' : 'no'; + case 'shareapi_allow_group_sharing': + return $groupSharingDisabled ? 'no' : 'yes'; + default: + return $default; } - return $default; } ); $this->instantiatePlugin(); - $this->groupManager->expects($this->once()) - ->method('search') - ->with($searchTerm, $this->limit, $this->offset) - ->willReturn($groupResponse); + if (!$groupSharingDisabled) { + $this->groupManager->expects($this->once()) + ->method('search') + ->with($searchTerm, $this->limit, $this->offset) + ->willReturn($groupResponse); + } if ($singleGroup !== false) { $this->groupManager->expects($this->once()) @@ -497,8 +494,10 @@ class GroupPluginTest extends TestCase { $moreResults = $this->plugin->search($searchTerm, $this->limit, $this->offset, $this->searchResult); $result = $this->searchResult->asArray(); - $this->assertEquals($exactExpected, $result['exact']['groups']); - $this->assertEquals($expected, $result['groups']); + if (!$groupSharingDisabled) { + $this->assertEquals($exactExpected, $result['exact']['groups']); + $this->assertEquals($expected, $result['groups']); + } $this->assertSame($reachedEnd, $moreResults); } } |