2013-11-08 11:57:28 +00:00
|
|
|
<?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;
|
|
|
|
|
2014-02-19 08:31:54 +00:00
|
|
|
/**
|
|
|
|
* @param string $uid
|
|
|
|
* @param string $home
|
|
|
|
*/
|
2013-11-08 11:57:28 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-03 00:52:41 +00:00
|
|
|
/**
|
2016-05-20 13:38:20 +00:00
|
|
|
* Class HomeCacheTest
|
2015-11-03 00:52:41 +00:00
|
|
|
*
|
|
|
|
* @group DB
|
|
|
|
*
|
|
|
|
* @package Test\Files\Cache
|
|
|
|
*/
|
2016-05-20 13:38:20 +00:00
|
|
|
class HomeCacheTest extends \Test\TestCase {
|
2013-11-08 11:57:28 +00:00
|
|
|
/**
|
|
|
|
* @var \OC\Files\Storage\Home $storage
|
|
|
|
*/
|
|
|
|
private $storage;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \OC\Files\Cache\HomeCache $cache
|
|
|
|
*/
|
|
|
|
private $cache;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \OC\User\User $user
|
|
|
|
*/
|
|
|
|
private $user;
|
|
|
|
|
2014-11-07 14:23:15 +00:00
|
|
|
protected function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
2015-12-18 10:19:53 +00:00
|
|
|
$this->user = new DummyUser('foo', \OC::$server->getTempManager()->getTemporaryFolder());
|
2013-11-08 11:57:28 +00:00
|
|
|
$this->storage = new \OC\Files\Storage\Home(array('user' => $this->user));
|
|
|
|
$this->cache = $this->storage->getCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-01-07 16:41:04 +00:00
|
|
|
* 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.
|
2013-11-08 11:57:28 +00:00
|
|
|
*/
|
|
|
|
public function testRootFolderSizeIgnoresUnknownUpdate() {
|
2014-01-07 16:41:04 +00:00
|
|
|
$dir1 = 'files/knownsize';
|
|
|
|
$dir2 = 'files/unknownsize';
|
2013-11-08 11:57:28 +00:00
|
|
|
$fileData = array();
|
|
|
|
$fileData[''] = array('size' => -1, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
|
2014-01-07 16:41:04 +00:00
|
|
|
$fileData['files'] = array('size' => -1, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
|
2013-11-08 11:57:28 +00:00
|
|
|
$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['']);
|
2014-01-07 16:41:04 +00:00
|
|
|
$this->cache->put('files', $fileData['files']);
|
2013-11-08 11:57:28 +00:00
|
|
|
$this->cache->put($dir1, $fileData[$dir1]);
|
|
|
|
$this->cache->put($dir2, $fileData[$dir2]);
|
|
|
|
|
2014-01-07 16:41:04 +00:00
|
|
|
$this->assertTrue($this->cache->inCache('files'));
|
2013-11-08 11:57:28 +00:00
|
|
|
$this->assertTrue($this->cache->inCache($dir1));
|
|
|
|
$this->assertTrue($this->cache->inCache($dir2));
|
|
|
|
|
2014-01-07 16:41:04 +00:00
|
|
|
// check that files and root size ignored the unknown sizes
|
|
|
|
$this->assertEquals(1000, $this->cache->calculateFolderSize('files'));
|
2013-11-08 11:57:28 +00:00
|
|
|
|
|
|
|
// clean up
|
|
|
|
$this->cache->remove('');
|
2014-01-07 16:41:04 +00:00
|
|
|
$this->cache->remove('files');
|
2013-11-08 11:57:28 +00:00
|
|
|
$this->cache->remove($dir1);
|
|
|
|
$this->cache->remove($dir2);
|
|
|
|
|
2014-01-07 16:41:04 +00:00
|
|
|
$this->assertFalse($this->cache->inCache('files'));
|
2013-11-08 11:57:28 +00:00
|
|
|
$this->assertFalse($this->cache->inCache($dir1));
|
|
|
|
$this->assertFalse($this->cache->inCache($dir2));
|
|
|
|
}
|
2013-11-18 16:39:52 +00:00
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
2013-11-08 11:57:28 +00:00
|
|
|
}
|