Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2014-02-19 12:52:32 +0400
committerRobin Appelman <icewind@owncloud.com>2014-02-19 12:52:51 +0400
commiteea1abae2076825789f4b2abd2e476b93004714d (patch)
treed321df6e18c91ec81f3ddfcc679b86b523919446 /tests
parent2166683e3b5810bfeca2540a038e212fb8ca75ed (diff)
add unit tests for watcher policies
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/files/cache/watcher.php56
1 files changed, 55 insertions, 1 deletions
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