From 5101bc54faea28d1210eb24f72abd76944c83af6 Mon Sep 17 00:00:00 2001
From: Vincent Petry <pvince81@owncloud.com>
Date: Thu, 4 Dec 2014 14:01:23 +0100
Subject: [PATCH] Add login/logout to TestCase base class

---
 tests/lib/testcase.php | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/tests/lib/testcase.php b/tests/lib/testcase.php
index 27c2832953..1ea3aa1354 100644
--- a/tests/lib/testcase.php
+++ b/tests/lib/testcase.php
@@ -148,4 +148,25 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
 		\OC_FileProxy::$enabled = true;
 		\OC_FileProxy::clearProxies();
 	}
+
+	/**
+	 * Login and setup FS as a given user,
+	 * sets the given user as the current user.
+	 *
+	 * @param string $user user id
+	 */
+	static protected function loginAsUser($user) {
+		self::logout();
+		\OC\Files\Filesystem::tearDown();
+		\OC_User::setUserId($user);
+		\OC_Util::setupFS($user);
+	}
+
+	/**
+	 * Logout the current user and tear down the filesystem.
+	 */
+	static protected function logout() {
+		\OC_Util::tearDownFS();
+		\OC_User::setUserId('');
+	}
 }
-- 
GitLab