diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2014-11-12 15:54:41 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2014-11-17 10:48:19 +0100 |
commit | 6625d5c88f74edade459ec7e2ee0bfb79f21fedd (patch) | |
tree | c615a82f5838b8ebded306c4c474751d2f2e782a /tests/lib/files | |
parent | 289a27778e78bb69830b5b05f4084627a781157b (diff) | |
download | nextcloud-server-6625d5c88f74edade459ec7e2ee0bfb79f21fedd.tar.gz nextcloud-server-6625d5c88f74edade459ec7e2ee0bfb79f21fedd.zip |
Correctly restore previous root mount point after testing
Diffstat (limited to 'tests/lib/files')
-rw-r--r-- | tests/lib/files/cache/updater.php | 15 | ||||
-rw-r--r-- | tests/lib/files/cache/updaterlegacy.php | 9 | ||||
-rw-r--r-- | tests/lib/files/cache/watcher.php | 15 | ||||
-rw-r--r-- | tests/lib/files/etagtest.php | 15 | ||||
-rw-r--r-- | tests/lib/files/filesystem.php | 21 | ||||
-rw-r--r-- | tests/lib/files/node/integration.php | 14 | ||||
-rw-r--r-- | tests/lib/files/utils/scanner.php | 18 | ||||
-rw-r--r-- | tests/lib/files/view.php | 16 |
8 files changed, 103 insertions, 20 deletions
diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php index 96b4207ad43..9e7330db20c 100644 --- a/tests/lib/files/cache/updater.php +++ b/tests/lib/files/cache/updater.php @@ -33,7 +33,13 @@ class Updater extends \PHPUnit_Framework_TestCase { */ protected $updater; - public function setUp() { + /** @var \OC\Files\Storage\Storage */ + private $originalStorage; + + protected function setUp() { + parent::setUp(); + + $this->originalStorage = Filesystem::getStorage('/'); $this->storage = new Temporary(array()); Filesystem::clearMounts(); Filesystem::mount($this->storage, array(), '/'); @@ -42,6 +48,13 @@ class Updater extends \PHPUnit_Framework_TestCase { $this->cache = $this->storage->getCache(); } + protected function tearDown() { + Filesystem::clearMounts(); + Filesystem::mount($this->originalStorage, array(), '/'); + + parent::tearDown(); + } + public function testNewFile() { $this->storage->file_put_contents('foo.txt', 'bar'); $this->assertFalse($this->cache->inCache('foo.txt')); diff --git a/tests/lib/files/cache/updaterlegacy.php b/tests/lib/files/cache/updaterlegacy.php index c80c3168ad6..d16a062fcca 100644 --- a/tests/lib/files/cache/updaterlegacy.php +++ b/tests/lib/files/cache/updaterlegacy.php @@ -29,6 +29,9 @@ class UpdaterLegacy extends \PHPUnit_Framework_TestCase { */ private $cache; + /** @var \OC\Files\Storage\Storage */ + private $originalStorage; + private static $user; public function setUp() { @@ -51,7 +54,8 @@ class UpdaterLegacy extends \PHPUnit_Framework_TestCase { $this->scanner->scan(''); $this->cache = $this->storage->getCache(); - \OC\Files\Filesystem::tearDown(); + $this->originalStorage = Filesystem::getStorage('/'); + Filesystem::tearDown(); if (!self::$user) { self::$user = uniqid(); } @@ -59,7 +63,7 @@ class UpdaterLegacy extends \PHPUnit_Framework_TestCase { \OC_User::createUser(self::$user, 'password'); \OC_User::setUserId(self::$user); - \OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files'); + Filesystem::init(self::$user, '/' . self::$user . '/files'); Filesystem::clearMounts(); Filesystem::mount($this->storage, array(), '/' . self::$user . '/files'); @@ -74,6 +78,7 @@ class UpdaterLegacy extends \PHPUnit_Framework_TestCase { $result = \OC_User::deleteUser(self::$user); $this->assertTrue($result); Filesystem::tearDown(); + Filesystem::mount($this->originalStorage, array(), '/'); // reset app files_encryption if ($this->stateFilesEncryption) { \OC_App::enable('files_encryption'); diff --git a/tests/lib/files/cache/watcher.php b/tests/lib/files/cache/watcher.php index 22c11b9a4e0..0b04b9e7058 100644 --- a/tests/lib/files/cache/watcher.php +++ b/tests/lib/files/cache/watcher.php @@ -15,16 +15,27 @@ class Watcher extends \PHPUnit_Framework_TestCase { */ private $storages = array(); - public function setUp() { + /** @var \OC\Files\Storage\Storage */ + private $originalStorage; + + protected function setUp() { + parent::setUp(); + + $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); \OC\Files\Filesystem::clearMounts(); } - public function tearDown() { + protected function tearDown() { foreach ($this->storages as $storage) { $cache = $storage->getCache(); $ids = $cache->getAll(); $cache->clear(); } + + \OC\Files\Filesystem::clearMounts(); + \OC\Files\Filesystem::mount($this->originalStorage, array(), '/'); + + parent::tearDown(); } /** diff --git a/tests/lib/files/etagtest.php b/tests/lib/files/etagtest.php index b5dec107e79..8f29ed0bc63 100644 --- a/tests/lib/files/etagtest.php +++ b/tests/lib/files/etagtest.php @@ -11,7 +11,7 @@ namespace Test\Files; use OC\Files\Filesystem; use OCP\Share; -class EtagTest extends \PHPUnit_Framework_TestCase { +class EtagTest extends \Test\TestCase { private $datadir; private $tmpDir; @@ -23,7 +23,12 @@ class EtagTest extends \PHPUnit_Framework_TestCase { */ private $userBackend; - public function setUp() { + /** @var \OC\Files\Storage\Storage */ + private $originalStorage; + + protected function setUp() { + parent::setUp(); + \OC_Hook::clear('OC_Filesystem', 'setup'); \OCP\Util::connectHook('OC_Filesystem', 'setup', '\OC\Files\Storage\Shared', 'setup'); \OCP\Share::registerBackend('file', 'OC_Share_Backend_File'); @@ -37,13 +42,17 @@ class EtagTest extends \PHPUnit_Framework_TestCase { $this->userBackend = new \OC_User_Dummy(); \OC_User::useBackend($this->userBackend); + $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); \OC_Util::tearDownFS(); } - public function tearDown() { + 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(), '/'); + + parent::tearDown(); } public function testNewUser() { diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php index 930a252bcb2..88e98fbb8c6 100644 --- a/tests/lib/files/filesystem.php +++ b/tests/lib/files/filesystem.php @@ -22,12 +22,15 @@ namespace Test\Files; -class Filesystem extends \PHPUnit_Framework_TestCase { +class Filesystem extends \Test\TestCase { /** * @var array tmpDirs */ private $tmpDirs = array(); + /** @var \OC\Files\Storage\Storage */ + private $originalStorage; + /** * @return array */ @@ -37,19 +40,23 @@ class Filesystem extends \PHPUnit_Framework_TestCase { return array('datadir' => $dir); } - public function tearDown() { + protected function setUp() { + parent::setUp(); + + $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); + \OC_User::setUserId(''); + \OC\Files\Filesystem::clearMounts(); + } + + 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(''); } - public function setUp() { - \OC_User::setUserId(''); - \OC\Files\Filesystem::clearMounts(); - } - public function testMount() { \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', self::getStorageData(), '/'); $this->assertEquals('/', \OC\Files\Filesystem::getMountPoint('/')); diff --git a/tests/lib/files/node/integration.php b/tests/lib/files/node/integration.php index 319f2f9f5f7..cde2eb22b7b 100644 --- a/tests/lib/files/node/integration.php +++ b/tests/lib/files/node/integration.php @@ -20,6 +20,9 @@ class IntegrationTests extends \PHPUnit_Framework_TestCase { */ private $root; + /** @var \OC\Files\Storage\Storage */ + private $originalStorage; + /** * @var \OC\Files\Storage\Storage[] */ @@ -30,7 +33,10 @@ class IntegrationTests extends \PHPUnit_Framework_TestCase { */ private $view; - public function setUp() { + protected function setUp() { + parent::setUp(); + + $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); \OC\Files\Filesystem::init('', ''); \OC\Files\Filesystem::clearMounts(); $manager = \OC\Files\Filesystem::getMountManager(); @@ -54,11 +60,15 @@ class IntegrationTests extends \PHPUnit_Framework_TestCase { $this->root->mount($subStorage, '/substorage/'); } - public function tearDown() { + protected function tearDown() { foreach ($this->storages as $storage) { $storage->getCache()->clear(); } \OC\Files\Filesystem::clearMounts(); + + \OC\Files\Filesystem::mount($this->originalStorage, array(), '/'); + + parent::tearDown(); } public function testBasicFile() { diff --git a/tests/lib/files/utils/scanner.php b/tests/lib/files/utils/scanner.php index 27b9b8dd4f4..db6a3fa7842 100644 --- a/tests/lib/files/utils/scanner.php +++ b/tests/lib/files/utils/scanner.php @@ -38,7 +38,23 @@ class TestScanner extends \OC\Files\Utils\Scanner { } } -class Scanner extends \PHPUnit_Framework_TestCase { + +class Scanner extends \Test\TestCase { + /** @var \OC\Files\Storage\Storage */ + private $originalStorage; + + protected function setUp() { + parent::setUp(); + + $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); + } + + protected function tearDown() { + \OC\Files\Filesystem::mount($this->originalStorage, array(), '/'); + + parent::tearDown(); + } + public function testReuseExistingRoot() { $storage = new Temporary(array()); $mount = new Mount($storage, ''); diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index 931f5acd95a..f42308318d5 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -22,9 +22,15 @@ class View extends \PHPUnit_Framework_TestCase { private $storages = array(); private $user; + /** @var \OC\Files\Storage\Storage */ private $tempStorage; - public function setUp() { + /** @var \OC\Files\Storage\Storage */ + private $originalStorage; + + protected function setUp() { + parent::setUp(); + \OC_User::clearBackends(); \OC_User::useBackend(new \OC_User_Dummy()); @@ -33,12 +39,13 @@ class View extends \PHPUnit_Framework_TestCase { $this->user = \OC_User::getUser(); \OC_User::setUserId('test'); + $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); \OC\Files\Filesystem::clearMounts(); $this->tempStorage = null; } - public function tearDown() { + protected function tearDown() { \OC_User::setUserId($this->user); foreach ($this->storages as $storage) { $cache = $storage->getCache(); @@ -49,6 +56,11 @@ class View extends \PHPUnit_Framework_TestCase { if ($this->tempStorage && !\OC_Util::runningOnWindows()) { system('rm -rf ' . escapeshellarg($this->tempStorage->getDataDir())); } + + \OC\Files\Filesystem::clearMounts(); + \OC\Files\Filesystem::mount($this->originalStorage, array(), '/'); + + parent::tearDown(); } /** |