DI for root.php

Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
This commit is contained in:
Lukas Reschke 2016-11-02 23:16:51 +01:00
parent 8653d14862
commit 68cebef64c
No known key found for this signature in database
GPG Key ID: B9F6980CF6E759B1
8 changed files with 344 additions and 149 deletions

View File

@ -36,6 +36,8 @@ use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException; use OCP\Files\NotPermittedException;
use OC\Hooks\PublicEmitter; use OC\Hooks\PublicEmitter;
use OCP\Files\IRootFolder; use OCP\Files\IRootFolder;
use OCP\ILogger;
use OCP\IUserManager;
/** /**
* Class Root * Class Root
@ -57,42 +59,43 @@ use OCP\Files\IRootFolder;
* @package OC\Files\Node * @package OC\Files\Node
*/ */
class Root extends Folder implements IRootFolder { class Root extends Folder implements IRootFolder {
/** @var Manager */
/**
* @var \OC\Files\Mount\Manager $mountManager
*/
private $mountManager; private $mountManager;
/** @var PublicEmitter */
/**
* @var \OC\Hooks\PublicEmitter
*/
private $emitter; private $emitter;
/** @var null|\OC\User\User */
/**
* @var \OC\User\User $user
*/
private $user; private $user;
/** @var CappedMemoryCache */
private $userFolderCache; private $userFolderCache;
/** @var IUserMountCache */
/**
* @var IUserMountCache
*/
private $userMountCache; private $userMountCache;
/** @var ILogger */
private $logger;
/** @var IUserManager */
private $userManager;
/** /**
* @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 * @param IUserMountCache $userMountCache
* @param ILogger $logger
* @param IUserManager $userManager
*/ */
public function __construct($manager, $view, $user, IUserMountCache $userMountCache) { public function __construct($manager,
$view,
$user,
IUserMountCache $userMountCache,
ILogger $logger,
IUserManager $userManager) {
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; $this->userMountCache = $userMountCache;
$this->logger = $logger;
$this->userManager = $userManager;
} }
/** /**
@ -345,12 +348,21 @@ class Root extends Folder implements IRootFolder {
* *
* @param String $userId user ID * @param String $userId user ID
* @return \OCP\Files\Folder * @return \OCP\Files\Folder
* @throws \OC\User\NoUserException
*/ */
public function getUserFolder($userId) { public function getUserFolder($userId) {
$userObject = \OC::$server->getUserManager()->get($userId); $userObject = $this->userManager->get($userId);
if (is_null($userObject)) { if (is_null($userObject)) {
\OCP\Util::writeLog('files', 'Backends provided no user object for ' . $userId, \OCP\Util::ERROR); $this->logger->error(
sprintf(
'Backends provided no user object for %s',
$userId
),
[
'app' => 'files',
]
);
throw new \OC\User\NoUserException('Backends provided no user object'); throw new \OC\User\NoUserException('Backends provided no user object');
} }

View File

@ -182,7 +182,14 @@ class Server extends ServerContainer implements IServerContainer {
$this->registerService('RootFolder', function (Server $c) { $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, $c->getUserMountCache()); $root = new Root(
$manager,
$view,
null,
$c->getUserMountCache(),
$this->getLogger(),
$this->getUserManager()
);
$connector = new HookConnector($root, $view); $connector = new HookConnector($root, $view);
$connector->viewToNode(); $connector->viewToNode();
return $root; return $root;

View File

@ -10,19 +10,22 @@ namespace Test\Files\Node;
use OC\Files\FileInfo; use OC\Files\FileInfo;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\ILogger;
use OCP\IUserManager;
class FileTest extends \Test\TestCase { class FileTest extends \Test\TestCase {
/** @var \OC\User\User */ /** @var \OC\User\User */
private $user; private $user;
/** @var \OC\Files\Mount\Manager */ /** @var \OC\Files\Mount\Manager */
private $manager; private $manager;
/** @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 */ /** @var \OCP\Files\Config\IUserMountCache|\PHPUnit_Framework_MockObject_MockObject */
private $userMountCache; private $userMountCache;
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
private $logger;
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
private $userManager;
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
@ -30,7 +33,6 @@ class FileTest extends \Test\TestCase {
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->user = new \OC\User\User('', new \Test\Util\User\Dummy, null, $config); $this->user = new \OC\User\User('', new \Test\Util\User\Dummy, null, $config);
$this->manager = $this->getMockBuilder('\OC\Files\Mount\Manager') $this->manager = $this->getMockBuilder('\OC\Files\Mount\Manager')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
@ -40,6 +42,8 @@ class FileTest extends \Test\TestCase {
$this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache') $this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->logger = $this->createMock(ILogger::class);
$this->userManager = $this->createMock(IUserManager::class);
} }
protected function getMockStorage() { protected function getMockStorage() {
@ -58,7 +62,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, $this->userMountCache]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock(); ->getMock();
$root->expects($this->exactly(2)) $root->expects($this->exactly(2))
@ -108,7 +112,14 @@ class FileTest extends \Test\TestCase {
$hooksRun++; $hooksRun++;
}; };
$root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user, $this->userMountCache); $root = new \OC\Files\Node\Root(
$this->manager,
$this->view,
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
);
$root->listen('\OC\Files', 'preDelete', $preListener); $root->listen('\OC\Files', 'preDelete', $preListener);
$root->listen('\OC\Files', 'postDelete', $postListener); $root->listen('\OC\Files', 'postDelete', $postListener);
@ -138,7 +149,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, $this->userMountCache]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock(); ->getMock();
$root->expects($this->any()) $root->expects($this->any())
@ -157,7 +168,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, $this->userMountCache]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock(); ->getMock();
$hook = function ($file) { $hook = function ($file) {
@ -187,7 +198,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, $this->userMountCache]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock(); ->getMock();
$root->expects($this->any()) $root->expects($this->any())
@ -206,7 +217,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, $this->userMountCache]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock(); ->getMock();
$root->expects($this->any()) $root->expects($this->any())
@ -233,7 +244,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, $this->userMountCache]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock(); ->getMock();
$this->view->expects($this->once()) $this->view->expects($this->once())
@ -248,7 +259,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, $this->userMountCache]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock(); ->getMock();
$this->view->expects($this->once()) $this->view->expects($this->once())
@ -265,7 +276,14 @@ 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, $this->userMountCache); $root = new \OC\Files\Node\Root(
$this->manager,
$this->view,
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
);
$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');
@ -293,8 +311,14 @@ 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, $this->userMountCache); $root = new \OC\Files\Node\Root(
$this->manager,
new $this->view,
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
);
$hooksCalled = 0; $hooksCalled = 0;
$hook = function ($file) use (&$hooksCalled) { $hook = function ($file) use (&$hooksCalled) {
$hooksCalled++; $hooksCalled++;
@ -326,8 +350,14 @@ 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, $this->userMountCache); $root = new \OC\Files\Node\Root(
$this->manager,
$this->view,
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
);
$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');
}; };
@ -345,8 +375,14 @@ 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, $this->userMountCache); $root = new \OC\Files\Node\Root(
$this->manager,
$this->view,
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
);
$hook = function () { $hook = function () {
throw new \Exception('Hooks are not supposed to be called'); throw new \Exception('Hooks are not supposed to be called');
}; };
@ -364,8 +400,14 @@ 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, $this->userMountCache); $root = new \OC\Files\Node\Root(
$this->manager,
new $this->view,
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
);
$hook = function () { $hook = function () {
throw new \Exception('Hooks are not supposed to be called'); throw new \Exception('Hooks are not supposed to be called');
}; };
@ -382,7 +424,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, $this->userMountCache]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock(); ->getMock();
$this->view->expects($this->any()) $this->view->expects($this->any())
@ -415,7 +457,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, $this->userMountCache]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock(); ->getMock();
/** /**
@ -453,7 +495,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, $this->userMountCache]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock(); ->getMock();
$this->view->expects($this->never()) $this->view->expects($this->never())
@ -475,7 +517,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, $this->userMountCache]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock(); ->getMock();
$this->view->expects($this->never()) $this->view->expects($this->never())
@ -496,7 +538,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, $this->userMountCache]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock(); ->getMock();
$this->view->expects($this->any()) $this->view->expects($this->any())
@ -526,7 +568,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, $this->userMountCache]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock(); ->getMock();
$this->view->expects($this->any()) $this->view->expects($this->any())
@ -553,7 +595,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, $this->userMountCache]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock(); ->getMock();
/** /**
@ -583,7 +625,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, $this->userMountCache]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock(); ->getMock();
$this->view->expects($this->never()) $this->view->expects($this->never())

View File

@ -18,11 +18,13 @@ use OC\Files\Node\Node;
use OC\Files\Node\Root; use OC\Files\Node\Root;
use OC\Files\Storage\Temporary; use OC\Files\Storage\Temporary;
use OC\Files\Storage\Wrapper\Jail; use OC\Files\Storage\Wrapper\Jail;
use OC\User\User;
use OCP\Files\Mount\IMountPoint; use OCP\Files\Mount\IMountPoint;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OC\Files\View; use OC\Files\View;
use OCP\Files\Storage; use OCP\Files\Storage;
use OCP\ILogger;
use OCP\IUserManager;
/** /**
* Class FolderTest * Class FolderTest
@ -32,10 +34,14 @@ use OCP\Files\Storage;
* @package Test\Files\Node * @package Test\Files\Node
*/ */
class FolderTest extends \Test\TestCase { class FolderTest extends \Test\TestCase {
/** @var User */
private $user; private $user;
/** @var \OCP\Files\Config\IUserMountCache|\PHPUnit_Framework_MockObject_MockObject */ /** @var \OCP\Files\Config\IUserMountCache|\PHPUnit_Framework_MockObject_MockObject */
private $userMountCache; private $userMountCache;
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
private $logger;
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
private $userManager;
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
@ -43,6 +49,8 @@ class FolderTest extends \Test\TestCase {
$this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache') $this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->logger = $this->createMock(ILogger::class);
$this->userManager = $this->createMock(IUserManager::class);
} }
protected function getMockStorage() { protected function getMockStorage() {
@ -64,7 +72,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, $this->userMountCache]) ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock(); ->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
@ -118,7 +126,14 @@ 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, $this->userMountCache); $root = new \OC\Files\Node\Root(
$manager,
$view,
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
);
$root->listen('\OC\Files', 'preDelete', $preListener); $root->listen('\OC\Files', 'preDelete', $preListener);
$root->listen('\OC\Files', 'postDelete', $postListener); $root->listen('\OC\Files', 'postDelete', $postListener);
@ -150,7 +165,9 @@ 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, $this->userMountCache])->getMock(); $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -171,7 +188,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, $this->userMountCache]) ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock(); ->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
@ -202,7 +219,9 @@ 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, $this->userMountCache])->getMock(); $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -221,7 +240,9 @@ 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, $this->userMountCache])->getMock(); $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -243,7 +264,9 @@ 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, $this->userMountCache])->getMock(); $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -263,7 +286,9 @@ 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, $this->userMountCache])->getMock(); $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -293,7 +318,9 @@ 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, $this->userMountCache])->getMock(); $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -313,7 +340,9 @@ 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, $this->userMountCache])->getMock(); $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -343,7 +372,9 @@ 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, $this->userMountCache])->getMock(); $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -363,7 +394,9 @@ 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, $this->userMountCache])->getMock(); $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -383,7 +416,9 @@ 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, $this->userMountCache])->getMock(); $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -431,8 +466,10 @@ 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']) $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); ->setMethods(['getUser', 'getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -480,7 +517,9 @@ 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, $this->userMountCache])->getMock(); $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -528,7 +567,9 @@ 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, $this->userMountCache])->getMock(); $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -576,7 +617,9 @@ 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, $this->userMountCache])->getMock(); $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock();
$root->expects($this->any()) $root->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
@ -656,8 +699,10 @@ 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(['getMountsIn', 'getMount']) $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); ->setMethods(['getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock();
$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();
@ -707,8 +752,10 @@ 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(['getMountsIn', 'getMount']) $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); ->setMethods(['getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock();
$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();
@ -757,8 +804,10 @@ 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(['getMountsIn', 'getMount']) $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); ->setMethods(['getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock();
$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');
@ -837,8 +886,10 @@ 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']) $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); ->setMethods(['getUser', 'getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock();
$view->expects($this->any()) $view->expects($this->any())
->method('file_exists') ->method('file_exists')
@ -863,8 +914,10 @@ 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']) $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); ->setMethods(['getUser', 'getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->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();
@ -922,8 +975,10 @@ 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']) $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); ->setMethods(['getUser', 'getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->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();
@ -979,8 +1034,10 @@ 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']) $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); ->setMethods(['getUser', 'getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->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

@ -13,6 +13,8 @@ use OC\Files\Node\Root;
use OC\Files\Storage\Temporary; use OC\Files\Storage\Temporary;
use OC\Files\View; use OC\Files\View;
use OCP\Files\Node; use OCP\Files\Node;
use OCP\ILogger;
use OCP\IUserManager;
use Test\TestCase; use Test\TestCase;
use Test\Traits\MountProviderTrait; use Test\Traits\MountProviderTrait;
use Test\Traits\UserTrait; use Test\Traits\UserTrait;
@ -54,7 +56,9 @@ class HookConnectorTest extends TestCase {
Filesystem::getMountManager(), Filesystem::getMountManager(),
$this->view, $this->view,
\OC::$server->getUserManager()->get($this->userId), \OC::$server->getUserManager()->get($this->userId),
\OC::$server->getUserMountCache() \OC::$server->getUserMountCache(),
$this->createMock(ILogger::class),
$this->createMock(IUserManager::class)
); );
} }

View File

@ -12,6 +12,8 @@ use OC\Files\Node\Root;
use OC\Files\Storage\Temporary; use OC\Files\Storage\Temporary;
use OC\Files\View; use OC\Files\View;
use OC\User\User; use OC\User\User;
use OCP\ILogger;
use OCP\IUserManager;
/** /**
* Class IntegrationTest * Class IntegrationTest
@ -47,7 +49,14 @@ 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, \OC::$server->getUserMountCache()); $this->root = new Root(
$manager,
$this->view,
$user,
\OC::$server->getUserMountCache(),
$this->createMock(ILogger::class),
$this->createMock(IUserManager::class)
);
$storage = new Temporary(array()); $storage = new Temporary(array());
$subStorage = new Temporary(array()); $subStorage = new Temporary(array());
$this->storages[] = $storage; $this->storages[] = $storage;

View File

@ -9,21 +9,24 @@
namespace Test\Files\Node; namespace Test\Files\Node;
use OC\Files\FileInfo; use OC\Files\FileInfo;
use OCP\ILogger;
use OCP\IUserManager;
class NodeTest extends \Test\TestCase { class NodeTest extends \Test\TestCase {
/** @var \OC\User\User */ /** @var \OC\User\User */
private $user; private $user;
/** @var \OC\Files\Mount\Manager */ /** @var \OC\Files\Mount\Manager */
private $manager; private $manager;
/** @var \OC\Files\View|\PHPUnit_Framework_MockObject_MockObject */ /** @var \OC\Files\View|\PHPUnit_Framework_MockObject_MockObject */
private $view; private $view;
/** @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 */ /** @var \OCP\Files\Config\IUserMountCache|\PHPUnit_Framework_MockObject_MockObject */
private $userMountCache; private $userMountCache;
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
private $logger;
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
private $userManager;
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
@ -34,9 +37,7 @@ class NodeTest extends \Test\TestCase {
$urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator') $urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->user = new \OC\User\User('', new \Test\Util\User\Dummy, null, $config, $urlGenerator); $this->user = new \OC\User\User('', new \Test\Util\User\Dummy, null, $config, $urlGenerator);
$this->manager = $this->getMockBuilder('\OC\Files\Mount\Manager') $this->manager = $this->getMockBuilder('\OC\Files\Mount\Manager')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
@ -46,8 +47,10 @@ class NodeTest extends \Test\TestCase {
$this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache') $this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->logger = $this->createMock(ILogger::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->root = $this->getMockBuilder('\OC\Files\Node\Root') $this->root = $this->getMockBuilder('\OC\Files\Node\Root')
->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache]) ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock(); ->getMock();
} }
@ -273,7 +276,14 @@ class NodeTest extends \Test\TestCase {
$hooksRun++; $hooksRun++;
}; };
$root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user, $this->userMountCache); $root = new \OC\Files\Node\Root(
$this->manager,
$this->view,
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
);
$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

@ -8,18 +8,31 @@
namespace Test\Files\Node; namespace Test\Files\Node;
use OC\Cache\CappedMemoryCache;
use OC\Files\FileInfo; use OC\Files\FileInfo;
use OC\Files\Mount\Manager; use OC\Files\Mount\Manager;
use OC\User\NoUserException; use OC\Files\Node\Folder;
use OC\Files\View;
use OCP\ILogger;
use OCP\IUser;
use OCP\IUserManager;
/**
* Class RootTest
*
* @package Test\Files\Node
*/
class RootTest extends \Test\TestCase { class RootTest extends \Test\TestCase {
/** @var \OC\User\User */ /** @var \OC\User\User */
private $user; private $user;
/** @var \OC\Files\Mount\Manager */ /** @var \OC\Files\Mount\Manager */
private $manager; private $manager;
/** @var \OCP\Files\Config\IUserMountCache|\PHPUnit_Framework_MockObject_MockObject */ /** @var \OCP\Files\Config\IUserMountCache|\PHPUnit_Framework_MockObject_MockObject */
private $userMountCache; private $userMountCache;
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
private $logger;
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
private $userManager;
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
@ -32,13 +45,14 @@ class RootTest extends \Test\TestCase {
->getMock(); ->getMock();
$this->user = new \OC\User\User('', new \Test\Util\User\Dummy, null, $config, $urlgenerator); $this->user = new \OC\User\User('', new \Test\Util\User\Dummy, null, $config, $urlgenerator);
$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') $this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->logger = $this->createMock(ILogger::class);
$this->userManager = $this->createMock(IUserManager::class);
} }
protected function getFileInfo($data) { protected function getFileInfo($data) {
@ -58,7 +72,14 @@ 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, $this->userMountCache); $root = new \OC\Files\Node\Root(
$this->manager,
$view,
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
);
$view->expects($this->once()) $view->expects($this->once())
->method('getFileInfo') ->method('getFileInfo')
@ -87,7 +108,14 @@ 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, $this->userMountCache); $root = new \OC\Files\Node\Root(
$this->manager,
$view,
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
);
$view->expects($this->once()) $view->expects($this->once())
->method('getFileInfo') ->method('getFileInfo')
@ -108,7 +136,14 @@ 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, $this->userMountCache); $root = new \OC\Files\Node\Root(
$this->manager,
$view,
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
);
$root->get('/../foo'); $root->get('/../foo');
} }
@ -123,63 +158,82 @@ 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, $this->userMountCache); $root = new \OC\Files\Node\Root(
$this->manager,
$view,
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
);
$root->get('/bar/foo'); $root->get('/bar/foo');
} }
public function testGetUserFolder() { public function testGetUserFolder() {
$this->logout(); $root = new \OC\Files\Node\Root(
$manager = new Manager(); $this->manager,
$this->createMock(View::class),
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
);
$user = $this->createMock(IUser::class);
$user
->expects($this->once())
->method('getUID')
->willReturn('MyUserId');
$this->userManager
->expects($this->once())
->method('get')
->with('MyUserId')
->willReturn($user);
/** @var CappedMemoryCache|\PHPUnit_Framework_MockObject_MockObject $cappedMemoryCache */
$cappedMemoryCache = $this->createMock(CappedMemoryCache::class);
$cappedMemoryCache
->expects($this->once())
->method('hasKey')
->willReturn(true);
$folder = $this->createMock(Folder::class);
$cappedMemoryCache
->expects($this->once())
->method('get')
->with('MyUserId')
->willReturn($folder);
$this->invokePrivate($root, 'userFolderCache', [$cappedMemoryCache]);
$this->assertEquals($folder, $root->getUserFolder('MyUserId'));
}
/** /**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view * @expectedException \OC\User\NoUserException
* @expectedExceptionMessage Backends provided no user object
*/ */
$view = new \OC\Files\View(); public function testGetUserFolderWithNoUserObj() {
$root = new \OC\Files\Node\Root(
$this->createMock(Manager::class),
$this->createMock(View::class),
null,
$this->userMountCache,
$this->logger,
$this->userManager
);
$this->userManager
->expects($this->once())
->method('get')
->with('NotExistingUser')
->willReturn(null);
$this->logger
->expects($this->once())
->method('error')
->with(
'Backends provided no user object for NotExistingUser',
[
'app' => 'files',
]
);
$user1 = $this->getUniqueID('user1_'); $root->getUserFolder('NotExistingUser');
$user2 = $this->getUniqueID('user2_');
\OC_User::clearBackends();
// needed for loginName2UserName mapping
$userBackend = $this->createMock(\OC\User\Database::class);
\OC::$server->getUserManager()->registerBackend($userBackend);
$userBackend->expects($this->any())
->method('userExists')
->will($this->returnValueMap([
[$user1, true],
[$user2, true],
[strtoupper($user1), true],
[strtoupper($user2), true],
]));
$userBackend->expects($this->any())
->method('loginName2UserName')
->will($this->returnValueMap([
[strtoupper($user1), $user1],
[$user1, $user1],
[strtoupper($user2), $user2],
[$user2, $user2],
]));
$this->loginAsUser($user1);
$root = new \OC\Files\Node\Root($manager, $view, null, $this->userMountCache);
$folder = $root->getUserFolder($user1);
$this->assertEquals('/' . $user1 . '/files', $folder->getPath());
$folder = $root->getUserFolder($user2);
$this->assertEquals('/' . $user2 . '/files', $folder->getPath());
// case difference must not matter here
$folder = $root->getUserFolder(strtoupper($user2));
$this->assertEquals('/' . $user2 . '/files', $folder->getPath());
$thrown = false;
try {
$folder = $root->getUserFolder($this->getUniqueID('unexist'));
} catch (NoUserException $e) {
$thrown = true;
}
$this->assertTrue($thrown);
} }
} }