aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Util
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Util')
-rw-r--r--tests/lib/Util/Group/Dummy.php75
-rw-r--r--tests/lib/Util/User/Dummy.php32
2 files changed, 49 insertions, 58 deletions
diff --git a/tests/lib/Util/Group/Dummy.php b/tests/lib/Util/Group/Dummy.php
index 3735a5e1167..fab94cdc645 100644
--- a/tests/lib/Util/Group/Dummy.php
+++ b/tests/lib/Util/Group/Dummy.php
@@ -1,40 +1,25 @@
<?php
+
/**
- * @author Arthur Schiwon <blizzz@owncloud.com>
- * @author Felix Moeller <mail@felixmoeller.de>
- * @author Lukas Reschke <lukas@owncloud.com>
- * @author Michael Gapczynski <GapczynskiM@gmail.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <icewind@owncloud.com>
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- * @author Roeland Jago Douma <rullzer@owncloud.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @copyright Copyright (c) 2016, 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\Util\Group;
-use OC\Group\Backend;
+use OCP\Group\Backend\ABackend;
+use OCP\Group\Backend\IAddToGroupBackend;
+use OCP\Group\Backend\ICountUsersBackend;
+use OCP\Group\Backend\ICreateGroupBackend;
+use OCP\Group\Backend\IDeleteGroupBackend;
+use OCP\Group\Backend\IRemoveFromGroupBackend;
+use Test\Util\User\Dummy as DummyUser;
/**
- * dummy group backend, does not keep state, only for testing use
+ * Dummy group backend, does not keep state, only for testing use
*/
-class Dummy extends Backend {
+class Dummy extends ABackend implements ICreateGroupBackend, IDeleteGroupBackend, IAddToGroupBackend, IRemoveFromGroupBackend, ICountUsersBackend {
private $groups = [];
/**
* Try to create a new group
@@ -44,7 +29,7 @@ class Dummy extends Backend {
* Tries to create a new group. If the group name already exists, false will
* be returned.
*/
- public function createGroup($gid) {
+ public function createGroup(string $gid): bool {
if (!isset($this->groups[$gid])) {
$this->groups[$gid] = [];
return true;
@@ -60,7 +45,7 @@ class Dummy extends Backend {
*
* Deletes a group and removes it from the group_user-table
*/
- public function deleteGroup($gid) {
+ public function deleteGroup(string $gid): bool {
if (isset($this->groups[$gid])) {
unset($this->groups[$gid]);
return true;
@@ -93,7 +78,7 @@ class Dummy extends Backend {
*
* Adds a user to a group.
*/
- public function addToGroup($uid, $gid) {
+ public function addToGroup(string $uid, string $gid): bool {
if (isset($this->groups[$gid])) {
if (array_search($uid, $this->groups[$gid]) === false) {
$this->groups[$gid][] = $uid;
@@ -114,7 +99,7 @@ class Dummy extends Backend {
*
* removes the user from a group.
*/
- public function removeFromGroup($uid, $gid) {
+ public function removeFromGroup(string $uid, string $gid): bool {
if (isset($this->groups[$gid])) {
if (($index = array_search($uid, $this->groups[$gid])) !== false) {
unset($this->groups[$gid][$index]);
@@ -192,6 +177,25 @@ class Dummy extends Backend {
}
}
+ public function searchInGroup(string $gid, string $search = '', int $limit = -1, int $offset = 0): array {
+ if (isset($this->groups[$gid])) {
+ if (empty($search)) {
+ $length = $limit < 0 ? null : $limit;
+ $users = array_slice($this->groups[$gid], $offset, $length);
+ return array_map(fn ($user) => new DummyUser($user, ''));
+ }
+ $result = [];
+ foreach ($this->groups[$gid] as $user) {
+ if (stripos($user, $search) !== false) {
+ $result[$user] = new DummyUser($user, '');
+ }
+ }
+ return $result;
+ } else {
+ return [];
+ }
+ }
+
/**
* get the number of all users in a group
* @param string $gid
@@ -200,7 +204,7 @@ class Dummy extends Backend {
* @param int $offset
* @return int
*/
- public function countUsersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
+ public function countUsersInGroup(string $gid, string $search = ''): int {
if (isset($this->groups[$gid])) {
if (empty($search)) {
return count($this->groups[$gid]);
@@ -213,5 +217,10 @@ class Dummy extends Backend {
}
return $count;
}
+ return 0;
+ }
+
+ public function groupExists($gid) {
+ return isset($this->groups[$gid]);
}
}
diff --git a/tests/lib/Util/User/Dummy.php b/tests/lib/Util/User/Dummy.php
index 478b7599701..6ecd378c1de 100644
--- a/tests/lib/Util/User/Dummy.php
+++ b/tests/lib/Util/User/Dummy.php
@@ -1,38 +1,20 @@
<?php
+
/**
- * @author Andreas Fischer <bantu@owncloud.com>
- * @author Arthur Schiwon <blizzz@owncloud.com>
- * @author Jörn Friedrich Dreyer <jfd@butonic.de>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <icewind@owncloud.com>
- * @author Robin McCorkell <rmccorkell@karoshi.org.uk>
- * @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: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace Test\Util\User;
use OC\User\Backend;
+use OCP\IUserBackend;
/**
* dummy user backend, does not keep state, only for testing use
*/
-class Dummy extends Backend implements \OCP\IUserBackend {
+class Dummy extends Backend implements IUserBackend {
private $users = [];
private $displayNames = [];
@@ -168,7 +150,7 @@ class Dummy extends Backend implements \OCP\IUserBackend {
}
public function getDisplayName($uid) {
- return isset($this->displayNames[$uid])? $this->displayNames[$uid]: $uid;
+ return $this->displayNames[$uid] ?? $uid;
}
/**