diff options
author | Robin Appelman <icewind@owncloud.com> | 2014-06-02 17:17:00 +0400 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2014-06-10 18:20:51 +0400 |
commit | 81f6e78c0c4d8feb173fef88f3b797c779369e95 (patch) | |
tree | e1481d6d8ebb80e28401ea740459e4180c8ffce7 /tests | |
parent | a543f466993eedadf690c648a956870fcf340cb6 (diff) |
propagate changes in the scanner
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/files/utils/scanner.php | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/lib/files/utils/scanner.php b/tests/lib/files/utils/scanner.php index a021d215ae5..4610e2b4d46 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,6 +28,14 @@ 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 { @@ -71,4 +80,51 @@ 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(''); + + $this->assertEquals(array('/foo', '/foo/foo.txt', '/foo/folder', '/foo/folder/bar.txt'), $propagator->getChanges()); + $this->assertEquals(array('/', '/foo', '/foo/folder'), $propagator->getAllParents()); + + $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(''); + + $this->assertEquals(array('/foo/foo.txt'), $propagator->getChanges()); + $this->assertEquals(array('/', '/foo'), $propagator->getAllParents()); + + $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']); + } } |