]> source.dussan.org Git - nextcloud-server.git/commitdiff
add unit tests for watcher policies
authorRobin Appelman <icewind@owncloud.com>
Wed, 19 Feb 2014 08:52:32 +0000 (09:52 +0100)
committerRobin Appelman <icewind@owncloud.com>
Wed, 19 Feb 2014 08:52:51 +0000 (09:52 +0100)
tests/lib/files/cache/watcher.php

index 1920c2769079a37ac6b2c5e00916fa74c0eaa554..7f4f3c5ee98bce52ee2c03b8f27c4ad615b7eb52 100644 (file)
@@ -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