1
0

TestCase.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Provisioning_API\Tests;
  8. use OCP\IGroupManager;
  9. use OCP\IUser;
  10. use OCP\IUserManager;
  11. abstract class TestCase extends \Test\TestCase {
  12. /** @var IUser[] */
  13. protected $users = [];
  14. /** @var IUserManager */
  15. protected $userManager;
  16. /** @var IGroupManager */
  17. protected $groupManager;
  18. protected function setUp(): void {
  19. parent::setUp();
  20. $this->userManager = \OC::$server->getUserManager();
  21. $this->groupManager = \OC::$server->getGroupManager();
  22. $this->groupManager->createGroup('admin');
  23. }
  24. /**
  25. * Generates a temp user
  26. * @param int $num number of users to generate
  27. * @return IUser[]|IUser
  28. */
  29. protected function generateUsers($num = 1) {
  30. $users = [];
  31. for ($i = 0; $i < $num; $i++) {
  32. $user = $this->userManager->createUser($this->getUniqueID(), 'password');
  33. $this->users[] = $user;
  34. $users[] = $user;
  35. }
  36. return count($users) == 1 ? reset($users) : $users;
  37. }
  38. protected function tearDown(): void {
  39. foreach ($this->users as $user) {
  40. $user->delete();
  41. }
  42. $this->groupManager->get('admin')->delete();
  43. parent::tearDown();
  44. }
  45. }