diff --git a/apps/files/tests/ajax_rename.php b/apps/files/tests/ajax_rename.php index 789177bb35..34e7f5085d 100644 --- a/apps/files/tests/ajax_rename.php +++ b/apps/files/tests/ajax_rename.php @@ -38,21 +38,15 @@ class Test_OC_Files_App_Rename extends \Test\TestCase { */ private $files; - private $originalStorage; - protected function setUp() { parent::setUp(); - $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); - // mock OC_L10n if (!self::$user) { self::$user = uniqid(); } \OC_User::createUser(self::$user, 'password'); - \OC_User::setUserId(self::$user); - - \OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files'); + $this->loginAsUser(self::$user); $l10nMock = $this->getMock('\OC_L10N', array('t'), array(), '', false); $l10nMock->expects($this->any()) @@ -72,9 +66,8 @@ class Test_OC_Files_App_Rename extends \Test\TestCase { protected function tearDown() { $result = \OC_User::deleteUser(self::$user); $this->assertTrue($result); - \OC\Files\Filesystem::tearDown(); - \OC\Files\Filesystem::mount($this->originalStorage, array(), '/'); + $this->logout(); parent::tearDown(); } diff --git a/apps/files_trashbin/tests/storage.php b/apps/files_trashbin/tests/storage.php index f1ac055d33..d5bd7c318d 100644 --- a/apps/files_trashbin/tests/storage.php +++ b/apps/files_trashbin/tests/storage.php @@ -34,11 +34,6 @@ class Storage extends \Test\TestCase { */ private $user; - /** - * @var \OC\Files\Storage\Storage - **/ - private $originalStorage; - /** * @var \OC\Files\View */ @@ -61,8 +56,6 @@ class Storage extends \Test\TestCase { // this will setup the FS $this->loginAsUser($this->user); - $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); - \OCA\Files_Trashbin\Storage::setupStorage(); $this->rootView = new \OC\Files\View('/'); @@ -73,7 +66,6 @@ class Storage extends \Test\TestCase { protected function tearDown() { \OC\Files\Filesystem::getLoader()->removeStorageWrapper('oc_trashbin'); - \OC\Files\Filesystem::mount($this->originalStorage, array(), '/'); $this->logout(); \OC_User::deleteUser($this->user); \OC_Hook::clear(); diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php index 970af2e68d..7c3ebd5a6f 100644 --- a/tests/lib/files/cache/updater.php +++ b/tests/lib/files/cache/updater.php @@ -33,16 +33,12 @@ class Updater extends \Test\TestCase { */ protected $updater; - /** @var \OC\Files\Storage\Storage */ - private $originalStorage; - protected function setUp() { parent::setUp(); - $this->originalStorage = Filesystem::getStorage('/'); + $this->loginAsUser(); $this->storage = new Temporary(array()); - Filesystem::clearMounts(); Filesystem::mount($this->storage, array(), '/'); $this->view = new View(''); $this->updater = new \OC\Files\Cache\Updater($this->view); @@ -51,8 +47,8 @@ class Updater extends \Test\TestCase { protected function tearDown() { Filesystem::clearMounts(); - Filesystem::mount($this->originalStorage, array(), '/'); + $this->logout(); parent::tearDown(); } diff --git a/tests/lib/files/cache/updaterlegacy.php b/tests/lib/files/cache/updaterlegacy.php index 6bdacbe34f..f4d52e9a39 100644 --- a/tests/lib/files/cache/updaterlegacy.php +++ b/tests/lib/files/cache/updaterlegacy.php @@ -27,9 +27,6 @@ class UpdaterLegacy extends \Test\TestCase { */ private $cache; - /** @var \OC\Files\Storage\Storage */ - private $originalStorage; - private static $user; protected function setUp() { @@ -48,14 +45,12 @@ class UpdaterLegacy extends \Test\TestCase { $this->scanner->scan(''); $this->cache = $this->storage->getCache(); - $this->originalStorage = Filesystem::getStorage('/'); - Filesystem::tearDown(); if (!self::$user) { self::$user = $this->getUniqueID(); } \OC_User::createUser(self::$user, 'password'); - \OC_User::setUserId(self::$user); + $this->loginAsUser(self::$user); Filesystem::init(self::$user, '/' . self::$user . '/files'); @@ -71,9 +66,8 @@ class UpdaterLegacy extends \Test\TestCase { } $result = \OC_User::deleteUser(self::$user); $this->assertTrue($result); - Filesystem::tearDown(); - Filesystem::mount($this->originalStorage, array(), '/'); + $this->logout(); parent::tearDown(); } diff --git a/tests/lib/files/cache/watcher.php b/tests/lib/files/cache/watcher.php index ee605c64e0..e6947e36a1 100644 --- a/tests/lib/files/cache/watcher.php +++ b/tests/lib/files/cache/watcher.php @@ -15,14 +15,10 @@ class Watcher extends \Test\TestCase { */ private $storages = array(); - /** @var \OC\Files\Storage\Storage */ - private $originalStorage; - protected function setUp() { parent::setUp(); - $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); - \OC\Files\Filesystem::clearMounts(); + $this->loginAsUser(); } protected function tearDown() { @@ -32,9 +28,7 @@ class Watcher extends \Test\TestCase { $cache->clear(); } - \OC\Files\Filesystem::clearMounts(); - \OC\Files\Filesystem::mount($this->originalStorage, array(), '/'); - + $this->logout(); parent::tearDown(); } diff --git a/tests/lib/files/etagtest.php b/tests/lib/files/etagtest.php index eec24d9f4c..055927652b 100644 --- a/tests/lib/files/etagtest.php +++ b/tests/lib/files/etagtest.php @@ -16,16 +16,11 @@ class EtagTest extends \Test\TestCase { private $tmpDir; - private $uid; - /** * @var \OC_User_Dummy $userBackend */ private $userBackend; - /** @var \OC\Files\Storage\Storage */ - private $originalStorage; - protected function setUp() { parent::setUp(); @@ -37,21 +32,15 @@ class EtagTest extends \Test\TestCase { $this->datadir = \OC_Config::getValue('datadirectory'); $this->tmpDir = \OC_Helper::tmpFolder(); \OC_Config::setValue('datadirectory', $this->tmpDir); - $this->uid = \OC_User::getUser(); - \OC_User::setUserId(null); $this->userBackend = new \OC_User_Dummy(); \OC_User::useBackend($this->userBackend); - $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); - \OC_Util::tearDownFS(); } protected function tearDown() { \OC_Config::setValue('datadirectory', $this->datadir); - \OC_User::setUserId($this->uid); - \OC_Util::setupFS($this->uid); - \OC\Files\Filesystem::mount($this->originalStorage, array(), '/'); + $this->logout(); parent::tearDown(); } @@ -59,9 +48,7 @@ class EtagTest extends \Test\TestCase { $user1 = $this->getUniqueID('user_'); $this->userBackend->createUser($user1, ''); - \OC_Util::tearDownFS(); - \OC_User::setUserId($user1); - \OC_Util::setupFS($user1); + $this->loginAsUser($user1); Filesystem::mkdir('/folder'); Filesystem::mkdir('/folder/subfolder'); Filesystem::file_put_contents('/foo.txt', 'asd'); diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php index 7bf59315d7..98e96e0cc7 100644 --- a/tests/lib/files/filesystem.php +++ b/tests/lib/files/filesystem.php @@ -28,9 +28,6 @@ class Filesystem extends \Test\TestCase { */ private $tmpDirs = array(); - /** @var \OC\Files\Storage\Storage */ - private $originalStorage; - /** * @return array */ @@ -42,20 +39,15 @@ class Filesystem extends \Test\TestCase { protected function setUp() { parent::setUp(); - - $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); - \OC_User::setUserId(''); - \OC\Files\Filesystem::clearMounts(); + $this->loginAsUser(); } protected function tearDown() { foreach ($this->tmpDirs as $dir) { \OC_Helper::rmdirr($dir); } - \OC\Files\Filesystem::clearMounts(); - \OC\Files\Filesystem::mount($this->originalStorage, array(), '/'); - \OC_User::setUserId(''); + $this->logout(); parent::tearDown(); } diff --git a/tests/lib/files/node/integration.php b/tests/lib/files/node/integration.php index 456a4a0e28..4e36260724 100644 --- a/tests/lib/files/node/integration.php +++ b/tests/lib/files/node/integration.php @@ -20,9 +20,6 @@ class IntegrationTests extends \Test\TestCase { */ private $root; - /** @var \OC\Files\Storage\Storage */ - private $originalStorage; - /** * @var \OC\Files\Storage\Storage[] */ @@ -36,9 +33,6 @@ class IntegrationTests extends \Test\TestCase { protected function setUp() { parent::setUp(); - $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); - \OC\Files\Filesystem::init('', ''); - \OC\Files\Filesystem::clearMounts(); $manager = \OC\Files\Filesystem::getMountManager(); \OC_Hook::clear('OC_Filesystem'); @@ -49,7 +43,8 @@ class IntegrationTests extends \Test\TestCase { \OC_Hook::connect('OC_Filesystem', 'post_touch', '\OC\Files\Cache\Updater', 'touchHook'); $user = new User($this->getUniqueID('user'), new \OC_User_Dummy); - \OC_User::setUserId($user->getUID()); + $this->loginAsUser($user->getUID()); + $this->view = new View(); $this->root = new Root($manager, $this->view, $user); $storage = new Temporary(array()); @@ -64,9 +59,8 @@ class IntegrationTests extends \Test\TestCase { foreach ($this->storages as $storage) { $storage->getCache()->clear(); } - \OC\Files\Filesystem::clearMounts(); - \OC\Files\Filesystem::mount($this->originalStorage, array(), '/'); + $this->logout(); parent::tearDown(); } diff --git a/tests/lib/files/utils/scanner.php b/tests/lib/files/utils/scanner.php index 65ddfe4751..dfc683c1bc 100644 --- a/tests/lib/files/utils/scanner.php +++ b/tests/lib/files/utils/scanner.php @@ -39,18 +39,14 @@ class TestScanner extends \OC\Files\Utils\Scanner { } class Scanner extends \Test\TestCase { - /** @var \OC\Files\Storage\Storage */ - private $originalStorage; - protected function setUp() { parent::setUp(); - $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); + $this->loginAsUser(); } protected function tearDown() { - \OC\Files\Filesystem::mount($this->originalStorage, array(), '/'); - + $this->logout(); parent::tearDown(); } diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index cd9f2d4afd..2ea9e8de78 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -27,9 +27,6 @@ class View extends \Test\TestCase { /** @var \OC\Files\Storage\Storage */ private $tempStorage; - /** @var \OC\Files\Storage\Storage */ - private $originalStorage; - protected function setUp() { parent::setUp(); @@ -39,9 +36,10 @@ class View extends \Test\TestCase { //login \OC_User::createUser('test', 'test'); $this->user = \OC_User::getUser(); - \OC_User::setUserId('test'); - $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); + $this->loginAsUser('test'); + // clear mounts but somehow keep the root storage + // that was initialized above... \OC\Files\Filesystem::clearMounts(); $this->tempStorage = null; @@ -59,9 +57,7 @@ class View extends \Test\TestCase { system('rm -rf ' . escapeshellarg($this->tempStorage->getDataDir())); } - \OC\Files\Filesystem::clearMounts(); - \OC\Files\Filesystem::mount($this->originalStorage, array(), '/'); - + $this->logout(); parent::tearDown(); } diff --git a/tests/lib/preview.php b/tests/lib/preview.php index 003ecedb65..ea9de9b777 100644 --- a/tests/lib/preview.php +++ b/tests/lib/preview.php @@ -26,6 +26,8 @@ class Preview extends TestCase { protected function setUp() { parent::setUp(); + // FIXME: use proper tearDown with $this->loginAsUser() and $this->logout() + // (would currently break the tests for some reason) $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); // create a new user with his own filesystem view diff --git a/tests/lib/streamwrappers.php b/tests/lib/streamwrappers.php index fc3d02acae..6216c5a4be 100644 --- a/tests/lib/streamwrappers.php +++ b/tests/lib/streamwrappers.php @@ -72,6 +72,8 @@ class Test_StreamWrappers extends \Test\TestCase { } public function testOC() { + // FIXME: use proper tearDown with $this->loginAsUser() and $this->logout() + // (would currently break the tests for some reason) $originalStorage = \OC\Files\Filesystem::getStorage('/'); \OC\Files\Filesystem::clearMounts(); diff --git a/tests/lib/testcase.php b/tests/lib/testcase.php index a83be71319..e66dfb1335 100644 --- a/tests/lib/testcase.php +++ b/tests/lib/testcase.php @@ -167,9 +167,9 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { * Login and setup FS as a given user, * sets the given user as the current user. * - * @param string $user user id + * @param string $user user id or empty for a generic FS */ - static protected function loginAsUser($user) { + static protected function loginAsUser($user = '') { self::logout(); \OC\Files\Filesystem::tearDown(); \OC_User::setUserId($user);