1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
<?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\Cache;
class DummyUser extends \OC\User\User {
/**
* @var string $home
*/
private $home;
/**
* @var string $uid
*/
private $uid;
/**
* @param string $uid
* @param string $home
*/
public function __construct($uid, $home) {
$this->home = $home;
$this->uid = $uid;
}
/**
* @return string
*/
public function getHome() {
return $this->home;
}
/**
* @return string
*/
public function getUID() {
return $this->uid;
}
}
/**
* Class HomeCacheTest
*
* @group DB
*
* @package Test\Files\Cache
*/
class HomeCacheTest extends \Test\TestCase {
/**
* @var \OC\Files\Storage\Home $storage
*/
private $storage;
/**
* @var \OC\Files\Cache\HomeCache $cache
*/
private $cache;
/**
* @var \OC\User\User $user
*/
private $user;
protected function setUp() {
parent::setUp();
$this->user = new DummyUser('foo', \OC::$server->getTempManager()->getTemporaryFolder());
$this->storage = new \OC\Files\Storage\Home(array('user' => $this->user));
$this->cache = $this->storage->getCache();
}
/**
* Tests that the root and files folder size calculation ignores the subdirs
* that have an unknown size. This makes sure that quota calculation still
* works as it's based on the "files" folder size.
*/
public function testRootFolderSizeIgnoresUnknownUpdate() {
$dir1 = 'files/knownsize';
$dir2 = 'files/unknownsize';
$fileData = array();
$fileData[''] = array('size' => -1, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
$fileData['files'] = array('size' => -1, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
$fileData[$dir1] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
$fileData[$dir2] = array('size' => -1, 'mtime' => 25, 'mimetype' => 'httpd/unix-directory');
$this->cache->put('', $fileData['']);
$this->cache->put('files', $fileData['files']);
$this->cache->put($dir1, $fileData[$dir1]);
$this->cache->put($dir2, $fileData[$dir2]);
$this->assertTrue($this->cache->inCache('files'));
$this->assertTrue($this->cache->inCache($dir1));
$this->assertTrue($this->cache->inCache($dir2));
// check that files and root size ignored the unknown sizes
$this->assertEquals(1000, $this->cache->calculateFolderSize('files'));
// clean up
$this->cache->remove('');
$this->cache->remove('files');
$this->cache->remove($dir1);
$this->cache->remove($dir2);
$this->assertFalse($this->cache->inCache('files'));
$this->assertFalse($this->cache->inCache($dir1));
$this->assertFalse($this->cache->inCache($dir2));
}
public function testRootFolderSizeIsFilesSize() {
$dir1 = 'files';
$afile = 'test.txt';
$fileData = array();
$fileData[''] = array('size' => 1500, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
$fileData[$dir1] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
$fileData[$afile] = array('size' => 500, 'mtime' => 20);
$this->cache->put('', $fileData['']);
$this->cache->put($dir1, $fileData[$dir1]);
$this->assertTrue($this->cache->inCache($dir1));
// check that root size ignored the unknown sizes
$data = $this->cache->get('files');
$this->assertEquals(1000, $data['size']);
$data = $this->cache->get('');
$this->assertEquals(1000, $data['size']);
// clean up
$this->cache->remove('');
$this->cache->remove($dir1);
$this->assertFalse($this->cache->inCache($dir1));
}
}
|