diff options
Diffstat (limited to 'tests/lib/files')
-rw-r--r-- | tests/lib/files/cache/cache.php | 5 | ||||
-rw-r--r-- | tests/lib/files/cache/scanner.php | 18 | ||||
-rw-r--r-- | tests/lib/files/storage/storage.php | 53 | ||||
-rw-r--r-- | tests/lib/files/utils/scanner.php | 74 |
4 files changed, 100 insertions, 50 deletions
diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php index 527c1d1b2a1..247373a5cb9 100644 --- a/tests/lib/files/cache/cache.php +++ b/tests/lib/files/cache/cache.php @@ -127,6 +127,11 @@ class Cache extends \PHPUnit_Framework_TestCase { $this->assertEquals(1025, $this->cache->calculateFolderSize($file1)); + $this->cache->remove($file2); + $this->cache->remove($file3); + $this->cache->remove($file4); + $this->assertEquals(0, $this->cache->calculateFolderSize($file1)); + $this->cache->remove('folder'); $this->assertFalse($this->cache->inCache('folder/foo')); $this->assertFalse($this->cache->inCache('folder/bar')); diff --git a/tests/lib/files/cache/scanner.php b/tests/lib/files/cache/scanner.php index 263ceadccc7..f6deb93a49e 100644 --- a/tests/lib/files/cache/scanner.php +++ b/tests/lib/files/cache/scanner.php @@ -143,6 +143,24 @@ class Scanner extends \PHPUnit_Framework_TestCase { $newData = $this->cache->get(''); $this->assertEquals($oldData['etag'], $newData['etag']); $this->assertEquals(-1, $newData['size']); + + $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE); + $oldData = $this->cache->get(''); + $this->assertNotEquals(-1, $oldData['size']); + $this->scanner->scanFile('', \OC\Files\Cache\Scanner::REUSE_ETAG + \OC\Files\Cache\Scanner::REUSE_SIZE); + $newData = $this->cache->get(''); + $this->assertEquals($oldData['etag'], $newData['etag']); + $this->assertEquals($oldData['size'], $newData['size']); + + $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG + \OC\Files\Cache\Scanner::REUSE_SIZE); + $newData = $this->cache->get(''); + $this->assertEquals($oldData['etag'], $newData['etag']); + $this->assertEquals($oldData['size'], $newData['size']); + + $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG + \OC\Files\Cache\Scanner::REUSE_SIZE); + $newData = $this->cache->get(''); + $this->assertEquals($oldData['etag'], $newData['etag']); + $this->assertEquals($oldData['size'], $newData['size']); } public function testRemovedFile() { diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index fbf502fbc1c..3f339a10016 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -176,68 +176,21 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertEquals(filesize($textFile), $this->instance->filesize('/lorem.txt')); $stat = $this->instance->stat('/lorem.txt'); - //only size and mtime are requered in the result + //only size and mtime are required in the result $this->assertEquals($stat['size'], $this->instance->filesize('/lorem.txt')); $this->assertEquals($stat['mtime'], $mTime); - $mtimeStart = time(); - $supportsTouch = $this->instance->touch('/lorem.txt'); - $mtimeEnd = time(); - if ($supportsTouch !== false) { + if ($this->instance->touch('/lorem.txt', 100) !== false) { $mTime = $this->instance->filemtime('/lorem.txt'); - $this->assertTrue(($mtimeStart - 5) <= $mTime); - $this->assertTrue($mTime <= ($mtimeEnd + 5)); - - $this->assertTrue($this->instance->hasUpdated('/lorem.txt', $mtimeStart - 5)); - - if ($this->instance->touch('/lorem.txt', 100) !== false) { - $mTime = $this->instance->filemtime('/lorem.txt'); - $this->assertEquals($mTime, 100); - } + $this->assertEquals($mTime, 100); } $mtimeStart = time(); - $fh = $this->instance->fopen('/lorem.txt', 'a'); - fwrite($fh, ' '); - fclose($fh); - clearstatcache(); - $mtimeEnd = time(); - $mTime = $this->instance->filemtime('/lorem.txt'); - $this->assertTrue(($mtimeStart - 5) <= $mTime); - $this->assertTrue($mTime <= ($mtimeEnd + 5)); $this->instance->unlink('/lorem.txt'); $this->assertTrue($this->instance->hasUpdated('/', $mtimeStart - 5)); } - public function testSearch() { - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; - $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile, 'r')); - $pngFile = \OC::$SERVERROOT . '/tests/data/logo-wide.png'; - $this->instance->file_put_contents('/logo-wide.png', file_get_contents($pngFile, 'r')); - $svgFile = \OC::$SERVERROOT . '/tests/data/logo-wide.svg'; - $this->instance->file_put_contents('/logo-wide.svg', file_get_contents($svgFile, 'r')); - $result = $this->instance->search('logo'); - $this->assertEquals(2, count($result)); - $this->assertContains('/logo-wide.svg', $result); - $this->assertContains('/logo-wide.png', $result); - } - - public function testSearchInSubFolder() { - $this->instance->mkdir('sub'); - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; - $this->instance->file_put_contents('/sub/lorem.txt', file_get_contents($textFile, 'r')); - $pngFile = \OC::$SERVERROOT . '/tests/data/logo-wide.png'; - $this->instance->file_put_contents('/sub/logo-wide.png', file_get_contents($pngFile, 'r')); - $svgFile = \OC::$SERVERROOT . '/tests/data/logo-wide.svg'; - $this->instance->file_put_contents('/sub/logo-wide.svg', file_get_contents($svgFile, 'r')); - - $result = $this->instance->search('logo'); - $this->assertEquals(2, count($result)); - $this->assertContains('/sub/logo-wide.svg', $result); - $this->assertContains('/sub/logo-wide.png', $result); - } - public function testFOpen() { $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; 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); + } +} |