optimize Folder::getById to use less queries

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2016-09-18 18:36:53 +02:00
parent b2d68c0009
commit 0d842e0550
No known key found for this signature in database
GPG Key ID: 425003AC385454C5
14 changed files with 328 additions and 157 deletions

View File

@ -53,6 +53,11 @@ class CachedMountInfo implements ICachedMountInfo {
*/ */
protected $mountId; protected $mountId;
/**
* @var string
*/
protected $rootInternalPath;
/** /**
* CachedMountInfo constructor. * CachedMountInfo constructor.
* *
@ -61,13 +66,15 @@ class CachedMountInfo implements ICachedMountInfo {
* @param int $rootId * @param int $rootId
* @param string $mountPoint * @param string $mountPoint
* @param int|null $mountId * @param int|null $mountId
* @param string $rootInternalPath
*/ */
public function __construct(IUser $user, $storageId, $rootId, $mountPoint, $mountId = null) { public function __construct(IUser $user, $storageId, $rootId, $mountPoint, $mountId = null, $rootInternalPath = '') {
$this->user = $user; $this->user = $user;
$this->storageId = $storageId; $this->storageId = $storageId;
$this->rootId = $rootId; $this->rootId = $rootId;
$this->mountPoint = $mountPoint; $this->mountPoint = $mountPoint;
$this->mountId = $mountId; $this->mountId = $mountId;
$this->rootInternalPath = $rootInternalPath;
} }
/** /**
@ -122,4 +129,13 @@ class CachedMountInfo implements ICachedMountInfo {
public function getMountId() { public function getMountId() {
return $this->mountId; return $this->mountId;
} }
/**
* Get the internal path (within the storage) of the root of the mount
*
* @return string
*/
public function getRootInternalPath() {
return $this->rootInternalPath;
}
} }

View File

@ -76,4 +76,13 @@ class LazyStorageMountInfo extends CachedMountInfo {
public function getMountId() { public function getMountId() {
return $this->mount->getMountId(); return $this->mount->getMountId();
} }
/**
* Get the internal path (within the storage) of the root of the mount
*
* @return string
*/
public function getRootInternalPath() {
return $this->mount->getInternalPath($this->mount->getMountPoint());
}
} }

View File

@ -31,6 +31,7 @@ use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\Config\ICachedMountInfo; use OCP\Files\Config\ICachedMountInfo;
use OCP\Files\Config\IUserMountCache; use OCP\Files\Config\IUserMountCache;
use OCP\Files\Mount\IMountPoint; use OCP\Files\Mount\IMountPoint;
use OCP\Files\Node;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\ICache; use OCP\ICache;
use OCP\IDBConnection; use OCP\IDBConnection;
@ -187,7 +188,7 @@ class UserMountCache implements IUserMountCache {
private function dbRowToMountInfo(array $row) { private function dbRowToMountInfo(array $row) {
$user = $this->userManager->get($row['user_id']); $user = $this->userManager->get($row['user_id']);
return new CachedMountInfo($user, (int)$row['storage_id'], (int)$row['root_id'], $row['mount_point'], $row['mount_id']); return new CachedMountInfo($user, (int)$row['storage_id'], (int)$row['root_id'], $row['mount_point'], $row['mount_id'], isset($row['path'])? $row['path']:'');
} }
/** /**
@ -197,8 +198,9 @@ class UserMountCache implements IUserMountCache {
public function getMountsForUser(IUser $user) { public function getMountsForUser(IUser $user) {
if (!isset($this->mountsForUsers[$user->getUID()])) { if (!isset($this->mountsForUsers[$user->getUID()])) {
$builder = $this->connection->getQueryBuilder(); $builder = $this->connection->getQueryBuilder();
$query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id') $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path')
->from('mounts') ->from('mounts', 'm')
->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid'))
->where($builder->expr()->eq('user_id', $builder->createPositionalParameter($user->getUID()))); ->where($builder->expr()->eq('user_id', $builder->createPositionalParameter($user->getUID())));
$rows = $query->execute()->fetchAll(); $rows = $query->execute()->fetchAll();
@ -214,8 +216,9 @@ class UserMountCache implements IUserMountCache {
*/ */
public function getMountsForStorageId($numericStorageId) { public function getMountsForStorageId($numericStorageId) {
$builder = $this->connection->getQueryBuilder(); $builder = $this->connection->getQueryBuilder();
$query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id') $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path')
->from('mounts') ->from('mounts', 'm')
->innerJoin('m', 'filecache', 'f' , $builder->expr()->eq('m.root_id', 'f.fileid'))
->where($builder->expr()->eq('storage_id', $builder->createPositionalParameter($numericStorageId, IQueryBuilder::PARAM_INT))); ->where($builder->expr()->eq('storage_id', $builder->createPositionalParameter($numericStorageId, IQueryBuilder::PARAM_INT)));
$rows = $query->execute()->fetchAll(); $rows = $query->execute()->fetchAll();
@ -229,8 +232,9 @@ class UserMountCache implements IUserMountCache {
*/ */
public function getMountsForRootId($rootFileId) { public function getMountsForRootId($rootFileId) {
$builder = $this->connection->getQueryBuilder(); $builder = $this->connection->getQueryBuilder();
$query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id') $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path')
->from('mounts') ->from('mounts', 'm')
->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid'))
->where($builder->expr()->eq('root_id', $builder->createPositionalParameter($rootFileId, IQueryBuilder::PARAM_INT))); ->where($builder->expr()->eq('root_id', $builder->createPositionalParameter($rootFileId, IQueryBuilder::PARAM_INT)));
$rows = $query->execute()->fetchAll(); $rows = $query->execute()->fetchAll();
@ -246,7 +250,7 @@ class UserMountCache implements IUserMountCache {
private function getCacheInfoFromFileId($fileId) { private function getCacheInfoFromFileId($fileId) {
if (!isset($this->cacheInfoCache[$fileId])) { if (!isset($this->cacheInfoCache[$fileId])) {
$builder = $this->connection->getQueryBuilder(); $builder = $this->connection->getQueryBuilder();
$query = $builder->select('storage', 'path') $query = $builder->select('storage', 'path', 'mimetype')
->from('filecache') ->from('filecache')
->where($builder->expr()->eq('fileid', $builder->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))); ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)));
@ -254,7 +258,8 @@ class UserMountCache implements IUserMountCache {
if (is_array($row)) { if (is_array($row)) {
$this->cacheInfoCache[$fileId] = [ $this->cacheInfoCache[$fileId] = [
(int)$row['storage'], (int)$row['storage'],
$row['path'] $row['path'],
(int)$row['mimetype']
]; ];
} else { } else {
throw new NotFoundException('File with id "' . $fileId . '" not found'); throw new NotFoundException('File with id "' . $fileId . '" not found');
@ -281,15 +286,10 @@ class UserMountCache implements IUserMountCache {
if ($fileId === $mount->getRootId()) { if ($fileId === $mount->getRootId()) {
return true; return true;
} }
try { $internalMountPath = $mount->getRootInternalPath();
list(, $internalMountPath) = $this->getCacheInfoFromFileId($mount->getRootId());
} catch (NotFoundException $e) {
return false;
}
return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath . '/'; return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath . '/';
}); });
} }
/** /**

View File

@ -28,6 +28,7 @@ namespace OC\Files\Node;
use OC\DB\QueryBuilder\Literal; use OC\DB\QueryBuilder\Literal;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\Config\ICachedMountInfo;
use OCP\Files\FileInfo; use OCP\Files\FileInfo;
use OCP\Files\Mount\IMountPoint; use OCP\Files\Mount\IMountPoint;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
@ -83,7 +84,7 @@ class Folder extends Node implements \OCP\Files\Folder {
public function getDirectoryListing() { public function getDirectoryListing() {
$folderContent = $this->view->getDirectoryContent($this->path); $folderContent = $this->view->getDirectoryContent($this->path);
return array_map(function(FileInfo $info) { return array_map(function (FileInfo $info) {
if ($info->getMimetype() === 'httpd/unix-directory') { if ($info->getMimetype() === 'httpd/unix-directory') {
return new Folder($this->root, $this->view, $info->getPath(), $info); return new Folder($this->root, $this->view, $info->getPath(), $info);
} else { } else {
@ -253,7 +254,7 @@ class Folder extends Node implements \OCP\Files\Folder {
} }
} }
return array_map(function(FileInfo $file) { return array_map(function (FileInfo $file) {
return $this->createNode($file->getPath(), $file); return $this->createNode($file->getPath(), $file);
}, $files); }, $files);
} }
@ -263,29 +264,45 @@ class Folder extends Node implements \OCP\Files\Folder {
* @return \OC\Files\Node\Node[] * @return \OC\Files\Node\Node[]
*/ */
public function getById($id) { public function getById($id) {
$mountCache = $this->root->getUserMountCache();
$mountsContainingFile = $mountCache->getMountsForFileId($id);
$mounts = $this->root->getMountsIn($this->path); $mounts = $this->root->getMountsIn($this->path);
$mounts[] = $this->root->getMount($this->path); $mounts[] = $this->root->getMount($this->path);
// reverse the array so we start with the storage this view is in /** @var IMountPoint[] $folderMounts */
// which is the most likely to contain the file we're looking for $folderMounts = array_combine(array_map(function (IMountPoint $mountPoint) {
$mounts = array_reverse($mounts); return $mountPoint->getMountPoint();
}, $mounts), $mounts);
$nodes = array(); /** @var ICachedMountInfo[] $mountsContainingFile */
foreach ($mounts as $mount) { $mountsContainingFile = array_values(array_filter($mountsContainingFile, function (ICachedMountInfo $cachedMountInfo) use ($folderMounts) {
/** return isset($folderMounts[$cachedMountInfo->getMountPoint()]);
* @var \OC\Files\Mount\MountPoint $mount }));
*/
if ($mount->getStorage()) { if (count($mountsContainingFile) === 0) {
$cache = $mount->getStorage()->getCache(); return [];
$internalPath = $cache->getPathById($id);
if (is_string($internalPath)) {
$fullPath = $mount->getMountPoint() . $internalPath;
if (!is_null($path = $this->getRelativePath($fullPath))) {
$nodes[] = $this->get($path);
}
}
}
} }
return $nodes;
// we only need to get the cache info once, since all mounts we found point to the same storage
$mount = $folderMounts[$mountsContainingFile[0]->getMountPoint()];
$cacheEntry = $mount->getStorage()->getCache()->get($id);
// cache jails will hide the "true" internal path
$internalPath = ltrim($mountsContainingFile[0]->getRootInternalPath() . '/' . $cacheEntry->getPath(), '/');
$nodes = array_map(function (ICachedMountInfo $cachedMountInfo) use ($cacheEntry, $folderMounts, $internalPath) {
$mount = $folderMounts[$cachedMountInfo->getMountPoint()];
$pathRelativeToMount = substr($internalPath, strlen($cachedMountInfo->getRootInternalPath()));
$pathRelativeToMount = ltrim($pathRelativeToMount, '/');
$absolutePath = $cachedMountInfo->getMountPoint() . $pathRelativeToMount;
return $this->root->createNode($absolutePath, new \OC\Files\FileInfo(
$absolutePath, $mount->getStorage(), $cacheEntry->getPath(), $cacheEntry, $mount,
\OC::$server->getUserManager()->get($mount->getStorage()->getOwner($pathRelativeToMount))
));
}, $mountsContainingFile);
return array_filter($nodes, function (Node $node) {
return $this->getRelativePath($node->getPath());
});
} }
public function getFreeSpace() { public function getFreeSpace() {

View File

@ -31,6 +31,7 @@ namespace OC\Files\Node;
use OC\Cache\CappedMemoryCache; use OC\Cache\CappedMemoryCache;
use OC\Files\Mount\Manager; use OC\Files\Mount\Manager;
use OC\Files\Mount\MountPoint; use OC\Files\Mount\MountPoint;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException; use OCP\Files\NotPermittedException;
use OC\Hooks\PublicEmitter; use OC\Hooks\PublicEmitter;
@ -74,17 +75,24 @@ class Root extends Folder implements IRootFolder {
private $userFolderCache; private $userFolderCache;
/**
* @var IUserMountCache
*/
private $userMountCache;
/** /**
* @param \OC\Files\Mount\Manager $manager * @param \OC\Files\Mount\Manager $manager
* @param \OC\Files\View $view * @param \OC\Files\View $view
* @param \OC\User\User|null $user * @param \OC\User\User|null $user
* @param IUserMountCache $userMountCache
*/ */
public function __construct($manager, $view, $user) { public function __construct($manager, $view, $user, IUserMountCache $userMountCache) {
parent::__construct($this, $view, ''); parent::__construct($this, $view, '');
$this->mountManager = $manager; $this->mountManager = $manager;
$this->user = $user; $this->user = $user;
$this->emitter = new PublicEmitter(); $this->emitter = new PublicEmitter();
$this->userFolderCache = new CappedMemoryCache(); $this->userFolderCache = new CappedMemoryCache();
$this->userMountCache = $userMountCache;
} }
/** /**
@ -361,4 +369,8 @@ class Root extends Folder implements IRootFolder {
public function clearCache() { public function clearCache() {
$this->userFolderCache = new CappedMemoryCache(); $this->userFolderCache = new CappedMemoryCache();
} }
public function getUserMountCache() {
return $this->userMountCache;
}
} }

View File

@ -175,10 +175,10 @@ class Server extends ServerContainer implements IServerContainer {
$this->registerService('SystemTagObjectMapper', function (Server $c) { $this->registerService('SystemTagObjectMapper', function (Server $c) {
return $c->query('SystemTagManagerFactory')->getObjectMapper(); return $c->query('SystemTagManagerFactory')->getObjectMapper();
}); });
$this->registerService('RootFolder', function () { $this->registerService('RootFolder', function (Server $c) {
$manager = \OC\Files\Filesystem::getMountManager(null); $manager = \OC\Files\Filesystem::getMountManager(null);
$view = new View(); $view = new View();
$root = new Root($manager, $view, null); $root = new Root($manager, $view, null, $c->getUserMountCache());
$connector = new HookConnector($root, $view); $connector = new HookConnector($root, $view);
$connector->viewToNode(); $connector->viewToNode();
return $root; return $root;

View File

@ -68,4 +68,12 @@ interface ICachedMountInfo {
* @since 9.1.0 * @since 9.1.0
*/ */
public function getMountId(); public function getMountId();
/**
* Get the internal path (within the storage) of the root of the mount
*
* @return string
* @since 9.2.0
*/
public function getRootInternalPath();
} }

View File

@ -64,7 +64,9 @@ class UserMountCacheTest extends TestCase {
} }
} }
private function getStorage($storageId, $rootId) { private function getStorage($storageId) {
$rootId = $this->createCacheEntry('', $storageId);
$storageCache = $this->getMockBuilder('\OC\Files\Cache\Storage') $storageCache = $this->getMockBuilder('\OC\Files\Cache\Storage')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
@ -89,7 +91,7 @@ class UserMountCacheTest extends TestCase {
->method('getCache') ->method('getCache')
->will($this->returnValue($cache)); ->will($this->returnValue($cache));
return $storage; return [$storage, $rootId];
} }
private function clearCache() { private function clearCache() {
@ -99,7 +101,7 @@ class UserMountCacheTest extends TestCase {
public function testNewMounts() { public function testNewMounts() {
$user = $this->userManager->get('u1'); $user = $this->userManager->get('u1');
$storage = $this->getStorage(10, 20); list($storage) = $this->getStorage(10);
$mount = new MountPoint($storage, '/asd/'); $mount = new MountPoint($storage, '/asd/');
$this->cache->registerMounts($user, [$mount]); $this->cache->registerMounts($user, [$mount]);
@ -119,7 +121,7 @@ class UserMountCacheTest extends TestCase {
public function testSameMounts() { public function testSameMounts() {
$user = $this->userManager->get('u1'); $user = $this->userManager->get('u1');
$storage = $this->getStorage(10, 20); list($storage) = $this->getStorage(10);
$mount = new MountPoint($storage, '/asd/'); $mount = new MountPoint($storage, '/asd/');
$this->cache->registerMounts($user, [$mount]); $this->cache->registerMounts($user, [$mount]);
@ -143,7 +145,7 @@ class UserMountCacheTest extends TestCase {
public function testRemoveMounts() { public function testRemoveMounts() {
$user = $this->userManager->get('u1'); $user = $this->userManager->get('u1');
$storage = $this->getStorage(10, 20); list($storage) = $this->getStorage(10);
$mount = new MountPoint($storage, '/asd/'); $mount = new MountPoint($storage, '/asd/');
$this->cache->registerMounts($user, [$mount]); $this->cache->registerMounts($user, [$mount]);
@ -162,7 +164,7 @@ class UserMountCacheTest extends TestCase {
public function testChangeMounts() { public function testChangeMounts() {
$user = $this->userManager->get('u1'); $user = $this->userManager->get('u1');
$storage = $this->getStorage(10, 20); list($storage) = $this->getStorage(10);
$mount = new MountPoint($storage, '/bar/'); $mount = new MountPoint($storage, '/bar/');
$this->cache->registerMounts($user, [$mount]); $this->cache->registerMounts($user, [$mount]);
@ -185,7 +187,7 @@ class UserMountCacheTest extends TestCase {
public function testChangeMountId() { public function testChangeMountId() {
$user = $this->userManager->get('u1'); $user = $this->userManager->get('u1');
$storage = $this->getStorage(10, 20); list($storage) = $this->getStorage(10);
$mount = new MountPoint($storage, '/foo/', null, null, null, null); $mount = new MountPoint($storage, '/foo/', null, null, null, null);
$this->cache->registerMounts($user, [$mount]); $this->cache->registerMounts($user, [$mount]);
@ -209,8 +211,10 @@ class UserMountCacheTest extends TestCase {
$user1 = $this->userManager->get('u1'); $user1 = $this->userManager->get('u1');
$user2 = $this->userManager->get('u2'); $user2 = $this->userManager->get('u2');
$mount1 = new MountPoint($this->getStorage(1, 2), '/foo/'); list($storage1, $id1) = $this->getStorage(1);
$mount2 = new MountPoint($this->getStorage(3, 4), '/bar/'); list($storage2, $id2) = $this->getStorage(2);
$mount1 = new MountPoint($storage1, '/foo/');
$mount2 = new MountPoint($storage2, '/bar/');
$this->cache->registerMounts($user1, [$mount1, $mount2]); $this->cache->registerMounts($user1, [$mount1, $mount2]);
$this->cache->registerMounts($user2, [$mount2]); $this->cache->registerMounts($user2, [$mount2]);
@ -222,69 +226,73 @@ class UserMountCacheTest extends TestCase {
$this->assertCount(2, $cachedMounts); $this->assertCount(2, $cachedMounts);
$this->assertEquals('/foo/', $cachedMounts[0]->getMountPoint()); $this->assertEquals('/foo/', $cachedMounts[0]->getMountPoint());
$this->assertEquals($user1, $cachedMounts[0]->getUser()); $this->assertEquals($user1, $cachedMounts[0]->getUser());
$this->assertEquals(2, $cachedMounts[0]->getRootId()); $this->assertEquals($id1, $cachedMounts[0]->getRootId());
$this->assertEquals(1, $cachedMounts[0]->getStorageId()); $this->assertEquals(1, $cachedMounts[0]->getStorageId());
$this->assertEquals('/bar/', $cachedMounts[1]->getMountPoint()); $this->assertEquals('/bar/', $cachedMounts[1]->getMountPoint());
$this->assertEquals($user1, $cachedMounts[1]->getUser()); $this->assertEquals($user1, $cachedMounts[1]->getUser());
$this->assertEquals(4, $cachedMounts[1]->getRootId()); $this->assertEquals($id2, $cachedMounts[1]->getRootId());
$this->assertEquals(3, $cachedMounts[1]->getStorageId()); $this->assertEquals(2, $cachedMounts[1]->getStorageId());
} }
public function testGetMountsByStorageId() { public function testGetMountsByStorageId() {
$user1 = $this->userManager->get('u1'); $user1 = $this->userManager->get('u1');
$user2 = $this->userManager->get('u2'); $user2 = $this->userManager->get('u2');
$mount1 = new MountPoint($this->getStorage(1, 2), '/foo/'); list($storage1, $id1) = $this->getStorage(1);
$mount2 = new MountPoint($this->getStorage(3, 4), '/bar/'); list($storage2, $id2) = $this->getStorage(2);
$mount1 = new MountPoint($storage1, '/foo/');
$mount2 = new MountPoint($storage2, '/bar/');
$this->cache->registerMounts($user1, [$mount1, $mount2]); $this->cache->registerMounts($user1, [$mount1, $mount2]);
$this->cache->registerMounts($user2, [$mount2]); $this->cache->registerMounts($user2, [$mount2]);
$this->clearCache(); $this->clearCache();
$cachedMounts = $this->cache->getMountsForStorageId(3); $cachedMounts = $this->cache->getMountsForStorageId(2);
$this->sortMounts($cachedMounts); $this->sortMounts($cachedMounts);
$this->assertCount(2, $cachedMounts); $this->assertCount(2, $cachedMounts);
$this->assertEquals('/bar/', $cachedMounts[0]->getMountPoint()); $this->assertEquals('/bar/', $cachedMounts[0]->getMountPoint());
$this->assertEquals($user1, $cachedMounts[0]->getUser()); $this->assertEquals($user1, $cachedMounts[0]->getUser());
$this->assertEquals(4, $cachedMounts[0]->getRootId()); $this->assertEquals($id2, $cachedMounts[0]->getRootId());
$this->assertEquals(3, $cachedMounts[0]->getStorageId()); $this->assertEquals(2, $cachedMounts[0]->getStorageId());
$this->assertEquals('/bar/', $cachedMounts[1]->getMountPoint()); $this->assertEquals('/bar/', $cachedMounts[1]->getMountPoint());
$this->assertEquals($user2, $cachedMounts[1]->getUser()); $this->assertEquals($user2, $cachedMounts[1]->getUser());
$this->assertEquals(4, $cachedMounts[1]->getRootId()); $this->assertEquals($id2, $cachedMounts[1]->getRootId());
$this->assertEquals(3, $cachedMounts[1]->getStorageId()); $this->assertEquals(2, $cachedMounts[1]->getStorageId());
} }
public function testGetMountsByRootId() { public function testGetMountsByRootId() {
$user1 = $this->userManager->get('u1'); $user1 = $this->userManager->get('u1');
$user2 = $this->userManager->get('u2'); $user2 = $this->userManager->get('u2');
$mount1 = new MountPoint($this->getStorage(1, 2), '/foo/'); list($storage1, $id1) = $this->getStorage(1);
$mount2 = new MountPoint($this->getStorage(3, 4), '/bar/'); list($storage2, $id2) = $this->getStorage(2);
$mount1 = new MountPoint($storage1, '/foo/');
$mount2 = new MountPoint($storage2, '/bar/');
$this->cache->registerMounts($user1, [$mount1, $mount2]); $this->cache->registerMounts($user1, [$mount1, $mount2]);
$this->cache->registerMounts($user2, [$mount2]); $this->cache->registerMounts($user2, [$mount2]);
$this->clearCache(); $this->clearCache();
$cachedMounts = $this->cache->getMountsForRootId(4); $cachedMounts = $this->cache->getMountsForRootId($id2);
$this->sortMounts($cachedMounts); $this->sortMounts($cachedMounts);
$this->assertCount(2, $cachedMounts); $this->assertCount(2, $cachedMounts);
$this->assertEquals('/bar/', $cachedMounts[0]->getMountPoint()); $this->assertEquals('/bar/', $cachedMounts[0]->getMountPoint());
$this->assertEquals($user1, $cachedMounts[0]->getUser()); $this->assertEquals($user1, $cachedMounts[0]->getUser());
$this->assertEquals(4, $cachedMounts[0]->getRootId()); $this->assertEquals($id2, $cachedMounts[0]->getRootId());
$this->assertEquals(3, $cachedMounts[0]->getStorageId()); $this->assertEquals(2, $cachedMounts[0]->getStorageId());
$this->assertEquals('/bar/', $cachedMounts[1]->getMountPoint()); $this->assertEquals('/bar/', $cachedMounts[1]->getMountPoint());
$this->assertEquals($user2, $cachedMounts[1]->getUser()); $this->assertEquals($user2, $cachedMounts[1]->getUser());
$this->assertEquals(4, $cachedMounts[1]->getRootId()); $this->assertEquals($id2, $cachedMounts[1]->getRootId());
$this->assertEquals(3, $cachedMounts[1]->getStorageId()); $this->assertEquals(2, $cachedMounts[1]->getStorageId());
} }
private function sortMounts(&$mounts) { private function sortMounts(&$mounts) {
@ -294,7 +302,8 @@ class UserMountCacheTest extends TestCase {
} }
private function createCacheEntry($internalPath, $storageId) { private function createCacheEntry($internalPath, $storageId) {
$this->connection->insertIfNotExist('*PREFIX*filecache', [ $internalPath = trim($internalPath, '/');
$inserted = $this->connection->insertIfNotExist('*PREFIX*filecache', [
'storage' => $storageId, 'storage' => $storageId,
'path' => $internalPath, 'path' => $internalPath,
'path_hash' => md5($internalPath), 'path_hash' => md5($internalPath),
@ -309,17 +318,23 @@ class UserMountCacheTest extends TestCase {
'etag' => '', 'etag' => '',
'permissions' => 31 'permissions' => 31
], ['storage', 'path_hash']); ], ['storage', 'path_hash']);
$id = (int)$this->connection->lastInsertId('*PREFIX*filecache'); if ($inserted) {
$this->fileIds[] = $id; $id = (int)$this->connection->lastInsertId('*PREFIX*filecache');
$this->fileIds[] = $id;
} else {
$sql = 'SELECT fileid FROM *PREFIX*filecache WHERE `storage` = ? AND `path_hash` =?';
$query = $this->connection->prepare($sql);
$query->execute([$storageId, md5($internalPath)]);
return (int)$query->fetchColumn();
}
return $id; return $id;
} }
public function testGetMountsForFileIdRootId() { public function testGetMountsForFileIdRootId() {
$user1 = $this->userManager->get('u1'); $user1 = $this->userManager->get('u1');
$rootId = $this->createCacheEntry('', 2); list($storage1, $rootId) = $this->getStorage(2);
$mount1 = new MountPoint($storage1, '/foo/');
$mount1 = new MountPoint($this->getStorage(2, $rootId), '/foo/');
$this->cache->registerMounts($user1, [$mount1]); $this->cache->registerMounts($user1, [$mount1]);
@ -338,10 +353,10 @@ class UserMountCacheTest extends TestCase {
public function testGetMountsForFileIdSubFolder() { public function testGetMountsForFileIdSubFolder() {
$user1 = $this->userManager->get('u1'); $user1 = $this->userManager->get('u1');
$rootId = $this->createCacheEntry('', 2);
$fileId = $this->createCacheEntry('/foo/bar', 2); $fileId = $this->createCacheEntry('/foo/bar', 2);
$mount1 = new MountPoint($this->getStorage(2, $rootId), '/foo/'); list($storage1, $rootId) = $this->getStorage(2);
$mount1 = new MountPoint($storage1, '/foo/');
$this->cache->registerMounts($user1, [$mount1]); $this->cache->registerMounts($user1, [$mount1]);
@ -360,11 +375,19 @@ class UserMountCacheTest extends TestCase {
public function testGetMountsForFileIdSubFolderMount() { public function testGetMountsForFileIdSubFolderMount() {
$user1 = $this->userManager->get('u1'); $user1 = $this->userManager->get('u1');
$this->createCacheEntry('', 2); list($storage1, $rootId) = $this->getStorage(2);
$folderId = $this->createCacheEntry('/foo', 2); $folderId = $this->createCacheEntry('/foo', 2);
$fileId = $this->createCacheEntry('/foo/bar', 2); $fileId = $this->createCacheEntry('/foo/bar', 2);
$mount1 = new MountPoint($this->getStorage(2, $folderId), '/foo/');
$mount1 = $this->getMockBuilder('\OC\Files\Mount\MountPoint')
->setConstructorArgs([$storage1, '/'])
->setMethods(['getStorageRootId'])
->getMock();
$mount1->expects($this->any())
->method('getStorageRootId')
->will($this->returnValue($folderId));
$this->cache->registerMounts($user1, [$mount1]); $this->cache->registerMounts($user1, [$mount1]);
@ -374,20 +397,30 @@ class UserMountCacheTest extends TestCase {
$this->assertCount(1, $cachedMounts); $this->assertCount(1, $cachedMounts);
$this->assertEquals('/foo/', $cachedMounts[0]->getMountPoint()); $this->assertEquals('/', $cachedMounts[0]->getMountPoint());
$this->assertEquals($user1, $cachedMounts[0]->getUser()); $this->assertEquals($user1, $cachedMounts[0]->getUser());
$this->assertEquals($folderId, $cachedMounts[0]->getRootId()); $this->assertEquals($folderId, $cachedMounts[0]->getRootId());
$this->assertEquals(2, $cachedMounts[0]->getStorageId()); $this->assertEquals(2, $cachedMounts[0]->getStorageId());
$this->assertEquals('foo', $cachedMounts[0]->getRootInternalPath());
} }
public function testGetMountsForFileIdSubFolderMountOutside() { public function testGetMountsForFileIdSubFolderMountOutside() {
$user1 = $this->userManager->get('u1'); $user1 = $this->userManager->get('u1');
$this->createCacheEntry('', 2); list($storage1, $rootId) = $this->getStorage(2);
$folderId = $this->createCacheEntry('/foo', 2); $folderId = $this->createCacheEntry('/foo', 2);
$fileId = $this->createCacheEntry('/bar/asd', 2); $fileId = $this->createCacheEntry('/bar/asd', 2);
$mount1 = new MountPoint($this->getStorage(2, $folderId), '/foo/'); $mount1 = $this->getMockBuilder('\OC\Files\Mount\MountPoint')
->setConstructorArgs([$storage1, '/foo/'])
->setMethods(['getStorageRootId'])
->getMock();
$mount1->expects($this->any())
->method('getStorageRootId')
->will($this->returnValue($folderId));
$this->cache->registerMounts($user1, [$mount1]);
$this->cache->registerMounts($user1, [$mount1]); $this->cache->registerMounts($user1, [$mount1]);

View File

@ -21,6 +21,9 @@ class FileTest extends \Test\TestCase {
/** @var \OC\Files\View|\PHPUnit_Framework_MockObject_MockObject */ /** @var \OC\Files\View|\PHPUnit_Framework_MockObject_MockObject */
private $view; private $view;
/** @var \OCP\Files\Config\IUserMountCache|\PHPUnit_Framework_MockObject_MockObject */
private $userMountCache;
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
$config = $this->getMockBuilder('\OCP\IConfig') $config = $this->getMockBuilder('\OCP\IConfig')
@ -34,6 +37,9 @@ class FileTest extends \Test\TestCase {
$this->view = $this->getMockBuilder('\OC\Files\View') $this->view = $this->getMockBuilder('\OC\Files\View')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache')
->disableOriginalConstructor()
->getMock();
} }
protected function getMockStorage() { protected function getMockStorage() {
@ -52,7 +58,7 @@ class FileTest extends \Test\TestCase {
public function testDelete() { public function testDelete() {
/** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
$root = $this->getMockBuilder('\OC\Files\Node\Root') $root = $this->getMockBuilder('\OC\Files\Node\Root')
->setConstructorArgs([$this->manager, $this->view, $this->user]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache])
->getMock(); ->getMock();
$root->expects($this->exactly(2)) $root->expects($this->exactly(2))
@ -102,7 +108,7 @@ class FileTest extends \Test\TestCase {
$hooksRun++; $hooksRun++;
}; };
$root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user); $root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user, $this->userMountCache);
$root->listen('\OC\Files', 'preDelete', $preListener); $root->listen('\OC\Files', 'preDelete', $preListener);
$root->listen('\OC\Files', 'postDelete', $postListener); $root->listen('\OC\Files', 'postDelete', $postListener);
@ -132,7 +138,7 @@ class FileTest extends \Test\TestCase {
public function testDeleteNotPermitted() { public function testDeleteNotPermitted() {
/** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
$root = $this->getMockBuilder('\OC\Files\Node\Root') $root = $this->getMockBuilder('\OC\Files\Node\Root')
->setConstructorArgs([$this->manager, $this->view, $this->user]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache])
->getMock(); ->getMock();
$root->expects($this->any()) $root->expects($this->any())
@ -151,7 +157,7 @@ class FileTest extends \Test\TestCase {
public function testGetContent() { public function testGetContent() {
/** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
$root = $this->getMockBuilder('\OC\Files\Node\Root') $root = $this->getMockBuilder('\OC\Files\Node\Root')
->setConstructorArgs([$this->manager, $this->view, $this->user]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache])
->getMock(); ->getMock();
$hook = function ($file) { $hook = function ($file) {
@ -181,7 +187,7 @@ class FileTest extends \Test\TestCase {
public function testGetContentNotPermitted() { public function testGetContentNotPermitted() {
/** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
$root = $this->getMockBuilder('\OC\Files\Node\Root') $root = $this->getMockBuilder('\OC\Files\Node\Root')
->setConstructorArgs([$this->manager, $this->view, $this->user]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache])
->getMock(); ->getMock();
$root->expects($this->any()) $root->expects($this->any())
@ -200,7 +206,7 @@ class FileTest extends \Test\TestCase {
public function testPutContent() { public function testPutContent() {
/** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
$root = $this->getMockBuilder('\OC\Files\Node\Root') $root = $this->getMockBuilder('\OC\Files\Node\Root')
->setConstructorArgs([$this->manager, $this->view, $this->user]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache])
->getMock(); ->getMock();
$root->expects($this->any()) $root->expects($this->any())
@ -227,7 +233,7 @@ class FileTest extends \Test\TestCase {
public function testPutContentNotPermitted() { public function testPutContentNotPermitted() {
/** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
$root = $this->getMockBuilder('\OC\Files\Node\Root') $root = $this->getMockBuilder('\OC\Files\Node\Root')
->setConstructorArgs([$this->manager, $this->view, $this->user]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache])
->getMock(); ->getMock();
$this->view->expects($this->once()) $this->view->expects($this->once())
@ -242,7 +248,7 @@ class FileTest extends \Test\TestCase {
public function testGetMimeType() { public function testGetMimeType() {
/** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
$root = $this->getMockBuilder('\OC\Files\Node\Root') $root = $this->getMockBuilder('\OC\Files\Node\Root')
->setConstructorArgs([$this->manager, $this->view, $this->user]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache])
->getMock(); ->getMock();
$this->view->expects($this->once()) $this->view->expects($this->once())
@ -259,7 +265,7 @@ class FileTest extends \Test\TestCase {
fwrite($stream, 'bar'); fwrite($stream, 'bar');
rewind($stream); rewind($stream);
$root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user); $root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user, $this->userMountCache);
$hook = function ($file) { $hook = function ($file) {
throw new \Exception('Hooks are not supposed to be called'); throw new \Exception('Hooks are not supposed to be called');
@ -287,7 +293,7 @@ class FileTest extends \Test\TestCase {
public function testFOpenWrite() { public function testFOpenWrite() {
$stream = fopen('php://memory', 'w+'); $stream = fopen('php://memory', 'w+');
$root = new \OC\Files\Node\Root($this->manager, new $this->view, $this->user); $root = new \OC\Files\Node\Root($this->manager, new $this->view, $this->user, $this->userMountCache);
$hooksCalled = 0; $hooksCalled = 0;
$hook = function ($file) use (&$hooksCalled) { $hook = function ($file) use (&$hooksCalled) {
@ -320,7 +326,7 @@ class FileTest extends \Test\TestCase {
* @expectedException \OCP\Files\NotPermittedException * @expectedException \OCP\Files\NotPermittedException
*/ */
public function testFOpenReadNotPermitted() { public function testFOpenReadNotPermitted() {
$root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user); $root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user, $this->userMountCache);
$hook = function ($file) { $hook = function ($file) {
throw new \Exception('Hooks are not supposed to be called'); throw new \Exception('Hooks are not supposed to be called');
@ -339,7 +345,7 @@ class FileTest extends \Test\TestCase {
* @expectedException \OCP\Files\NotPermittedException * @expectedException \OCP\Files\NotPermittedException
*/ */
public function testFOpenReadWriteNoReadPermissions() { public function testFOpenReadWriteNoReadPermissions() {
$root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user); $root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user, $this->userMountCache);
$hook = function () { $hook = function () {
throw new \Exception('Hooks are not supposed to be called'); throw new \Exception('Hooks are not supposed to be called');
@ -358,7 +364,7 @@ class FileTest extends \Test\TestCase {
* @expectedException \OCP\Files\NotPermittedException * @expectedException \OCP\Files\NotPermittedException
*/ */
public function testFOpenReadWriteNoWritePermissions() { public function testFOpenReadWriteNoWritePermissions() {
$root = new \OC\Files\Node\Root($this->manager, new $this->view, $this->user); $root = new \OC\Files\Node\Root($this->manager, new $this->view, $this->user, $this->userMountCache);
$hook = function () { $hook = function () {
throw new \Exception('Hooks are not supposed to be called'); throw new \Exception('Hooks are not supposed to be called');
@ -376,7 +382,7 @@ class FileTest extends \Test\TestCase {
public function testCopySameStorage() { public function testCopySameStorage() {
/** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
$root = $this->getMockBuilder('\OC\Files\Node\Root') $root = $this->getMockBuilder('\OC\Files\Node\Root')
->setConstructorArgs([$this->manager, $this->view, $this->user]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache])
->getMock(); ->getMock();
$this->view->expects($this->any()) $this->view->expects($this->any())
@ -409,7 +415,7 @@ class FileTest extends \Test\TestCase {
public function testCopyNotPermitted() { public function testCopyNotPermitted() {
/** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
$root = $this->getMockBuilder('\OC\Files\Node\Root') $root = $this->getMockBuilder('\OC\Files\Node\Root')
->setConstructorArgs([$this->manager, $this->view, $this->user]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache])
->getMock(); ->getMock();
/** /**
@ -447,7 +453,7 @@ class FileTest extends \Test\TestCase {
public function testCopyNoParent() { public function testCopyNoParent() {
/** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
$root = $this->getMockBuilder('\OC\Files\Node\Root') $root = $this->getMockBuilder('\OC\Files\Node\Root')
->setConstructorArgs([$this->manager, $this->view, $this->user]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache])
->getMock(); ->getMock();
$this->view->expects($this->never()) $this->view->expects($this->never())
@ -469,7 +475,7 @@ class FileTest extends \Test\TestCase {
public function testCopyParentIsFile() { public function testCopyParentIsFile() {
/** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
$root = $this->getMockBuilder('\OC\Files\Node\Root') $root = $this->getMockBuilder('\OC\Files\Node\Root')
->setConstructorArgs([$this->manager, $this->view, $this->user]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache])
->getMock(); ->getMock();
$this->view->expects($this->never()) $this->view->expects($this->never())
@ -490,7 +496,7 @@ class FileTest extends \Test\TestCase {
public function testMoveSameStorage() { public function testMoveSameStorage() {
/** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
$root = $this->getMockBuilder('\OC\Files\Node\Root') $root = $this->getMockBuilder('\OC\Files\Node\Root')
->setConstructorArgs([$this->manager, $this->view, $this->user]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache])
->getMock(); ->getMock();
$this->view->expects($this->any()) $this->view->expects($this->any())
@ -520,7 +526,7 @@ class FileTest extends \Test\TestCase {
public function testMoveNotPermitted() { public function testMoveNotPermitted() {
/** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
$root = $this->getMockBuilder('\OC\Files\Node\Root') $root = $this->getMockBuilder('\OC\Files\Node\Root')
->setConstructorArgs([$this->manager, $this->view, $this->user]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache])
->getMock(); ->getMock();
$this->view->expects($this->any()) $this->view->expects($this->any())
@ -547,7 +553,7 @@ class FileTest extends \Test\TestCase {
public function testMoveNoParent() { public function testMoveNoParent() {
/** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
$root = $this->getMockBuilder('\OC\Files\Node\Root') $root = $this->getMockBuilder('\OC\Files\Node\Root')
->setConstructorArgs([$this->manager, $this->view, $this->user]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache])
->getMock(); ->getMock();
/** /**
@ -577,7 +583,7 @@ class FileTest extends \Test\TestCase {
public function testMoveParentIsFile() { public function testMoveParentIsFile() {
/** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
$root = $this->getMockBuilder('\OC\Files\Node\Root') $root = $this->getMockBuilder('\OC\Files\Node\Root')
->setConstructorArgs([$this->manager, $this->view, $this->user]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache])
->getMock(); ->getMock();
$this->view->expects($this->never()) $this->view->expects($this->never())

View File

@ -9,6 +9,8 @@
namespace Test\Files\Node; namespace Test\Files\Node;
use OC\Files\Cache\Cache; use OC\Files\Cache\Cache;
use OC\Files\Cache\CacheEntry;
use OC\Files\Config\CachedMountInfo;
use OC\Files\FileInfo; use OC\Files\FileInfo;
use OC\Files\Mount\Manager; use OC\Files\Mount\Manager;
use OC\Files\Mount\MountPoint; use OC\Files\Mount\MountPoint;
@ -32,9 +34,15 @@ use OCP\Files\Storage;
class FolderTest extends \Test\TestCase { class FolderTest extends \Test\TestCase {
private $user; private $user;
/** @var \OCP\Files\Config\IUserMountCache|\PHPUnit_Framework_MockObject_MockObject */
private $userMountCache;
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
$this->user = new \OC\User\User('', new \Test\Util\User\Dummy); $this->user = new \OC\User\User('', new \Test\Util\User\Dummy);
$this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache')
->disableOriginalConstructor()
->getMock();
} }
protected function getMockStorage() { protected function getMockStorage() {
@ -56,7 +64,7 @@ class FolderTest extends \Test\TestCase {
*/ */
$view = $this->createMock(View::class); $view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class) $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user]) ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])
->getMock(); ->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
@ -110,7 +118,7 @@ class FolderTest extends \Test\TestCase {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/ */
$view = $this->createMock(View::class); $view = $this->createMock(View::class);
$root = new \OC\Files\Node\Root($manager, $view, $this->user); $root = new \OC\Files\Node\Root($manager, $view, $this->user, $this->userMountCache);
$root->listen('\OC\Files', 'preDelete', $preListener); $root->listen('\OC\Files', 'preDelete', $preListener);
$root->listen('\OC\Files', 'postDelete', $postListener); $root->listen('\OC\Files', 'postDelete', $postListener);
@ -142,7 +150,7 @@ class FolderTest extends \Test\TestCase {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/ */
$view = $this->createMock(View::class); $view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock(); $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -163,7 +171,7 @@ class FolderTest extends \Test\TestCase {
*/ */
$view = $this->createMock(View::class); $view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class) $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user]) ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])
->getMock(); ->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
@ -194,7 +202,7 @@ class FolderTest extends \Test\TestCase {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/ */
$view = $this->createMock(View::class); $view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock(); $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -213,7 +221,7 @@ class FolderTest extends \Test\TestCase {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/ */
$view = $this->createMock(View::class); $view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock(); $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -235,7 +243,7 @@ class FolderTest extends \Test\TestCase {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/ */
$view = $this->createMock(View::class); $view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock(); $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -255,7 +263,7 @@ class FolderTest extends \Test\TestCase {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/ */
$view = $this->createMock(View::class); $view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock(); $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -285,7 +293,7 @@ class FolderTest extends \Test\TestCase {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/ */
$view = $this->createMock(View::class); $view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock(); $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -305,7 +313,7 @@ class FolderTest extends \Test\TestCase {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/ */
$view = $this->createMock(View::class); $view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock(); $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -335,7 +343,7 @@ class FolderTest extends \Test\TestCase {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/ */
$view = $this->createMock(View::class); $view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock(); $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -355,7 +363,7 @@ class FolderTest extends \Test\TestCase {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/ */
$view = $this->createMock(View::class); $view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock(); $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -375,7 +383,7 @@ class FolderTest extends \Test\TestCase {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/ */
$view = $this->createMock(View::class); $view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock(); $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -423,7 +431,8 @@ class FolderTest extends \Test\TestCase {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/ */
$view = $this->createMock(View::class); $view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount'])->setConstructorArgs([$manager, $view, $this->user])->getMock(); $root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -471,7 +480,7 @@ class FolderTest extends \Test\TestCase {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/ */
$view = $this->createMock(View::class); $view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock(); $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -519,7 +528,7 @@ class FolderTest extends \Test\TestCase {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/ */
$view = $this->createMock(View::class); $view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock(); $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -567,7 +576,7 @@ class FolderTest extends \Test\TestCase {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/ */
$view = $this->createMock(View::class); $view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock(); $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -647,26 +656,34 @@ class FolderTest extends \Test\TestCase {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/ */
$view = $this->createMock(View::class); $view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount'])->setConstructorArgs([$manager, $view, $this->user])->getMock(); $root = $this->getMockBuilder(Root::class)->setMethods(['getMountsIn', 'getMount'])
$root->expects($this->any()) ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock();
->method('getUser')
->will($this->returnValue($this->user));
$storage = $this->createMock(\OC\Files\Storage\Storage::class); $storage = $this->createMock(\OC\Files\Storage\Storage::class);
$mount = new MountPoint($storage, '/bar'); $mount = new MountPoint($storage, '/bar');
$cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([''])->getMock(); $cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([''])->getMock();
$view->expects($this->once()) $fileInfo = new CacheEntry(['path' => 'foo/qwerty', 'mimetype' => 'text/plain'], null);
->method('getFileInfo')
->will($this->returnValue(new FileInfo('/bar/foo/qwerty', null, 'qwerty', ['mimetype' => 'text/plain'], null)));
$storage->expects($this->once()) $storage->expects($this->once())
->method('getCache') ->method('getCache')
->will($this->returnValue($cache)); ->will($this->returnValue($cache));
$this->userMountCache->expects($this->any())
->method('getMountsForFileId')
->with(1)
->will($this->returnValue([new CachedMountInfo(
$this->user,
1,
0,
'/bar/',
1,
''
)]));
$cache->expects($this->once()) $cache->expects($this->once())
->method('getPathById') ->method('get')
->with('1') ->with(1)
->will($this->returnValue('foo/qwerty')); ->will($this->returnValue($fileInfo));
$root->expects($this->once()) $root->expects($this->once())
->method('getMountsIn') ->method('getMountsIn')
@ -690,22 +707,34 @@ class FolderTest extends \Test\TestCase {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/ */
$view = $this->createMock(View::class); $view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount'])->setConstructorArgs([$manager, $view, $this->user])->getMock(); $root = $this->getMockBuilder(Root::class)->setMethods(['getMountsIn', 'getMount'])
$root->expects($this->any()) ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock();
->method('getUser')
->will($this->returnValue($this->user));
$storage = $this->createMock(\OC\Files\Storage\Storage::class); $storage = $this->createMock(\OC\Files\Storage\Storage::class);
$mount = new MountPoint($storage, '/bar'); $mount = new MountPoint($storage, '/bar');
$cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([''])->getMock(); $cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([''])->getMock();
$fileInfo = new CacheEntry(['path' => 'foobar', 'mimetype' => 'text/plain'], null);
$storage->expects($this->once()) $storage->expects($this->once())
->method('getCache') ->method('getCache')
->will($this->returnValue($cache)); ->will($this->returnValue($cache));
$this->userMountCache->expects($this->any())
->method('getMountsForFileId')
->with(1)
->will($this->returnValue([new CachedMountInfo(
$this->user,
1,
0,
'/bar/',
1,
''
)]));
$cache->expects($this->once()) $cache->expects($this->once())
->method('getPathById') ->method('get')
->with('1') ->with(1)
->will($this->returnValue('foobar')); ->will($this->returnValue($fileInfo));
$root->expects($this->once()) $root->expects($this->once())
->method('getMountsIn') ->method('getMountsIn')
@ -719,7 +748,7 @@ class FolderTest extends \Test\TestCase {
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo'); $node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
$result = $node->getById(1); $result = $node->getById(1);
$this->assertCount(0, $result); $this->assertEquals(0, count($result));
} }
public function testGetByIdMultipleStorages() { public function testGetByIdMultipleStorages() {
@ -728,27 +757,49 @@ class FolderTest extends \Test\TestCase {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/ */
$view = $this->createMock(View::class); $view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount'])->setConstructorArgs([$manager, $view, $this->user])->getMock(); $root = $this->getMockBuilder(Root::class)->setMethods(['getMountsIn', 'getMount'])
$root->expects($this->any()) ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock();
->method('getUser')
->will($this->returnValue($this->user));
$storage = $this->createMock(\OC\Files\Storage\Storage::class); $storage = $this->createMock(\OC\Files\Storage\Storage::class);
$mount1 = new MountPoint($storage, '/bar'); $mount1 = new MountPoint($storage, '/bar');
$mount2 = new MountPoint($storage, '/bar/foo/asd'); $mount2 = new MountPoint($storage, '/bar/foo/asd');
$cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([''])->getMock(); $cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([''])->getMock();
$view->expects($this->any()) $fileInfo = new CacheEntry(['path' => 'foo/qwerty', 'mimetype' => 'text/plain'], null);
->method('getFileInfo')
->will($this->returnValue(new FileInfo('/bar/foo/qwerty', null, 'qwerty', ['mimetype' => 'plain'], null))); $storage->expects($this->once())
->method('getCache')
->will($this->returnValue($cache));
$this->userMountCache->expects($this->any())
->method('getMountsForFileId')
->with(1)
->will($this->returnValue([
new CachedMountInfo(
$this->user,
1,
0,
'/bar/',
1,
''
),
new CachedMountInfo(
$this->user,
1,
0,
'/bar/foo/asd/',
1,
''
)
]));
$storage->expects($this->any()) $storage->expects($this->any())
->method('getCache') ->method('getCache')
->will($this->returnValue($cache)); ->will($this->returnValue($cache));
$cache->expects($this->any()) $cache->expects($this->any())
->method('getPathById') ->method('get')
->with('1') ->with(1)
->will($this->returnValue('foo/qwerty')); ->will($this->returnValue($fileInfo));
$root->expects($this->any()) $root->expects($this->any())
->method('getMountsIn') ->method('getMountsIn')
@ -786,7 +837,8 @@ class FolderTest extends \Test\TestCase {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/ */
$view = $this->createMock(View::class); $view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount'])->setConstructorArgs([$manager, $view, $this->user])->getMock(); $root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock();
$view->expects($this->any()) $view->expects($this->any())
->method('file_exists') ->method('file_exists')
@ -811,7 +863,8 @@ class FolderTest extends \Test\TestCase {
*/ */
$view = $this->createMock(View::class); $view = $this->createMock(View::class);
/** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\Node\Root $root */ /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\Node\Root $root */
$root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount'])->setConstructorArgs([$manager, $view, $this->user])->getMock(); $root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock();
/** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */ /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */
$folderInfo = $this->getMockBuilder('\OC\Files\FileInfo') $folderInfo = $this->getMockBuilder('\OC\Files\FileInfo')
->disableOriginalConstructor()->getMock(); ->disableOriginalConstructor()->getMock();
@ -869,7 +922,8 @@ class FolderTest extends \Test\TestCase {
*/ */
$view = $this->createMock(View::class); $view = $this->createMock(View::class);
/** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\Node\Root $root */ /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\Node\Root $root */
$root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount'])->setConstructorArgs([$manager, $view, $this->user])->getMock(); $root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock();
/** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */ /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */
$folderInfo = $this->getMockBuilder('\OC\Files\FileInfo') $folderInfo = $this->getMockBuilder('\OC\Files\FileInfo')
->disableOriginalConstructor()->getMock(); ->disableOriginalConstructor()->getMock();
@ -925,7 +979,8 @@ class FolderTest extends \Test\TestCase {
*/ */
$view = $this->createMock(View::class); $view = $this->createMock(View::class);
/** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\Node\Root $root */ /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\Node\Root $root */
$root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount'])->setConstructorArgs([$manager, $view, $this->user])->getMock(); $root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock();
/** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */ /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */
$folderInfo = $this->getMockBuilder('\OC\Files\FileInfo') $folderInfo = $this->getMockBuilder('\OC\Files\FileInfo')
->disableOriginalConstructor()->getMock(); ->disableOriginalConstructor()->getMock();

View File

@ -50,7 +50,12 @@ class HookConnectorTest extends TestCase {
$this->registerMount($this->userId, new Temporary(), '/' . $this->userId . '/files/'); $this->registerMount($this->userId, new Temporary(), '/' . $this->userId . '/files/');
\OC_Util::setupFS($this->userId); \OC_Util::setupFS($this->userId);
$this->view = new View(); $this->view = new View();
$this->root = new Root(Filesystem::getMountManager(), $this->view, \OC::$server->getUserManager()->get($this->userId)); $this->root = new Root(
Filesystem::getMountManager(),
$this->view,
\OC::$server->getUserManager()->get($this->userId),
\OC::$server->getUserMountCache()
);
} }
public function tearDown() { public function tearDown() {

View File

@ -47,7 +47,7 @@ class IntegrationTest extends \Test\TestCase {
$this->loginAsUser($user->getUID()); $this->loginAsUser($user->getUID());
$this->view = new View(); $this->view = new View();
$this->root = new Root($manager, $this->view, $user); $this->root = new Root($manager, $this->view, $user, \OC::$server->getUserMountCache());
$storage = new Temporary(array()); $storage = new Temporary(array());
$subStorage = new Temporary(array()); $subStorage = new Temporary(array());
$this->storages[] = $storage; $this->storages[] = $storage;

View File

@ -22,6 +22,8 @@ class NodeTest extends \Test\TestCase {
/** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject */ /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject */
private $root; private $root;
/** @var \OCP\Files\Config\IUserMountCache|\PHPUnit_Framework_MockObject_MockObject */
private $userMountCache;
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
@ -41,8 +43,11 @@ class NodeTest extends \Test\TestCase {
$this->view = $this->getMockBuilder('\OC\Files\View') $this->view = $this->getMockBuilder('\OC\Files\View')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache')
->disableOriginalConstructor()
->getMock();
$this->root = $this->getMockBuilder('\OC\Files\Node\Root') $this->root = $this->getMockBuilder('\OC\Files\Node\Root')
->setConstructorArgs([$this->manager, $this->view, $this->user]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache])
->getMock(); ->getMock();
} }
@ -268,7 +273,7 @@ class NodeTest extends \Test\TestCase {
$hooksRun++; $hooksRun++;
}; };
$root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user); $root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user, $this->userMountCache);
$root->listen('\OC\Files', 'preTouch', $preListener); $root->listen('\OC\Files', 'preTouch', $preListener);
$root->listen('\OC\Files', 'postTouch', $postListener); $root->listen('\OC\Files', 'postTouch', $postListener);

View File

@ -16,6 +16,8 @@ class RootTest extends \Test\TestCase {
/** @var \OC\Files\Mount\Manager */ /** @var \OC\Files\Mount\Manager */
private $manager; private $manager;
/** @var \OCP\Files\Config\IUserMountCache|\PHPUnit_Framework_MockObject_MockObject */
private $userMountCache;
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
@ -32,6 +34,9 @@ class RootTest extends \Test\TestCase {
$this->manager = $this->getMockBuilder('\OC\Files\Mount\Manager') $this->manager = $this->getMockBuilder('\OC\Files\Mount\Manager')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache')
->disableOriginalConstructor()
->getMock();
} }
protected function getFileInfo($data) { protected function getFileInfo($data) {
@ -51,7 +56,7 @@ class RootTest extends \Test\TestCase {
$view = $this->getMockBuilder('\OC\Files\View') $view = $this->getMockBuilder('\OC\Files\View')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$root = new \OC\Files\Node\Root($this->manager, $view, $this->user); $root = new \OC\Files\Node\Root($this->manager, $view, $this->user, $this->userMountCache);
$view->expects($this->once()) $view->expects($this->once())
->method('getFileInfo') ->method('getFileInfo')
@ -80,7 +85,7 @@ class RootTest extends \Test\TestCase {
$view = $this->getMockBuilder('\OC\Files\View') $view = $this->getMockBuilder('\OC\Files\View')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$root = new \OC\Files\Node\Root($this->manager, $view, $this->user); $root = new \OC\Files\Node\Root($this->manager, $view, $this->user, $this->userMountCache);
$view->expects($this->once()) $view->expects($this->once())
->method('getFileInfo') ->method('getFileInfo')
@ -101,7 +106,7 @@ class RootTest extends \Test\TestCase {
$view = $this->getMockBuilder('\OC\Files\View') $view = $this->getMockBuilder('\OC\Files\View')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$root = new \OC\Files\Node\Root($this->manager, $view, $this->user); $root = new \OC\Files\Node\Root($this->manager, $view, $this->user, $this->userMountCache);
$root->get('/../foo'); $root->get('/../foo');
} }
@ -116,7 +121,7 @@ class RootTest extends \Test\TestCase {
$view = $this->getMockBuilder('\OC\Files\View') $view = $this->getMockBuilder('\OC\Files\View')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$root = new \OC\Files\Node\Root($this->manager, $view, $this->user); $root = new \OC\Files\Node\Root($this->manager, $view, $this->user, $this->userMountCache);
$root->get('/bar/foo'); $root->get('/bar/foo');
} }