123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- namespace Test\Files\Cache;
- class DummyUser extends \OC\User\User {
-
- private $home;
-
- private $uid;
-
- public function __construct($uid, $home) {
- $this->home = $home;
- $this->uid = $uid;
- }
-
- public function getHome() {
- return $this->home;
- }
-
- public function getUID() {
- return $this->uid;
- }
- }
- class HomeCacheTest extends \Test\TestCase {
-
- private $storage;
-
- private $cache;
-
- private $user;
- protected function setUp(): void {
- parent::setUp();
- $this->user = new DummyUser('foo', \OC::$server->getTempManager()->getTemporaryFolder());
- $this->storage = new \OC\Files\Storage\Home(['user' => $this->user]);
- $this->cache = $this->storage->getCache();
- }
-
- public function testRootFolderSizeIgnoresUnknownUpdate() {
- $dir1 = 'files/knownsize';
- $dir2 = 'files/unknownsize';
- $fileData = [];
- $fileData[''] = ['size' => -1, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory'];
- $fileData['files'] = ['size' => -1, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory'];
- $fileData[$dir1] = ['size' => 1000, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory'];
- $fileData[$dir2] = ['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));
-
- $this->assertEquals(1000, $this->cache->calculateFolderSize('files'));
-
- $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 = [];
- $fileData[''] = ['size' => 1500, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory'];
- $fileData[$dir1] = ['size' => 1000, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory'];
- $fileData[$afile] = ['size' => 500, 'mtime' => 20];
- $this->cache->put('', $fileData['']);
- $this->cache->put($dir1, $fileData[$dir1]);
- $this->assertTrue($this->cache->inCache($dir1));
-
- $data = $this->cache->get('files');
- $this->assertEquals(1000, $data['size']);
- $data = $this->cache->get('');
- $this->assertEquals(1000, $data['size']);
-
- $this->cache->remove('');
- $this->cache->remove($dir1);
- $this->assertFalse($this->cache->inCache($dir1));
- }
- }
|