2015-08-20 08:38:51 -04:00
|
|
|
<?php
|
2025-06-30 09:04:05 -04:00
|
|
|
|
2015-08-20 08:38:51 -04:00
|
|
|
/**
|
2024-05-10 09:09:14 -04:00
|
|
|
* SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2015-08-20 08:38:51 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace Test\Traits;
|
|
|
|
|
|
2022-02-23 12:29:08 -05:00
|
|
|
use OC\User\User;
|
2024-10-08 05:12:01 -04:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2022-02-23 12:29:08 -05:00
|
|
|
use OCP\IUser;
|
2025-06-12 12:31:58 -04:00
|
|
|
use OCP\IUserManager;
|
2024-10-08 05:12:01 -04:00
|
|
|
use OCP\Server;
|
2025-06-30 10:56:59 -04:00
|
|
|
use OCP\UserInterface;
|
2022-02-23 12:29:08 -05:00
|
|
|
|
|
|
|
|
class DummyUser extends User {
|
2025-06-12 12:31:58 -04:00
|
|
|
public function __construct(
|
|
|
|
|
private string $uid,
|
|
|
|
|
) {
|
|
|
|
|
parent::__construct($this->uid, null, Server::get(IEventDispatcher::class));
|
2022-02-23 12:29:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getUID(): string {
|
|
|
|
|
return $this->uid;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-20 08:38:51 -04:00
|
|
|
/**
|
|
|
|
|
* Allow creating users in a temporary backend
|
|
|
|
|
*/
|
|
|
|
|
trait UserTrait {
|
|
|
|
|
/**
|
2025-06-30 10:56:59 -04:00
|
|
|
* @var \Test\Util\User\Dummy|UserInterface
|
2015-08-20 08:38:51 -04:00
|
|
|
*/
|
|
|
|
|
protected $userBackend;
|
|
|
|
|
|
2022-02-23 12:29:08 -05:00
|
|
|
protected function createUser($name, $password): IUser {
|
2015-08-20 08:38:51 -04:00
|
|
|
$this->userBackend->createUser($name, $password);
|
2022-02-23 12:29:08 -05:00
|
|
|
return new DummyUser($name);
|
2015-08-20 08:38:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function setUpUserTrait() {
|
2015-09-21 18:56:36 -04:00
|
|
|
$this->userBackend = new \Test\Util\User\Dummy();
|
2025-06-12 12:31:58 -04:00
|
|
|
Server::get(IUserManager::class)->registerBackend($this->userBackend);
|
2015-08-20 08:38:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function tearDownUserTrait() {
|
2025-06-12 12:31:58 -04:00
|
|
|
Server::get(IUserManager::class)->removeBackend($this->userBackend);
|
2015-08-20 08:38:51 -04:00
|
|
|
}
|
|
|
|
|
}
|