summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-01-09 17:27:55 +0100
committerVincent Petry <pvince81@owncloud.com>2014-01-14 16:37:48 +0100
commit88dc71381f54612213061157cb5241ac5b6feae1 (patch)
tree78b4260472dd17ace99ad6cea3a1a1aee27544b1 /tests
parentc6ca9be4063855557621c992adfc40c4e408b487 (diff)
downloadnextcloud-server-88dc71381f54612213061157cb5241ac5b6feae1.tar.gz
nextcloud-server-88dc71381f54612213061157cb5241ac5b6feae1.zip
Fix calculated folder size to use unencrypted size
The encrypted size was used when calculating folder sizes. This fix now also sums up the unencrypted size and shows that one when available. Backport of 4faba49 to stable6
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/files/cache/cache.php45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php
index 052d70dd0b4..7d9329328a3 100644
--- a/tests/lib/files/cache/cache.php
+++ b/tests/lib/files/cache/cache.php
@@ -137,6 +137,51 @@ class Cache extends \PHPUnit_Framework_TestCase {
$this->assertFalse($this->cache->inCache('folder/bar'));
}
+ public function testEncryptedFolder() {
+ $file1 = 'folder';
+ $file2 = 'folder/bar';
+ $file3 = 'folder/foo';
+ $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
+ $fileData = array();
+ $fileData['bar'] = array('size' => 1000, 'unencrypted_size' => 900, 'encrypted' => 1, 'mtime' => 20, 'mimetype' => 'foo/file');
+ $fileData['foo'] = array('size' => 20, 'unencrypted_size' => 16, 'encrypted' => 1, 'mtime' => 25, 'mimetype' => 'foo/file');
+
+ $this->cache->put($file1, $data1);
+ $this->cache->put($file2, $fileData['bar']);
+ $this->cache->put($file3, $fileData['foo']);
+
+ $content = $this->cache->getFolderContents($file1);
+ $this->assertEquals(count($content), 2);
+ foreach ($content as $cachedData) {
+ $data = $fileData[$cachedData['name']];
+ // indirect retrieval swaps unencrypted_size and size
+ $this->assertEquals($data['unencrypted_size'], $cachedData['size']);
+ }
+
+ $file4 = 'folder/unkownSize';
+ $fileData['unkownSize'] = array('size' => -1, 'mtime' => 25, 'mimetype' => 'foo/file');
+ $this->cache->put($file4, $fileData['unkownSize']);
+
+ $this->assertEquals(-1, $this->cache->calculateFolderSize($file1));
+
+ $fileData['unkownSize'] = array('size' => 5, 'mtime' => 25, 'mimetype' => 'foo/file');
+ $this->cache->put($file4, $fileData['unkownSize']);
+
+ $this->assertEquals(916, $this->cache->calculateFolderSize($file1));
+ // direct cache entry retrieval returns the original values
+ $this->assertEquals(1025, $this->cache->get($file1)['size']);
+ $this->assertEquals(916, $this->cache->get($file1)['unencrypted_size']);
+
+ $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'));
+ }
+
public function testRootFolderSizeForNonHomeStorage() {
$dir1 = 'knownsize';
$dir2 = 'unknownsize';