Merge pull request #1915 from nextcloud/downstream-26398

Add using casing check/fix for initMountPoints
This commit is contained in:
Lukas Reschke 2016-11-03 12:14:28 +01:00 коммит произвёл GitHub
Родитель e11197bc48 6920e609c0
Коммит b33ceb6fdd
15 изменённых файлов: 497 добавлений и 112 удалений

Просмотреть файл

@ -91,23 +91,21 @@ class TransferOwnership extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output) {
$this->sourceUser = $input->getArgument('source-user');
$this->destinationUser = $input->getArgument('destination-user');
$source = $this->userManager->get($this->sourceUser);
$destination = $this->userManager->get($this->destinationUser);
$sourceUserObject = $this->userManager->get($input->getArgument('source-user'));
$destinationUserObject = $this->userManager->get($input->getArgument('destination-user'));
if (!$source instanceof IUser) {
if (!$sourceUserObject instanceof IUser) {
$output->writeln("<error>Unknown source user $this->sourceUser</error>");
return;
}
if (!$destination instanceof IUser) {
if (!$destinationUserObject instanceof IUser) {
$output->writeln("<error>Unknown destination user $this->destinationUser</error>");
return;
}
$this->sourceUser = $source->getUID();
$this->destinationUser = $destination->getUID();
$this->sourceUser = $sourceUserObject->getUID();
$this->destinationUser = $destinationUserObject->getUID();
// target user has to be ready
if (!\OC::$server->getEncryptionManager()->isReadyForUser($this->destinationUser)) {

Просмотреть файл

@ -394,9 +394,6 @@ class Filesystem {
if ($user === null || $user === false || $user === '') {
throw new \OC\User\NoUserException('Attempted to initialize mount points for null user and no user in session');
}
if (isset(self::$usersSetup[$user])) {
return;
}
$userManager = \OC::$server->getUserManager();
$userObject = $userManager->get($user);
@ -406,6 +403,17 @@ class Filesystem {
throw new \OC\User\NoUserException('Backends provided no user object for ' . $user);
}
// workaround in case of different casings
if ($user !== $userObject->getUID()) {
$stack = json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 50));
\OCP\Util::writeLog('files', 'initMountPoints() called with wrong user casing. This could be a bug. Expected: "' . $userObject->getUID() . '" got "' . $user . '". Stack: ' . $stack, \OCP\Util::WARN);
}
$user = $userObject->getUID();
if (isset(self::$usersSetup[$user])) {
return;
}
self::$usersSetup[$user] = true;
/** @var \OC\Files\Config\MountProviderCollection $mountConfigManager */

Просмотреть файл

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

Просмотреть файл

@ -182,7 +182,14 @@ class Server extends ServerContainer implements IServerContainer {
$this->registerService('RootFolder', function (Server $c) {
$manager = \OC\Files\Filesystem::getMountManager(null);
$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->viewToNode();
return $root;

Просмотреть файл

@ -45,6 +45,8 @@ namespace OC\Share;
use OC\Files\Filesystem;
use OCA\FederatedFileSharing\DiscoveryManager;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\ILogger;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\IDBConnection;
use OCP\IConfig;
@ -128,14 +130,39 @@ class Share extends Constants {
* Find which users can access a shared item
* @param string $path to the file
* @param string $ownerUser owner of the file
* @param IUserManager $userManager
* @param ILogger $logger
* @param boolean $includeOwner include owner to the list of users with access to the file
* @param boolean $returnUserPaths Return an array with the user => path map
* @param boolean $recursive take all parent folders into account (default true)
* @return array
* @note $path needs to be relative to user data dir, e.g. 'file.txt'
* not '/admin/data/file.txt'
* @throws \OC\User\NoUserException
*/
public static function getUsersSharingFile($path, $ownerUser, $includeOwner = false, $returnUserPaths = false, $recursive = true) {
public static function getUsersSharingFile($path,
$ownerUser,
IUserManager $userManager,
ILogger $logger,
$includeOwner = false,
$returnUserPaths = false,
$recursive = true) {
$userObject = $userManager->get($ownerUser);
if (is_null($userObject)) {
$logger->error(
sprintf(
'Backends provided no user object for %s',
$ownerUser
),
[
'app' => 'files',
]
);
throw new \OC\User\NoUserException('Backends provided no user object');
}
$ownerUser = $userObject->getUID();
Filesystem::initMountPoints($ownerUser);
$shares = $sharePaths = $fileTargets = array();

Просмотреть файл

@ -89,7 +89,15 @@ class Share extends \OC\Share\Constants {
* @since 5.0.0 - $recursive was added in 9.0.0
*/
public static function getUsersSharingFile($path, $ownerUser, $includeOwner = false, $returnUserPaths = false, $recursive = true) {
return \OC\Share\Share::getUsersSharingFile($path, $ownerUser, $includeOwner, $returnUserPaths, $recursive);
return \OC\Share\Share::getUsersSharingFile(
$path,
$ownerUser,
\OC::$server->getUserManager(),
\OC::$server->getLogger(),
$includeOwner,
$returnUserPaths,
$recursive
);
}
/**

Просмотреть файл

@ -26,6 +26,7 @@ namespace Test;
use OC\Avatar;
use OC\AvatarManager;
use OC\Files\AppData\AppData;
use OCP\Files\IAppData;
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\IConfig;
@ -48,7 +49,7 @@ class AvatarManagerTest extends \Test\TestCase {
private $logger;
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
private $config;
/** @var AvatarManager */
/** @var AvatarManager | \PHPUnit_Framework_MockObject_MockObject */
private $avatarManager;
public function setUp() {
@ -101,8 +102,29 @@ class AvatarManagerTest extends \Test\TestCase {
->with('valid-user')
->willReturn($folder);
$expected = new Avatar($folder, $this->l10n, $user, $this->logger, $this->config);;
$expected = new Avatar($folder, $this->l10n, $user, $this->logger, $this->config);
$this->assertEquals($expected, $this->avatarManager->getAvatar('valid-user'));
}
public function testGetAvatarValidUserDifferentCasing() {
$user = $this->createMock(IUser::class);
$this->userManager->expects($this->once())
->method('get')
->with('vaLid-USER')
->willReturn($user);
$user->expects($this->once())
->method('getUID')
->willReturn('valid-user');
$folder = $this->createMock(ISimpleFolder::class);
$this->appData
->expects($this->once())
->method('getFolder')
->with('valid-user')
->willReturn($folder);
$expected = new Avatar($folder, $this->l10n, $user, $this->logger, $this->config);
$this->assertEquals($expected, $this->avatarManager->getAvatar('vaLid-USER'));
}
}

Просмотреть файл

@ -368,6 +368,39 @@ class FilesystemTest extends \Test\TestCase {
$this->assertEquals(2, $thrown);
}
public function testUserNameCasing() {
$this->logout();
$userId = $this->getUniqueID('user_');
\OC_User::clearBackends();
// needed for loginName2UserName mapping
$userBackend = $this->createMock(\OC\User\Database::class);
\OC::$server->getUserManager()->registerBackend($userBackend);
$userBackend->expects($this->once())
->method('userExists')
->with(strtoupper($userId))
->will($this->returnValue(true));
$userBackend->expects($this->once())
->method('loginName2UserName')
->with(strtoupper($userId))
->will($this->returnValue($userId));
$view = new \OC\Files\View();
$this->assertFalse($view->file_exists('/' . $userId));
\OC\Files\Filesystem::initMountPoints(strtoupper($userId));
list($storage1, $path1) = $view->resolvePath('/' . $userId);
list($storage2, $path2) = $view->resolvePath('/' . strtoupper($userId));
$this->assertTrue($storage1->instanceOfStorage('\OCP\Files\IHomeStorage'));
$this->assertEquals('', $path1);
// not mounted, still on the local root storage
$this->assertEquals(strtoupper($userId), $path2);
}
/**
* Tests that the home storage is used for the user's mount point
*/

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -12,6 +12,8 @@ use OC\Files\Node\Root;
use OC\Files\Storage\Temporary;
use OC\Files\View;
use OC\User\User;
use OCP\ILogger;
use OCP\IUserManager;
/**
* Class IntegrationTest
@ -47,7 +49,14 @@ class IntegrationTest extends \Test\TestCase {
$this->loginAsUser($user->getUID());
$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());
$subStorage = new Temporary(array());
$this->storages[] = $storage;

Просмотреть файл

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

Просмотреть файл

@ -8,16 +8,31 @@
namespace Test\Files\Node;
use OC\Cache\CappedMemoryCache;
use OC\Files\FileInfo;
use OC\Files\Mount\Manager;
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 {
/** @var \OC\User\User */
private $user;
/** @var \OC\Files\Mount\Manager */
private $manager;
/** @var \OCP\Files\Config\IUserMountCache|\PHPUnit_Framework_MockObject_MockObject */
private $userMountCache;
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
private $logger;
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
private $userManager;
protected function setUp() {
parent::setUp();
@ -30,13 +45,14 @@ class RootTest extends \Test\TestCase {
->getMock();
$this->user = new \OC\User\User('', new \Test\Util\User\Dummy, null, $config, $urlgenerator);
$this->manager = $this->getMockBuilder('\OC\Files\Mount\Manager')
->disableOriginalConstructor()
->getMock();
$this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache')
->disableOriginalConstructor()
->getMock();
$this->logger = $this->createMock(ILogger::class);
$this->userManager = $this->createMock(IUserManager::class);
}
protected function getFileInfo($data) {
@ -56,7 +72,14 @@ class RootTest extends \Test\TestCase {
$view = $this->getMockBuilder('\OC\Files\View')
->disableOriginalConstructor()
->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())
->method('getFileInfo')
@ -85,7 +108,14 @@ class RootTest extends \Test\TestCase {
$view = $this->getMockBuilder('\OC\Files\View')
->disableOriginalConstructor()
->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())
->method('getFileInfo')
@ -106,7 +136,14 @@ class RootTest extends \Test\TestCase {
$view = $this->getMockBuilder('\OC\Files\View')
->disableOriginalConstructor()
->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');
}
@ -121,8 +158,82 @@ class RootTest extends \Test\TestCase {
$view = $this->getMockBuilder('\OC\Files\View')
->disableOriginalConstructor()
->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');
}
public function testGetUserFolder() {
$root = new \OC\Files\Node\Root(
$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'));
}
/**
* @expectedException \OC\User\NoUserException
* @expectedExceptionMessage Backends provided no user object
*/
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',
]
);
$root->getUserFolder('NotExistingUser');
}
}

Просмотреть файл

@ -20,6 +20,9 @@
*/
namespace Test\Share;
use OC\Share\Share;
use OCP\ILogger;
use OCP\IUserManager;
/**
* Class Test_Share
@ -1631,6 +1634,31 @@ class ShareTest extends \Test\TestCase {
$this->assertEquals('Sharing failed, because the user ' . $this->user1 . ' is the original sharer', $e->getMessage());
}
}
/**
* @expectedException \OC\User\NoUserException
* @expectedExceptionMessage Backends provided no user object
*/
public function testGetUsersSharingFileWithException() {
$userManager = $this->createMock(IUserManager::class);
$logger = $this->createMock(ILogger::class);
$userManager
->expects($this->once())
->method('get')
->with('test')
->willReturn(null);
$logger
->expects($this->once())
->method('error')
->with(
'Backends provided no user object for test',
[
'app' => 'files',
]
);
Share::getUsersSharingFile('/my/file/path', 'test', $userManager, $logger);
}
}
class DummyShareClass extends \OC\Share\Share {