]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add login/logout to TestCase base class
authorVincent Petry <pvince81@owncloud.com>
Thu, 4 Dec 2014 13:01:23 +0000 (14:01 +0100)
committerVincent Petry <pvince81@owncloud.com>
Wed, 10 Dec 2014 15:11:27 +0000 (16:11 +0100)
tests/lib/testcase.php

index 27c283295350bfe2e7b7cc228b4fa913b3a11562..1ea3aa135479ef6f0de1c17979471124558124fc 100644 (file)
@@ -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('');
+       }
 }