TestCase.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. }