summaryrefslogtreecommitdiffstats
path: root/tests/lib/files
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/files')
-rw-r--r--tests/lib/files/cache/cache.php136
-rw-r--r--tests/lib/files/cache/permissions.php6
-rw-r--r--tests/lib/files/cache/updater.php9
-rw-r--r--tests/lib/files/cache/watcher.php10
-rw-r--r--tests/lib/files/filesystem.php2
-rw-r--r--tests/lib/files/mount.php58
-rw-r--r--tests/lib/files/mount/manager.php67
-rw-r--r--tests/lib/files/view.php73
8 files changed, 283 insertions, 78 deletions
diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php
index 250842805e5..f272655925b 100644
--- a/tests/lib/files/cache/cache.php
+++ b/tests/lib/files/cache/cache.php
@@ -8,6 +8,8 @@
namespace Test\Files\Cache;
+use PHPUnit_Framework_MockObject_MockObject;
+
class LongId extends \OC\Files\Storage\Temporary {
public function getId() {
return 'long:' . str_repeat('foo', 50) . parent::getId();
@@ -19,11 +21,19 @@ class Cache extends \PHPUnit_Framework_TestCase {
* @var \OC\Files\Storage\Temporary $storage;
*/
private $storage;
+ /**
+ * @var \OC\Files\Storage\Temporary $storage2;
+ */
+ private $storage2;
/**
* @var \OC\Files\Cache\Cache $cache
*/
private $cache;
+ /**
+ * @var \OC\Files\Cache\Cache $cache2
+ */
+ private $cache2;
public function testSimple() {
$file1 = 'foo';
@@ -162,13 +172,21 @@ class Cache extends \PHPUnit_Framework_TestCase {
$file4 = 'folder/foo/1';
$file5 = 'folder/foo/2';
$data = array('size' => 100, 'mtime' => 50, 'mimetype' => 'foo/bar');
+ $folderData = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
- $this->cache->put($file1, $data);
- $this->cache->put($file2, $data);
- $this->cache->put($file3, $data);
+ $this->cache->put($file1, $folderData);
+ $this->cache->put($file2, $folderData);
+ $this->cache->put($file3, $folderData);
$this->cache->put($file4, $data);
$this->cache->put($file5, $data);
+ /* simulate a second user with a different storage id but the same folder structure */
+ $this->cache2->put($file1, $folderData);
+ $this->cache2->put($file2, $folderData);
+ $this->cache2->put($file3, $folderData);
+ $this->cache2->put($file4, $data);
+ $this->cache2->put($file5, $data);
+
$this->cache->move('folder/foo', 'folder/foobar');
$this->assertFalse($this->cache->inCache('folder/foo'));
@@ -179,6 +197,16 @@ class Cache extends \PHPUnit_Framework_TestCase {
$this->assertTrue($this->cache->inCache('folder/foobar'));
$this->assertTrue($this->cache->inCache('folder/foobar/1'));
$this->assertTrue($this->cache->inCache('folder/foobar/2'));
+
+ /* the folder structure of the second user must not change! */
+ $this->assertTrue($this->cache2->inCache('folder/bar'));
+ $this->assertTrue($this->cache2->inCache('folder/foo'));
+ $this->assertTrue($this->cache2->inCache('folder/foo/1'));
+ $this->assertTrue($this->cache2->inCache('folder/foo/2'));
+
+ $this->assertFalse($this->cache2->inCache('folder/foobar'));
+ $this->assertFalse($this->cache2->inCache('folder/foobar/1'));
+ $this->assertFalse($this->cache2->inCache('folder/foobar/2'));
}
function testGetIncomplete() {
@@ -210,6 +238,23 @@ class Cache extends \PHPUnit_Framework_TestCase {
$this->assertEquals(array($storageId, 'foo'), \OC\Files\Cache\Cache::getById($id));
}
+ function testStorageMTime() {
+ $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->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
+ $cachedData = $this->cache->get('foo');
+ $this->assertEquals(30, $cachedData['storage_mtime']);
+ $this->assertEquals(25, $cachedData['mtime']);
+ }
+
function testLongId() {
$storage = new LongId(array());
$cache = $storage->getCache();
@@ -219,12 +264,97 @@ class Cache extends \PHPUnit_Framework_TestCase {
$this->assertEquals(array(md5($storageId), 'foo'), \OC\Files\Cache\Cache::getById($id));
}
+ /**
+ * @brief this test show the bug resulting if we have no normalizer installed
+ */
+ public function testWithoutNormalizer() {
+ // folder name "Schön" with U+00F6 (normalized)
+ $folderWith00F6 = "\x53\x63\x68\xc3\xb6\x6e";
+
+ // folder name "Schön" with U+0308 (un-normalized)
+ $folderWith0308 = "\x53\x63\x68\x6f\xcc\x88\x6e";
+
+ /**
+ * @var \OC\Files\Cache\Cache | PHPUnit_Framework_MockObject_MockObject $cacheMock
+ */
+ $cacheMock = $this->getMock('\OC\Files\Cache\Cache', array('normalize'), array($this->storage), '', true);
+
+ $cacheMock->expects($this->any())
+ ->method('normalize')
+ ->will($this->returnArgument(0));
+
+ $data = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
+
+ // put root folder
+ $this->assertFalse($cacheMock->get('folder'));
+ $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));
+
+ // get un-normalized folder by name
+ $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 is our bug, we have two different hashes with the same name (Schön)
+ $this->assertEquals(2, count($cacheMock->getFolderContents('folder')));
+ }
+
+ /**
+ * @brief this test shows that there is no bug if we use the normalizer
+ */
+ public function testWithNormalizer() {
+
+ if(!class_exists('Patchwork\PHP\Shim\Normalizer')) {
+ $this->markTestSkipped('The 3rdparty Normalizer extension is not available.');
+ return;
+ }
+
+ // folder name "Schön" with U+00F6 (normalized)
+ $folderWith00F6 = "\x53\x63\x68\xc3\xb6\x6e";
+
+ // folder name "Schön" with U+0308 (un-normalized)
+ $folderWith0308 = "\x53\x63\x68\x6f\xcc\x88\x6e";
+
+ $data = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
+
+ // put root folder
+ $this->assertFalse($this->cache->get('folder'));
+ $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));
+
+ // get un-normalized folder by name
+ $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));
+
+ // at this point we should have only one folder named "Schön"
+ $this->assertEquals(1, count($this->cache->getFolderContents('folder')));
+ }
+
public function tearDown() {
$this->cache->clear();
}
public function setUp() {
$this->storage = new \OC\Files\Storage\Temporary(array());
+ $this->storage2 = new \OC\Files\Storage\Temporary(array());
$this->cache = new \OC\Files\Cache\Cache($this->storage);
+ $this->cache2 = new \OC\Files\Cache\Cache($this->storage2);
}
}
diff --git a/tests/lib/files/cache/permissions.php b/tests/lib/files/cache/permissions.php
index 56dbbc4518e..7e6e11e2eb2 100644
--- a/tests/lib/files/cache/permissions.php
+++ b/tests/lib/files/cache/permissions.php
@@ -14,8 +14,8 @@ class Permissions extends \PHPUnit_Framework_TestCase {
*/
private $permissionsCache;
- function setUp(){
- $this->permissionsCache=new \OC\Files\Cache\Permissions('dummy');
+ function setUp() {
+ $this->permissionsCache = new \OC\Files\Cache\Permissions('dummy');
}
function testSimple() {
@@ -23,8 +23,10 @@ class Permissions extends \PHPUnit_Framework_TestCase {
$user = uniqid();
$this->assertEquals(-1, $this->permissionsCache->get(1, $user));
+ $this->assertNotContains($user, $this->permissionsCache->getUsers(1));
$this->permissionsCache->set(1, $user, 1);
$this->assertEquals(1, $this->permissionsCache->get(1, $user));
+ $this->assertContains($user, $this->permissionsCache->getUsers(1));
$this->assertEquals(-1, $this->permissionsCache->get(2, $user));
$this->assertEquals(-1, $this->permissionsCache->get(1, $user . '2'));
diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php
index aaf932c97fe..dad3cd7e650 100644
--- a/tests/lib/files/cache/updater.php
+++ b/tests/lib/files/cache/updater.php
@@ -42,14 +42,11 @@ class Updater extends \PHPUnit_Framework_TestCase {
$this->scanner->scan('');
$this->cache = $this->storage->getCache();
+ \OC\Files\Filesystem::tearDown();
if (!self::$user) {
- if (!\OC\Files\Filesystem::getView()) {
- self::$user = uniqid();
- \OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files');
- } else {
- self::$user = \OC_User::getUser();
- }
+ self::$user = uniqid();
}
+ \OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files');
Filesystem::clearMounts();
Filesystem::mount($this->storage, array(), '/' . self::$user . '/files');
diff --git a/tests/lib/files/cache/watcher.php b/tests/lib/files/cache/watcher.php
index 8ef6ab44d10..e43c86ed438 100644
--- a/tests/lib/files/cache/watcher.php
+++ b/tests/lib/files/cache/watcher.php
@@ -35,7 +35,7 @@ class Watcher extends \PHPUnit_Framework_TestCase {
$updater = $storage->getWatcher();
//set the mtime to the past so it can detect an mtime change
- $cache->put('', array('mtime' => 10));
+ $cache->put('', array('storage_mtime' => 10));
$this->assertTrue($cache->inCache('folder/bar.txt'));
$this->assertTrue($cache->inCache('folder/bar2.txt'));
@@ -47,14 +47,14 @@ class Watcher extends \PHPUnit_Framework_TestCase {
$cachedData = $cache->get('bar.test');
$this->assertEquals(3, $cachedData['size']);
- $cache->put('bar.test', array('mtime' => 10));
+ $cache->put('bar.test', array('storage_mtime' => 10));
$storage->file_put_contents('bar.test', 'test data');
$updater->checkUpdate('bar.test');
$cachedData = $cache->get('bar.test');
$this->assertEquals(9, $cachedData['size']);
- $cache->put('folder', array('mtime' => 10));
+ $cache->put('folder', array('storage_mtime' => 10));
$storage->unlink('folder/bar2.txt');
$updater->checkUpdate('folder');
@@ -69,7 +69,7 @@ class Watcher extends \PHPUnit_Framework_TestCase {
$updater = $storage->getWatcher();
//set the mtime to the past so it can detect an mtime change
- $cache->put('', array('mtime' => 10));
+ $cache->put('', array('storage_mtime' => 10));
$storage->unlink('foo.txt');
$storage->rename('folder', 'foo.txt');
@@ -85,7 +85,7 @@ class Watcher extends \PHPUnit_Framework_TestCase {
$updater = $storage->getWatcher();
//set the mtime to the past so it can detect an mtime change
- $cache->put('foo.txt', array('mtime' => 10));
+ $cache->put('foo.txt', array('storage_mtime' => 10));
$storage->unlink('foo.txt');
$storage->rename('folder', 'foo.txt');
diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php
index 6ce45e6178a..bef70cc725b 100644
--- a/tests/lib/files/filesystem.php
+++ b/tests/lib/files/filesystem.php
@@ -72,7 +72,7 @@ class Filesystem extends \PHPUnit_Framework_TestCase {
$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'));
- if (class_exists('Normalizer')) {
+ if (class_exists('Patchwork\PHP\Shim\Normalizer')) {
$this->assertEquals("/foo/bar\xC3\xBC", \OC\Files\Filesystem::normalizePath("/foo/baru\xCC\x88"));
}
}
diff --git a/tests/lib/files/mount.php b/tests/lib/files/mount.php
deleted file mode 100644
index a3dc06cc668..00000000000
--- a/tests/lib/files/mount.php
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php
-/**
- * Copyright (c) 2013 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;
-
-use \OC\Files\Storage\Temporary;
-
-class LongId extends Temporary {
- public function getId() {
- return 'long:' . str_repeat('foo', 50) . parent::getId();
- }
-}
-
-class Mount extends \PHPUnit_Framework_TestCase {
- public function setup() {
- \OC_Util::setupFS();
- \OC\Files\Mount::clear();
- }
-
- public function testFind() {
- $this->assertNull(\OC\Files\Mount::find('/'));
-
- $rootMount = new \OC\Files\Mount(new Temporary(array()), '/');
- $this->assertEquals($rootMount, \OC\Files\Mount::find('/'));
- $this->assertEquals($rootMount, \OC\Files\Mount::find('/foo/bar'));
-
- $storage = new Temporary(array());
- $mount = new \OC\Files\Mount($storage, '/foo');
- $this->assertEquals($rootMount, \OC\Files\Mount::find('/'));
- $this->assertEquals($mount, \OC\Files\Mount::find('/foo/bar'));
-
- $this->assertEquals(1, count(\OC\Files\Mount::findIn('/')));
- new \OC\Files\Mount(new Temporary(array()), '/bar');
- $this->assertEquals(2, count(\OC\Files\Mount::findIn('/')));
-
- $id = $mount->getStorageId();
- $this->assertEquals(array($mount), \OC\Files\Mount::findByStorageId($id));
-
- $mount2 = new \OC\Files\Mount($storage, '/foo/bar');
- $this->assertEquals(array($mount, $mount2), \OC\Files\Mount::findByStorageId($id));
- }
-
- public function testLong() {
- $storage = new LongId(array());
- $mount = new \OC\Files\Mount($storage, '/foo');
-
- $id = $mount->getStorageId();
- $storageId = $storage->getId();
- $this->assertEquals(array($mount), \OC\Files\Mount::findByStorageId($id));
- $this->assertEquals(array($mount), \OC\Files\Mount::findByStorageId($storageId));
- $this->assertEquals(array($mount), \OC\Files\Mount::findByStorageId(md5($storageId)));
- }
-}
diff --git a/tests/lib/files/mount/manager.php b/tests/lib/files/mount/manager.php
new file mode 100644
index 00000000000..154c35ccead
--- /dev/null
+++ b/tests/lib/files/mount/manager.php
@@ -0,0 +1,67 @@
+<?php
+/**
+ * Copyright (c) 2013 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\Mount;
+
+use \OC\Files\Storage\Temporary;
+
+class LongId extends Temporary {
+ public function getId() {
+ return 'long:' . str_repeat('foo', 50) . parent::getId();
+ }
+}
+
+class Manager extends \PHPUnit_Framework_TestCase {
+ /**
+ * @var \OC\Files\Mount\Manager
+ */
+ private $manager;
+
+ public function setup() {
+ $this->manager = new \OC\Files\Mount\Manager();
+ }
+
+ public function testFind() {
+ $this->assertNull($this->manager->find('/'));
+
+ $rootMount = new \OC\Files\Mount\Mount(new Temporary(array()), '/');
+ $this->manager->addMount($rootMount);
+ $this->assertEquals($rootMount, $this->manager->find('/'));
+ $this->assertEquals($rootMount, $this->manager->find('/foo/bar'));
+
+ $storage = new Temporary(array());
+ $mount1 = new \OC\Files\Mount\Mount($storage, '/foo');
+ $this->manager->addMount($mount1);
+ $this->assertEquals($rootMount, $this->manager->find('/'));
+ $this->assertEquals($mount1, $this->manager->find('/foo/bar'));
+
+ $this->assertEquals(1, count($this->manager->findIn('/')));
+ $mount2 = new \OC\Files\Mount\Mount(new Temporary(array()), '/bar');
+ $this->manager->addMount($mount2);
+ $this->assertEquals(2, count($this->manager->findIn('/')));
+
+ $id = $mount1->getStorageId();
+ $this->assertEquals(array($mount1), $this->manager->findByStorageId($id));
+
+ $mount3 = new \OC\Files\Mount\Mount($storage, '/foo/bar');
+ $this->manager->addMount($mount3);
+ $this->assertEquals(array($mount1, $mount3), $this->manager->findByStorageId($id));
+ }
+
+ public function testLong() {
+ $storage = new LongId(array());
+ $mount = new \OC\Files\Mount\Mount($storage, '/foo');
+ $this->manager->addMount($mount);
+
+ $id = $mount->getStorageId();
+ $storageId = $storage->getId();
+ $this->assertEquals(array($mount), $this->manager->findByStorageId($id));
+ $this->assertEquals(array($mount), $this->manager->findByStorageId($storageId));
+ $this->assertEquals(array($mount), $this->manager->findByStorageId(md5($storageId)));
+ }
+}
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index a064e44f3ef..01f9a9cca11 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -7,6 +7,12 @@
namespace Test\Files;
+class TemporaryNoTouch extends \OC\Files\Storage\Temporary {
+ public function touch($path, $mtime = null) {
+ return false;
+ }
+}
+
class View extends \PHPUnit_Framework_TestCase {
/**
* @var \OC\Files\Storage\Storage[] $storages;
@@ -220,7 +226,7 @@ class View extends \PHPUnit_Framework_TestCase {
$cachedData = $rootView->getFileInfo('foo.txt');
$this->assertEquals(16, $cachedData['size']);
- $rootView->putFileInfo('foo.txt', array('mtime' => 10));
+ $rootView->putFileInfo('foo.txt', array('storage_mtime' => 10));
$storage1->file_put_contents('foo.txt', 'foo');
clearstatcache();
@@ -228,12 +234,73 @@ class View extends \PHPUnit_Framework_TestCase {
$this->assertEquals(3, $cachedData['size']);
}
+ function testCopyBetweenStorages() {
+ $storage1 = $this->getTestStorage();
+ $storage2 = $this->getTestStorage();
+ \OC\Files\Filesystem::mount($storage1, array(), '/');
+ \OC\Files\Filesystem::mount($storage2, array(), '/substorage');
+
+ $rootView = new \OC\Files\View('');
+ $rootView->mkdir('substorage/emptyfolder');
+ $rootView->copy('substorage', 'anotherfolder');
+ $this->assertTrue($rootView->is_dir('/anotherfolder'));
+ $this->assertTrue($rootView->is_dir('/substorage'));
+ $this->assertTrue($rootView->is_dir('/anotherfolder/emptyfolder'));
+ $this->assertTrue($rootView->is_dir('/substorage/emptyfolder'));
+ $this->assertTrue($rootView->file_exists('/anotherfolder/foo.txt'));
+ $this->assertTrue($rootView->file_exists('/anotherfolder/foo.png'));
+ $this->assertTrue($rootView->file_exists('/anotherfolder/folder/bar.txt'));
+ $this->assertTrue($rootView->file_exists('/substorage/foo.txt'));
+ $this->assertTrue($rootView->file_exists('/substorage/foo.png'));
+ $this->assertTrue($rootView->file_exists('/substorage/folder/bar.txt'));
+ }
+
+ function testMoveBetweenStorages() {
+ $storage1 = $this->getTestStorage();
+ $storage2 = $this->getTestStorage();
+ \OC\Files\Filesystem::mount($storage1, array(), '/');
+ \OC\Files\Filesystem::mount($storage2, array(), '/substorage');
+
+ $rootView = new \OC\Files\View('');
+ $rootView->rename('foo.txt', 'substorage/folder/foo.txt');
+ $this->assertFalse($rootView->file_exists('foo.txt'));
+ $this->assertTrue($rootView->file_exists('substorage/folder/foo.txt'));
+ $rootView->rename('substorage/folder', 'anotherfolder');
+ $this->assertFalse($rootView->is_dir('substorage/folder'));
+ $this->assertTrue($rootView->file_exists('anotherfolder/foo.txt'));
+ $this->assertTrue($rootView->file_exists('anotherfolder/bar.txt'));
+ }
+
+ function testTouch() {
+ $storage = $this->getTestStorage(true, '\Test\Files\TemporaryNoTouch');
+
+ \OC\Files\Filesystem::mount($storage, array(), '/');
+
+ $rootView = new \OC\Files\View('');
+ $oldCachedData = $rootView->getFileInfo('foo.txt');
+
+ $rootView->touch('foo.txt', 500);
+
+ $cachedData = $rootView->getFileInfo('foo.txt');
+ $this->assertEquals(500, $cachedData['mtime']);
+ $this->assertEquals($oldCachedData['storage_mtime'], $cachedData['storage_mtime']);
+
+ $rootView->putFileInfo('foo.txt', array('storage_mtime' => 1000)); //make sure the watcher detects the change
+ $rootView->file_put_contents('foo.txt', 'asd');
+ $cachedData = $rootView->getFileInfo('foo.txt');
+ $this->assertGreaterThanOrEqual($cachedData['mtime'], $oldCachedData['mtime']);
+ $this->assertEquals($cachedData['storage_mtime'], $cachedData['mtime']);
+ }
+
/**
* @param bool $scan
* @return \OC\Files\Storage\Storage
*/
- private function getTestStorage($scan = true) {
- $storage = new \OC\Files\Storage\Temporary(array());
+ private function getTestStorage($scan = true, $class = '\OC\Files\Storage\Temporary') {
+ /**
+ * @var \OC\Files\Storage\Storage $storage
+ */
+ $storage = new $class(array());
$textData = "dummy file data\n";
$imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
$storage->mkdir('folder');