nextcloud/tests/lib/Util/User/Dummy.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

101 lines
2 KiB
PHP
Raw Normal View History

2012-04-13 16:52:06 -04:00
<?php
2012-04-13 16:52:06 -04:00
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
2013-05-28 17:46:57 -04:00
*/
2015-09-21 18:56:36 -04:00
namespace Test\Util\User;
use OC\User\Backend;
use OCP\IUserBackend;
2015-09-21 18:56:36 -04:00
/**
* dummy user backend, does not keep state, only for testing use
*/
class Dummy extends Backend implements IUserBackend {
private array $users = [];
private array $displayNames = [];
public function createUser($uid, $password): bool {
2013-05-28 17:46:57 -04:00
if (isset($this->users[$uid])) {
2012-04-13 16:52:06 -04:00
return false;
2013-05-28 17:46:57 -04:00
} else {
$this->users[$uid] = $password;
2012-04-13 16:52:06 -04:00
return true;
}
}
public function deleteUser($uid): bool {
2013-05-28 17:46:57 -04:00
if (isset($this->users[$uid])) {
2012-04-13 16:52:06 -04:00
unset($this->users[$uid]);
return true;
2013-05-28 17:46:57 -04:00
} else {
2012-04-13 16:52:06 -04:00
return false;
}
}
public function setPassword($uid, $password): bool {
2013-05-28 17:46:57 -04:00
if (isset($this->users[$uid])) {
$this->users[$uid] = $password;
2012-04-13 16:52:06 -04:00
return true;
2013-05-28 17:46:57 -04:00
} else {
2012-04-13 16:52:06 -04:00
return false;
}
}
public function checkPassword($uid, $password): string|false {
if (isset($this->users[$uid]) && $this->users[$uid] === $password) {
return $uid;
2012-04-13 16:52:06 -04:00
}
return false;
2012-04-13 16:52:06 -04:00
}
public function loginName2UserName($loginName): string|false {
if (isset($this->users[strtolower($loginName)])) {
return strtolower($loginName);
}
return false;
}
public function getUsers($search = '', $limit = null, $offset = null): array {
if (empty($search)) {
return array_keys($this->users);
}
$result = [];
foreach (array_keys($this->users) as $user) {
if (stripos($user, $search) !== false) {
$result[] = $user;
}
}
return $result;
2012-04-13 16:52:06 -04:00
}
public function userExists($uid): bool {
2012-04-13 16:52:06 -04:00
return isset($this->users[$uid]);
}
public function hasUserListings(): bool {
return true;
}
2014-01-08 07:26:48 -05:00
public function countUsers(): int {
2014-01-08 07:26:48 -05:00
return 0;
}
public function setDisplayName($uid, $displayName): bool {
$this->displayNames[$uid] = $displayName;
return true;
}
public function getDisplayName($uid): string {
return $this->displayNames[$uid] ?? $uid;
}
public function getBackendName(): string {
return 'Dummy';
}
2012-04-13 16:52:06 -04:00
}