summaryrefslogtreecommitdiffstats
path: root/apps/provisioning_api
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2015-08-19 09:43:40 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2015-08-26 11:00:13 +0200
commitef3aa1218eab7f4c50758d0d359c383eae4a3e95 (patch)
tree6f06342ee9e020f40b7f14574c9ec7a4589c2fc9 /apps/provisioning_api
parente95863822153e6b88a365e6db83444bdf1c4c0ce (diff)
downloadnextcloud-server-ef3aa1218eab7f4c50758d0d359c383eae4a3e95.tar.gz
nextcloud-server-ef3aa1218eab7f4c50758d0d359c383eae4a3e95.zip
[provisioning api] Updated tests
* Test pass again * Code coverage getUsers is at 100% again
Diffstat (limited to 'apps/provisioning_api')
-rw-r--r--apps/provisioning_api/tests/userstest.php78
1 files changed, 77 insertions, 1 deletions
diff --git a/apps/provisioning_api/tests/userstest.php b/apps/provisioning_api/tests/userstest.php
index 350586f8335..3869af87e5a 100644
--- a/apps/provisioning_api/tests/userstest.php
+++ b/apps/provisioning_api/tests/userstest.php
@@ -63,10 +63,16 @@ class UsersTest extends TestCase {
$this->groupManager,
$this->userSession
);
+
+ $this->userSession->setUser(null);
}
// Test getting the list of users
- public function testGetUsers() {
+ public function testGetUsersAsAdmin() {
+ $user = $this->generateUsers();
+ $this->groupManager->get('admin')->addUser($user);
+ $this->userSession->setUser($user);
+
$result = $this->api->getUsers();
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
@@ -103,6 +109,70 @@ class UsersTest extends TestCase {
$this->assertEquals(array_keys($this->userManager->search('', 1, 1)), $data['users']);
}
+ public function testGetUsersAsSubAdmin() {
+ $user = $this->generateUsers(10);
+ $this->userSession->setUser($user[0]);
+ $group = $this->groupManager->createGroup($this->getUniqueID());
+ \OC_SubAdmin::createSubAdmin($user[0]->getUID(), $group->getGID());
+
+ //Empty list
+ $result = $this->api->getUsers([]);
+ $this->assertInstanceOf('OC_OCS_Result', $result);
+ $this->assertTrue($result->succeeded());
+ $this->assertEquals(['users' => []], $result->getData());
+
+ //Some users in group
+ $group->addUser($user[1]);
+ $group->addUser($user[2]);
+ $group->addUser($user[3]);
+ $group->addUser($user[4]);
+
+ $result = $this->api->getUsers([]);
+ $this->assertInstanceOf('OC_OCS_Result', $result);
+ $this->assertTrue($result->succeeded());
+ $this->assertArrayHasKey('users', $result->getData());
+
+ $this->assertContains($user[1]->getUID(), $result->getData()['users']);
+ $this->assertContains($user[2]->getUID(), $result->getData()['users']);
+ $this->assertContains($user[3]->getUID(), $result->getData()['users']);
+ $this->assertContains($user[4]->getUID(), $result->getData()['users']);
+
+ $uids = [
+ $user[1]->getUID(),
+ $user[2]->getUID(),
+ $user[3]->getUID(),
+ $user[4]->getUID()
+ ];
+ sort($uids);
+
+ $_GET['limit'] = 2;
+ $_GET['offset'] = 1;
+ $result = $this->api->getUsers([]);
+
+ $this->assertInstanceOf('OC_OCS_Result', $result);
+ $this->assertTrue($result->succeeded());
+ $this->assertEquals(['users' => array_slice($uids, 1, 2)], $result->getData());
+ }
+
+ public function testGetUsersNoUser() {
+ $result = $this->api->getUsers([]);
+
+ $this->assertInstanceOf('OC_OCS_Result', $result);
+ $this->assertFalse($result->succeeded());
+ $this->assertEquals(\OCP\API::RESPOND_UNAUTHORISED, $result->getStatusCode());
+ }
+
+ public function testGetUsersAsUser() {
+ $user = $this->generateUsers();
+ $this->userSession->setUser($user);
+
+ $result = $this->api->getUsers();
+ $this->assertInstanceOf('OC_OCS_Result', $result);
+ $this->assertFalse($result->succeeded());
+ $this->assertEquals(\OCP\API::RESPOND_UNAUTHORISED, $result->getStatusCode());
+
+ }
+
public function testAddUser() {
$this->resetParams();
$_POST['userid'] = $this->getUniqueID();
@@ -794,6 +864,9 @@ class UsersTest extends TestCase {
}
public function testAddToGroupNoGroupId() {
+ $user = $this->generateUsers();
+ $this->userSession->setUser($user);
+
$_POST['groupid'] = '';
$result = $this->api->addToGroup([
'userid' => $this->getUniqueID(),
@@ -935,6 +1008,9 @@ class UsersTest extends TestCase {
}
public function testRemoveFromGroupNoGroupId() {
+ $user = $this->generateUsers();
+ $this->userSession->setUser($user);
+
$result = $this->api->removeFromGroup([
'_delete' => [
'groupid' => ''