nextcloud/apps/provisioning_api/tests/TestCase.php

75 lines
1.9 KiB
PHP
Raw Normal View History

<?php
/**
2016-07-21 17:49:16 +03:00
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Joas Schilling <coding@schilljs.com>
2015-03-26 13:44:34 +03:00
* @author Morris Jobke <hey@morrisjobke.de>
2016-07-21 17:49:16 +03:00
* @author Roeland Jago Douma <roeland@famdouma.nl>
2016-01-12 17:02:16 +03:00
* @author Thomas Müller <thomas.mueller@tmit.eu>
*
2015-03-26 13:44:34 +03:00
* @license AGPL-3.0
*
2015-03-26 13:44:34 +03:00
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
2015-03-26 13:44:34 +03:00
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2015-03-26 13:44:34 +03:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
2015-03-26 13:44:34 +03:00
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\Provisioning_API\Tests;
use OCP\IUser;
2015-08-11 13:51:00 +03:00
use OCP\IUserManager;
use OCP\IGroupManager;
abstract class TestCase extends \Test\TestCase {
/** @var IUser[] */
protected $users = array();
2015-08-11 13:51:00 +03:00
/** @var IUserManager */
protected $userManager;
/** @var IGroupManager */
protected $groupManager;
protected function setUp() {
parent::setUp();
2015-07-25 23:37:14 +03:00
$this->userManager = \OC::$server->getUserManager();
$this->groupManager = \OC::$server->getGroupManager();
$this->groupManager->createGroup('admin');
}
/**
* Generates a temp user
* @param int $num number of users to generate
* @return IUser[]|IUser
*/
protected function generateUsers($num = 1) {
$users = array();
for ($i = 0; $i < $num; $i++) {
2015-07-25 23:37:14 +03:00
$user = $this->userManager->createUser($this->getUniqueID(), 'password');
$this->users[] = $user;
$users[] = $user;
}
return count($users) == 1 ? reset($users) : $users;
}
protected function tearDown() {
foreach($this->users as $user) {
2015-07-25 23:37:14 +03:00
$user->delete();
}
2015-07-25 23:37:14 +03:00
$this->groupManager->get('admin')->delete();
parent::tearDown();
}
}