aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/files
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/files')
-rw-r--r--tests/lib/files/cache/cache.php55
-rw-r--r--tests/lib/files/cache/homecache.php95
-rw-r--r--tests/lib/files/filesystem.php121
-rw-r--r--tests/lib/files/storage/home.php29
4 files changed, 283 insertions, 17 deletions
diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php
index 247373a5cb9..052d70dd0b4 100644
--- a/tests/lib/files/cache/cache.php
+++ b/tests/lib/files/cache/cache.php
@@ -18,11 +18,11 @@ class LongId extends \OC\Files\Storage\Temporary {
class Cache extends \PHPUnit_Framework_TestCase {
/**
- * @var \OC\Files\Storage\Temporary $storage;
+ * @var \OC\Files\Storage\Temporary $storage ;
*/
private $storage;
/**
- * @var \OC\Files\Storage\Temporary $storage2;
+ * @var \OC\Files\Storage\Temporary $storage2 ;
*/
private $storage2;
@@ -137,6 +137,33 @@ class Cache extends \PHPUnit_Framework_TestCase {
$this->assertFalse($this->cache->inCache('folder/bar'));
}
+ public function testRootFolderSizeForNonHomeStorage() {
+ $dir1 = 'knownsize';
+ $dir2 = 'unknownsize';
+ $fileData = array();
+ $fileData[''] = array('size' => -1, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
+ $fileData[$dir1] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
+ $fileData[$dir2] = array('size' => -1, 'mtime' => 25, 'mimetype' => 'httpd/unix-directory');
+
+ $this->cache->put('', $fileData['']);
+ $this->cache->put($dir1, $fileData[$dir1]);
+ $this->cache->put($dir2, $fileData[$dir2]);
+
+ $this->assertTrue($this->cache->inCache($dir1));
+ $this->assertTrue($this->cache->inCache($dir2));
+
+ // check that root size ignored the unknown sizes
+ $this->assertEquals(-1, $this->cache->calculateFolderSize(''));
+
+ // clean up
+ $this->cache->remove('');
+ $this->cache->remove($dir1);
+ $this->cache->remove($dir2);
+
+ $this->assertFalse($this->cache->inCache($dir1));
+ $this->assertFalse($this->cache->inCache($dir2));
+ }
+
function testStatus() {
$this->assertEquals(\OC\Files\Cache\Cache::NOT_FOUND, $this->cache->getStatus('foo'));
$this->cache->put('foo', array('size' => -1));
@@ -247,14 +274,14 @@ class Cache extends \PHPUnit_Framework_TestCase {
$data = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file');
$this->cache->put('foo', $data);
$cachedData = $this->cache->get('foo');
- $this->assertEquals($data['mtime'], $cachedData['storage_mtime']);//if no storage_mtime is saved, mtime should be used
+ $this->assertEquals($data['mtime'], $cachedData['storage_mtime']); //if no storage_mtime is saved, mtime should be used
- $this->cache->put('foo', array('storage_mtime' => 30));//when setting storage_mtime, mtime is also set
+ $this->cache->put('foo', array('storage_mtime' => 30)); //when setting storage_mtime, mtime is also set
$cachedData = $this->cache->get('foo');
$this->assertEquals(30, $cachedData['storage_mtime']);
$this->assertEquals(30, $cachedData['mtime']);
- $this->cache->put('foo', array('mtime' => 25));//setting mtime does not change storage_mtime
+ $this->cache->put('foo', array('mtime' => 25)); //setting mtime does not change storage_mtime
$cachedData = $this->cache->get('foo');
$this->assertEquals(30, $cachedData['storage_mtime']);
$this->assertEquals(25, $cachedData['mtime']);
@@ -295,18 +322,18 @@ class Cache extends \PHPUnit_Framework_TestCase {
$this->assertGreaterThan(0, $cacheMock->put('folder', $data));
// put un-normalized folder
- $this->assertFalse($cacheMock->get('folder/' .$folderWith0308));
- $this->assertGreaterThan(0, $cacheMock->put('folder/' .$folderWith0308, $data));
+ $this->assertFalse($cacheMock->get('folder/' . $folderWith0308));
+ $this->assertGreaterThan(0, $cacheMock->put('folder/' . $folderWith0308, $data));
// get un-normalized folder by name
- $unNormalizedFolderName = $cacheMock->get('folder/' .$folderWith0308);
+ $unNormalizedFolderName = $cacheMock->get('folder/' . $folderWith0308);
// check if database layer normalized the folder name (this should not happen)
$this->assertEquals($folderWith0308, $unNormalizedFolderName['name']);
// put normalized folder
$this->assertFalse($cacheMock->get('folder/' . $folderWith00F6));
- $this->assertGreaterThan(0, $cacheMock->put('folder/' .$folderWith00F6, $data));
+ $this->assertGreaterThan(0, $cacheMock->put('folder/' . $folderWith00F6, $data));
// this is our bug, we have two different hashes with the same name (Schön)
$this->assertEquals(2, count($cacheMock->getFolderContents('folder')));
@@ -317,7 +344,7 @@ class Cache extends \PHPUnit_Framework_TestCase {
*/
public function testWithNormalizer() {
- if(!class_exists('Patchwork\PHP\Shim\Normalizer')) {
+ if (!class_exists('Patchwork\PHP\Shim\Normalizer')) {
$this->markTestSkipped('The 3rdparty Normalizer extension is not available.');
return;
}
@@ -335,18 +362,18 @@ class Cache extends \PHPUnit_Framework_TestCase {
$this->assertGreaterThan(0, $this->cache->put('folder', $data));
// put un-normalized folder
- $this->assertFalse($this->cache->get('folder/' .$folderWith0308));
- $this->assertGreaterThan(0, $this->cache->put('folder/' .$folderWith0308, $data));
+ $this->assertFalse($this->cache->get('folder/' . $folderWith0308));
+ $this->assertGreaterThan(0, $this->cache->put('folder/' . $folderWith0308, $data));
// get un-normalized folder by name
- $unNormalizedFolderName = $this->cache->get('folder/' .$folderWith0308);
+ $unNormalizedFolderName = $this->cache->get('folder/' . $folderWith0308);
// check if folder name was normalized
$this->assertEquals($folderWith00F6, $unNormalizedFolderName['name']);
// put normalized folder
$this->assertTrue(is_array($this->cache->get('folder/' . $folderWith00F6)));
- $this->assertGreaterThan(0, $this->cache->put('folder/' .$folderWith00F6, $data));
+ $this->assertGreaterThan(0, $this->cache->put('folder/' . $folderWith00F6, $data));
// at this point we should have only one folder named "Schön"
$this->assertEquals(1, count($this->cache->getFolderContents('folder')));
diff --git a/tests/lib/files/cache/homecache.php b/tests/lib/files/cache/homecache.php
new file mode 100644
index 00000000000..ebf2b7270da
--- /dev/null
+++ b/tests/lib/files/cache/homecache.php
@@ -0,0 +1,95 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Files\Cache;
+
+class DummyUser extends \OC\User\User {
+ /**
+ * @var string $home
+ */
+ private $home;
+
+ /**
+ * @var string $uid
+ */
+ private $uid;
+
+ public function __construct($uid, $home) {
+ $this->home = $home;
+ $this->uid = $uid;
+ }
+
+ /**
+ * @return string
+ */
+ public function getHome() {
+ return $this->home;
+ }
+
+ /**
+ * @return string
+ */
+ public function getUID() {
+ return $this->uid;
+ }
+}
+
+class HomeCache extends \PHPUnit_Framework_TestCase {
+ /**
+ * @var \OC\Files\Storage\Home $storage
+ */
+ private $storage;
+
+ /**
+ * @var \OC\Files\Cache\HomeCache $cache
+ */
+ private $cache;
+
+ /**
+ * @var \OC\User\User $user
+ */
+ private $user;
+
+ public function setUp() {
+ $this->user = new DummyUser('foo', \OC_Helper::tmpFolder());
+ $this->storage = new \OC\Files\Storage\Home(array('user' => $this->user));
+ $this->cache = $this->storage->getCache();
+ }
+
+ /**
+ * Tests that the root folder size calculation ignores the subdirs that have an unknown
+ * size. This makes sure that quota calculation still works as it's based on the root
+ * folder size.
+ */
+ public function testRootFolderSizeIgnoresUnknownUpdate() {
+ $dir1 = 'knownsize';
+ $dir2 = 'unknownsize';
+ $fileData = array();
+ $fileData[''] = array('size' => -1, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
+ $fileData[$dir1] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
+ $fileData[$dir2] = array('size' => -1, 'mtime' => 25, 'mimetype' => 'httpd/unix-directory');
+
+ $this->cache->put('', $fileData['']);
+ $this->cache->put($dir1, $fileData[$dir1]);
+ $this->cache->put($dir2, $fileData[$dir2]);
+
+ $this->assertTrue($this->cache->inCache($dir1));
+ $this->assertTrue($this->cache->inCache($dir2));
+
+ // check that root size ignored the unknown sizes
+ $this->assertEquals(1000, $this->cache->calculateFolderSize(''));
+
+ // clean up
+ $this->cache->remove('');
+ $this->cache->remove($dir1);
+ $this->cache->remove($dir2);
+
+ $this->assertFalse($this->cache->inCache($dir1));
+ $this->assertFalse($this->cache->inCache($dir2));
+ }
+}
diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php
index bef70cc725b..7cb57bf95ad 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();
}
@@ -66,17 +69,72 @@ class Filesystem extends \PHPUnit_Framework_TestCase {
}
public function testNormalize() {
+ $this->assertEquals('/', \OC\Files\Filesystem::normalizePath(''));
+ $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('/'));
+ $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('/', false));
+ $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('//'));
+ $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('//', false));
$this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('/path/'));
$this->assertEquals('/path/', \OC\Files\Filesystem::normalizePath('/path/', false));
$this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('path'));
- $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('\path'));
$this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo//bar/'));
+ $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('/foo//bar/', false));
$this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo////bar'));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo/////bar'));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo/bar/.'));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo/bar/./'));
+ $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('/foo/bar/./', false));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo/bar/./.'));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo/bar/././'));
+ $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('/foo/bar/././', false));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo/./bar/'));
+ $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('/foo/./bar/', false));
+ $this->assertEquals('/foo/.bar', \OC\Files\Filesystem::normalizePath('/foo/.bar/'));
+ $this->assertEquals('/foo/.bar/', \OC\Files\Filesystem::normalizePath('/foo/.bar/', false));
+ $this->assertEquals('/foo/.bar/tee', \OC\Files\Filesystem::normalizePath('/foo/.bar/tee'));
+
+ // normalize does not resolve '..' (by design)
+ $this->assertEquals('/foo/..', \OC\Files\Filesystem::normalizePath('/foo/../'));
+
if (class_exists('Patchwork\PHP\Shim\Normalizer')) {
$this->assertEquals("/foo/bar\xC3\xBC", \OC\Files\Filesystem::normalizePath("/foo/baru\xCC\x88"));
}
}
+ public function testNormalizeWindowsPaths() {
+ $this->assertEquals('/', \OC\Files\Filesystem::normalizePath(''));
+ $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('\\'));
+ $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('\\', false));
+ $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('\\\\'));
+ $this->assertEquals('/', \OC\Files\Filesystem::normalizePath('\\\\', false));
+ $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('\\path'));
+ $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('\\path', false));
+ $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('\\path\\'));
+ $this->assertEquals('/path/', \OC\Files\Filesystem::normalizePath('\\path\\', false));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\\\bar\\'));
+ $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('\\foo\\\\bar\\', false));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\\\\\\\bar'));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\\\\\\\\\bar'));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\bar\\.'));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\bar\\.\\'));
+ $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('\\foo\\bar\\.\\', false));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\bar\\.\\.'));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\bar\\.\\.\\'));
+ $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('\\foo\\bar\\.\\.\\', false));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('\\foo\\.\\bar\\'));
+ $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::normalizePath('\\foo\\.\\bar\\', false));
+ $this->assertEquals('/foo/.bar', \OC\Files\Filesystem::normalizePath('\\foo\\.bar\\'));
+ $this->assertEquals('/foo/.bar/', \OC\Files\Filesystem::normalizePath('\\foo\\.bar\\', false));
+ $this->assertEquals('/foo/.bar/tee', \OC\Files\Filesystem::normalizePath('\\foo\\.bar\\tee'));
+
+ // normalize does not resolve '..' (by design)
+ $this->assertEquals('/foo/..', \OC\Files\Filesystem::normalizePath('\\foo\\..\\'));
+
+ if (class_exists('Patchwork\PHP\Shim\Normalizer')) {
+ $this->assertEquals("/foo/bar\xC3\xBC", \OC\Files\Filesystem::normalizePath("\\foo\\baru\xCC\x88"));
+ }
+ }
+
public function testHooks() {
if(\OC\Files\Filesystem::getView()){
$user = \OC_User::getUser();
@@ -103,6 +161,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());
+ }
}