[Pkg-owncloud-commits] [owncloud] 25/457: Fix provisioning API unit tests for login

David Prévot taffit at moszumanska.debian.org
Sun Jun 28 20:05:18 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit 5899b7b6ea1f8573370168333c16df38d80a5a38
Author: Vincent Petry <pvince81 at owncloud.com>
Date:   Mon May 18 12:28:54 2015 +0200

    Fix provisioning API unit tests for login
    
    Properly login the user every time to make sure their FS is properly
    setup.
---
 apps/provisioning_api/tests/appstest.php   |  2 +-
 apps/provisioning_api/tests/groupstest.php | 12 ++---
 apps/provisioning_api/tests/userstest.php  | 86 +++++++++++++++---------------
 3 files changed, 51 insertions(+), 49 deletions(-)

diff --git a/apps/provisioning_api/tests/appstest.php b/apps/provisioning_api/tests/appstest.php
index 140dd28..94bff8b 100644
--- a/apps/provisioning_api/tests/appstest.php
+++ b/apps/provisioning_api/tests/appstest.php
@@ -44,7 +44,7 @@ class AppsTest extends TestCase {
 
 		$user = $this->generateUsers();
 		\OC_Group::addToGroup($user, 'admin');
-		\OC_User::setUserId($user);
+		self::loginAsUser($user);
 
 		$result = \OCA\provisioning_API\Apps::getApps(array());
 
diff --git a/apps/provisioning_api/tests/groupstest.php b/apps/provisioning_api/tests/groupstest.php
index 94bde52..cb677d9 100644
--- a/apps/provisioning_api/tests/groupstest.php
+++ b/apps/provisioning_api/tests/groupstest.php
@@ -27,7 +27,7 @@ class GroupsTest extends TestCase {
 	public function testGetGroupAsUser() {
 
 		$users = $this->generateUsers(2);
-		\OC_User::setUserId($users[0]);
+		self::loginAsUser($users[0]);
 
 		$group = $this->getUniqueID();
 		\OC_Group::createGroup($group);
@@ -46,7 +46,7 @@ class GroupsTest extends TestCase {
 	public function testGetGroupAsSubadmin() {
 
 		$users = $this->generateUsers(2);
-		\OC_User::setUserId($users[0]);
+		self::loginAsUser($users[0]);
 
 		$group = $this->getUniqueID();
 		\OC_Group::createGroup($group);
@@ -75,7 +75,7 @@ class GroupsTest extends TestCase {
 	public function testGetGroupAsIrrelevantSubadmin() {
 
 		$users = $this->generateUsers(2);
-		\OC_User::setUserId($users[0]);
+		self::loginAsUser($users[0]);
 
 		$group = $this->getUniqueID();
 		\OC_Group::createGroup($group);
@@ -99,7 +99,7 @@ class GroupsTest extends TestCase {
 	public function testGetGroupAsAdmin() {
 
 		$users = $this->generateUsers(2);
-		\OC_User::setUserId($users[0]);
+		self::loginAsUser($users[0]);
 
 		$group = $this->getUniqueID();
 		\OC_Group::createGroup($group);
@@ -120,7 +120,7 @@ class GroupsTest extends TestCase {
 	public function testGetSubAdminsOfGroup() {
 		$user1 = $this->generateUsers();
 		$user2 = $this->generateUsers();
-		\OC_User::setUserId($user1);
+		self::loginAsUser($user1);
 		\OC_Group::addToGroup($user1, 'admin');
 		$group1 = $this->getUniqueID();
 		\OC_Group::createGroup($group1);
@@ -135,7 +135,7 @@ class GroupsTest extends TestCase {
 		\OC_Group::deleteGroup($group1);
 
 		$user1 = $this->generateUsers();
-		\OC_User::setUserId($user1);
+		self::loginAsUser($user1);
 		\OC_Group::addToGroup($user1, 'admin');
 		$result = \OCA\provisioning_api\Groups::getSubAdminsOfGroup(array(
 			'groupid' => $this->getUniqueID(),
diff --git a/apps/provisioning_api/tests/userstest.php b/apps/provisioning_api/tests/userstest.php
index c6a6133..0ba7635 100644
--- a/apps/provisioning_api/tests/userstest.php
+++ b/apps/provisioning_api/tests/userstest.php
@@ -81,7 +81,7 @@ class UsersTest extends TestCase {
 
 	public function testGetUserOnSelf() {
 		$user = $this->generateUsers();
-		\OC_User::setUserId($user);
+		self::loginAsUser($user);
 		$params['userid'] = $user;
 		$result = \OCA\provisioning_API\Users::getUser($params);
 		$this->assertInstanceOf('OC_OCS_Result', $result);
@@ -92,7 +92,7 @@ class UsersTest extends TestCase {
 	public function testGetUserOnNonExistingUser() {
 		$user = $this->generateUsers();
 		\OC_Group::addToGroup($user, 'admin');
-		\OC_User::setUserId($user);
+		self::loginAsUser($user);
 		$params = array();
 		$params['userid'] = $this->getUniqueID();
 		while(\OC_User::userExists($params['userid'])) {
@@ -108,7 +108,7 @@ class UsersTest extends TestCase {
 	public function testGetUserOnOtherUser() {
 		$users = $this->generateUsers(2);
 		$params['userid'] = $users[0];
-		\OC_User::setUserId($users[1]);
+		self::loginAsUser($users[1]);
 		$result = \OCA\provisioning_API\Users::getUser($params);
 		$this->assertInstanceOf('OC_OCS_Result', $result);
 		$this->assertFalse($result->succeeded());
@@ -116,8 +116,10 @@ class UsersTest extends TestCase {
 		// Now as as admin
 		$users = $this->generateUsers(2);
 		$params['userid'] = $users[0];
+		// login to generate home
+		self::loginAsUser($users[0]);
 		\OC_Group::addToGroup($users[1], 'admin');
-		\OC_User::setUserId($users[1]);
+		self::loginAsUser($users[1]);
 		$result = \OCA\provisioning_API\Users::getUser($params);
 		$this->assertInstanceOf('OC_OCS_Result', $result);
 		$this->assertTrue($result->succeeded());
@@ -129,7 +131,7 @@ class UsersTest extends TestCase {
 
 		// Test editing own name
 		$user = $this->generateUsers();
-		\OC_User::setUserId($user);
+		self::loginAsUser($user);
 		$result = \OCA\provisioning_API\Users::editUser(
 			array(
 				'userid' => $user,
@@ -150,7 +152,7 @@ class UsersTest extends TestCase {
 		// Test admin editing users name
 		$user = $this->generateUsers();
 		\OC_Group::addToGroup($user, 'admin');
-		\OC_User::setUserId($user);
+		self::loginAsUser($user);
 		$user2 = $this->generateUsers();
 		$result = \OCA\provisioning_API\Users::editUser(
 			array(
@@ -171,7 +173,7 @@ class UsersTest extends TestCase {
 
 		// Test editing other users name
 		$user = $this->generateUsers();
-		\OC_User::setUserId($user);
+		self::loginAsUser($user);
 		$user2 = $this->generateUsers();
 		$result = \OCA\provisioning_API\Users::editUser(
 			array(
@@ -195,7 +197,7 @@ class UsersTest extends TestCase {
 	public function testEditOwnQuota($expected, $quota) {
 		$user = $this->generateUsers();
 		\OC_Group::addToGroup($user, 'admin');
-		\OC_User::setUserId($user);
+		self::loginAsUser($user);
 		$result = \OCA\provisioning_API\Users::editUser(
 			[
 				'userid' => $user,
@@ -222,7 +224,7 @@ class UsersTest extends TestCase {
 	public function testAdminEditOwnQuota() {
 		$user = $this->generateUsers();
 		\OC_Group::addToGroup($user, 'admin');
-		\OC_User::setUserId($user);
+		self::loginAsUser($user);
 		$result = \OCA\provisioning_API\Users::editUser(
 			array(
 				'userid' => $user,
@@ -239,7 +241,7 @@ class UsersTest extends TestCase {
 	public function testAdminEditOtherUserQuota() {
 		$user = $this->generateUsers();
 		\OC_Group::addToGroup($user, 'admin');
-		\OC_User::setUserId($user);
+		self::loginAsUser($user);
 		$user2 = $this->generateUsers();
 		$result = \OCA\provisioning_API\Users::editUser(
 			array(
@@ -256,7 +258,7 @@ class UsersTest extends TestCase {
 
 	public function testUserEditOtherUserQuota() {
 		$user = $this->generateUsers();
-		\OC_User::setUserId($user);
+		self::loginAsUser($user);
 		$user2 = $this->generateUsers();
 		$result = \OCA\provisioning_API\Users::editUser(
 			array(
@@ -274,7 +276,7 @@ class UsersTest extends TestCase {
 	public function testUserEditOwnEmail() {
 		$user = $this->generateUsers();
 		$email = 'test at example.com';
-		\OC_User::setUserId($user);
+		self::loginAsUser($user);
 		$result = \OCA\provisioning_API\Users::editUser(
 			array(
 				'userid' => $user,
@@ -292,7 +294,7 @@ class UsersTest extends TestCase {
 	public function testUserEditOtherUserEmailAsUser() {
 		$users = $this->generateUsers(2);
 		$email = 'test at example.com';
-		\OC_User::setUserId($users[0]);
+		self::loginAsUser($users[0]);
 		$result = \OCA\provisioning_API\Users::editUser(
 			array(
 				'userid' => $users[1],
@@ -309,7 +311,7 @@ class UsersTest extends TestCase {
 	public function testUserEditOtherUserEmailAsAdmin() {
 		$users = $this->generateUsers(2);
 		$email = 'test at example.com';
-		\OC_User::setUserId($users[0]);
+		self::loginAsUser($users[0]);
 		\OC_Group::addToGroup($users[0], 'admin');
 		$result = \OCA\provisioning_API\Users::editUser(
 			array(
@@ -327,7 +329,7 @@ class UsersTest extends TestCase {
 
 	public function testDeleteSelf() {
 		$user = $this->generateUsers();
-		\OC_User::setUserId($user);
+		self::loginAsUser($user);
 		$result = \OCA\provisioning_API\Users::deleteUser(array(
 			'userid' => $user,
 			));
@@ -337,7 +339,7 @@ class UsersTest extends TestCase {
 
 	public function testDeleteOtherAsUser() {
 		$user = $this->generateUsers();
-		\OC_User::setUserId($user);
+		self::loginAsUser($user);
 		$user2 = $this->generateUsers();
 		$result = \OCA\provisioning_API\Users::deleteUser(array(
 			'userid' => $user2,
@@ -348,7 +350,7 @@ class UsersTest extends TestCase {
 
 	public function testDeleteOtherAsSubAdmin() {
 		$user = $this->generateUsers();
-		\OC_User::setUserId($user);
+		self::loginAsUser($user);
 		$user2 = $this->generateUsers();
 		$group = $this->getUniqueID();
 		\OC_Group::createGroup($group);
@@ -365,7 +367,7 @@ class UsersTest extends TestCase {
 
 	public function testDeleteOtherAsIrelevantSubAdmin() {
 		$user = $this->generateUsers();
-		\OC_User::setUserId($user);
+		self::loginAsUser($user);
 		$user2 = $this->generateUsers();
 		$group = $this->getUniqueID();
 		$group2 = $this->getUniqueID();
@@ -386,7 +388,7 @@ class UsersTest extends TestCase {
 	public function testDeleteOtherAsAdmin() {
 		$user = $this->generateUsers();
 		\OC_Group::addToGroup($user, 'admin');
-		\OC_User::setUserId($user);
+		self::loginAsUser($user);
 		$user2 = $this->generateUsers();
 		$result = \OCA\provisioning_API\Users::deleteUser(array(
 			'userid' => $user2,
@@ -398,7 +400,7 @@ class UsersTest extends TestCase {
 	public function testDeleteSelfAsAdmin() {
 		$user = $this->generateUsers();
 		\OC_Group::addToGroup($user, 'admin');
-		\OC_User::setUserId($user);
+		self::loginAsUser($user);
 		$result = \OCA\provisioning_API\Users::deleteUser(array(
 			'userid' => $user,
 			));
@@ -408,7 +410,7 @@ class UsersTest extends TestCase {
 
 	public function testGetUsersGroupsOnSelf() {
 		$user = $this->generateUsers();
-		\OC_User::setUserId($user);
+		self::loginAsUser($user);
 		$group = $this->getUniqueID();
 		\OC_Group::createGroup($group);
 		\OC_Group::addToGroup($user, $group);
@@ -426,7 +428,7 @@ class UsersTest extends TestCase {
 	public function testGetUsersGroupOnOther() {
 		$user1 = $this->generateUsers();
 		$user2 = $this->generateUsers();
-		\OC_User::setUserId($user1);
+		self::loginAsUser($user1);
 		$group = $this->getUniqueID();
 		\OC_Group::createGroup($group);
 		\OC_Group::addToGroup($user2, $group);
@@ -442,7 +444,7 @@ class UsersTest extends TestCase {
 		$user1 = $this->generateUsers();
 		\OC_Group::addToGroup($user1, 'admin');
 		$user2 = $this->generateUsers();
-		\OC_User::setUserId($user1);
+		self::loginAsUser($user1);
 		$group = $this->getUniqueID();
 		\OC_Group::createGroup($group);
 		\OC_Group::addToGroup($user2, $group);
@@ -460,7 +462,7 @@ class UsersTest extends TestCase {
 	public function testGetUsersGroupsOnOtherAsSubAdmin() {
 		$user1 = $this->generateUsers();
 		$user2 = $this->generateUsers();
-		\OC_User::setUserId($user1);
+		self::loginAsUser($user1);
 		$group1 = $this->getUniqueID();
 		$group2 = $this->getUniqueID();
 		\OC_Group::createGroup($group1);
@@ -484,7 +486,7 @@ class UsersTest extends TestCase {
 	public function testGetUsersGroupsOnOtherAsIrelevantSubAdmin() {
 		$user1 = $this->generateUsers();
 		$user2 = $this->generateUsers();
-		\OC_User::setUserId($user1);
+		self::loginAsUser($user1);
 		$group1 = $this->getUniqueID();
 		$group2 = $this->getUniqueID();
 		\OC_Group::createGroup($group1);
@@ -505,7 +507,7 @@ class UsersTest extends TestCase {
 		$user = $this->generateUsers();
 		$group = $this->getUniqueID();
 		\OC_Group::createGroup($group);
-		\OC_User::setUserId($user);
+		self::loginAsUser($user);
 		$_POST['groupid'] = $group;
 		$result = \OCA\provisioning_API\Users::addToGroup(array(
 			'userid' => $user,
@@ -522,7 +524,7 @@ class UsersTest extends TestCase {
 		$group = $this->getUniqueID();
 		\OC_Group::createGroup($group);
 		$user2 = $this->generateUsers();
-		\OC_User::setUserId($user);
+		self::loginAsUser($user);
 		$_POST['groupid'] = $group;
 		$result = \OCA\provisioning_API\Users::addToGroup(array(
 			'userid' => $user2,
@@ -536,7 +538,7 @@ class UsersTest extends TestCase {
 	public function testAddToGroupAsSubAdmin() {
 		$user1 = $this->generateUsers();
 		$user2 = $this->generateUsers();
-		\OC_User::setUserId($user1);
+		self::loginAsUser($user1);
 		$group1 = $this->getUniqueID();
 		\OC_Group::createGroup($group1);
 		\OC_SubAdmin::createSubAdmin($user1, $group1);
@@ -553,7 +555,7 @@ class UsersTest extends TestCase {
 	public function testAddToGroupAsIrelevantSubAdmin() {
 		$user1 = $this->generateUsers();
 		$user2 = $this->generateUsers();
-		\OC_User::setUserId($user1);
+		self::loginAsUser($user1);
 		$group1 = $this->getUniqueID();
 		$group2 = $this->getUniqueID();
 		\OC_Group::createGroup($group1);
@@ -573,7 +575,7 @@ class UsersTest extends TestCase {
 	// test delete /cloud/users/{userid}/groups
 	public function testRemoveFromGroupAsSelf() {
 		$user1 = $this->generateUsers();
-		\OC_User::setUserId($user1);
+		self::loginAsUser($user1);
 		$group1 = $this->getUniqueID();
 		\OC_Group::createGroup($group1);
 		\OC_Group::addToGroup($user1, $group1);
@@ -592,7 +594,7 @@ class UsersTest extends TestCase {
 	public function testRemoveFromGroupAsAdmin() {
 		$user1 = $this->generateUsers();
 		$user2 = $this->generateUsers();
-		\OC_User::setUserId($user1);
+		self::loginAsUser($user1);
 		$group1 = $this->getUniqueID();
 		\OC_Group::createGroup($group1);
 		\OC_Group::addToGroup($user2, $group1);
@@ -611,7 +613,7 @@ class UsersTest extends TestCase {
 
 	public function testRemoveFromGroupAsSubAdmin() {
 		$user1 = $this->generateUsers();
-		\OC_User::setUserId($user1);
+		self::loginAsUser($user1);
 		$user2 = $this->generateUsers();
 		$group1 = $this->getUniqueID();
 		\OC_Group::createGroup($group1);
@@ -632,7 +634,7 @@ class UsersTest extends TestCase {
 
 	public function testRemoveFromGroupAsIrelevantSubAdmin() {
 		$user1 = $this->generateUsers();
-		\OC_User::setUserId($user1);
+		self::loginAsUser($user1);
 		$user2 = $this->generateUsers();
 		$group1 = $this->getUniqueID();
 		$group2 = $this->getUniqueID();
@@ -657,7 +659,7 @@ class UsersTest extends TestCase {
 	public function testCreateSubAdmin() {
 		$user1 = $this->generateUsers();
 		$user2 = $this->generateUsers();
-		\OC_User::setUserId($user1);
+		self::loginAsUser($user1);
 		\OC_Group::addToGroup($user1, 'admin');
 		$group1 = $this->getUniqueID();
 		\OC_Group::createGroup($group1);
@@ -674,7 +676,7 @@ class UsersTest extends TestCase {
 
 		$user1 = $this->generateUsers();
 		$user2 = $this->generateUsers();
-		\OC_User::setUserId($user1);
+		self::loginAsUser($user1);
 		\OC_Group::addToGroup($user1, 'admin');
 		$_POST['groupid'] = 'admin';
 		$result = \OCA\provisioning_api\Users::addSubAdmin(array(
@@ -687,7 +689,7 @@ class UsersTest extends TestCase {
 		$this->resetParams();
 
 		$user1 = $this->generateUsers();
-		\OC_User::setUserId($user1);
+		self::loginAsUser($user1);
 		\OC_Group::addToGroup($user1, 'admin');
 		$group1 = $this->getUniqueID();
 		\OC_Group::createGroup($group1);
@@ -704,7 +706,7 @@ class UsersTest extends TestCase {
 	public function testRemoveSubAdmin() {
 		$user1 = $this->generateUsers();
 		$user2 = $this->generateUsers();
-		\OC_User::setUserId($user1);
+		self::loginAsUser($user1);
 		\OC_Group::addToGroup($user1, 'admin');
 		$group1 = $this->getUniqueID();
 		\OC_Group::createGroup($group1);
@@ -721,7 +723,7 @@ class UsersTest extends TestCase {
 		\OC_Group::deleteGroup($group1);
 
 		$user1 = $this->generateUsers();
-		\OC_User::setUserId($user1);
+		self::loginAsUser($user1);
 		\OC_Group::addToGroup($user1, 'admin');
 		$result = \OCA\provisioning_api\Users::removeSubAdmin(array(
 			'userid' => $this->getUniqueID(),
@@ -737,7 +739,7 @@ class UsersTest extends TestCase {
 
 		$user1 = $this->generateUsers();
 		$user2 = $this->generateUsers();
-		\OC_User::setUserId($user1);
+		self::loginAsUser($user1);
 		\OC_Group::addToGroup($user1, 'admin');
 		$group1 = $this->getUniqueID();
 		\OC_Group::createGroup($group1);
@@ -757,7 +759,7 @@ class UsersTest extends TestCase {
 	public function testGetSubAdminGroups() {
 		$user1 = $this->generateUsers();
 		$user2 = $this->generateUsers();
-		\OC_User::setUserId($user1);
+		self::loginAsUser($user1);
 		\OC_Group::addToGroup($user1, 'admin');
 		$group1 = $this->getUniqueID();
 		\OC_Group::createGroup($group1);
@@ -772,7 +774,7 @@ class UsersTest extends TestCase {
 		\OC_Group::deleteGroup($group1);
 
 		$user1 = $this->generateUsers();
-		\OC_User::setUserId($user1);
+		self::loginAsUser($user1);
 		\OC_Group::addToGroup($user1, 'admin');
 		$group1 = $this->getUniqueID();
 		$result = \OCA\provisioning_api\Users::getUserSubAdminGroups(array(
@@ -786,7 +788,7 @@ class UsersTest extends TestCase {
 	public function testSubAdminOfGroupAlreadySubAdmin() {
 		$user1 = $this->generateUsers();
 		$user2 = $this->generateUsers();
-		\OC_User::setUserId($user1);
+		self::loginAsUser($user1);
 		\OC_Group::addToGroup($user1, 'admin');
 		$group1 = $this->getUniqueID();
 		\OC_Group::createGroup($group1);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list