summaryrefslogtreecommitdiffstats
path: root/tests/lib/files
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/files')
-rw-r--r--tests/lib/files/cache/homecache.php4
-rw-r--r--tests/lib/files/cache/watcher.php56
-rw-r--r--tests/lib/files/etagtest.php3
-rw-r--r--tests/lib/files/node/integration.php3
-rw-r--r--tests/lib/files/node/root.php1
-rw-r--r--tests/lib/files/storage/home.php4
-rw-r--r--tests/lib/files/storage/storage.php19
-rw-r--r--tests/lib/files/storage/wrapper/quota.php28
-rw-r--r--tests/lib/files/stream/quota.php4
-rw-r--r--tests/lib/files/view.php3
10 files changed, 117 insertions, 8 deletions
diff --git a/tests/lib/files/cache/homecache.php b/tests/lib/files/cache/homecache.php
index 87fd0dba4c6..dbcf6e9caa0 100644
--- a/tests/lib/files/cache/homecache.php
+++ b/tests/lib/files/cache/homecache.php
@@ -19,6 +19,10 @@ class DummyUser extends \OC\User\User {
*/
private $uid;
+ /**
+ * @param string $uid
+ * @param string $home
+ */
public function __construct($uid, $home) {
$this->home = $home;
$this->uid = $uid;
diff --git a/tests/lib/files/cache/watcher.php b/tests/lib/files/cache/watcher.php
index 1920c276907..7f4f3c5ee98 100644
--- a/tests/lib/files/cache/watcher.php
+++ b/tests/lib/files/cache/watcher.php
@@ -11,7 +11,7 @@ namespace Test\Files\Cache;
class Watcher extends \PHPUnit_Framework_TestCase {
/**
- * @var \OC\Files\Storage\Storage[] $storages;
+ * @var \OC\Files\Storage\Storage[] $storages
*/
private $storages = array();
@@ -105,6 +105,60 @@ class Watcher extends \PHPUnit_Framework_TestCase {
$this->assertTrue($cache->inCache('foo.txt/bar.txt'));
}
+ public function testPolicyNever() {
+ $storage = $this->getTestStorage();
+ $cache = $storage->getCache();
+ $updater = $storage->getWatcher();
+
+ //set the mtime to the past so it can detect an mtime change
+ $cache->put('foo.txt', array('storage_mtime' => 10));
+
+ $updater->setPolicy(\OC\Files\Cache\Watcher::CHECK_NEVER);
+
+ $storage->file_put_contents('foo.txt', 'q');
+ $this->assertFalse($updater->checkUpdate('foo.txt'));
+
+ $cache->put('foo.txt', array('storage_mtime' => 20));
+ $storage->file_put_contents('foo.txt', 'w');
+ $this->assertFalse($updater->checkUpdate('foo.txt'));
+ }
+
+ public function testPolicyOnce() {
+ $storage = $this->getTestStorage();
+ $cache = $storage->getCache();
+ $updater = $storage->getWatcher();
+
+ //set the mtime to the past so it can detect an mtime change
+ $cache->put('foo.txt', array('storage_mtime' => 10));
+
+ $updater->setPolicy(\OC\Files\Cache\Watcher::CHECK_ONCE);
+
+ $storage->file_put_contents('foo.txt', 'q');
+ $this->assertTrue($updater->checkUpdate('foo.txt'));
+
+ $cache->put('foo.txt', array('storage_mtime' => 20));
+ $storage->file_put_contents('foo.txt', 'w');
+ $this->assertFalse($updater->checkUpdate('foo.txt'));
+ }
+
+ public function testPolicyAlways() {
+ $storage = $this->getTestStorage();
+ $cache = $storage->getCache();
+ $updater = $storage->getWatcher();
+
+ //set the mtime to the past so it can detect an mtime change
+ $cache->put('foo.txt', array('storage_mtime' => 10));
+
+ $updater->setPolicy(\OC\Files\Cache\Watcher::CHECK_ALWAYS);
+
+ $storage->file_put_contents('foo.txt', 'q');
+ $this->assertTrue($updater->checkUpdate('foo.txt'));
+
+ $cache->put('foo.txt', array('storage_mtime' => 20));
+ $storage->file_put_contents('foo.txt', 'w');
+ $this->assertTrue($updater->checkUpdate('foo.txt'));
+ }
+
/**
* @param bool $scan
* @return \OC\Files\Storage\Storage
diff --git a/tests/lib/files/etagtest.php b/tests/lib/files/etagtest.php
index 6c41413c4df..ce05adb188a 100644
--- a/tests/lib/files/etagtest.php
+++ b/tests/lib/files/etagtest.php
@@ -68,6 +68,9 @@ class EtagTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals($originalEtags, $this->getEtags($files));
}
+ /**
+ * @param string[] $files
+ */
private function getEtags($files) {
$etags = array();
foreach ($files as $file) {
diff --git a/tests/lib/files/node/integration.php b/tests/lib/files/node/integration.php
index 14e1d05853d..319f2f9f5f7 100644
--- a/tests/lib/files/node/integration.php
+++ b/tests/lib/files/node/integration.php
@@ -9,10 +9,7 @@
namespace Test\Files\Node;
use OC\Files\Cache\Cache;
-use OC\Files\Mount\Manager;
use OC\Files\Node\Root;
-use OCP\Files\NotFoundException;
-use OCP\Files\NotPermittedException;
use OC\Files\Storage\Temporary;
use OC\Files\View;
use OC\User\User;
diff --git a/tests/lib/files/node/root.php b/tests/lib/files/node/root.php
index 97eaf7f7162..27f1a937826 100644
--- a/tests/lib/files/node/root.php
+++ b/tests/lib/files/node/root.php
@@ -8,7 +8,6 @@
namespace Test\Files\Node;
-use OC\Files\Cache\Cache;
use OCP\Files\NotPermittedException;
use OC\Files\Mount\Manager;
diff --git a/tests/lib/files/storage/home.php b/tests/lib/files/storage/home.php
index 885291e4404..51315a2a556 100644
--- a/tests/lib/files/storage/home.php
+++ b/tests/lib/files/storage/home.php
@@ -29,6 +29,10 @@ class DummyUser extends User {
private $uid;
+ /**
+ * @param string $uid
+ * @param string $home
+ */
public function __construct($uid, $home) {
$this->uid = $uid;
$this->home = $home;
diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php
index 182c014d999..f9291758606 100644
--- a/tests/lib/files/storage/storage.php
+++ b/tests/lib/files/storage/storage.php
@@ -27,6 +27,17 @@ abstract class Storage extends \PHPUnit_Framework_TestCase {
* @var \OC\Files\Storage\Storage instance
*/
protected $instance;
+ protected $waitDelay = 0;
+
+ /**
+ * Sleep for the number of seconds specified in the
+ * $waitDelay attribute
+ */
+ protected function wait() {
+ if ($this->waitDelay > 0) {
+ sleep($this->waitDelay);
+ }
+ }
/**
* the root folder of the storage should always exist, be readable and be recognized as a directory
@@ -77,6 +88,7 @@ abstract class Storage extends \PHPUnit_Framework_TestCase {
$this->assertFalse($this->instance->mkdir('/'.$directory)); //cant create existing folders
$this->assertTrue($this->instance->rmdir('/'.$directory));
+ $this->wait();
$this->assertFalse($this->instance->file_exists('/'.$directory));
$this->assertFalse($this->instance->rmdir('/'.$directory)); //cant remove non existing folders
@@ -97,6 +109,8 @@ abstract class Storage extends \PHPUnit_Framework_TestCase {
array('folder'),
array(' folder'),
array('folder '),
+ array('folder with space'),
+ array('spéciäl földer'),
);
}
/**
@@ -144,6 +158,7 @@ abstract class Storage extends \PHPUnit_Framework_TestCase {
$this->assertEquals($this->instance->file_get_contents('/source.txt'), $this->instance->file_get_contents('/target.txt'));
$this->instance->rename('/source.txt', '/target2.txt');
+ $this->wait();
$this->assertTrue($this->instance->file_exists('/target2.txt'));
$this->assertFalse($this->instance->file_exists('/source.txt'));
$this->assertEquals(file_get_contents($textFile), $this->instance->file_get_contents('/target2.txt'));
@@ -225,6 +240,7 @@ abstract class Storage extends \PHPUnit_Framework_TestCase {
$this->assertTrue($this->instance->file_exists('/lorem.txt'));
$this->assertTrue($this->instance->unlink('/lorem.txt'));
+ $this->wait();
$this->assertFalse($this->instance->file_exists('/lorem.txt'));
}
@@ -259,9 +275,11 @@ abstract class Storage extends \PHPUnit_Framework_TestCase {
public function testRecursiveRmdir() {
$this->instance->mkdir('folder');
$this->instance->mkdir('folder/bar');
+ $this->wait();
$this->instance->file_put_contents('folder/asd.txt', 'foobar');
$this->instance->file_put_contents('folder/bar/foo.txt', 'asd');
$this->assertTrue($this->instance->rmdir('folder'));
+ $this->wait();
$this->assertFalse($this->instance->file_exists('folder/asd.txt'));
$this->assertFalse($this->instance->file_exists('folder/bar/foo.txt'));
$this->assertFalse($this->instance->file_exists('folder/bar'));
@@ -274,6 +292,7 @@ abstract class Storage extends \PHPUnit_Framework_TestCase {
$this->instance->file_put_contents('folder/asd.txt', 'foobar');
$this->instance->file_put_contents('folder/bar/foo.txt', 'asd');
$this->assertTrue($this->instance->unlink('folder'));
+ $this->wait();
$this->assertFalse($this->instance->file_exists('folder/asd.txt'));
$this->assertFalse($this->instance->file_exists('folder/bar/foo.txt'));
$this->assertFalse($this->instance->file_exists('folder/bar'));
diff --git a/tests/lib/files/storage/wrapper/quota.php b/tests/lib/files/storage/wrapper/quota.php
index 87bafb64d41..43eae78415d 100644
--- a/tests/lib/files/storage/wrapper/quota.php
+++ b/tests/lib/files/storage/wrapper/quota.php
@@ -27,6 +27,9 @@ class Quota extends \Test\Files\Storage\Storage {
\OC_Helper::rmdirr($this->tmpDir);
}
+ /**
+ * @param integer $limit
+ */
protected function getLimitedStorage($limit) {
$storage = new \OC\Files\Storage\Local(array('datadir' => $this->tmpDir));
$storage->getScanner()->scan('');
@@ -59,7 +62,7 @@ class Quota extends \Test\Files\Storage\Storage {
$this->assertEquals('foobarqwe', $instance->file_get_contents('foo'));
}
- public function testReturnFalseWhenFopenFailed(){
+ public function testReturnFalseWhenFopenFailed() {
$failStorage = $this->getMock(
'\OC\Files\Storage\Local',
array('fopen'),
@@ -73,7 +76,7 @@ class Quota extends \Test\Files\Storage\Storage {
$this->assertFalse($instance->fopen('failedfopen', 'r'));
}
- public function testReturnRegularStreamOnRead(){
+ public function testReturnRegularStreamOnRead() {
$instance = $this->getLimitedStorage(9);
// create test file first
@@ -92,11 +95,30 @@ class Quota extends \Test\Files\Storage\Storage {
fclose($stream);
}
- public function testReturnQuotaStreamOnWrite(){
+ public function testReturnQuotaStreamOnWrite() {
$instance = $this->getLimitedStorage(9);
$stream = $instance->fopen('foo', 'w+');
$meta = stream_get_meta_data($stream);
$this->assertEquals('user-space', $meta['wrapper_type']);
fclose($stream);
}
+
+ public function testSpaceRoot() {
+ $storage = $this->getMockBuilder('\OC\Files\Storage\Local')->disableOriginalConstructor()->getMock();
+ $cache = $this->getMockBuilder('\OC\Files\Cache\Cache')->disableOriginalConstructor()->getMock();
+ $storage->expects($this->once())
+ ->method('getCache')
+ ->will($this->returnValue($cache));
+ $storage->expects($this->once())
+ ->method('free_space')
+ ->will($this->returnValue(2048));
+ $cache->expects($this->once())
+ ->method('get')
+ ->with('files')
+ ->will($this->returnValue(array('size' => 50)));
+
+ $instance = new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => 1024, 'root' => 'files'));
+
+ $this->assertEquals(1024 - 50, $instance->free_space(''));
+ }
}
diff --git a/tests/lib/files/stream/quota.php b/tests/lib/files/stream/quota.php
index b11f0ac74c0..d5edace544d 100644
--- a/tests/lib/files/stream/quota.php
+++ b/tests/lib/files/stream/quota.php
@@ -13,6 +13,10 @@ class Quota extends \PHPUnit_Framework_TestCase {
\OC\Files\Stream\Quota::clear();
}
+ /**
+ * @param string $mode
+ * @param integer $limit
+ */
protected function getStream($mode, $limit) {
$source = fopen('php://temp', $mode);
return \OC\Files\Stream\Quota::wrap($source, $limit);
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index 72a2f854cb2..371d1ed1798 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -7,6 +7,8 @@
namespace Test\Files;
+use OC\Files\Cache\Watcher;
+
class TemporaryNoTouch extends \OC\Files\Storage\Temporary {
public function touch($path, $mtime = null) {
return false;
@@ -249,6 +251,7 @@ class View extends \PHPUnit_Framework_TestCase {
function testWatcher() {
$storage1 = $this->getTestStorage();
\OC\Files\Filesystem::mount($storage1, array(), '/');
+ $storage1->getWatcher()->setPolicy(Watcher::CHECK_ALWAYS);
$rootView = new \OC\Files\View('');