summaryrefslogtreecommitdiffstats
path: root/apps/provisioning_api/tests
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2015-07-25 22:37:14 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2015-08-02 10:22:26 +0200
commitcea72c47f923b8ed5a82a50af75d5a832c78d074 (patch)
treebd07f520f717d7ce4d2e424a7a93618a4da3f37e /apps/provisioning_api/tests
parenta4822f9f9a0a1cad9c9f5ff52cf624f9d6b9df36 (diff)
downloadnextcloud-server-cea72c47f923b8ed5a82a50af75d5a832c78d074.tar.gz
nextcloud-server-cea72c47f923b8ed5a82a50af75d5a832c78d074.zip
[provisioning_api] Move tests to OCP
Diffstat (limited to 'apps/provisioning_api/tests')
-rw-r--r--apps/provisioning_api/tests/appstest.php6
-rw-r--r--apps/provisioning_api/tests/groupstest.php64
-rw-r--r--apps/provisioning_api/tests/testcase.php13
-rw-r--r--apps/provisioning_api/tests/userstest.php318
4 files changed, 202 insertions, 199 deletions
diff --git a/apps/provisioning_api/tests/appstest.php b/apps/provisioning_api/tests/appstest.php
index 2a623098444..d6db5d56976 100644
--- a/apps/provisioning_api/tests/appstest.php
+++ b/apps/provisioning_api/tests/appstest.php
@@ -29,6 +29,8 @@ class AppsTest extends TestCase {
public function setup() {
parent::setup();
$this->appManager = \OC::$server->getAppManager();
+ $this->groupManager = \OC::$server->getGroupManager();
+ $this->userSession = \OC::$server->getUserSession();
$this->api = new \OCA\Provisioning_API\Apps($this->appManager);
}
@@ -51,8 +53,8 @@ class AppsTest extends TestCase {
public function testGetApps() {
$user = $this->generateUsers();
- \OC_Group::addToGroup($user, 'admin');
- self::loginAsUser($user);
+ $this->groupManager->get('admin')->addUser($user);
+ $this->userSession->setUser($user);
$result = $this->api->getApps([]);
diff --git a/apps/provisioning_api/tests/groupstest.php b/apps/provisioning_api/tests/groupstest.php
index 0cebd6e9d94..2743e3e04f6 100644
--- a/apps/provisioning_api/tests/groupstest.php
+++ b/apps/provisioning_api/tests/groupstest.php
@@ -41,10 +41,10 @@ class GroupsTest extends TestCase {
public function testGetGroupAsUser() {
$users = $this->generateUsers(2);
- self::loginAsUser($users[0]);
+ $this->userSession->setUser($users[0]);
$group = $this->groupManager->createGroup($this->getUniqueID());
- $group->addUser($this->userManager->get($users[1]));
+ $group->addUser($users[1]);
$result = $this->api->getGroup(array(
'groupid' => $group->getGID(),
@@ -59,17 +59,17 @@ class GroupsTest extends TestCase {
public function testGetGroupAsSubadmin() {
$users = $this->generateUsers(2);
- self::loginAsUser($users[0]);
+ $this->userSession->setUser($users[0]);
$group = $this->groupManager->createGroup($this->getUniqueID());
- $group->addUser($this->userManager->get($users[0]));
- $group->addUser($this->userManager->get($users[1]));
+ $group->addUser($users[0]);
+ $group->addUser($users[1]);
- \OC_SubAdmin::createSubAdmin($users[0], $group->getGID());
+ \OC_SubAdmin::createSubAdmin($users[0]->getUID(), $group->getGID());
- $result = $this->api->getGroup(array(
+ $result = $this->api->getGroup([
'groupid' => $group->getGID(),
- ));
+ ]);
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
@@ -78,6 +78,10 @@ class GroupsTest extends TestCase {
$resultData = $result->getData();
$resultData = $resultData['users'];
+ $users = array_map(function($user) {
+ return $user->getUID();
+ }, $users);
+
sort($users);
sort($resultData);
$this->assertEquals($users, $resultData);
@@ -87,18 +91,18 @@ class GroupsTest extends TestCase {
public function testGetGroupAsIrrelevantSubadmin() {
$users = $this->generateUsers(2);
- self::loginAsUser($users[0]);
+ $this->userSession->setUser($users[0]);
$group1 = $this->groupManager->createGroup($this->getUniqueID());
$group2 = $this->groupManager->createGroup($this->getUniqueID());
- $group1->addUser($this->userManager->get($users[1]));
- $group2->addUser($this->userManager->get($users[0]));
+ $group1->addUser($users[1]);
+ $group2->addUser($users[0]);
- \OC_SubAdmin::createSubAdmin($users[0], $group2->getGID());
+ \OC_SubAdmin::createSubAdmin($users[0]->getUID(), $group2->getGID());
- $result = $this->api->getGroup(array(
+ $result = $this->api->getGroup([
'groupid' => $group1->getGID(),
- ));
+ ]);
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertFalse($result->succeeded());
@@ -109,45 +113,45 @@ class GroupsTest extends TestCase {
public function testGetGroupAsAdmin() {
$users = $this->generateUsers(2);
- self::loginAsUser($users[0]);
+ $this->userSession->setUser($users[0]);
$group = $this->groupManager->createGroup($this->getUniqueID());
- $group->addUser($this->userManager->get($users[1]));
- $this->groupManager->get('admin')->addUser($this->userManager->get($users[0]));
+ $group->addUser($users[1]);
+ $this->groupManager->get('admin')->addUser($users[0]);
- $result = $this->api->getGroup(array(
+ $result = $this->api->getGroup([
'groupid' => $group->getGID(),
- ));
+ ]);
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
- $this->assertEquals(array('users' => array($users[1])), $result->getData());
+ $this->assertEquals(['users' => [$users[1]->getUID()]], $result->getData());
}
public function testGetSubAdminsOfGroup() {
$user1 = $this->generateUsers();
$user2 = $this->generateUsers();
- self::loginAsUser($user1);
- $this->groupManager->get('admin')->addUser($this->userManager->get($user1));
+ $this->userSession->setUser($user1);
+ $this->groupManager->get('admin')->addUser($user1);
$group1 = $this->groupManager->createGroup($this->getUniqueID());
- \OC_SubAdmin::createSubAdmin($user2, $group1->getGID());
- $result = $this->api->getSubAdminsOfGroup(array(
+ \OC_SubAdmin::createSubAdmin($user2->getUID(), $group1->getGID());
+ $result = $this->api->getSubAdminsOfGroup([
'groupid' => $group1->getGID(),
- ));
+ ]);
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
$data = $result->getData();
- $this->assertEquals($user2, reset($data));
+ $this->assertEquals($user2->getUID(), reset($data));
$group1->delete();
$user1 = $this->generateUsers();
- self::loginAsUser($user1);
- $this->groupManager->get('admin')->addUser($this->userManager->get($user1));
- $result = $this->api->getSubAdminsOfGroup(array(
+ $this->userSession->setUser($user1);
+ $this->groupManager->get('admin')->addUser($user1);
+ $result = $this->api->getSubAdminsOfGroup([
'groupid' => $this->getUniqueID(),
- ));
+ ]);
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertFalse($result->succeeded());
$this->assertEquals(101, $result->getStatusCode());
diff --git a/apps/provisioning_api/tests/testcase.php b/apps/provisioning_api/tests/testcase.php
index 3d0468daa12..0c7beee4f60 100644
--- a/apps/provisioning_api/tests/testcase.php
+++ b/apps/provisioning_api/tests/testcase.php
@@ -27,7 +27,10 @@ abstract class TestCase extends \Test\TestCase {
protected function setUp() {
parent::setUp();
- \OC_Group::createGroup('admin');
+
+ $this->userManager = \OC::$server->getUserManager();
+ $this->groupManager = \OC::$server->getGroupManager();
+ $this->groupManager->createGroup('admin');
}
/**
@@ -38,8 +41,7 @@ abstract class TestCase extends \Test\TestCase {
protected function generateUsers($num = 1) {
$users = array();
for ($i = 0; $i < $num; $i++) {
- $user = $this->getUniqueID();
- \OC_User::createUser($user, 'password');
+ $user = $this->userManager->createUser($this->getUniqueID(), 'password');
$this->users[] = $user;
$users[] = $user;
}
@@ -48,11 +50,10 @@ abstract class TestCase extends \Test\TestCase {
protected function tearDown() {
foreach($this->users as $user) {
- \OC_User::deleteUser($user);
+ $user->delete();
}
- \OC_Group::deleteGroup('admin');
-
+ $this->groupManager->get('admin')->delete();
parent::tearDown();
}
}
diff --git a/apps/provisioning_api/tests/userstest.php b/apps/provisioning_api/tests/userstest.php
index 941b24d0f86..7e7b97e87fe 100644
--- a/apps/provisioning_api/tests/userstest.php
+++ b/apps/provisioning_api/tests/userstest.php
@@ -57,12 +57,12 @@ class UsersTest extends TestCase {
$this->assertEquals(count($this->userManager->search('', null, null)), $count);
$user = $this->generateUsers();
- $_GET['search'] = $user;
+ $_GET['search'] = $user->getUID();
$result = $this->api->getUsers();
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
$data = $result->getData();
- $this->assertEquals($user, reset($data['users']));
+ $this->assertEquals($user->getUID(), reset($data['users']));
// Add several users
$this->generateUsers(10);
@@ -94,13 +94,13 @@ class UsersTest extends TestCase {
$this->assertTrue($result->succeeded());
$this->assertTrue($this->userManager->userExists($_POST['userid']));
$this->assertEquals($_POST['userid'], $this->userManager->checkPassword($_POST['userid'], $_POST['password'])->getUID());
- $this->users[] = $_POST['userid'];
+ $this->users[] = $this->userManager->get($_POST['userid']);
}
public function testGetUserOnSelf() {
$user = $this->generateUsers();
- self::loginAsUser($user);
- $params['userid'] = $user;
+ $this->userSession->setUser($user);
+ $params['userid'] = $user->getUID();
$result = $this->api->getUser($params);
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
@@ -109,8 +109,8 @@ class UsersTest extends TestCase {
public function testGetUserOnNonExistingUser() {
$user = $this->generateUsers();
- \OC_Group::addToGroup($user, 'admin');
- self::loginAsUser($user);
+ $this->groupManager->get('admin')->addUser($user);
+ $this->userSession->setUser($user);
$params = array();
$params['userid'] = $this->getUniqueID();
while($this->userManager->userExists($params['userid'])) {
@@ -126,32 +126,32 @@ class UsersTest extends TestCase {
public function testGetUserOnOtherUser() {
$users = $this->generateUsers(2);
$params['userid'] = $users[0];
- self::loginAsUser($users[1]);
+ $this->userSession->setUser($users[1]);
$result = $this->api->getUser($params);
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertFalse($result->succeeded());
// Now as as admin
$users = $this->generateUsers(2);
- $params['userid'] = $users[0];
+ $params['userid'] = $users[0]->getUID();
// login to generate home
- self::loginAsUser($users[0]);
- \OC_Group::addToGroup($users[1], 'admin');
- self::loginAsUser($users[1]);
+ $this->userSession->setUser($users[0]);
+ $this->groupManager->get('admin')->addUser($users[1]);
+ $this->userSession->setUser($users[1]);
$result = $this->api->getUser($params);
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
$data = $result->getData();
- $this->assertEquals(\OC::$server->getConfig()->getUserValue($users[0], 'core', 'enabled', 'true'), $data['enabled']);
+ $this->assertEquals(\OC::$server->getConfig()->getUserValue($users[0]->getUID(), 'core', 'enabled', 'true'), $data['enabled']);
}
public function testEditOwnDisplayName() {
// Test editing own name
$user = $this->generateUsers();
- self::loginAsUser($user);
+ $this->userSession->setUser($user);
$result = $this->api->editUser(
array(
- 'userid' => $user,
+ 'userid' => $user->getUID(),
'_put' => array(
'key' => 'display',
'value' => 'newname',
@@ -160,39 +160,39 @@ class UsersTest extends TestCase {
);
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
- $this->assertEquals('newname', $this->userManager->get($user)->getDisplayName());
+ $this->assertEquals('newname', $user->getDisplayName());
}
public function testAdminEditDisplayNameOfUser() {
// Test admin editing users name
$user = $this->generateUsers();
- \OC_Group::addToGroup($user, 'admin');
- self::loginAsUser($user);
+ $this->groupManager->get('admin')->addUser($user);
+ $this->userSession->setUser($user);
$user2 = $this->generateUsers();
$result = $this->api->editUser(
- array(
- 'userid' => $user2,
- '_put' => array(
+ [
+ 'userid' => $user2->getUID(),
+ '_put' => [
'key' => 'display',
'value' => 'newname',
- ),
- )
+ ],
+ ]
);
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
- $this->assertEquals('newname', $this->userManager->get($user2)->getDisplayName());
+ $this->assertEquals('newname', $user2->getDisplayName());
}
public function testUserEditOtherUserDisplayName() {
// Test editing other users name
$user = $this->generateUsers();
- self::loginAsUser($user);
+ $this->userSession->setUser($user);
$user2 = $this->generateUsers();
$result = $this->api->editUser(
array(
- 'userid' => $user2,
+ 'userid' => $user2->getUID(),
'_put' => array(
'key' => 'display',
'value' => 'newname',
@@ -211,11 +211,11 @@ class UsersTest extends TestCase {
*/
public function testEditOwnQuota($expected, $quota) {
$user = $this->generateUsers();
- $this->groupManager->get('admin')->addUser($this->userManager->get($user));
- self::loginAsUser($user);
+ $this->groupManager->get('admin')->addUser($user);
+ $this->userSession->setUser($user);
$result = $this->api->editUser(
[
- 'userid' => $user,
+ 'userid' => $user->getUID(),
'_put' => [
'key' => 'quota',
'value' => $quota,
@@ -238,11 +238,11 @@ class UsersTest extends TestCase {
public function testAdminEditOwnQuota() {
$user = $this->generateUsers();
- $this->groupManager->get('admin')->addUser($this->userManager->get($user));
- self::loginAsUser($user);
+ $this->groupManager->get('admin')->addUser($user);
+ $this->userSession->setUser($user);
$result = $this->api->editUser(
array(
- 'userid' => $user,
+ 'userid' => $user->getUID(),
'_put' => array(
'key' => 'quota',
'value' => '20G',
@@ -255,12 +255,12 @@ class UsersTest extends TestCase {
public function testAdminEditOtherUserQuota() {
$user = $this->generateUsers();
- $this->groupManager->get('admin')->addUser($this->userManager->get($user));
- self::loginAsUser($user);
+ $this->groupManager->get('admin')->addUser($user);
+ $this->userSession->setUser($user);
$user2 = $this->generateUsers();
$result = $this->api->editUser(
array(
- 'userid' => $user2,
+ 'userid' => $user2->getUID(),
'_put' => array(
'key' => 'quota',
'value' => '20G',
@@ -273,11 +273,11 @@ class UsersTest extends TestCase {
public function testUserEditOtherUserQuota() {
$user = $this->generateUsers();
- self::loginAsUser($user);
+ $this->userSession->setUser($user);
$user2 = $this->generateUsers();
$result = $this->api->editUser(
array(
- 'userid' => $user2,
+ 'userid' => $user2->getUID(),
'_put' => array(
'key' => 'quota',
'value' => '20G',
@@ -291,10 +291,10 @@ class UsersTest extends TestCase {
public function testUserEditOwnEmail() {
$user = $this->generateUsers();
$email = 'test@example.com';
- self::loginAsUser($user);
+ $this->userSession->setUser($user);
$result = $this->api->editUser(
array(
- 'userid' => $user,
+ 'userid' => $user->getUID(),
'_put' => array(
'key' => 'email',
'value' => $email,
@@ -303,16 +303,16 @@ class UsersTest extends TestCase {
);
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
- $this->assertEquals($email, \OC::$server->getConfig()->getUserValue($user, 'settings', 'email', null));
+ $this->assertEquals($email, \OC::$server->getConfig()->getUserValue($user->getUID(), 'settings', 'email', null));
}
public function testUserEditOtherUserEmailAsUser() {
$users = $this->generateUsers(2);
$email = 'test@example.com';
- self::loginAsUser($users[0]);
+ $this->userSession->setUser($users[0]);
$result = $this->api->editUser(
array(
- 'userid' => $users[1],
+ 'userid' => $users[1]->getUID(),
'_put' => array(
'key' => 'email',
'value' => $email,
@@ -326,11 +326,11 @@ class UsersTest extends TestCase {
public function testUserEditOtherUserEmailAsAdmin() {
$users = $this->generateUsers(2);
$email = 'test@example.com';
- self::loginAsUser($users[0]);
- $this->groupManager->get('admin')->addUser($this->userManager->get($users[0]));
+ $this->userSession->setUser($users[0]);
+ $this->groupManager->get('admin')->addUser($users[0]);
$result = $this->api->editUser(
array(
- 'userid' => $users[1],
+ 'userid' => $users[1]->getUID(),
'_put' => array(
'key' => 'email',
'value' => $email,
@@ -339,14 +339,14 @@ class UsersTest extends TestCase {
);
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
- $this->assertEquals($email, \OC::$server->getConfig()->getUserValue($users[1], 'settings', 'email', null));
+ $this->assertEquals($email, \OC::$server->getConfig()->getUserValue($users[1]->getUID(), 'settings', 'email', null));
}
public function testDeleteSelf() {
$user = $this->generateUsers();
- self::loginAsUser($user);
+ $this->userSession->setUser($user);
$result = $this->api->deleteUser(array(
- 'userid' => $user,
+ 'userid' => $user->getUID(),
));
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertFalse($result->succeeded());
@@ -354,10 +354,10 @@ class UsersTest extends TestCase {
public function testDeleteOtherAsUser() {
$user = $this->generateUsers();
- self::loginAsUser($user);
+ $this->userSession->setUser($user);
$user2 = $this->generateUsers();
$result = $this->api->deleteUser(array(
- 'userid' => $user2,
+ 'userid' => $user2->getUID(),
));
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertFalse($result->succeeded());
@@ -365,34 +365,31 @@ class UsersTest extends TestCase {
public function testDeleteOtherAsSubAdmin() {
$user = $this->generateUsers();
- self::loginAsUser($user);
+ $this->userSession->setUser($user);
$user2 = $this->generateUsers();
- $group = $this->getUniqueID();
- $this->groupManager->createGroup($group);
- $this->groupManager->get($group)->addUser($this->userManager->get($user));
- $this->groupManager->get($group)->addUser($this->userManager->get($user2));
- \OC_SubAdmin::createSubAdmin($user, $group);
+ $group = $this->groupManager->createGroup($this->getUniqueID());
+ $group->addUser($user);
+ $group->addUser($user2);
+ \OC_SubAdmin::createSubAdmin($user->getUID(), $group->getGID());
$result = $this->api->deleteUser(array(
- 'userid' => $user2,
+ 'userid' => $user2->getUID(),
));
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
- $this->groupManager->get($group)->delete();
+ $group->delete();
}
public function testDeleteOtherAsIrelevantSubAdmin() {
$user = $this->generateUsers();
- self::loginAsUser($user);
+ $this->userSession->setUser($user);
$user2 = $this->generateUsers();
- $group = $this->getUniqueID();
- $group2 = $this->getUniqueID();
- $group = $this->groupManager->createGroup($group);
- $group2 = $this->groupManager->createGroup($group2);
- $group->addUser($this->userManager->get($user));
- $group2->addUser($this->userManager->get($user2));
- \OC_SubAdmin::createSubAdmin($user, $group->getGID());
+ $group = $this->groupManager->createGroup($this->getUniqueID());
+ $group2 = $this->groupManager->createGroup($this->getUniqueID());
+ $group->addUser($user);
+ $group2->addUser($user2);
+ \OC_SubAdmin::createSubAdmin($user->getUID(), $group->getGID());
$result = $this->api->deleteUser(array(
- 'userid' => $user2,
+ 'userid' => $user2->getUID(),
));
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertFalse($result->succeeded());
@@ -402,11 +399,11 @@ class UsersTest extends TestCase {
public function testDeleteOtherAsAdmin() {
$user = $this->generateUsers();
- $this->groupManager->get('admin')->addUser($this->userManager->get($user));
- self::loginAsUser($user);
+ $this->groupManager->get('admin')->addUser($user);
+ $this->userSession->setUser($user);
$user2 = $this->generateUsers();
$result = $this->api->deleteUser(array(
- 'userid' => $user2,
+ 'userid' => $user2->getUID(),
));
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
@@ -414,10 +411,10 @@ class UsersTest extends TestCase {
public function testDeleteSelfAsAdmin() {
$user = $this->generateUsers();
- $this->groupManager->get('admin')->addUser($this->userManager->get($user));
- self::loginAsUser($user);
+ $this->groupManager->get('admin')->addUser($user);
+ $this->userSession->setUser($user);
$result = $this->api->deleteUser(array(
- 'userid' => $user,
+ 'userid' => $user->getUID(),
));
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertFalse($result->succeeded());
@@ -425,12 +422,12 @@ class UsersTest extends TestCase {
public function testGetUsersGroupsOnSelf() {
$user = $this->generateUsers();
- self::loginAsUser($user);
+ $this->userSession->setUser($user);
$group = $this->getUniqueID();
$group = $this->groupManager->createGroup($group);
- $group->addUser($this->userManager->get($user));
+ $group->addUser($user);
$result = $this->api->getUsersGroups(array(
- 'userid' => $user,
+ 'userid' => $user->getUID(),
));
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
@@ -443,12 +440,12 @@ class UsersTest extends TestCase {
public function testGetUsersGroupOnOther() {
$user1 = $this->generateUsers();
$user2 = $this->generateUsers();
- self::loginAsUser($user1);
+ $this->userSession->setUser($user1);
$group = $this->getUniqueID();
$group = $this->groupManager->createGroup($group);
- $group->addUser($this->userManager->get($user2));
+ $group->addUser($user2);
$result = $this->api->getUsersGroups(array(
- 'userid' => $user2,
+ 'userid' => $user2->getUID(),
));
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertFalse($result->succeeded());
@@ -457,14 +454,14 @@ class UsersTest extends TestCase {
public function testGetUsersGroupOnOtherAsAdmin() {
$user1 = $this->generateUsers();
- $this->groupManager->get('admin')->addUser($this->userManager->get($user1));
+ $this->groupManager->get('admin')->addUser($user1);
$user2 = $this->generateUsers();
- self::loginAsUser($user1);
+ $this->userSession->setUser($user1);
$group = $this->getUniqueID();
$group = $this->groupManager->createGroup($group);
- $group->addUser($this->userManager->get($user2));
+ $group->addUser($user2);
$result = $this->api->getUsersGroups(array(
- 'userid' => $user2,
+ 'userid' => $user2->getUID(),
));
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
@@ -477,17 +474,17 @@ class UsersTest extends TestCase {
public function testGetUsersGroupsOnOtherAsSubAdmin() {
$user1 = $this->generateUsers();
$user2 = $this->generateUsers();
- self::loginAsUser($user1);
+ $this->userSession->setUser($user1);
$group1 = $this->getUniqueID();
$group2 = $this->getUniqueID();
$group1 = $this->groupManager->createGroup($group1);
$group2 = $this->groupManager->createGroup($group2);
- $group1->addUser($this->userManager->get($user2));
- $group2->addUser($this->userManager->get($user2));
- $group1->addUser($this->userManager->get($user1));
- \OC_SubAdmin::createSubAdmin($user1, $group1->getGID());
+ $group1->addUser($user2);
+ $group2->addUser($user2);
+ $group1->addUser($user1);
+ \OC_SubAdmin::createSubAdmin($user1->getUID(), $group1->getGID());
$result = $this->api->getUsersGroups(array(
- 'userid' => $user2,
+ 'userid' => $user2->getUID(),
));
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
@@ -501,16 +498,16 @@ class UsersTest extends TestCase {
public function testGetUsersGroupsOnOtherAsIrelevantSubAdmin() {
$user1 = $this->generateUsers();
$user2 = $this->generateUsers();
- self::loginAsUser($user1);
+ $this->userSession->setUser($user1);
$group1 = $this->getUniqueID();
$group2 = $this->getUniqueID();
$group1 = $this->groupManager->createGroup($group1);
$group2 = $this->groupManager->createGroup($group2);
- $group2->addUser($this->userManager->get($user2));
- $group1->addUser($this->userManager->get($user1));
- \OC_SubAdmin::createSubAdmin($user1, $group1->getGID());
+ $group2->addUser($user2);
+ $group1->addUser($user1);
+ \OC_SubAdmin::createSubAdmin($user1->getUID(), $group1->getGID());
$result = $this->api->getUsersGroups(array(
- 'userid' => $user2,
+ 'userid' => $user2->getUID(),
));
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertFalse($result->succeeded());
@@ -522,67 +519,67 @@ class UsersTest extends TestCase {
$user = $this->generateUsers();
$group = $this->getUniqueID();
$group = $this->groupManager->createGroup($group);
- self::loginAsUser($user);
+ $this->userSession->setUser($user);
$_POST['groupid'] = $group->getGID();
$result = $this->api->addToGroup(array(
- 'userid' => $user,
+ 'userid' => $user->getUID(),
));
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertFalse($result->succeeded());
- $this->assertFalse($group->inGroup($this->userManager->get($user)));
+ $this->assertFalse($group->inGroup($user));
$group->delete();
}
public function testAddToGroupAsAdmin() {
$user = $this->generateUsers();
- $this->groupManager->get('admin')->addUser($this->userManager->get($user));
+ $this->groupManager->get('admin')->addUser($user);
$group = $this->getUniqueID();
$group = $this->groupManager->createGroup($group);
$user2 = $this->generateUsers();
- self::loginAsUser($user);
+ $this->userSession->setUser($user);
$_POST['groupid'] = $group->getGID();
$result = $this->api->addToGroup(array(
- 'userid' => $user2,
+ 'userid' => $user2->getUID(),
));
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
- $this->assertTrue($group->inGroup($this->userManager->get($user2)));
+ $this->assertTrue($group->inGroup($user2));
$group->delete();
}
public function testAddToGroupAsSubAdmin() {
$user1 = $this->generateUsers();
$user2 = $this->generateUsers();
- self::loginAsUser($user1);
+ $this->userSession->setUser($user1);
$group1 = $this->getUniqueID();
$group1 = $this->groupManager->createGroup($group1);
- \OC_SubAdmin::createSubAdmin($user1, $group1->getGID());
+ \OC_SubAdmin::createSubAdmin($user1->getUID(), $group1->getGID());
$_POST['groupid'] = $group1->getGID();
$result = $this->api->addToGroup(array(
- 'userid' => $user2,
+ 'userid' => $user2->getUID(),
));
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertFalse($result->succeeded());
- $this->assertFalse($group1->inGroup($this->userManager->get($user2)));
+ $this->assertFalse($group1->inGroup($user2));
$group1->delete();
}
public function testAddToGroupAsIrelevantSubAdmin() {
$user1 = $this->generateUsers();
$user2 = $this->generateUsers();
- self::loginAsUser($user1);
+ $this->userSession->setUser($user1);
$group1 = $this->getUniqueID();
$group2 = $this->getUniqueID();
$group1 = $this->groupManager->createGroup($group1);
$group2 = $this->groupManager->createGroup($group2);
- \OC_SubAdmin::createSubAdmin($user1, $group1->getGID());
+ \OC_SubAdmin::createSubAdmin($user1->getUID(), $group1->getGID());
$_POST['groupid'] = $group2->getGID();
$result = $this->api->addToGroup(array(
- 'userid' => $user2,
+ 'userid' => $user2->getUID(),
));
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertFalse($result->succeeded());
- $this->assertFalse($group2->inGroup($this->userManager->get($user2)));
+ $this->assertFalse($group2->inGroup($user2));
$group1->delete();
$group2->delete();
}
@@ -590,83 +587,83 @@ class UsersTest extends TestCase {
// test delete /cloud/users/{userid}/groups
public function testRemoveFromGroupAsSelf() {
$user1 = $this->generateUsers();
- self::loginAsUser($user1);
+ $this->userSession->setUser($user1);
$group1 = $this->getUniqueID();
$group1 = $this->groupManager->createGroup($group1);
- $group1->addUser($this->userManager->get($user1));
+ $group1->addUser($user1);
$result = $this->api->removeFromGroup(array(
- 'userid' => $user1,
+ 'userid' => $user1->getUID(),
'_delete' => array(
'groupid' => $group1->getGID(),
),
));
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertFalse($result->succeeded());
- $this->assertTrue($group1->inGroup($this->userManager->get($user1)));
+ $this->assertTrue($group1->inGroup($user1));
$group1->delete();
}
public function testRemoveFromGroupAsAdmin() {
$user1 = $this->generateUsers();
$user2 = $this->generateUsers();
- self::loginAsUser($user1);
+ $this->userSession->setUser($user1);
$group1 = $this->getUniqueID();
$group1 = $this->groupManager->createGroup($group1);
- $group1->addUser($this->userManager->get($user2));
- $this->groupManager->get('admin')->addUser($this->userManager->get($user1));
+ $group1->addUser($user2);
+ $this->groupManager->get('admin')->addUser($user1);
$result = $this->api->removeFromGroup(array(
- 'userid' => $user2,
+ 'userid' => $user2->getUID(),
'_delete' => array(
'groupid' => $group1->getGID(),
),
));
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
- $this->assertFalse($group1->inGroup($this->userManager->get($user2)));
+ $this->assertFalse($group1->inGroup($user2));
$group1->delete();
}
public function testRemoveFromGroupAsSubAdmin() {
$user1 = $this->generateUsers();
- self::loginAsUser($user1);
+ $this->userSession->setUser($user1);
$user2 = $this->generateUsers();
$group1 = $this->getUniqueID();
$group1 = $this->groupManager->createGroup($group1);
- $group1->addUser($this->userManager->get($user1));
- $group1->addUser($this->userManager->get($user2));
- \OC_SubAdmin::createSubAdmin($user1, $group1->getGID());
+ $group1->addUser($user1);
+ $group1->addUser($user2);
+ \OC_SubAdmin::createSubAdmin($user1->getUID(), $group1->getGID());
$result = $this->api->removeFromGroup(array(
- 'userid' => $user2,
+ 'userid' => $user2->getUID(),
'_delete' => array(
'groupid' => $group1->getGID(),
),
));
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
- $this->assertFalse($group1->inGroup($this->userManager->get($user2)));
+ $this->assertFalse($group1->inGroup($user2));
$group1->delete();
}
public function testRemoveFromGroupAsIrelevantSubAdmin() {
$user1 = $this->generateUsers();
- self::loginAsUser($user1);
+ $this->userSession->setUser($user1);
$user2 = $this->generateUsers();
$group1 = $this->getUniqueID();
$group2 = $this->getUniqueID();
$group1 = $this->groupManager->createGroup($group1);
$group2 = $this->groupManager->createGroup($group2);
- $group1->addUser($this->userManager->get($user1));
- $group2->addUser($this->userManager->get($user2));
- \OC_SubAdmin::createSubAdmin($user1, $group1->getGID());
+ $group1->addUser($user1);
+ $group2->addUser($user2);
+ \OC_SubAdmin::createSubAdmin($user1->getUID(), $group1->getGID());
$result = $this->api->removeFromGroup(array(
- 'userid' => $user2,
+ 'userid' => $user2->getUID(),
'_delete' => array(
'groupid' => $group2->getGID(),
),
));
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertFalse($result->succeeded());
- $this->assertTrue($group2->inGroup($this->userManager->get($user2)));
+ $this->assertTrue($group2->inGroup($user2));
$group1->delete();
$group2->delete();
}
@@ -674,28 +671,28 @@ class UsersTest extends TestCase {
public function testCreateSubAdmin() {
$user1 = $this->generateUsers();
$user2 = $this->generateUsers();
- self::loginAsUser($user1);
- $this->groupManager->get('admin')->addUser($this->userManager->get($user1));
+ $this->userSession->setUser($user1);
+ $this->groupManager->get('admin')->addUser($user1);
$group1 = $this->getUniqueID();
$group1 = $this->groupManager->createGroup($group1);
$_POST['groupid'] = $group1->getGID();
$result = $this->api->addSubAdmin(array(
- 'userid' => $user2,
+ 'userid' => $user2->getUID(),
));
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
- $this->assertTrue(\OC_SubAdmin::isSubAdminofGroup($user2, $group1->getGID()));
+ $this->assertTrue(\OC_SubAdmin::isSubAdminofGroup($user2->getUID(), $group1->getGID()));
$group1->delete();
$this->resetParams();
$user1 = $this->generateUsers();
$user2 = $this->generateUsers();
- self::loginAsUser($user1);
- $this->groupManager->get('admin')->addUser($this->userManager->get($user1));
+ $this->userSession->setUser($user1);
+ $this->groupManager->get('admin')->addUser($user1);
$_POST['groupid'] = 'admin';
$result = $this->api->addSubAdmin(array(
- 'userid' => $user2,
+ 'userid' => $user2->getUID(),
));
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertEquals(103, $result->getStatusCode());
@@ -704,8 +701,8 @@ class UsersTest extends TestCase {
$this->resetParams();
$user1 = $this->generateUsers();
- self::loginAsUser($user1);
- $this->groupManager->get('admin')->addUser($this->userManager->get($user1));
+ $this->userSession->setUser($user1);
+ $this->groupManager->get('admin')->addUser($user1);
$group1 = $this->getUniqueID();
$group1 = $this->groupManager->createGroup($group1);
$_POST['groupid'] = $group1->getGID();
@@ -721,25 +718,25 @@ class UsersTest extends TestCase {
public function testRemoveSubAdmin() {
$user1 = $this->generateUsers();
$user2 = $this->generateUsers();
- self::loginAsUser($user1);
- \OC_Group::addToGroup($user1, 'admin');
+ $this->userSession->setUser($user1);
+ $this->groupManager->get('admin')->addUser($user1);
$group1 = $this->getUniqueID();
$group1 = $this->groupManager->createGroup($group1);
- \OC_SubAdmin::createSubAdmin($user2, $group1->getGID());
+ \OC_SubAdmin::createSubAdmin($user2->getUID(), $group1->getGID());
$result = $this->api->removeSubAdmin(array(
- 'userid' => $user2,
+ 'userid' => $user2->getUID(),
'_delete' => array(
'groupid' => $group1->getGID(),
),
));
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
- $this->assertTrue(!\OC_SubAdmin::isSubAdminofGroup($user2, $group1->getGID()));
+ $this->assertTrue(!\OC_SubAdmin::isSubAdminofGroup($user2->getUID(), $group1->getGID()));
$group1->delete();
$user1 = $this->generateUsers();
- self::loginAsUser($user1);
- $this->groupManager->get('admin')->addUser($this->userManager->get($user1));
+ $this->userSession->setUser($user1);
+ $this->groupManager->get('admin')->addUser($user1);
$result = $this->api->removeSubAdmin(array(
'userid' => $this->getUniqueID(),
'_delete' => array(
@@ -754,13 +751,13 @@ class UsersTest extends TestCase {
$user1 = $this->generateUsers();
$user2 = $this->generateUsers();
- self::loginAsUser($user1);
- $this->groupManager->get('admin')->addUser($this->userManager->get($user1));
+ $this->userSession->setUser($user1);
+ $this->groupManager->get('admin')->addUser($user1);
$group1 = $this->getUniqueID();
$group1 = $this->groupManager->createGroup($group1);
$_POST['groupid'] = $group1->getGID();
$result = $this->api->removeSubAdmin(array(
- 'userid' => $user2,
+ 'userid' => $user2->getUID(),
'_delete' => array(
'groupid' => $group1->getGID(),
),
@@ -774,13 +771,13 @@ class UsersTest extends TestCase {
public function testGetSubAdminGroups() {
$user1 = $this->generateUsers();
$user2 = $this->generateUsers();
- self::loginAsUser($user1);
- $this->groupManager->get('admin')->addUser($this->userManager->get($user1));
+ $this->userSession->setUser($user1);
+ $this->groupManager->get('admin')->addUser($user1);
$group1 = $this->getUniqueID();
$group1 = $this->groupManager->createGroup($group1);
- \OC_SubAdmin::createSubAdmin($user2, $group1->getGID());
+ \OC_SubAdmin::createSubAdmin($user2->getUID(), $group1->getGID());
$result = $this->api->getUserSubAdminGroups(array(
- 'userid' => $user2,
+ 'userid' => $user2->getUID(),
));
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
@@ -789,8 +786,8 @@ class UsersTest extends TestCase {
$group1->delete();
$user1 = $this->generateUsers();
- self::loginAsUser($user1);
- $this->groupManager->get('admin')->addUser($this->userManager->get($user1));
+ $this->userSession->setUser($user1);
+ $this->groupManager->get('admin')->addUser($user1);
$result = $this->api->getUserSubAdminGroups(array(
'userid' => $this->getUniqueID(),
));
@@ -802,15 +799,14 @@ class UsersTest extends TestCase {
public function testSubAdminOfGroupAlreadySubAdmin() {
$user1 = $this->generateUsers();
$user2 = $this->generateUsers();
- self::loginAsUser($user1);
- $this->groupManager->get('admin')->addUser($this->userManager->get($user1));
- $group1 = $this->getUniqueID();
- $group1 = $this->groupManager->createGroup($group1);
+ $this->userSession->setUser($user1);
+ $this->groupManager->get('admin')->addUser($user1);
+ $group1 = $this->groupManager->createGroup($this->getUniqueID());
//Make user2 subadmin of group1
$_POST['groupid'] = $group1->getGID();
$result = $this->api->addSubAdmin([
- 'userid' => $user2,
+ 'userid' => $user2->getUID(),
]);
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
@@ -818,7 +814,7 @@ class UsersTest extends TestCase {
//Make user2 subadmin of group1 again
$_POST['groupid'] = $group1->getGID();
$result = $this->api->addSubAdmin([
- 'userid' => $user2,
+ 'userid' => $user2->getUID(),
]);
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());