1
0

UserTrait.php 1017 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Test\Traits;
  8. use OC\User\User;
  9. use OCP\IUser;
  10. class DummyUser extends User {
  11. private string $uid;
  12. public function __construct(string $uid) {
  13. $this->uid = $uid;
  14. }
  15. public function getUID(): string {
  16. return $this->uid;
  17. }
  18. }
  19. /**
  20. * Allow creating users in a temporary backend
  21. */
  22. trait UserTrait {
  23. /**
  24. * @var \Test\Util\User\Dummy|\OCP\UserInterface
  25. */
  26. protected $userBackend;
  27. protected function createUser($name, $password): IUser {
  28. $this->userBackend->createUser($name, $password);
  29. return new DummyUser($name);
  30. }
  31. protected function setUpUserTrait() {
  32. $this->userBackend = new \Test\Util\User\Dummy();
  33. \OC::$server->getUserManager()->registerBackend($this->userBackend);
  34. }
  35. protected function tearDownUserTrait() {
  36. \OC::$server->getUserManager()->removeBackend($this->userBackend);
  37. }
  38. }