2014-12-22 13:54:50 +00:00
|
|
|
<?php
|
2015-02-26 10:37:37 +00:00
|
|
|
|
2014-12-22 13:54:50 +00:00
|
|
|
/**
|
2015-02-26 10:37:37 +00:00
|
|
|
* ownCloud
|
|
|
|
*
|
|
|
|
* @copyright (C) 2014 ownCloud, Inc.
|
2014-12-22 13:54:50 +00:00
|
|
|
*
|
2015-02-26 10:37:37 +00:00
|
|
|
* @author Tom <tom@owncloud.com>
|
|
|
|
* @author Thomas Müller <deepdiver@owncloud.com>
|
2014-12-22 13:54:50 +00:00
|
|
|
*
|
2015-02-26 10:37:37 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
2014-12-22 13:54:50 +00:00
|
|
|
*
|
2015-02-26 10:37:37 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2014-12-22 13:54:50 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-02-26 10:37:37 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
2014-12-22 13:54:50 +00:00
|
|
|
*
|
2015-02-26 10:37:37 +00:00
|
|
|
* You should have received a copy of the GNU Affero General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2014-12-22 13:54:50 +00:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 10:37:37 +00:00
|
|
|
|
2015-01-07 09:34:42 +00:00
|
|
|
namespace OCA\Provisioning_API\Tests;
|
2014-12-22 13:54:50 +00:00
|
|
|
|
2015-01-07 09:34:42 +00:00
|
|
|
class GroupsTest extends TestCase {
|
|
|
|
public function testGetGroupAsUser() {
|
2014-12-22 13:54:50 +00:00
|
|
|
|
|
|
|
$users = $this->generateUsers(2);
|
|
|
|
\OC_User::setUserId($users[0]);
|
|
|
|
|
2015-01-07 09:34:42 +00:00
|
|
|
$group = $this->getUniqueID();
|
2014-12-22 13:54:50 +00:00
|
|
|
\OC_Group::createGroup($group);
|
|
|
|
\OC_Group::addToGroup($users[1], $group);
|
|
|
|
|
|
|
|
$result = \OCA\provisioning_api\Groups::getGroup(array(
|
|
|
|
'groupid' => $group,
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
|
|
|
$this->assertEquals(\OC_API::RESPOND_UNAUTHORISED, $result->getStatusCode());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-07 09:34:42 +00:00
|
|
|
public function testGetGroupAsSubadmin() {
|
2014-12-22 13:54:50 +00:00
|
|
|
|
|
|
|
$users = $this->generateUsers(2);
|
|
|
|
\OC_User::setUserId($users[0]);
|
|
|
|
|
2015-01-07 09:34:42 +00:00
|
|
|
$group = $this->getUniqueID();
|
2014-12-22 13:54:50 +00:00
|
|
|
\OC_Group::createGroup($group);
|
|
|
|
\OC_Group::addToGroup($users[0], $group);
|
2015-01-02 19:07:31 +00:00
|
|
|
\OC_Group::addToGroup($users[1], $group);
|
2014-12-22 13:54:50 +00:00
|
|
|
|
|
|
|
\OC_SubAdmin::createSubAdmin($users[0], $group);
|
|
|
|
|
|
|
|
$result = \OCA\provisioning_api\Groups::getGroup(array(
|
|
|
|
'groupid' => $group,
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
2015-02-25 15:21:18 +00:00
|
|
|
$this->assertEquals(1, sizeof($result->getData()), 'Asserting the result data array only has the "users" key');
|
|
|
|
$this->assertArrayHasKey('users', $result->getData());
|
|
|
|
$resultData = $result->getData();
|
|
|
|
$resultData = $resultData['users'];
|
|
|
|
|
|
|
|
sort($users);
|
|
|
|
sort($resultData);
|
|
|
|
$this->assertEquals($users, $resultData);
|
2014-12-22 13:54:50 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-07 09:34:42 +00:00
|
|
|
public function testGetGroupAsIrrelevantSubadmin() {
|
2014-12-22 13:54:50 +00:00
|
|
|
|
|
|
|
$users = $this->generateUsers(2);
|
|
|
|
\OC_User::setUserId($users[0]);
|
|
|
|
|
2015-01-07 09:34:42 +00:00
|
|
|
$group = $this->getUniqueID();
|
2014-12-22 13:54:50 +00:00
|
|
|
\OC_Group::createGroup($group);
|
2015-01-07 09:34:42 +00:00
|
|
|
$group2 = $this->getUniqueID();
|
2014-12-22 13:54:50 +00:00
|
|
|
\OC_Group::createGroup($group2);
|
|
|
|
\OC_Group::addToGroup($users[1], $group);
|
|
|
|
\OC_Group::addToGroup($users[0], $group2);
|
|
|
|
|
|
|
|
\OC_SubAdmin::createSubAdmin($users[0], $group2);
|
|
|
|
|
|
|
|
$result = \OCA\provisioning_api\Groups::getGroup(array(
|
|
|
|
'groupid' => $group,
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
|
|
|
$this->assertEquals(\OC_API::RESPOND_UNAUTHORISED, $result->getStatusCode());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-07 09:34:42 +00:00
|
|
|
public function testGetGroupAsAdmin() {
|
2014-12-22 13:54:50 +00:00
|
|
|
|
|
|
|
$users = $this->generateUsers(2);
|
|
|
|
\OC_User::setUserId($users[0]);
|
|
|
|
|
2015-01-07 09:34:42 +00:00
|
|
|
$group = $this->getUniqueID();
|
2014-12-22 13:54:50 +00:00
|
|
|
\OC_Group::createGroup($group);
|
|
|
|
|
|
|
|
\OC_Group::addToGroup($users[1], $group);
|
|
|
|
\OC_Group::addToGroup($users[0], 'admin');
|
|
|
|
|
|
|
|
$result = \OCA\provisioning_api\Groups::getGroup(array(
|
|
|
|
'groupid' => $group,
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
$this->assertEquals(array('users' => array($users[1])), $result->getData());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-07 09:34:42 +00:00
|
|
|
public function testGetSubAdminsOfGroup() {
|
2014-12-22 13:54:50 +00:00
|
|
|
$user1 = $this->generateUsers();
|
|
|
|
$user2 = $this->generateUsers();
|
2015-01-07 09:34:42 +00:00
|
|
|
\OC_User::setUserId($user1);
|
|
|
|
\OC_Group::addToGroup($user1, 'admin');
|
|
|
|
$group1 = $this->getUniqueID();
|
|
|
|
\OC_Group::createGroup($group1);
|
|
|
|
\OC_SubAdmin::createSubAdmin($user2, $group1);
|
2014-12-22 13:54:50 +00:00
|
|
|
$result = \OCA\provisioning_api\Groups::getSubAdminsOfGroup(array(
|
|
|
|
'groupid' => $group1,
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertTrue($result->succeeded());
|
|
|
|
$data = $result->getData();
|
|
|
|
$this->assertEquals($user2, reset($data));
|
2015-01-07 09:34:42 +00:00
|
|
|
\OC_Group::deleteGroup($group1);
|
2014-12-22 13:54:50 +00:00
|
|
|
|
|
|
|
$user1 = $this->generateUsers();
|
2015-01-07 09:34:42 +00:00
|
|
|
\OC_User::setUserId($user1);
|
|
|
|
\OC_Group::addToGroup($user1, 'admin');
|
2014-12-22 13:54:50 +00:00
|
|
|
$result = \OCA\provisioning_api\Groups::getSubAdminsOfGroup(array(
|
2015-01-07 09:34:42 +00:00
|
|
|
'groupid' => $this->getUniqueID(),
|
2014-12-22 13:54:50 +00:00
|
|
|
));
|
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result);
|
|
|
|
$this->assertFalse($result->succeeded());
|
|
|
|
$this->assertEquals(101, $result->getStatusCode());
|
|
|
|
}
|
|
|
|
}
|