summaryrefslogtreecommitdiffstats
path: root/tests/lib/files/utils/scanner.php
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2013-08-12 15:37:15 +0200
committerRobin Appelman <icewind@owncloud.com>2013-08-12 15:37:15 +0200
commit1877a42a0dead02b7593f2b3166583106f32acb0 (patch)
treefbcbdadf9fe9834eb9ff80ccaa2ef98846d6f6de /tests/lib/files/utils/scanner.php
parent5ebff8cfc453552201f0bde1b0eeba13f540d0a6 (diff)
downloadnextcloud-server-1877a42a0dead02b7593f2b3166583106f32acb0.tar.gz
nextcloud-server-1877a42a0dead02b7593f2b3166583106f32acb0.zip
Scanner: additional tests for reusing etags during scanning
Diffstat (limited to 'tests/lib/files/utils/scanner.php')
-rw-r--r--tests/lib/files/utils/scanner.php74
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/lib/files/utils/scanner.php b/tests/lib/files/utils/scanner.php
new file mode 100644
index 00000000000..a021d215ae5
--- /dev/null
+++ b/tests/lib/files/utils/scanner.php
@@ -0,0 +1,74 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Files\Utils;
+
+use OC\Files\Mount\Mount;
+use OC\Files\Storage\Temporary;
+
+class TestScanner extends \OC\Files\Utils\Scanner {
+ /**
+ * @var \OC\Files\Mount\Mount[] $mounts
+ */
+ private $mounts = array();
+
+ /**
+ * @param \OC\Files\Mount\Mount $mount
+ */
+ public function addMount($mount) {
+ $this->mounts[] = $mount;
+ }
+
+ protected function getMounts($dir) {
+ return $this->mounts;
+ }
+}
+
+class Scanner extends \PHPUnit_Framework_TestCase {
+ public function testReuseExistingRoot() {
+ $storage = new Temporary(array());
+ $mount = new Mount($storage, '');
+ $cache = $storage->getCache();
+
+ $storage->mkdir('folder');
+ $storage->file_put_contents('foo.txt', 'qwerty');
+ $storage->file_put_contents('folder/bar.txt', 'qwerty');
+
+ $scanner = new TestScanner('');
+ $scanner->addMount($mount);
+
+ $scanner->scan('');
+ $this->assertTrue($cache->inCache('folder/bar.txt'));
+ $oldRoot = $cache->get('');
+
+ $scanner->scan('');
+ $newRoot = $cache->get('');
+ $this->assertEquals($oldRoot, $newRoot);
+ }
+
+ public function testReuseExistingFile() {
+ $storage = new Temporary(array());
+ $mount = new Mount($storage, '');
+ $cache = $storage->getCache();
+
+ $storage->mkdir('folder');
+ $storage->file_put_contents('foo.txt', 'qwerty');
+ $storage->file_put_contents('folder/bar.txt', 'qwerty');
+
+ $scanner = new TestScanner('');
+ $scanner->addMount($mount);
+
+ $scanner->scan('');
+ $this->assertTrue($cache->inCache('folder/bar.txt'));
+ $old = $cache->get('folder/bar.txt');
+
+ $scanner->scan('');
+ $new = $cache->get('folder/bar.txt');
+ $this->assertEquals($old, $new);
+ }
+}