aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Group
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Group')
-rw-r--r--tests/lib/Group/Backend.php40
-rw-r--r--tests/lib/Group/DatabaseTest.php49
-rw-r--r--tests/lib/Group/Dummy.php22
-rw-r--r--tests/lib/Group/GroupTest.php117
-rw-r--r--tests/lib/Group/HideFromCollaborationTest.php53
-rw-r--r--tests/lib/Group/ManagerTest.php377
-rw-r--r--tests/lib/Group/MetaDataTest.php62
7 files changed, 363 insertions, 357 deletions
diff --git a/tests/lib/Group/Backend.php b/tests/lib/Group/Backend.php
index 541ed78719b..3c068d8d64b 100644
--- a/tests/lib/Group/Backend.php
+++ b/tests/lib/Group/Backend.php
@@ -1,27 +1,9 @@
<?php
+
/**
- * @author Arthur Schiwon <blizzz@owncloud.com>
- * @author Felix Moeller <mail@felixmoeller.de>
- * @author Joas Schilling <nickvergessen@owncloud.com>
- * @author Robin Appelman <icewind@owncloud.com>
- * @author Scrutinizer Auto-Fixer <auto-fixer@scrutinizer-ci.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * 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, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace Test\Group;
@@ -61,7 +43,7 @@ abstract class Backend extends \Test\TestCase {
return $this->getUniqueID('test_');
}
- public function testAddRemove() {
+ public function testAddRemove(): void {
//get the number of groups we start with, in case there are exising groups
$startCount = count($this->backend->getGroups());
@@ -85,7 +67,7 @@ abstract class Backend extends \Test\TestCase {
$this->assertFalse((array_search($name2, $this->backend->getGroups()) !== false));
}
- public function testUser() {
+ public function testUser(): void {
$group1 = $this->getGroupName();
$group2 = $this->getGroupName();
$this->backend->createGroup($group1);
@@ -120,20 +102,20 @@ abstract class Backend extends \Test\TestCase {
$this->assertFalse($this->backend->inGroup($user1, $group1));
}
- public function testSearchGroups() {
+ public function testSearchGroups(): void {
$name1 = $this->getGroupName('foobarbaz');
- $name2 = $this->getGroupName('bazbarfoo');
+ $name2 = $this->getGroupName('bazfoobarfoo');
$name3 = $this->getGroupName('notme');
$this->backend->createGroup($name1);
$this->backend->createGroup($name2);
$this->backend->createGroup($name3);
- $result = $this->backend->getGroups('bar');
+ $result = $this->backend->getGroups('foobar');
$this->assertSame(2, count($result));
}
- public function testSearchUsers() {
+ public function testSearchUsers(): void {
$group = $this->getGroupName();
$this->backend->createGroup($group);
@@ -152,7 +134,7 @@ abstract class Backend extends \Test\TestCase {
$this->assertSame(2, $result);
}
- public function testAddDouble() {
+ public function testAddDouble(): void {
$group = $this->getGroupName();
$this->backend->createGroup($group);
diff --git a/tests/lib/Group/DatabaseTest.php b/tests/lib/Group/DatabaseTest.php
index 586d77e0ec0..ee6b4156040 100644
--- a/tests/lib/Group/DatabaseTest.php
+++ b/tests/lib/Group/DatabaseTest.php
@@ -1,30 +1,15 @@
<?php
+
/**
- * @author Arthur Schiwon <blizzz@owncloud.com>
- * @author Joas Schilling <nickvergessen@owncloud.com>
- * @author Robin Appelman <icewind@owncloud.com>
- * @author Scrutinizer Auto-Fixer <auto-fixer@scrutinizer-ci.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * 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, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace Test\Group;
+use OC\Group\Database;
+
/**
* Class Database
*
@@ -36,10 +21,8 @@ class DatabaseTest extends Backend {
/**
* get a new unique group name
* test cases can override this in order to clean up created groups
- *
- * @return string
*/
- public function getGroupName($name = null) {
+ public function getGroupName($name = null): string {
$name = parent::getGroupName($name);
$this->groups[] = $name;
return $name;
@@ -47,7 +30,7 @@ class DatabaseTest extends Backend {
protected function setUp(): void {
parent::setUp();
- $this->backend = new \OC\Group\Database();
+ $this->backend = new Database();
}
protected function tearDown(): void {
@@ -57,12 +40,22 @@ class DatabaseTest extends Backend {
parent::tearDown();
}
- public function testAddDoubleNoCache() {
+ public function testAddDoubleNoCache(): void {
$group = $this->getGroupName();
$this->backend->createGroup($group);
- $backend = new \OC\Group\Database();
- $this->assertFalse($backend->createGroup($group));
+ $backend = new Database();
+ $this->assertNull($backend->createGroup($group));
+ }
+
+ public function testAddLongGroupName(): void {
+ $groupName = $this->getUniqueID('test_', 100);
+
+ $gidCreated = $this->backend->createGroup($groupName);
+ $this->assertEquals(64, strlen($gidCreated));
+
+ $group = $this->backend->getGroupDetails($gidCreated);
+ $this->assertEquals(['displayName' => $groupName], $group);
}
}
diff --git a/tests/lib/Group/Dummy.php b/tests/lib/Group/Dummy.php
index d2d8b6332dd..5f2a81cf0aa 100644
--- a/tests/lib/Group/Dummy.php
+++ b/tests/lib/Group/Dummy.php
@@ -1,23 +1,9 @@
<?php
+
/**
- * ownCloud
- *
- * @author Robin Appelman
- * @copyright 2012 Robin Appelman icewind@owncloud.com
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This library 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 library. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Group;
diff --git a/tests/lib/Group/GroupTest.php b/tests/lib/Group/GroupTest.php
index b85496620b8..baae814675c 100644
--- a/tests/lib/Group/GroupTest.php
+++ b/tests/lib/Group/GroupTest.php
@@ -1,27 +1,26 @@
<?php
/**
- * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Group;
+use OC\Group\Group;
use OC\User\User;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUser;
use PHPUnit\Framework\MockObject\MockObject;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class GroupTest extends \Test\TestCase {
-
- /** @var EventDispatcherInterface|MockObject */
+ /** @var IEventDispatcher|MockObject */
protected $dispatcher;
protected function setUp(): void {
parent::setUp();
- $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->dispatcher = $this->createMock(IEventDispatcher::class);
}
/**
@@ -62,12 +61,12 @@ class GroupTest extends \Test\TestCase {
return $userManager;
}
- public function testGetUsersSingleBackend() {
+ public function testGetUsersSingleBackend(): void {
$backend = $this->getMockBuilder('OC\Group\Database')
->disableOriginalConstructor()
->getMock();
$userManager = $this->getUserManager();
- $group = new \OC\Group\Group('group1', [$backend], $this->dispatcher, $userManager);
+ $group = new Group('group1', [$backend], $this->dispatcher, $userManager);
$backend->expects($this->once())
->method('usersInGroup')
@@ -83,7 +82,7 @@ class GroupTest extends \Test\TestCase {
$this->assertEquals('user2', $user2->getUID());
}
- public function testGetUsersMultipleBackends() {
+ public function testGetUsersMultipleBackends(): void {
$backend1 = $this->getMockBuilder('OC\Group\Database')
->disableOriginalConstructor()
->getMock();
@@ -91,7 +90,7 @@ class GroupTest extends \Test\TestCase {
->disableOriginalConstructor()
->getMock();
$userManager = $this->getUserManager();
- $group = new \OC\Group\Group('group1', [$backend1, $backend2], $this->dispatcher, $userManager);
+ $group = new Group('group1', [$backend1, $backend2], $this->dispatcher, $userManager);
$backend1->expects($this->once())
->method('usersInGroup')
@@ -114,7 +113,7 @@ class GroupTest extends \Test\TestCase {
$this->assertEquals('user3', $user3->getUID());
}
- public function testInGroupSingleBackend() {
+ public function testInGroupSingleBackend(): void {
$backend = $this->getMockBuilder('OC\Group\Database')
->disableOriginalConstructor()
->getMock();
@@ -122,7 +121,7 @@ class GroupTest extends \Test\TestCase {
$userBackend = $this->getMockBuilder('\OC\User\Backend')
->disableOriginalConstructor()
->getMock();
- $group = new \OC\Group\Group('group1', [$backend], $this->dispatcher, $userManager);
+ $group = new Group('group1', [$backend], $this->dispatcher, $userManager);
$backend->expects($this->once())
->method('inGroup')
@@ -132,7 +131,7 @@ class GroupTest extends \Test\TestCase {
$this->assertTrue($group->inGroup($this->newUser('user1', $userBackend)));
}
- public function testInGroupMultipleBackends() {
+ public function testInGroupMultipleBackends(): void {
$backend1 = $this->getMockBuilder('OC\Group\Database')
->disableOriginalConstructor()
->getMock();
@@ -143,7 +142,7 @@ class GroupTest extends \Test\TestCase {
$userBackend = $this->getMockBuilder(\OC\User\Backend::class)
->disableOriginalConstructor()
->getMock();
- $group = new \OC\Group\Group('group1', [$backend1, $backend2], $this->dispatcher, $userManager);
+ $group = new Group('group1', [$backend1, $backend2], $this->dispatcher, $userManager);
$backend1->expects($this->once())
->method('inGroup')
@@ -158,7 +157,7 @@ class GroupTest extends \Test\TestCase {
$this->assertTrue($group->inGroup($this->newUser('user1', $userBackend)));
}
- public function testAddUser() {
+ public function testAddUser(): void {
$backend = $this->getMockBuilder('OC\Group\Database')
->disableOriginalConstructor()
->getMock();
@@ -166,7 +165,7 @@ class GroupTest extends \Test\TestCase {
$userBackend = $this->getMockBuilder('\OC\User\Backend')
->disableOriginalConstructor()
->getMock();
- $group = new \OC\Group\Group('group1', [$backend], $this->dispatcher, $userManager);
+ $group = new Group('group1', [$backend], $this->dispatcher, $userManager);
$backend->expects($this->once())
->method('inGroup')
@@ -183,7 +182,7 @@ class GroupTest extends \Test\TestCase {
$group->addUser($this->newUser('user1', $userBackend));
}
- public function testAddUserAlreadyInGroup() {
+ public function testAddUserAlreadyInGroup(): void {
$backend = $this->getMockBuilder('OC\Group\Database')
->disableOriginalConstructor()
->getMock();
@@ -191,7 +190,7 @@ class GroupTest extends \Test\TestCase {
$userBackend = $this->getMockBuilder('\OC\User\Backend')
->disableOriginalConstructor()
->getMock();
- $group = new \OC\Group\Group('group1', [$backend], $this->dispatcher, $userManager);
+ $group = new Group('group1', [$backend], $this->dispatcher, $userManager);
$backend->expects($this->once())
->method('inGroup')
@@ -207,7 +206,7 @@ class GroupTest extends \Test\TestCase {
$group->addUser($this->newUser('user1', $userBackend));
}
- public function testRemoveUser() {
+ public function testRemoveUser(): void {
$backend = $this->getMockBuilder('OC\Group\Database')
->disableOriginalConstructor()
->getMock();
@@ -215,7 +214,7 @@ class GroupTest extends \Test\TestCase {
$userBackend = $this->getMockBuilder('\OC\User\Backend')
->disableOriginalConstructor()
->getMock();
- $group = new \OC\Group\Group('group1', [$backend], $this->dispatcher, $userManager);
+ $group = new Group('group1', [$backend], $this->dispatcher, $userManager);
$backend->expects($this->once())
->method('inGroup')
@@ -232,7 +231,7 @@ class GroupTest extends \Test\TestCase {
$group->removeUser($this->newUser('user1', $userBackend));
}
- public function testRemoveUserNotInGroup() {
+ public function testRemoveUserNotInGroup(): void {
$backend = $this->getMockBuilder('OC\Group\Database')
->disableOriginalConstructor()
->getMock();
@@ -240,7 +239,7 @@ class GroupTest extends \Test\TestCase {
$userBackend = $this->getMockBuilder(\OC\User\Backend::class)
->disableOriginalConstructor()
->getMock();
- $group = new \OC\Group\Group('group1', [$backend], $this->dispatcher, $userManager);
+ $group = new Group('group1', [$backend], $this->dispatcher, $userManager);
$backend->expects($this->once())
->method('inGroup')
@@ -256,7 +255,7 @@ class GroupTest extends \Test\TestCase {
$group->removeUser($this->newUser('user1', $userBackend));
}
- public function testRemoveUserMultipleBackends() {
+ public function testRemoveUserMultipleBackends(): void {
$backend1 = $this->getMockBuilder('OC\Group\Database')
->disableOriginalConstructor()
->getMock();
@@ -267,7 +266,7 @@ class GroupTest extends \Test\TestCase {
$userBackend = $this->getMockBuilder('\OC\User\Backend')
->disableOriginalConstructor()
->getMock();
- $group = new \OC\Group\Group('group1', [$backend1, $backend2], $this->dispatcher, $userManager);
+ $group = new Group('group1', [$backend1, $backend2], $this->dispatcher, $userManager);
$backend1->expects($this->once())
->method('inGroup')
@@ -296,26 +295,26 @@ class GroupTest extends \Test\TestCase {
$group->removeUser($this->newUser('user1', $userBackend));
}
- public function testSearchUsers() {
+ public function testSearchUsers(): void {
$backend = $this->getMockBuilder('OC\Group\Database')
->disableOriginalConstructor()
->getMock();
$userManager = $this->getUserManager();
- $group = new \OC\Group\Group('group1', [$backend], $this->dispatcher, $userManager);
+ $group = new Group('group1', [$backend], $this->dispatcher, $userManager);
$backend->expects($this->once())
- ->method('usersInGroup')
+ ->method('searchInGroup')
->with('group1', '2')
- ->willReturn(['user2']);
+ ->willReturn(['user2' => new User('user2', null, $this->dispatcher)]);
$users = $group->searchUsers('2');
$this->assertEquals(1, count($users));
- $user2 = $users['user2'];
+ $user2 = reset($users);
$this->assertEquals('user2', $user2->getUID());
}
- public function testSearchUsersMultipleBackends() {
+ public function testSearchUsersMultipleBackends(): void {
$backend1 = $this->getMockBuilder('OC\Group\Database')
->disableOriginalConstructor()
->getMock();
@@ -323,44 +322,44 @@ class GroupTest extends \Test\TestCase {
->disableOriginalConstructor()
->getMock();
$userManager = $this->getUserManager();
- $group = new \OC\Group\Group('group1', [$backend1, $backend2], $this->dispatcher, $userManager);
+ $group = new Group('group1', [$backend1, $backend2], $this->dispatcher, $userManager);
$backend1->expects($this->once())
- ->method('usersInGroup')
+ ->method('searchInGroup')
->with('group1', '2')
- ->willReturn(['user2']);
+ ->willReturn(['user2' => new User('user2', null, $this->dispatcher)]);
$backend2->expects($this->once())
- ->method('usersInGroup')
+ ->method('searchInGroup')
->with('group1', '2')
- ->willReturn(['user2']);
+ ->willReturn(['user2' => new User('user2', null, $this->dispatcher)]);
$users = $group->searchUsers('2');
$this->assertEquals(1, count($users));
- $user2 = $users['user2'];
+ $user2 = reset($users);
$this->assertEquals('user2', $user2->getUID());
}
- public function testSearchUsersLimitAndOffset() {
+ public function testSearchUsersLimitAndOffset(): void {
$backend = $this->getMockBuilder('OC\Group\Database')
->disableOriginalConstructor()
->getMock();
$userManager = $this->getUserManager();
- $group = new \OC\Group\Group('group1', [$backend], $this->dispatcher, $userManager);
+ $group = new Group('group1', [$backend], $this->dispatcher, $userManager);
$backend->expects($this->once())
- ->method('usersInGroup')
+ ->method('searchInGroup')
->with('group1', 'user', 1, 1)
- ->willReturn(['user2']);
+ ->willReturn(['user2' => new User('user2', null, $this->dispatcher)]);
$users = $group->searchUsers('user', 1, 1);
$this->assertEquals(1, count($users));
- $user2 = $users['user2'];
+ $user2 = reset($users);
$this->assertEquals('user2', $user2->getUID());
}
- public function testSearchUsersMultipleBackendsLimitAndOffset() {
+ public function testSearchUsersMultipleBackendsLimitAndOffset(): void {
$backend1 = $this->getMockBuilder('OC\Group\Database')
->disableOriginalConstructor()
->getMock();
@@ -368,32 +367,32 @@ class GroupTest extends \Test\TestCase {
->disableOriginalConstructor()
->getMock();
$userManager = $this->getUserManager();
- $group = new \OC\Group\Group('group1', [$backend1, $backend2], $this->dispatcher, $userManager);
+ $group = new Group('group1', [$backend1, $backend2], $this->dispatcher, $userManager);
$backend1->expects($this->once())
- ->method('usersInGroup')
+ ->method('searchInGroup')
->with('group1', 'user', 2, 1)
- ->willReturn(['user2']);
+ ->willReturn(['user2' => new User('user2', null, $this->dispatcher)]);
$backend2->expects($this->once())
- ->method('usersInGroup')
+ ->method('searchInGroup')
->with('group1', 'user', 2, 1)
- ->willReturn(['user1']);
+ ->willReturn(['user1' => new User('user1', null, $this->dispatcher)]);
$users = $group->searchUsers('user', 2, 1);
$this->assertEquals(2, count($users));
- $user2 = $users['user2'];
- $user1 = $users['user1'];
+ $user2 = reset($users);
+ $user1 = next($users);
$this->assertEquals('user2', $user2->getUID());
$this->assertEquals('user1', $user1->getUID());
}
- public function testCountUsers() {
+ public function testCountUsers(): void {
$backend1 = $this->getMockBuilder('OC\Group\Database')
->disableOriginalConstructor()
->getMock();
$userManager = $this->getUserManager();
- $group = new \OC\Group\Group('group1', [$backend1], $this->dispatcher, $userManager);
+ $group = new Group('group1', [$backend1], $this->dispatcher, $userManager);
$backend1->expects($this->once())
->method('countUsersInGroup')
@@ -409,7 +408,7 @@ class GroupTest extends \Test\TestCase {
$this->assertSame(3, $users);
}
- public function testCountUsersMultipleBackends() {
+ public function testCountUsersMultipleBackends(): void {
$backend1 = $this->getMockBuilder('OC\Group\Database')
->disableOriginalConstructor()
->getMock();
@@ -417,7 +416,7 @@ class GroupTest extends \Test\TestCase {
->disableOriginalConstructor()
->getMock();
$userManager = $this->getUserManager();
- $group = new \OC\Group\Group('group1', [$backend1, $backend2], $this->dispatcher, $userManager);
+ $group = new Group('group1', [$backend1, $backend2], $this->dispatcher, $userManager);
$backend1->expects($this->once())
->method('countUsersInGroup')
@@ -440,12 +439,12 @@ class GroupTest extends \Test\TestCase {
$this->assertSame(7, $users);
}
- public function testCountUsersNoMethod() {
+ public function testCountUsersNoMethod(): void {
$backend1 = $this->getMockBuilder('OC\Group\Database')
->disableOriginalConstructor()
->getMock();
$userManager = $this->getUserManager();
- $group = new \OC\Group\Group('group1', [$backend1], $this->dispatcher, $userManager);
+ $group = new Group('group1', [$backend1], $this->dispatcher, $userManager);
$backend1->expects($this->never())
->method('countUsersInGroup');
@@ -458,12 +457,12 @@ class GroupTest extends \Test\TestCase {
$this->assertSame(false, $users);
}
- public function testDelete() {
+ public function testDelete(): void {
$backend = $this->getMockBuilder('OC\Group\Database')
->disableOriginalConstructor()
->getMock();
$userManager = $this->getUserManager();
- $group = new \OC\Group\Group('group1', [$backend], $this->dispatcher, $userManager);
+ $group = new Group('group1', [$backend], $this->dispatcher, $userManager);
$backend->expects($this->once())
->method('deleteGroup')
diff --git a/tests/lib/Group/HideFromCollaborationTest.php b/tests/lib/Group/HideFromCollaborationTest.php
new file mode 100644
index 00000000000..5ff7c797508
--- /dev/null
+++ b/tests/lib/Group/HideFromCollaborationTest.php
@@ -0,0 +1,53 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace Test\Group;
+
+use OC\Group\Group;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Group\Backend\ABackend;
+use OCP\Group\Backend\IHideFromCollaborationBackend;
+use OCP\IUserManager;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+abstract class HideFromCollaborationBackendTest extends ABackend implements IHideFromCollaborationBackend {
+
+}
+
+class HideFromCollaborationTest extends TestCase {
+
+ private IUserManager&MockObject $userManager;
+ private IEventDispatcher&MockObject $dispatcher;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->userManager = $this->createMock(IUserManager::class);
+ $this->dispatcher = $this->createMock(IEventDispatcher::class);
+ }
+
+
+ public function testHideFromCollaboration(): void {
+ // Arrange
+ $backend1 = $this->createMock(HideFromCollaborationBackendTest::class);
+ $backend1->method('hideGroup')
+ ->willReturn(false);
+ $backend2 = $this->createMock(HideFromCollaborationBackendTest::class);
+ $backend2->method('hideGroup')
+ ->willReturn(true);
+ $group = new Group('group1', [$backend1, $backend2], $this->dispatcher, $this->userManager);
+
+ // Act
+ $result = $group->hideFromCollaboration();
+
+ // Assert
+ $this->assertTrue($result);
+ }
+}
diff --git a/tests/lib/Group/ManagerTest.php b/tests/lib/Group/ManagerTest.php
index d689fd4eb7a..8515ef0e3e8 100644
--- a/tests/lib/Group/ManagerTest.php
+++ b/tests/lib/Group/ManagerTest.php
@@ -1,51 +1,57 @@
<?php
/**
- * @author Robin Appelman <icewind@owncloud.com>
- * @author Vincent Petry <pvince81@owncloud.com>
- *
- * @copyright Copyright (c) 2016, ownCloud GmbH.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * 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, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace Test\Group;
use OC\Group\Database;
use OC\User\Manager;
+use OC\User\User;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Group\Backend\ABackend;
+use OCP\Group\Backend\IAddToGroupBackend;
+use OCP\Group\Backend\ICreateGroupBackend;
+use OCP\Group\Backend\IGroupDetailsBackend;
+use OCP\Group\Backend\IRemoveFromGroupBackend;
+use OCP\Group\Backend\ISearchableGroupBackend;
use OCP\GroupInterface;
+use OCP\ICacheFactory;
use OCP\IUser;
+use OCP\Security\Ip\IRemoteAddress;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
+abstract class TestBackend extends ABackend implements ISearchableGroupBackend, IAddToGroupBackend, ICreateGroupBackend, IGroupDetailsBackend, IRemoveFromGroupBackend, GroupInterface {
+
+}
+
class ManagerTest extends TestCase {
/** @var Manager|MockObject */
protected $userManager;
- /** @var EventDispatcherInterface|MockObject */
+ /** @var IEventDispatcher|MockObject */
protected $dispatcher;
/** @var LoggerInterface|MockObject */
protected $logger;
+ /** @var ICacheFactory|MockObject */
+ private $cache;
+ /** @var IRemoteAddress|MockObject */
+ private $remoteIpAddress;
protected function setUp(): void {
parent::setUp();
$this->userManager = $this->createMock(Manager::class);
- $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->logger = $this->createMock(LoggerInterface::class);
+ $this->cache = $this->createMock(ICacheFactory::class);
+
+ $this->remoteIpAddress = $this->createMock(IRemoteAddress::class);
+ $this->remoteIpAddress->method('allowsAdminActions')->willReturn(true);
}
private function getTestUser($userId) {
@@ -65,28 +71,30 @@ class ManagerTest extends TestCase {
*/
private function getTestBackend($implementedActions = null) {
if ($implementedActions === null) {
- $implementedActions =
- GroupInterface::ADD_TO_GROUP |
- GroupInterface::REMOVE_FROM_GOUP |
- GroupInterface::COUNT_USERS |
- GroupInterface::CREATE_GROUP |
- GroupInterface::DELETE_GROUP;
+ $implementedActions
+ = GroupInterface::ADD_TO_GROUP
+ | GroupInterface::REMOVE_FROM_GOUP
+ | GroupInterface::COUNT_USERS
+ | GroupInterface::CREATE_GROUP
+ | GroupInterface::DELETE_GROUP;
}
// need to declare it this way due to optional methods
// thanks to the implementsActions logic
- $backend = $this->getMockBuilder(GroupInterface::class)
+ $backend = $this->getMockBuilder(TestBackend::class)
->disableOriginalConstructor()
- ->setMethods([
+ ->onlyMethods([
'getGroupDetails',
'implementsActions',
'getUserGroups',
'inGroup',
'getGroups',
'groupExists',
+ 'groupsExists',
'usersInGroup',
'createGroup',
'addToGroup',
'removeFromGroup',
+ 'searchInGroup',
])
->getMock();
$backend->expects($this->any())
@@ -97,7 +105,7 @@ class ManagerTest extends TestCase {
return $backend;
}
- public function testGet() {
+ public function testGet(): void {
/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend
*/
@@ -107,7 +115,7 @@ class ManagerTest extends TestCase {
->with('group1')
->willReturn(true);
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
$group = $manager->get('group1');
@@ -115,13 +123,13 @@ class ManagerTest extends TestCase {
$this->assertEquals('group1', $group->getGID());
}
- public function testGetNoBackend() {
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ public function testGetNoBackend(): void {
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$this->assertNull($manager->get('group1'));
}
- public function testGetNotExists() {
+ public function testGetNotExists(): void {
/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend
*/
@@ -131,17 +139,17 @@ class ManagerTest extends TestCase {
->with('group1')
->willReturn(false);
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
$this->assertNull($manager->get('group1'));
}
- public function testGetDeleted() {
+ public function testGetDeleted(): void {
$backend = new \Test\Util\Group\Dummy();
$backend->createGroup('group1');
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
$group = $manager->get('group1');
@@ -149,7 +157,7 @@ class ManagerTest extends TestCase {
$this->assertNull($manager->get('group1'));
}
- public function testGetMultipleBackends() {
+ public function testGetMultipleBackends(): void {
/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend1
*/
@@ -168,7 +176,7 @@ class ManagerTest extends TestCase {
->with('group1')
->willReturn(true);
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend1);
$manager->addBackend($backend2);
@@ -177,8 +185,8 @@ class ManagerTest extends TestCase {
$this->assertEquals('group1', $group->getGID());
}
- public function testCreate() {
- /**@var \PHPUnit\Framework\MockObject\MockObject|\OC\Group\Backend $backend */
+ public function testCreate(): void {
+ /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Group\Backend $backend */
$backendGroupCreated = false;
$backend = $this->getTestBackend();
$backend->expects($this->any())
@@ -194,23 +202,23 @@ class ManagerTest extends TestCase {
return true;
});
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
$group = $manager->createGroup('group1');
$this->assertEquals('group1', $group->getGID());
}
- public function testCreateFailure() {
- /**@var \PHPUnit\Framework\MockObject\MockObject|\OC\Group\Backend $backend */
+ public function testCreateFailure(): void {
+ /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Group\Backend $backend */
$backendGroupCreated = false;
$backend = $this->getTestBackend(
- GroupInterface::ADD_TO_GROUP |
- GroupInterface::REMOVE_FROM_GOUP |
- GroupInterface::COUNT_USERS |
- GroupInterface::CREATE_GROUP |
- GroupInterface::DELETE_GROUP |
- GroupInterface::GROUP_DETAILS
+ GroupInterface::ADD_TO_GROUP
+ | GroupInterface::REMOVE_FROM_GOUP
+ | GroupInterface::COUNT_USERS
+ | GroupInterface::CREATE_GROUP
+ | GroupInterface::DELETE_GROUP
+ | GroupInterface::GROUP_DETAILS
);
$backend->expects($this->any())
->method('groupExists')
@@ -223,14 +231,38 @@ class ManagerTest extends TestCase {
->method('getGroupDetails')
->willReturn([]);
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
$group = $manager->createGroup('group1');
$this->assertEquals(null, $group);
}
- public function testCreateExists() {
+ public function testCreateTooLong(): void {
+ /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Group\Backend $backend */
+ $backendGroupCreated = false;
+ $backend = $this->getTestBackend(
+ GroupInterface::ADD_TO_GROUP
+ | GroupInterface::REMOVE_FROM_GOUP
+ | GroupInterface::COUNT_USERS
+ | GroupInterface::CREATE_GROUP
+ | GroupInterface::DELETE_GROUP
+ | GroupInterface::GROUP_DETAILS
+ );
+ $groupName = str_repeat('x', 256);
+ $backend->expects($this->any())
+ ->method('groupExists')
+ ->with($groupName)
+ ->willReturn(false);
+
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
+ $manager->addBackend($backend);
+
+ $this->expectException(\Exception::class);
+ $group = $manager->createGroup($groupName);
+ }
+
+ public function testCreateExists(): void {
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Group\Backend $backend */
$backend = $this->getTestBackend();
$backend->expects($this->any())
@@ -240,14 +272,14 @@ class ManagerTest extends TestCase {
$backend->expects($this->never())
->method('createGroup');
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
$group = $manager->createGroup('group1');
$this->assertEquals('group1', $group->getGID());
}
- public function testSearch() {
+ public function testSearch(): void {
/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend
*/
@@ -257,11 +289,12 @@ class ManagerTest extends TestCase {
->with('1')
->willReturn(['group1']);
$backend->expects($this->once())
- ->method('groupExists')
- ->with('group1')
- ->willReturn(true);
+ ->method('getGroupDetails')
+ ->willReturnMap([
+ ['group1', ['displayName' => 'group1']],
+ ]);
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
$groups = $manager->search('1');
@@ -270,7 +303,7 @@ class ManagerTest extends TestCase {
$this->assertEquals('group1', $group1->getGID());
}
- public function testSearchMultipleBackends() {
+ public function testSearchMultipleBackends(): void {
/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend1
*/
@@ -280,8 +313,11 @@ class ManagerTest extends TestCase {
->with('1')
->willReturn(['group1']);
$backend1->expects($this->any())
- ->method('groupExists')
- ->willReturn(true);
+ ->method('getGroupDetails')
+ ->willReturnMap([
+ ['group1', ['displayName' => 'group1']],
+ ['group12', []],
+ ]);
/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend2
@@ -292,10 +328,13 @@ class ManagerTest extends TestCase {
->with('1')
->willReturn(['group12', 'group1']);
$backend2->expects($this->any())
- ->method('groupExists')
- ->willReturn(true);
+ ->method('getGroupDetails')
+ ->willReturnMap([
+ ['group12', ['displayName' => 'group12']],
+ ['group1', ['displayName' => 'group1']],
+ ]);
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend1);
$manager->addBackend($backend2);
@@ -307,9 +346,9 @@ class ManagerTest extends TestCase {
$this->assertEquals('group12', $group12->getGID());
}
- public function testSearchMultipleBackendsLimitAndOffset() {
+ public function testSearchMultipleBackendsLimitAndOffset(): void {
/**
- * @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend1
+ * @var \PHPUnit\Framework\MockObject\MockObject|\OC\Group\Backend $backend1
*/
$backend1 = $this->getTestBackend();
$backend1->expects($this->once())
@@ -317,11 +356,16 @@ class ManagerTest extends TestCase {
->with('1', 2, 1)
->willReturn(['group1']);
$backend1->expects($this->any())
- ->method('groupExists')
- ->willReturn(true);
+ ->method('getGroupDetails')
+ ->willReturnMap([
+ [1, []],
+ [2, []],
+ ['group1', ['displayName' => 'group1']],
+ ['group12', []],
+ ]);
/**
- * @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend2
+ * @var \PHPUnit\Framework\MockObject\MockObject|\OC\Group\Backend $backend2
*/
$backend2 = $this->getTestBackend();
$backend2->expects($this->once())
@@ -329,10 +373,15 @@ class ManagerTest extends TestCase {
->with('1', 2, 1)
->willReturn(['group12']);
$backend2->expects($this->any())
- ->method('groupExists')
- ->willReturn(true);
+ ->method('getGroupDetails')
+ ->willReturnMap([
+ [1, []],
+ [2, []],
+ ['group1', []],
+ ['group12', ['displayName' => 'group12']],
+ ]);
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend1);
$manager->addBackend($backend2);
@@ -344,29 +393,31 @@ class ManagerTest extends TestCase {
$this->assertEquals('group12', $group12->getGID());
}
- public function testSearchResultExistsButGroupDoesNot() {
+ public function testSearchResultExistsButGroupDoesNot(): void {
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Group\Backend $backend */
$backend = $this->createMock(Database::class);
$backend->expects($this->once())
->method('getGroups')
->with('1')
->willReturn(['group1']);
+ $backend->expects($this->never())
+ ->method('groupExists');
$backend->expects($this->once())
- ->method('groupExists')
- ->with('group1')
- ->willReturn(false);
+ ->method('getGroupsDetails')
+ ->with(['group1'])
+ ->willReturn([]);
/** @var \OC\User\Manager $userManager */
$userManager = $this->createMock(Manager::class);
- $manager = new \OC\Group\Manager($userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
$groups = $manager->search('1');
$this->assertEmpty($groups);
}
- public function testGetUserGroups() {
+ public function testGetUserGroups(): void {
/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend
*/
@@ -380,7 +431,7 @@ class ManagerTest extends TestCase {
->with('group1')
->willReturn(true);
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
$groups = $manager->getUserGroups($this->getTestUser('user1'));
@@ -389,7 +440,7 @@ class ManagerTest extends TestCase {
$this->assertEquals('group1', $group1->getGID());
}
- public function testGetUserGroupIds() {
+ public function testGetUserGroupIds(): void {
/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend
*/
@@ -398,10 +449,10 @@ class ManagerTest extends TestCase {
->with('myUID')
->willReturn(['123', 'abc']);
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
- /** @var \OC\User\User|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var User|\PHPUnit\Framework\MockObject\MockObject $user */
$user = $this->createMock(IUser::class);
$user->method('getUID')
->willReturn('myUID');
@@ -414,7 +465,7 @@ class ManagerTest extends TestCase {
}
}
- public function testGetUserGroupsWithDeletedGroup() {
+ public function testGetUserGroupsWithDeletedGroup(): void {
/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend
*/
@@ -428,10 +479,10 @@ class ManagerTest extends TestCase {
->with('group1')
->willReturn(false);
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
- /** @var \OC\User\User|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var User|\PHPUnit\Framework\MockObject\MockObject $user */
$user = $this->createMock(IUser::class);
$user->expects($this->atLeastOnce())
->method('getUID')
@@ -441,7 +492,7 @@ class ManagerTest extends TestCase {
$this->assertEmpty($groups);
}
- public function testInGroup() {
+ public function testInGroup(): void {
/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend
*/
@@ -454,13 +505,13 @@ class ManagerTest extends TestCase {
->method('groupExists')
->willReturn(true);
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
$this->assertTrue($manager->isInGroup('user1', 'group1'));
}
- public function testIsAdmin() {
+ public function testIsAdmin(): void {
/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend
*/
@@ -473,13 +524,13 @@ class ManagerTest extends TestCase {
->method('groupExists')
->willReturn(true);
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
$this->assertTrue($manager->isAdmin('user1'));
}
- public function testNotAdmin() {
+ public function testNotAdmin(): void {
/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend
*/
@@ -492,13 +543,13 @@ class ManagerTest extends TestCase {
->method('groupExists')
->willReturn(true);
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
$this->assertFalse($manager->isAdmin('user1'));
}
- public function testGetUserGroupsMultipleBackends() {
+ public function testGetUserGroupsMultipleBackends(): void {
/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend1
*/
@@ -523,7 +574,7 @@ class ManagerTest extends TestCase {
->method('groupExists')
->willReturn(true);
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend1);
$manager->addBackend($backend2);
@@ -535,7 +586,7 @@ class ManagerTest extends TestCase {
$this->assertEquals('group2', $group2->getGID());
}
- public function testDisplayNamesInGroupWithOneUserBackend() {
+ public function testDisplayNamesInGroupWithOneUserBackend(): void {
/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend
*/
@@ -555,7 +606,7 @@ class ManagerTest extends TestCase {
case 'user33': return true;
default:
return null;
- }
+ }
});
$this->userManager->expects($this->any())
@@ -582,7 +633,7 @@ class ManagerTest extends TestCase {
}
});
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
$users = $manager->displayNamesInGroup('testgroup', 'user3');
@@ -593,7 +644,7 @@ class ManagerTest extends TestCase {
$this->assertTrue(isset($users['user33']));
}
- public function testDisplayNamesInGroupWithOneUserBackendWithLimitSpecified() {
+ public function testDisplayNamesInGroupWithOneUserBackendWithLimitSpecified(): void {
/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend
*/
@@ -607,14 +658,14 @@ class ManagerTest extends TestCase {
->method('inGroup')
->willReturnCallback(function ($uid, $gid) {
switch ($uid) {
- case 'user1': return false;
- case 'user2': return true;
- case 'user3': return false;
- case 'user33': return true;
- case 'user333': return true;
- default:
- return null;
- }
+ case 'user1': return false;
+ case 'user2': return true;
+ case 'user3': return false;
+ case 'user33': return true;
+ case 'user333': return true;
+ default:
+ return null;
+ }
});
$this->userManager->expects($this->any())
@@ -642,7 +693,7 @@ class ManagerTest extends TestCase {
}
});
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
$users = $manager->displayNamesInGroup('testgroup', 'user3', 1);
@@ -654,7 +705,7 @@ class ManagerTest extends TestCase {
$this->assertFalse(isset($users['user333']));
}
- public function testDisplayNamesInGroupWithOneUserBackendWithLimitAndOffsetSpecified() {
+ public function testDisplayNamesInGroupWithOneUserBackendWithLimitAndOffsetSpecified(): void {
/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend
*/
@@ -668,14 +719,14 @@ class ManagerTest extends TestCase {
->method('inGroup')
->willReturnCallback(function ($uid) {
switch ($uid) {
- case 'user1': return false;
- case 'user2': return true;
- case 'user3': return false;
- case 'user33': return true;
- case 'user333': return true;
- default:
- return null;
- }
+ case 'user1': return false;
+ case 'user2': return true;
+ case 'user3': return false;
+ case 'user33': return true;
+ case 'user333': return true;
+ default:
+ return null;
+ }
});
$this->userManager->expects($this->any())
@@ -706,7 +757,7 @@ class ManagerTest extends TestCase {
}
});
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
$users = $manager->displayNamesInGroup('testgroup', 'user3', 1, 1);
@@ -718,9 +769,9 @@ class ManagerTest extends TestCase {
$this->assertTrue(isset($users['user333']));
}
- public function testDisplayNamesInGroupWithOneUserBackendAndSearchEmpty() {
+ public function testDisplayNamesInGroupWithOneUserBackendAndSearchEmpty(): void {
/**
- * @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend
+ * @var \PHPUnit\Framework\MockObject\MockObject|\OC\Group\Backend $backend
*/
$backend = $this->getTestBackend();
$backend->expects($this->exactly(1))
@@ -729,24 +780,13 @@ class ManagerTest extends TestCase {
->willReturn(true);
$backend->expects($this->once())
- ->method('usersInGroup')
+ ->method('searchInGroup')
->with('testgroup', '', -1, 0)
- ->willReturn(['user2', 'user33']);
+ ->willReturn(['user2' => $this->getTestUser('user2'), 'user33' => $this->getTestUser('user33')]);
- $this->userManager->expects($this->any())
- ->method('get')
- ->willReturnCallback(function ($uid) {
- switch ($uid) {
- case 'user1': return $this->getTestUser('user1');
- case 'user2': return $this->getTestUser('user2');
- case 'user3': return $this->getTestUser('user3');
- case 'user33': return $this->getTestUser('user33');
- default:
- return null;
- }
- });
+ $this->userManager->expects($this->never())->method('get');
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
$users = $manager->displayNamesInGroup('testgroup', '');
@@ -757,7 +797,7 @@ class ManagerTest extends TestCase {
$this->assertTrue(isset($users['user33']));
}
- public function testDisplayNamesInGroupWithOneUserBackendAndSearchEmptyAndLimitSpecified() {
+ public function testDisplayNamesInGroupWithOneUserBackendAndSearchEmptyAndLimitSpecified(): void {
/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend
*/
@@ -768,24 +808,13 @@ class ManagerTest extends TestCase {
->willReturn(true);
$backend->expects($this->once())
- ->method('usersInGroup')
+ ->method('searchInGroup')
->with('testgroup', '', 1, 0)
- ->willReturn(['user2']);
+ ->willReturn([new User('user2', null, $this->dispatcher)]);
- $this->userManager->expects($this->any())
- ->method('get')
- ->willReturnCallback(function ($uid) {
- switch ($uid) {
- case 'user1': return $this->getTestUser('user1');
- case 'user2': return $this->getTestUser('user2');
- case 'user3': return $this->getTestUser('user3');
- case 'user33': return $this->getTestUser('user33');
- default:
- return null;
- }
- });
+ $this->userManager->expects($this->never())->method('get');
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
$users = $manager->displayNamesInGroup('testgroup', '', 1);
@@ -796,7 +825,7 @@ class ManagerTest extends TestCase {
$this->assertFalse(isset($users['user33']));
}
- public function testDisplayNamesInGroupWithOneUserBackendAndSearchEmptyAndLimitAndOffsetSpecified() {
+ public function testDisplayNamesInGroupWithOneUserBackendAndSearchEmptyAndLimitAndOffsetSpecified(): void {
/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend
*/
@@ -807,24 +836,13 @@ class ManagerTest extends TestCase {
->willReturn(true);
$backend->expects($this->once())
- ->method('usersInGroup')
+ ->method('searchInGroup')
->with('testgroup', '', 1, 1)
- ->willReturn(['user33']);
+ ->willReturn(['user33' => $this->getTestUser('user33')]);
- $this->userManager->expects($this->any())
- ->method('get')
- ->willReturnCallback(function ($uid) {
- switch ($uid) {
- case 'user1': return $this->getTestUser('user1');
- case 'user2': return $this->getTestUser('user2');
- case 'user3': return $this->getTestUser('user3');
- case 'user33': return $this->getTestUser('user33');
- default:
- return null;
- }
- });
+ $this->userManager->expects($this->never())->method('get');
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
$users = $manager->displayNamesInGroup('testgroup', '', 1, 1);
@@ -835,7 +853,7 @@ class ManagerTest extends TestCase {
$this->assertTrue(isset($users['user33']));
}
- public function testGetUserGroupsWithAddUser() {
+ public function testGetUserGroupsWithAddUser(): void {
/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend
*/
@@ -852,7 +870,7 @@ class ManagerTest extends TestCase {
->with('group1')
->willReturn(true);
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
// prime cache
@@ -872,7 +890,7 @@ class ManagerTest extends TestCase {
$this->assertEquals('group1', $group1->getGID());
}
- public function testGetUserGroupsWithRemoveUser() {
+ public function testGetUserGroupsWithRemoveUser(): void {
/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend
*/
@@ -895,7 +913,7 @@ class ManagerTest extends TestCase {
->method('removeFromGroup')
->willReturn(true);
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
// prime cache
@@ -915,7 +933,7 @@ class ManagerTest extends TestCase {
$this->assertEquals($expectedGroups, $groups);
}
- public function testGetUserIdGroups() {
+ public function testGetUserIdGroups(): void {
/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend
*/
@@ -925,24 +943,24 @@ class ManagerTest extends TestCase {
->with('user1')
->willReturn(null);
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
$groups = $manager->getUserIdGroups('user1');
$this->assertEquals([], $groups);
}
- public function testGroupDisplayName() {
+ public function testGroupDisplayName(): void {
/**
* @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend
*/
$backend = $this->getTestBackend(
- GroupInterface::ADD_TO_GROUP |
- GroupInterface::REMOVE_FROM_GOUP |
- GroupInterface::COUNT_USERS |
- GroupInterface::CREATE_GROUP |
- GroupInterface::DELETE_GROUP |
- GroupInterface::GROUP_DETAILS
+ GroupInterface::ADD_TO_GROUP
+ | GroupInterface::REMOVE_FROM_GOUP
+ | GroupInterface::COUNT_USERS
+ | GroupInterface::CREATE_GROUP
+ | GroupInterface::DELETE_GROUP
+ | GroupInterface::GROUP_DETAILS
);
$backend->expects($this->any())
->method('getGroupDetails')
@@ -950,8 +968,7 @@ class ManagerTest extends TestCase {
['group1', ['gid' => 'group1', 'displayName' => 'Group One']],
['group2', ['gid' => 'group2']],
]);
-
- $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
+ $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress);
$manager->addBackend($backend);
// group with display name
diff --git a/tests/lib/Group/MetaDataTest.php b/tests/lib/Group/MetaDataTest.php
index 7ad6d631b4e..dee59eab8da 100644
--- a/tests/lib/Group/MetaDataTest.php
+++ b/tests/lib/Group/MetaDataTest.php
@@ -1,38 +1,22 @@
<?php
+
/**
- * @author Arthur Schiwon <blizzz@owncloud.com>
- * @author Lukas Reschke <lukas@owncloud.com>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * 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, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace Test\Group;
+use OC\Group\MetaData;
use OCP\IUserSession;
class MetaDataTest extends \Test\TestCase {
- /** @var \OC\Group\Manager */
- private $groupManager;
- /** @var \OCP\IUserSession */
- private $userSession;
- /** @var \OC\Group\MetaData */
- private $groupMetadata;
- /** @var bool */
- private $isAdmin = true;
+ private \OC\Group\Manager $groupManager;
+ private IUserSession $userSession;
+ private MetaData $groupMetadata;
+ private bool $isAdmin = true;
+ private bool $isDelegatedAdmin = true;
protected function setUp(): void {
parent::setUp();
@@ -40,9 +24,10 @@ class MetaDataTest extends \Test\TestCase {
->disableOriginalConstructor()
->getMock();
$this->userSession = $this->createMock(IUserSession::class);
- $this->groupMetadata = new \OC\Group\MetaData(
+ $this->groupMetadata = new MetaData(
'foo',
$this->isAdmin,
+ $this->isDelegatedAdmin,
$this->groupManager,
$this->userSession
);
@@ -54,29 +39,20 @@ class MetaDataTest extends \Test\TestCase {
->getMock();
$group->expects($this->exactly(6))
- ->method('getGID')
- ->will($this->onConsecutiveCalls(
- 'admin', 'admin',
- 'g2', 'g2',
- 'g3', 'g3'));
+ ->method('getGID')->willReturnOnConsecutiveCalls('admin', 'admin', 'g2', 'g2', 'g3', 'g3');
$group->expects($this->exactly(3))
- ->method('getDisplayName')
- ->will($this->onConsecutiveCalls(
- 'admin',
- 'g2',
- 'g3'));
+ ->method('getDisplayName')->willReturnOnConsecutiveCalls('admin', 'g2', 'g3');
$group->expects($this->exactly($countCallCount))
->method('count')
- ->with('')
- ->will($this->onConsecutiveCalls(2, 3, 5));
+ ->with('')->willReturnOnConsecutiveCalls(2, 3, 5);
return $group;
}
- public function testGet() {
+ public function testGet(): void {
$group = $this->getGroupMock();
$groups = array_fill(0, 3, $group);
@@ -95,7 +71,7 @@ class MetaDataTest extends \Test\TestCase {
$this->assertSame(0, $ordinaryGroups[0]['usercount']);
}
- public function testGetWithSorting() {
+ public function testGetWithSorting(): void {
$this->groupMetadata->setSorting(1);
$group = $this->getGroupMock(3);
$groups = array_fill(0, 3, $group);
@@ -114,7 +90,7 @@ class MetaDataTest extends \Test\TestCase {
$this->assertSame(5, $ordinaryGroups[0]['usercount']);
}
- public function testGetWithCache() {
+ public function testGetWithCache(): void {
$group = $this->getGroupMock();
$groups = array_fill(0, 3, $group);
@@ -132,7 +108,7 @@ class MetaDataTest extends \Test\TestCase {
//get() does not need to be tested with search parameters, because they are
//solely and only passed to GroupManager and Group.
- public function testGetGroupsAsAdmin() {
+ public function testGetGroupsAsAdmin(): void {
$this->groupManager
->expects($this->once())
->method('search')