TestCase.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCA\Provisioning_API\Tests;
  27. use OCP\IGroupManager;
  28. use OCP\IUser;
  29. use OCP\IUserManager;
  30. abstract class TestCase extends \Test\TestCase {
  31. /** @var IUser[] */
  32. protected $users = [];
  33. /** @var IUserManager */
  34. protected $userManager;
  35. /** @var IGroupManager */
  36. protected $groupManager;
  37. protected function setUp(): void {
  38. parent::setUp();
  39. $this->userManager = \OC::$server->getUserManager();
  40. $this->groupManager = \OC::$server->getGroupManager();
  41. $this->groupManager->createGroup('admin');
  42. }
  43. /**
  44. * Generates a temp user
  45. * @param int $num number of users to generate
  46. * @return IUser[]|IUser
  47. */
  48. protected function generateUsers($num = 1) {
  49. $users = [];
  50. for ($i = 0; $i < $num; $i++) {
  51. $user = $this->userManager->createUser($this->getUniqueID(), 'password');
  52. $this->users[] = $user;
  53. $users[] = $user;
  54. }
  55. return count($users) == 1 ? reset($users) : $users;
  56. }
  57. protected function tearDown(): void {
  58. foreach($this->users as $user) {
  59. $user->delete();
  60. }
  61. $this->groupManager->get('admin')->delete();
  62. parent::tearDown();
  63. }
  64. }