aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2013-11-12 15:46:01 +0100
committerVincent Petry <pvince81@owncloud.com>2013-11-12 18:01:02 +0100
commit34c92f665639baf6ea86a265855a2b2862755537 (patch)
treec8cc2b73f2cee74a449593673bf4213dbb4e81e7 /tests
parent1a65e3a72593a2eb343386e5008faea78f0b9c8f (diff)
downloadnextcloud-server-34c92f665639baf6ea86a265855a2b2862755537.tar.gz
nextcloud-server-34c92f665639baf6ea86a265855a2b2862755537.zip
Now using HomeStorage for legacy home storage ids
Legacy home storage ids with the format "local://path/to/datadir/user1" are now also wrapped by the HomeStorage.
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/files/filesystem.php64
-rw-r--r--tests/lib/files/storage/home.php29
2 files changed, 91 insertions, 2 deletions
diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php
index bef70cc725b..990e95ca595 100644
--- a/tests/lib/files/filesystem.php
+++ b/tests/lib/files/filesystem.php
@@ -41,9 +41,12 @@ class Filesystem extends \PHPUnit_Framework_TestCase {
foreach ($this->tmpDirs as $dir) {
\OC_Helper::rmdirr($dir);
}
+ \OC\Files\Filesystem::clearMounts();
+ \OC_User::setUserId('');
}
public function setUp() {
+ \OC_User::setUserId('');
\OC\Files\Filesystem::clearMounts();
}
@@ -103,6 +106,67 @@ class Filesystem extends \PHPUnit_Framework_TestCase {
// \OC\Files\Filesystem::file_put_contents('/bar//foo', $fh);
}
+ /**
+ * Tests that a local storage mount is used when passed user
+ * does not exist.
+ */
+ public function testLocalMountWhenUserDoesNotExist() {
+ $datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data");
+ $userId = uniqid('user_');
+
+ \OC\Files\Filesystem::initMountPoints($userId);
+
+ $homeMount = \OC\Files\Filesystem::getStorage('/' . $userId . '/');
+
+ $this->assertInstanceOf('\OC\Files\Storage\Local', $homeMount);
+ $this->assertEquals('local::' . $datadir . '/' . $userId . '/', $homeMount->getId());
+ }
+
+ /**
+ * Tests that the home storage is used for the user's mount point
+ */
+ public function testHomeMount() {
+ $userId = uniqid('user_');
+
+ \OC_User::createUser($userId, $userId);
+
+ \OC\Files\Filesystem::initMountPoints($userId);
+
+ $homeMount = \OC\Files\Filesystem::getStorage('/' . $userId . '/');
+
+ $this->assertInstanceOf('\OC\Files\Storage\Home', $homeMount);
+ $this->assertEquals('home::' . $userId, $homeMount->getId());
+
+ \OC_User::deleteUser($userId);
+ }
+
+ /**
+ * Tests that the home storage is used in legacy mode
+ * for the user's mount point
+ */
+ public function testLegacyHomeMount() {
+ $datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data");
+ $userId = uniqid('user_');
+
+ // insert storage into DB by constructing it
+ // to make initMountsPoint find its existence
+ $localStorage = new \OC\Files\Storage\Local(array('datadir' => $datadir . '/' . $userId . '/'));
+ // this will trigger the insert
+ $cache = $localStorage->getCache();
+
+ \OC_User::createUser($userId, $userId);
+ \OC\Files\Filesystem::initMountPoints($userId);
+
+ $homeMount = \OC\Files\Filesystem::getStorage('/' . $userId . '/');
+
+ $this->assertInstanceOf('\OC\Files\Storage\Home', $homeMount);
+ $this->assertEquals('local::' . $datadir. '/' . $userId . '/', $homeMount->getId());
+
+ \OC_User::deleteUser($userId);
+ // delete storage entry
+ $cache->clear();
+ }
+
public function dummyHook($arguments) {
$path = $arguments['path'];
$this->assertEquals($path, \OC\Files\Filesystem::normalizePath($path)); //the path passed to the hook should already be normalized
diff --git a/tests/lib/files/storage/home.php b/tests/lib/files/storage/home.php
index b01e07f7457..885291e4404 100644
--- a/tests/lib/files/storage/home.php
+++ b/tests/lib/files/storage/home.php
@@ -56,8 +56,8 @@ class Home extends Storage {
public function setUp() {
$this->tmpDir = \OC_Helper::tmpFolder();
- $userId = uniqid('user_');
- $this->user = new DummyUser($userId, $this->tmpDir);
+ $this->userId = uniqid('user_');
+ $this->user = new DummyUser($this->userId, $this->tmpDir);
$this->instance = new \OC\Files\Storage\Home(array('user' => $this->user));
}
@@ -65,7 +65,32 @@ class Home extends Storage {
\OC_Helper::rmdirr($this->tmpDir);
}
+ /**
+ * Tests that the root path matches the data dir
+ */
public function testRoot() {
$this->assertEquals($this->tmpDir, $this->instance->getLocalFolder(''));
}
+
+ /**
+ * Tests that the home id is in the format home::user1
+ */
+ public function testId() {
+ $this->assertEquals('home::' . $this->userId, $this->instance->getId());
+ }
+
+ /**
+ * Tests that the legacy home id is in the format local::/path/to/datadir/user1/
+ */
+ public function testLegacyId() {
+ $this->instance = new \OC\Files\Storage\Home(array('user' => $this->user, 'legacy' => true));
+ $this->assertEquals('local::' . $this->tmpDir . '/', $this->instance->getId());
+ }
+
+ /**
+ * Tests that getCache() returns an instance of HomeCache
+ */
+ public function testGetCacheReturnsHomeCache() {
+ $this->assertInstanceOf('\OC\Files\Cache\HomeCache', $this->instance->getCache());
+ }
}