summaryrefslogtreecommitdiffstats
path: root/tests/lib/files/utils/scanner.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/files/utils/scanner.php')
-rw-r--r--tests/lib/files/utils/scanner.php64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/lib/files/utils/scanner.php b/tests/lib/files/utils/scanner.php
index a021d215ae5..159a2a48677 100644
--- a/tests/lib/files/utils/scanner.php
+++ b/tests/lib/files/utils/scanner.php
@@ -8,6 +8,7 @@
namespace Test\Files\Utils;
+use OC\Files\Filesystem;
use OC\Files\Mount\Mount;
use OC\Files\Storage\Temporary;
@@ -27,12 +28,21 @@ class TestScanner extends \OC\Files\Utils\Scanner {
protected function getMounts($dir) {
return $this->mounts;
}
+
+ public function getPropagator() {
+ return $this->propagator;
+ }
+
+ public function setPropagator($propagator) {
+ $this->propagator = $propagator;
+ }
}
class Scanner extends \PHPUnit_Framework_TestCase {
public function testReuseExistingRoot() {
$storage = new Temporary(array());
$mount = new Mount($storage, '');
+ Filesystem::getMountManager()->addMount($mount);
$cache = $storage->getCache();
$storage->mkdir('folder');
@@ -54,6 +64,7 @@ class Scanner extends \PHPUnit_Framework_TestCase {
public function testReuseExistingFile() {
$storage = new Temporary(array());
$mount = new Mount($storage, '');
+ Filesystem::getMountManager()->addMount($mount);
$cache = $storage->getCache();
$storage->mkdir('folder');
@@ -71,4 +82,57 @@ class Scanner extends \PHPUnit_Framework_TestCase {
$new = $cache->get('folder/bar.txt');
$this->assertEquals($old, $new);
}
+
+ public function testChangePropagator() {
+ /**
+ * @var \OC\Files\Cache\ChangePropagator $propagator
+ */
+ $propagator = $this->getMock('\OC\Files\Cache\ChangePropagator', array('propagateChanges'), array(), '', false);
+
+ $storage = new Temporary(array());
+ $mount = new Mount($storage, '/foo');
+ Filesystem::getMountManager()->addMount($mount);
+ $cache = $storage->getCache();
+
+ $storage->mkdir('folder');
+ $storage->file_put_contents('foo.txt', 'qwerty');
+ $storage->file_put_contents('folder/bar.txt', 'qwerty');
+
+ $scanner = new TestScanner('');
+ $originalPropagator = $scanner->getPropagator();
+ $scanner->setPropagator($propagator);
+ $scanner->addMount($mount);
+
+ $scanner->scan('');
+
+ $changes = $propagator->getChanges();
+ $parents = $propagator->getAllParents();
+ sort($changes);
+ sort($parents);
+ $this->assertEquals(array('/foo', '/foo/folder', '/foo/folder/bar.txt', '/foo/foo.txt'), $changes);
+ $this->assertEquals(array('/', '/foo', '/foo/folder'), $parents);
+
+ $cache->put('foo.txt', array('mtime' => time() - 50));
+
+ $propagator = $this->getMock('\OC\Files\Cache\ChangePropagator', array('propagateChanges'), array(), '', false);
+ $scanner->setPropagator($propagator);
+ $storage->file_put_contents('foo.txt', 'asdasd');
+
+ $scanner->scan('');
+
+ $changes = $propagator->getChanges();
+ $parents = $propagator->getAllParents();
+ $this->assertEquals(array('/foo/foo.txt'), $changes);
+ $this->assertEquals(array('/', '/foo'), $parents);
+
+ $scanner->setPropagator($originalPropagator);
+
+ $oldInfo = $cache->get('');
+ $cache->put('foo.txt', array('mtime' => time() - 70));
+ $storage->file_put_contents('foo.txt', 'asdasd');
+
+ $scanner->scan('');
+ $newInfo = $cache->get('');
+ $this->assertNotEquals($oldInfo['etag'], $newInfo['etag']);
+ }
}