TestCase.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  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\IUser;
  27. use OCP\IUserManager;
  28. use OCP\IGroupManager;
  29. abstract class TestCase extends \Test\TestCase {
  30. /** @var IUser[] */
  31. protected $users = array();
  32. /** @var IUserManager */
  33. protected $userManager;
  34. /** @var IGroupManager */
  35. protected $groupManager;
  36. protected function setUp() {
  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 = array();
  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() {
  57. foreach($this->users as $user) {
  58. $user->delete();
  59. }
  60. $this->groupManager->get('admin')->delete();
  61. parent::tearDown();
  62. }
  63. }