UserTrait.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Copyright (c) 2015 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test\Traits;
  9. use OC\User\User;
  10. use OCP\IUser;
  11. class DummyUser extends User {
  12. private string $uid;
  13. public function __construct(string $uid) {
  14. $this->uid = $uid;
  15. }
  16. public function getUID(): string {
  17. return $this->uid;
  18. }
  19. }
  20. /**
  21. * Allow creating users in a temporary backend
  22. */
  23. trait UserTrait {
  24. /**
  25. * @var \Test\Util\User\Dummy|\OCP\UserInterface
  26. */
  27. protected $userBackend;
  28. protected function createUser($name, $password): IUser {
  29. $this->userBackend->createUser($name, $password);
  30. return new DummyUser($name);
  31. }
  32. protected function setUpUserTrait() {
  33. $this->userBackend = new \Test\Util\User\Dummy();
  34. \OC::$server->getUserManager()->registerBackend($this->userBackend);
  35. }
  36. protected function tearDownUserTrait() {
  37. \OC::$server->getUserManager()->removeBackend($this->userBackend);
  38. }
  39. }