aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/files
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2013-05-21 23:35:19 +0200
committerRobin Appelman <icewind@owncloud.com>2013-05-21 23:35:19 +0200
commit81fd1badc3feb72c3a4e597c670e8adcdca525da (patch)
treedda3deee50551ebdffa8a9021b528ac29fdbf369 /tests/lib/files
parentd7beac6d6f3ad588cee6c5ba8a2145b42fa184a2 (diff)
parentfb4d8ddf0a76da7e9f806b837f9cf23699671f75 (diff)
downloadnextcloud-server-81fd1badc3feb72c3a4e597c670e8adcdca525da.tar.gz
nextcloud-server-81fd1badc3feb72c3a4e597c670e8adcdca525da.zip
merge master into filecache_mtime
Diffstat (limited to 'tests/lib/files')
-rw-r--r--tests/lib/files/cache/cache.php9
-rw-r--r--tests/lib/files/cache/permissions.php6
-rw-r--r--tests/lib/files/cache/updater.php14
-rw-r--r--tests/lib/files/mapper.php52
-rw-r--r--tests/lib/files/mount.php58
-rw-r--r--tests/lib/files/mount/manager.php67
-rw-r--r--tests/lib/files/storage/storage.php9
7 files changed, 141 insertions, 74 deletions
diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php
index edcd1c487d0..1612a673838 100644
--- a/tests/lib/files/cache/cache.php
+++ b/tests/lib/files/cache/cache.php
@@ -162,10 +162,11 @@ 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);
@@ -244,4 +245,4 @@ class Cache extends \PHPUnit_Framework_TestCase {
$this->storage = new \OC\Files\Storage\Temporary(array());
$this->cache = new \OC\Files\Cache\Cache($this->storage);
}
-} \ No newline at end of file
+}
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 7a79f45a203..dad3cd7e650 100644
--- a/tests/lib/files/cache/updater.php
+++ b/tests/lib/files/cache/updater.php
@@ -42,18 +42,17 @@ 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');
+ \OC_Hook::clear('OC_Filesystem');
+
\OC_Hook::connect('OC_Filesystem', 'post_write', '\OC\Files\Cache\Updater', 'writeHook');
\OC_Hook::connect('OC_Filesystem', 'post_delete', '\OC\Files\Cache\Updater', 'deleteHook');
\OC_Hook::connect('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Updater', 'renameHook');
@@ -137,11 +136,10 @@ class Updater extends \PHPUnit_Framework_TestCase {
$this->assertFalse($this->cache->inCache('foo.txt'));
$this->assertTrue($this->cache->inCache('bar.txt'));
$cachedData = $this->cache->get('bar.txt');
- $this->assertNotEquals($fooCachedData['etag'], $cachedData['etag']);
+ $this->assertEquals($fooCachedData['fileid'], $cachedData['fileid']);
$mtime = $cachedData['mtime'];
$cachedData = $this->cache->get('');
$this->assertEquals(3 * $textSize + $imageSize, $cachedData['size']);
$this->assertNotEquals($rootCachedData['etag'], $cachedData['etag']);
- $this->assertEquals($mtime, $cachedData['mtime']);
}
}
diff --git a/tests/lib/files/mapper.php b/tests/lib/files/mapper.php
new file mode 100644
index 00000000000..e3859bc0f23
--- /dev/null
+++ b/tests/lib/files/mapper.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * ownCloud
+ *
+ * @author Thomas Müller
+ * @copyright 2013 Thomas Müller thomas.mueller@owncloud.com
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Test\Files;
+
+class Mapper extends \PHPUnit_Framework_TestCase {
+
+ /**
+ * @var \OC\Files\Mapper
+ */
+ private $mapper = null;
+
+ public function setUp() {
+ $this->mapper = new \OC\Files\Mapper('D:/');
+ }
+
+ public function testSlugifyPath() {
+ // with extension
+ $this->assertEquals('D:/text.txt', $this->mapper->slugifyPath('D:/text.txt'));
+ $this->assertEquals('D:/text-2.txt', $this->mapper->slugifyPath('D:/text.txt', 2));
+ $this->assertEquals('D:/a/b/text.txt', $this->mapper->slugifyPath('D:/a/b/text.txt'));
+
+ // without extension
+ $this->assertEquals('D:/text', $this->mapper->slugifyPath('D:/text'));
+ $this->assertEquals('D:/text-2', $this->mapper->slugifyPath('D:/text', 2));
+ $this->assertEquals('D:/a/b/text', $this->mapper->slugifyPath('D:/a/b/text'));
+
+ // with double dot
+ $this->assertEquals('D:/text-text.txt', $this->mapper->slugifyPath('D:/text.text.txt'));
+ $this->assertEquals('D:/text-text-2.txt', $this->mapper->slugifyPath('D:/text.text.txt', 2));
+ $this->assertEquals('D:/a/b/text-text.txt', $this->mapper->slugifyPath('D:/a/b/text.text.txt'));
+ }
+}
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/storage/storage.php b/tests/lib/files/storage/storage.php
index f78f66d8b8a..0e22f26ae83 100644
--- a/tests/lib/files/storage/storage.php
+++ b/tests/lib/files/storage/storage.php
@@ -224,8 +224,7 @@ abstract class Storage extends \PHPUnit_Framework_TestCase {
}
public function testSearchInSubFolder() {
- $this->instance->mkdir('sub')
- ;
+ $this->instance->mkdir('sub');
$textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$this->instance->file_put_contents('/sub/lorem.txt', file_get_contents($textFile, 'r'));
$pngFile = \OC::$SERVERROOT . '/tests/data/logo-wide.png';
@@ -258,4 +257,10 @@ abstract class Storage extends \PHPUnit_Framework_TestCase {
$content = stream_get_contents($fh);
$this->assertEquals(file_get_contents($textFile), $content);
}
+
+ public function testTouchCreateFile(){
+ $this->assertFalse($this->instance->file_exists('foo'));
+ $this->instance->touch('foo');
+ $this->assertTrue($this->instance->file_exists('foo'));
+ }
}