diff --git a/apps/files/tests/ajax_rename.php b/apps/files/tests/ajax_rename.php index 789177bb3539ff040058aede9883bad04878e825..34e7f5085dd97845b10c9932e282cd24d965ea88 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 f1ac055d3354c837f64512ec29967a0e5a7eecd5..d5bd7c318d3d50e7ea2a106ae754b61ea2f049aa 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 970af2e68df50728049242c6d7353ec2ea6deec4..7c3ebd5a6f9d340ca43b9df8e9eb5f4ccf046ea9 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 6bdacbe34fe7e96977fe6fb45b6468f516abb383..f4d52e9a390716aeca3ea27c6ada7e060a556179 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 ee605c64e01993d23d7af1cfa1eaace2cd4f0899..e6947e36a17a27c970511236a5f42013d859d8fd 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 eec24d9f4c6609b552f0d55df4c5e208806d977e..055927652bc747e43bb1969406285ae2a34ffce1 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 7bf59315d77d0de6ac6edaf3948526691d023180..98e96e0cc78a16b622244862119025e4a017da05 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 456a4a0e287f116e4a22891cd14a6c3b98413d2f..4e3626072401c4a21a10613910d37f333cfe3632 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 65ddfe47514cca9a9880189644f86b1149c7f9d1..dfc683c1bcfc84b960389125794bdc1492fd3950 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 cd9f2d4afd162d10281f8ab66261f50e59003410..2ea9e8de78f2c2b6cab13bbcd1a910c5be3d213a 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 003ecedb65a034b23b56d1ee423a9d2c54b34ce2..ea9de9b777e54c92ab2147ed0d7e67176b021aaa 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 fc3d02acae7218e1b65e2273c71c2cdccfdcabad..6216c5a4be89023598a2fbe21fbc0166591771b6 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 a83be713194a91ca6c331889fbd57edce283645f..e66dfb13353244a8ea307adc4e005d80758ef1fc 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);