TestCase.php 2.0 KB

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