adjust tests to new fs setup

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2022-02-23 18:29:08 +01:00
parent 5c0fe93498
commit 1c468129af
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
28 changed files with 252 additions and 109 deletions

View File

@ -34,6 +34,7 @@ use OC\Files\Storage\Temporary;
use OC\Files\View;
use OCA\DAV\Connector\Sabre\Directory;
use OCA\DAV\Connector\Sabre\ObjectTree;
use OCP\Files\Mount\IMountManager;
/**
* Class ObjectTreeTest
@ -266,7 +267,7 @@ class ObjectTreeTest extends \Test\TestCase {
];
}
public function testGetNodeForPathInvalidPath() {
$this->expectException(\OCA\DAV\Connector\Sabre\Exception\InvalidPath::class);
@ -287,8 +288,7 @@ class ObjectTreeTest extends \Test\TestCase {
$rootNode = $this->getMockBuilder(Directory::class)
->disableOriginalConstructor()
->getMock();
$mountManager = $this->getMockBuilder(Manager::class)
->getMock();
$mountManager = $this->createMock(IMountManager::class);
$tree = new \OCA\DAV\Connector\Sabre\ObjectTree();
$tree->init($rootNode, $view, $mountManager);
@ -314,8 +314,7 @@ class ObjectTreeTest extends \Test\TestCase {
$rootNode = $this->getMockBuilder(Directory::class)
->disableOriginalConstructor()
->getMock();
$mountManager = $this->getMockBuilder(Manager::class)
->getMock();
$mountManager = $this->createMock(IMountManager::class);
$tree = new \OCA\DAV\Connector\Sabre\ObjectTree();
$tree->init($rootNode, $view, $mountManager);

View File

@ -27,6 +27,10 @@ namespace OCA\Files_External\Tests;
use OC\Files\Mount\Manager;
use OCA\Files_External\Lib\PersonalMount;
use OCA\Files_External\Lib\StorageConfig;
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IMountProviderCollection;
use OCP\IUserSession;
use Test\TestCase;
class PersonalMountTest extends TestCase {
@ -47,7 +51,12 @@ class PersonalMountTest extends TestCase {
$mount = new PersonalMount($storageService, $storageConfig, 10, $storage, '/foo');
$mountManager = new Manager();
$mountManager = new Manager(
$this->createMock(IEventLogger::class),
$this->createMock(IMountProviderCollection::class),
$this->createMock(IUserSession::class),
$this->createMock(IEventDispatcher::class)
);
$mountManager->addMount($mount);
$this->assertEquals([$mount], $mountManager->findByStorageId('dummy'));

View File

@ -43,6 +43,7 @@ use OCP\EventDispatcher\IEventDispatcher;
use OCP\Federation\ICloudFederationFactory;
use OCP\Federation\ICloudFederationProviderManager;
use OCP\Files;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IStorageFactory;
use OCP\Http\Client\IClientService;
use OCP\IDBConnection;
@ -599,8 +600,9 @@ class Manager {
}
public function removeShare($mountPoint): bool {
$mountPointObj = $this->mountManager->find($mountPoint);
if ($mountPointObj === null) {
try {
$mountPointObj = $this->mountManager->find($mountPoint);
} catch (NotFoundException $e) {
$this->logger->error('Mount point to remove share not found', ['mountPoint' => $mountPoint]);
return false;
}

View File

@ -31,14 +31,18 @@
namespace OCA\Files_Sharing\Tests\External;
use OC\Federation\CloudIdManager;
use OC\Files\SetupManager;
use OC\Files\Storage\StorageFactory;
use OCA\Files_Sharing\External\Manager;
use OCA\Files_Sharing\External\MountProvider;
use OCA\Files_Sharing\Tests\TestCase;
use OCP\Contacts\IManager;
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Federation\ICloudFederationFactory;
use OCP\Federation\ICloudFederationProviderManager;
use OCP\Files\Config\IMountProviderCollection;
use OCP\Files\NotFoundException;
use OCP\Http\Client\IClientService;
use OCP\Http\Client\IResponse;
use OCP\IGroup;
@ -102,9 +106,13 @@ class ManagerTest extends TestCase {
parent::setUp();
$this->uid = $this->getUniqueID('user');
$this->createUser($this->uid, '');
$this->user = \OC::$server->getUserManager()->get($this->uid);
$this->mountManager = new \OC\Files\Mount\Manager();
$this->user = $this->createUser($this->uid, '');
$this->mountManager = new \OC\Files\Mount\Manager(
$this->createMock(IEventLogger::class),
$this->createMock(IMountProviderCollection::class),
$this->createMock(IUserSession::class),
$this->createMock(IEventDispatcher::class)
);
$this->clientService = $this->getMockBuilder(IClientService::class)
->disableOriginalConstructor()->getMock();
$this->cloudFederationProviderManager = $this->createMock(ICloudFederationProviderManager::class);
@ -740,12 +748,12 @@ class ManagerTest extends TestCase {
private function assertNotMount($mountPoint) {
$mountPoint = rtrim($mountPoint, '/');
$mount = $this->mountManager->find($this->getFullPath($mountPoint));
if ($mount) {
try {
$mount = $this->mountManager->find($this->getFullPath($mountPoint));
$this->assertInstanceOf('\OCP\Files\Mount\IMountPoint', $mount);
$this->assertNotEquals($this->getFullPath($mountPoint), rtrim($mount->getMountPoint(), '/'));
} else {
$this->assertNull($mount);
} catch (NotFoundException $e) {
}
}

View File

@ -271,7 +271,7 @@ return array(
'OCP\\Files\\Events\\Node\\BeforeNodeRenamedEvent' => $baseDir . '/lib/public/Files/Events/Node/BeforeNodeRenamedEvent.php',
'OCP\\Files\\Events\\Node\\BeforeNodeTouchedEvent' => $baseDir . '/lib/public/Files/Events/Node/BeforeNodeTouchedEvent.php',
'OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent' => $baseDir . '/lib/public/Files/Events/Node/BeforeNodeWrittenEvent.php',
'OCP\\Files\\Events\\Node\\FilesystemTearedDownEvent' => $baseDir . '/lib/public/Files/Events/Node/FilesystemTearedDownEvent.php',
'OCP\\Files\\Events\\Node\\FilesystemTornDownEvent' => $baseDir . '/lib/public/Files/Events/Node/FilesystemTornDownEvent.php',
'OCP\\Files\\Events\\Node\\NodeCopiedEvent' => $baseDir . '/lib/public/Files/Events/Node/NodeCopiedEvent.php',
'OCP\\Files\\Events\\Node\\NodeCreatedEvent' => $baseDir . '/lib/public/Files/Events/Node/NodeCreatedEvent.php',
'OCP\\Files\\Events\\Node\\NodeDeletedEvent' => $baseDir . '/lib/public/Files/Events/Node/NodeDeletedEvent.php',

View File

@ -300,7 +300,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\Files\\Events\\Node\\BeforeNodeRenamedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/BeforeNodeRenamedEvent.php',
'OCP\\Files\\Events\\Node\\BeforeNodeTouchedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/BeforeNodeTouchedEvent.php',
'OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/BeforeNodeWrittenEvent.php',
'OCP\\Files\\Events\\Node\\FilesystemTearedDownEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/FilesystemTearedDownEvent.php',
'OCP\\Files\\Events\\Node\\FilesystemTornDownEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/FilesystemTornDownEvent.php',
'OCP\\Files\\Events\\Node\\NodeCopiedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/NodeCopiedEvent.php',
'OCP\\Files\\Events\\Node\\NodeCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/NodeCreatedEvent.php',
'OCP\\Files\\Events\\Node\\NodeDeletedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/NodeDeletedEvent.php',

View File

@ -43,7 +43,7 @@ use OC\Files\Mount\MountPoint;
use OC\Lockdown\Filesystem\NullStorage;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IMountProvider;
use OCP\Files\Events\Node\FilesystemTearedDownEvent;
use OCP\Files\Events\Node\FilesystemTornDownEvent;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IStorageFactory;
use OCP\ILogger;
@ -336,7 +336,7 @@ class Filesystem {
self::$defaultInstance = new View($root);
/** @var IEventDispatcher $eventDispatcher */
$eventDispatcher = \OC::$server->get(IEventDispatcher::class);
$eventDispatcher->addListener(FilesystemTearedDownEvent::class, function () {
$eventDispatcher->addListener(FilesystemTornDownEvent::class, function () {
self::$defaultInstance = null;
self::$usersSetup = [];
self::$loaded = false;

View File

@ -40,7 +40,7 @@ use OC\Hooks\PublicEmitter;
use OC\User\NoUserException;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\Events\Node\FilesystemTearedDownEvent;
use OCP\Files\Events\Node\FilesystemTornDownEvent;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
@ -102,7 +102,7 @@ class Root extends Folder implements IRootFolder {
$this->userMountCache = $userMountCache;
$this->logger = $logger;
$this->userManager = $userManager;
$eventDispatcher->addListener(FilesystemTearedDownEvent::class, function () {
$eventDispatcher->addListener(FilesystemTornDownEvent::class, function () {
$this->userFolderCache = new CappedMemoryCache();
});
}

View File

@ -38,7 +38,7 @@ use OCP\Constants;
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IMountProviderCollection;
use OCP\Files\Events\Node\FilesystemTearedDownEvent;
use OCP\Files\Events\Node\FilesystemTornDownEvent;
use OCP\Files\Mount\IMountManager;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Storage\IStorage;
@ -201,6 +201,6 @@ class SetupManager {
$this->setupUsers = [];
$this->rootSetup = false;
$this->mountManager->clear();
$this->eventDispatcher->dispatchTyped(new FilesystemTearedDownEvent());
$this->eventDispatcher->dispatchTyped(new FilesystemTornDownEvent());
}
}

View File

@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2022 Robin Appelman <robin@icewind.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCP\Files\Events\Node;
use OCP\EventDispatcher\Event;
/**
* Event fired after the filesystem has been torn down
*/
class FilesystemTornDownEvent extends Event {
}

View File

@ -23,6 +23,7 @@
namespace Test\Cache;
use OC\Files\Storage\Local;
use OCP\Files\Mount\IMountManager;
use Test\Traits\UserTrait;
/**
@ -68,15 +69,12 @@ class FileCacheTest extends TestCache {
//clear all proxies and hooks so we can do clean testing
\OC_Hook::clear('OC_Filesystem');
//set up temporary storage
$this->storage = \OC\Files\Filesystem::getStorage('/');
\OC\Files\Filesystem::clearMounts();
/** @var IMountManager $manager */
$manager = \OC::$server->get(IMountManager::class);
$manager->removeMount('/test');
$storage = new \OC\Files\Storage\Temporary([]);
\OC\Files\Filesystem::mount($storage, [], '/');
$datadir = str_replace('local::', '', $storage->getId());
$config = \OC::$server->getConfig();
$this->datadir = $config->getSystemValue('cachedirectory', \OC::$SERVERROOT.'/data/cache');
$config->setSystemValue('cachedirectory', $datadir);
\OC\Files\Filesystem::mount($storage, [], '/test/cache');
//set up the users dir
$this->rootView = new \OC\Files\View('');
@ -94,17 +92,12 @@ class FileCacheTest extends TestCache {
}
\OC_User::setUserId($this->user);
\OC::$server->getConfig()->setSystemValue('cachedirectory', $this->datadir);
if ($this->instance) {
$this->instance->clear();
$this->instance = null;
}
// Restore the original mount point
\OC\Files\Filesystem::clearMounts();
\OC\Files\Filesystem::mount($this->storage, [], '/');
parent::tearDown();
}

View File

@ -10,6 +10,7 @@ namespace Test\Files\Cache;
use OC\Files\Filesystem as Filesystem;
use OC\Files\View;
use OCP\Files\Mount\IMountManager;
/**
* Class UpdaterLegacyTest
@ -61,7 +62,10 @@ class UpdaterLegacyTest extends \Test\TestCase {
Filesystem::init(self::$user, '/' . self::$user . '/files');
Filesystem::clearMounts();
/** @var IMountManager $manager */
$manager = \OC::$server->get(IMountManager::class);
$manager->removeMount('/' . self::$user);
Filesystem::mount($this->storage, [], '/' . self::$user . '/files');
\OC_Hook::clear('OC_Filesystem');

View File

@ -50,8 +50,6 @@ class UpdaterTest extends \Test\TestCase {
}
protected function tearDown(): void {
Filesystem::clearMounts();
$this->logout();
parent::tearDown();
}

View File

@ -45,6 +45,8 @@ class UserMountCacheTest extends TestCase {
private $fileIds = [];
protected function setUp(): void {
parent::setUp();
$this->fileIds = [];
$this->connection = \OC::$server->getDatabaseConnection();
$config = $this->getMockBuilder(IConfig::class)

View File

@ -9,6 +9,10 @@
namespace Test\Files\Mount;
use OC\Files\Storage\Temporary;
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IMountProviderCollection;
use OCP\IUserSession;
class LongId extends Temporary {
public function getId() {
@ -24,12 +28,15 @@ class ManagerTest extends \Test\TestCase {
protected function setUp(): void {
parent::setUp();
$this->manager = new \OC\Files\Mount\Manager();
$this->manager = new \OC\Files\Mount\Manager(
$this->createMock(IEventLogger::class),
$this->createMock(IMountProviderCollection::class),
$this->createMock(IUserSession::class),
$this->createMock(IEventDispatcher::class),
);
}
public function testFind() {
$this->assertNull($this->manager->find('/'));
$rootMount = new \OC\Files\Mount\MountPoint(new Temporary([]), '/');
$this->manager->addMount($rootMount);
$this->assertEquals($rootMount, $this->manager->find('/'));

View File

@ -35,7 +35,7 @@ class FileTest extends NodeTest {
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, $this->logger, $this->userManager])
->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$hook = function ($file) {
@ -65,7 +65,7 @@ class FileTest extends NodeTest {
/** @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, $this->logger, $this->userManager])
->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$root->expects($this->any())
@ -84,7 +84,7 @@ class FileTest extends NodeTest {
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, $this->logger, $this->userManager])
->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$root->expects($this->any())
@ -111,7 +111,7 @@ class FileTest extends NodeTest {
/** @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, $this->logger, $this->userManager])
->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$this->view->expects($this->once())
@ -126,7 +126,7 @@ class FileTest extends NodeTest {
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, $this->logger, $this->userManager])
->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$this->view->expects($this->once())
@ -149,7 +149,8 @@ class FileTest extends NodeTest {
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
$this->userManager,
$this->eventDispatcher
);
$hook = function ($file) {
@ -184,7 +185,8 @@ class FileTest extends NodeTest {
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
$this->userManager,
$this->eventDispatcher
);
$hooksCalled = 0;
$hook = function ($file) use (&$hooksCalled) {
@ -223,7 +225,8 @@ class FileTest extends NodeTest {
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
$this->userManager,
$this->eventDispatcher
);
$hook = function ($file) {
throw new \Exception('Hooks are not supposed to be called');
@ -248,7 +251,8 @@ class FileTest extends NodeTest {
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
$this->userManager,
$this->eventDispatcher
);
$hook = function () {
throw new \Exception('Hooks are not supposed to be called');
@ -273,7 +277,8 @@ class FileTest extends NodeTest {
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
$this->userManager,
$this->eventDispatcher
);
$hook = function () {
throw new \Exception('Hooks are not supposed to be called');

View File

@ -61,7 +61,7 @@ class FolderTest extends NodeTest {
*/
$view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$root->expects($this->any())
->method('getUser')
@ -93,7 +93,7 @@ class FolderTest extends NodeTest {
*/
$view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$root->expects($this->any())
->method('getUser')
@ -113,7 +113,7 @@ class FolderTest extends NodeTest {
*/
$view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$root->expects($this->any())
->method('getUser')
@ -136,7 +136,7 @@ class FolderTest extends NodeTest {
*/
$view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$root->expects($this->any())
->method('getUser')
@ -157,7 +157,7 @@ class FolderTest extends NodeTest {
*/
$view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$root->expects($this->any())
->method('getUser')
@ -187,7 +187,7 @@ class FolderTest extends NodeTest {
*/
$view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$root->method('getUser')
->willReturn($this->user);
@ -207,7 +207,7 @@ class FolderTest extends NodeTest {
*/
$view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$root->expects($this->any())
->method('getUser')
@ -237,7 +237,7 @@ class FolderTest extends NodeTest {
*/
$view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$root->method('getUser')
->willReturn($this->user);
@ -257,7 +257,7 @@ class FolderTest extends NodeTest {
*/
$view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$root->method('getUser')
->willReturn($this->user);
@ -277,7 +277,7 @@ class FolderTest extends NodeTest {
*/
$view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$root->method('getUser')
->willReturn($this->user);
@ -321,7 +321,7 @@ class FolderTest extends NodeTest {
$view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)
->setMethods(['getUser', 'getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$root->expects($this->any())
->method('getUser')
@ -364,7 +364,7 @@ class FolderTest extends NodeTest {
*/
$view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$root->method('getUser')
->willReturn($this->user);
@ -407,7 +407,7 @@ class FolderTest extends NodeTest {
*/
$view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$root->expects($this->any())
->method('getUser')
@ -479,7 +479,7 @@ class FolderTest extends NodeTest {
$view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)
->setMethods(['getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$storage = $this->createMock(\OC\Files\Storage\Storage::class);
$mount = new MountPoint($storage, '/bar');
@ -530,7 +530,7 @@ class FolderTest extends NodeTest {
$view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)
->setMethods(['getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$storage = $this->createMock(\OC\Files\Storage\Storage::class);
$mount = new MountPoint($storage, '/bar');
@ -577,7 +577,7 @@ class FolderTest extends NodeTest {
$view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)
->setMethods(['getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$storage = $this->createMock(\OC\Files\Storage\Storage::class);
$mount = new MountPoint($storage, '/bar');
@ -627,7 +627,7 @@ class FolderTest extends NodeTest {
$view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)
->setMethods(['getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$storage = $this->createMock(\OC\Files\Storage\Storage::class);
$mount1 = new MountPoint($storage, '/bar');
@ -697,7 +697,7 @@ class FolderTest extends NodeTest {
$view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)
->setMethods(['getUser', 'getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$view->expects($this->any())
@ -725,7 +725,7 @@ class FolderTest extends NodeTest {
/** @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, $this->logger, $this->userManager])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\FileInfo $folderInfo */
$folderInfo = $this->getMockBuilder(FileInfo::class)
@ -793,7 +793,7 @@ class FolderTest extends NodeTest {
/** @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, $this->logger, $this->userManager])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\FileInfo $folderInfo */
$folderInfo = $this->getMockBuilder(FileInfo::class)
@ -860,7 +860,7 @@ class FolderTest extends NodeTest {
/** @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, $this->logger, $this->userManager])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\FileInfo $folderInfo */
$folderInfo = $this->getMockBuilder(FileInfo::class)
@ -947,7 +947,7 @@ class FolderTest extends NodeTest {
*/
$view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$root->expects($this->any())
->method('getUser')

View File

@ -78,7 +78,8 @@ class HookConnectorTest extends TestCase {
\OC::$server->getUserManager()->get($this->userId),
\OC::$server->getUserMountCache(),
$this->createMock(ILogger::class),
$this->createMock(IUserManager::class)
$this->createMock(IUserManager::class),
$this->createMock(IEventDispatcher::class)
);
$this->legacyDispatcher = \OC::$server->getEventDispatcher();
$this->eventDispatcher = \OC::$server->query(IEventDispatcher::class);

View File

@ -11,9 +11,11 @@ namespace Test\Files\Node;
use OC\Files\Node\Root;
use OC\Files\Storage\Temporary;
use OC\Files\View;
use OC\User\User;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Mount\IMountManager;
use OCP\ILogger;
use OCP\IUserManager;
use Test\Traits\UserTrait;
/**
* Class IntegrationTest
@ -23,6 +25,8 @@ use OCP\IUserManager;
* @package Test\Files\Node
*/
class IntegrationTest extends \Test\TestCase {
use UserTrait;
/**
* @var \OC\Files\Node\Root $root
*/
@ -41,11 +45,12 @@ class IntegrationTest extends \Test\TestCase {
protected function setUp(): void {
parent::setUp();
$manager = \OC\Files\Filesystem::getMountManager();
/** @var IMountManager $manager */
$manager = \OC::$server->get(IMountManager::class);
\OC_Hook::clear('OC_Filesystem');
$user = new User($this->getUniqueID('user'), new \Test\Util\User\Dummy, \OC::$server->getEventDispatcher());
$user = $this->createUser($this->getUniqueID('user'), '');
$this->loginAsUser($user->getUID());
$this->view = new View();
@ -55,7 +60,8 @@ class IntegrationTest extends \Test\TestCase {
$user,
\OC::$server->getUserMountCache(),
$this->createMock(ILogger::class),
$this->createMock(IUserManager::class)
$this->createMock(IUserManager::class),
$this->createMock(IEventDispatcher::class)
);
$storage = new Temporary([]);
$subStorage = new Temporary([]);
@ -63,6 +69,7 @@ class IntegrationTest extends \Test\TestCase {
$this->storages[] = $subStorage;
$this->root->mount($storage, '/');
$this->root->mount($subStorage, '/substorage/');
$manager->removeMount('/' . $user->getUID());
}
protected function tearDown(): void {

View File

@ -11,6 +11,7 @@ namespace Test\Files\Node;
use OC\Files\FileInfo;
use OC\Files\Mount\Manager;
use OC\Files\View;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
@ -39,6 +40,8 @@ abstract class NodeTest extends \Test\TestCase {
protected $logger;
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
protected $userManager;
/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
protected $eventDispatcher;
protected function setUp(): void {
parent::setUp();
@ -55,8 +58,9 @@ abstract class NodeTest extends \Test\TestCase {
->getMock();
$this->logger = $this->createMock(ILogger::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->root = $this->getMockBuilder('\OC\Files\Node\Root')
->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->eventDispatcher])
->getMock();
}
@ -151,7 +155,8 @@ abstract class NodeTest extends \Test\TestCase {
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
$this->userManager,
$this->eventDispatcher
);
$root->listen('\OC\Files', 'preDelete', $preListener);
@ -409,7 +414,8 @@ abstract class NodeTest extends \Test\TestCase {
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
$this->userManager,
$this->eventDispatcher
);
$root->listen('\OC\Files', 'preTouch', $preListener);
$root->listen('\OC\Files', 'postTouch', $postListener);
@ -592,7 +598,7 @@ abstract class NodeTest extends \Test\TestCase {
public function testMoveCopyHooks($operationMethod, $viewMethod, $preHookName, $postHookName) {
/** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject $root */
$root = $this->getMockBuilder('\OC\Files\Node\Root')
->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->setMethods(['get'])
->getMock();

View File

@ -13,6 +13,7 @@ use OC\Files\FileInfo;
use OC\Files\Mount\Manager;
use OC\Files\Node\Folder;
use OC\Files\View;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\ILogger;
use OCP\IUser;
use OCP\IUserManager;
@ -33,6 +34,8 @@ class RootTest extends \Test\TestCase {
private $logger;
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
private $userManager;
/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
private $eventDispatcher;
protected function setUp(): void {
parent::setUp();
@ -46,6 +49,7 @@ class RootTest extends \Test\TestCase {
->getMock();
$this->logger = $this->createMock(ILogger::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
}
protected function getFileInfo($data) {
@ -71,7 +75,8 @@ class RootTest extends \Test\TestCase {
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
$this->userManager,
$this->eventDispatcher
);
$view->expects($this->once())
@ -107,7 +112,8 @@ class RootTest extends \Test\TestCase {
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
$this->userManager,
$this->eventDispatcher
);
$view->expects($this->once())
@ -135,7 +141,8 @@ class RootTest extends \Test\TestCase {
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
$this->userManager,
$this->eventDispatcher
);
$root->get('/../foo');
@ -157,7 +164,8 @@ class RootTest extends \Test\TestCase {
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
$this->userManager,
$this->eventDispatcher
);
$root->get('/bar/foo');
@ -170,7 +178,8 @@ class RootTest extends \Test\TestCase {
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager
$this->userManager,
$this->eventDispatcher
);
$user = $this->createMock(IUser::class);
$user
@ -210,7 +219,8 @@ class RootTest extends \Test\TestCase {
null,
$this->userMountCache,
$this->logger,
$this->userManager
$this->userManager,
$this->eventDispatcher
);
$this->userManager
->expects($this->once())

View File

@ -30,7 +30,7 @@ class PathVerificationTest extends \Test\TestCase {
$this->view = new View();
}
public function testPathVerificationFileNameTooLong() {
$this->expectException(\OCP\Files\InvalidPathException::class);
$this->expectExceptionMessage('File name is too long');

View File

@ -11,6 +11,7 @@ use OC\Cache\CappedMemoryCache;
use OC\Files\Cache\Watcher;
use OC\Files\Filesystem;
use OC\Files\Mount\MountPoint;
use OC\Files\SetupManager;
use OC\Files\Storage\Common;
use OC\Files\Storage\Storage;
use OC\Files\Storage\Temporary;
@ -19,6 +20,7 @@ use OCP\Constants;
use OCP\Files\Config\IMountProvider;
use OCP\Files\FileInfo;
use OCP\Files\GenericFileException;
use OCP\Files\Mount\IMountManager;
use OCP\Files\Storage\IStorage;
use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
@ -104,9 +106,10 @@ class ViewTest extends \Test\TestCase {
$this->groupObject->addUser($this->userObject);
self::loginAsUser($this->user);
// clear mounts but somehow keep the root storage
// that was initialized above...
Filesystem::clearMounts();
/** @var IMountManager $manager */
$manager = \OC::$server->get(IMountManager::class);
$manager->removeMount('/test');
$this->tempStorage = null;
}
@ -125,6 +128,10 @@ class ViewTest extends \Test\TestCase {
self::logout();
/** @var SetupManager $setupManager */
$setupManager = \OC::$server->get(SetupManager::class);
$setupManager->setupRoot();
$this->userObject->delete();
$this->groupObject->delete();
@ -224,12 +231,14 @@ class ViewTest extends \Test\TestCase {
$storage1 = $this->getTestStorage();
$storage2 = $this->getTestStorage();
$storage3 = $this->getTestStorage();
Filesystem::mount($storage1, [], '/');
Filesystem::mount($storage2, [], '/substorage');
Filesystem::mount($storage3, [], '/folder/anotherstorage');
$rootView = new View('');
$cachedData = $rootView->getFileInfo('/foo.txt');
/** @var int $id1 */
$id1 = $cachedData['fileid'];
@ -316,7 +325,6 @@ class ViewTest extends \Test\TestCase {
public function testCacheIncompleteFolder() {
$storage1 = $this->getTestStorage(false);
Filesystem::clearMounts();
Filesystem::mount($storage1, [], '/incomplete');
$rootView = new View('/incomplete');

View File

@ -9,6 +9,8 @@
namespace Test;
use OC\Files\Storage\Temporary;
use OCP\Files\Mount\IMountManager;
use Test\Traits\UserTrait;
/**
* Test the storage functions of OC_Helper
@ -16,6 +18,8 @@ use OC\Files\Storage\Temporary;
* @group DB
*/
class HelperStorageTest extends \Test\TestCase {
use UserTrait;
/** @var string */
private $user;
/** @var \OC\Files\Storage\Storage */
@ -27,14 +31,15 @@ class HelperStorageTest extends \Test\TestCase {
parent::setUp();
$this->user = $this->getUniqueID('user_');
\OC_User::useBackend('dummy');
\OC::$server->getUserManager()->createUser($this->user, $this->user);
$this->createUser($this->user, $this->user);
$this->storage = \OC\Files\Filesystem::getStorage('/');
\OC\Files\Filesystem::tearDown();
\OC_User::setUserId($this->user);
\OC\Files\Filesystem::init($this->user, '/' . $this->user . '/files');
\OC\Files\Filesystem::clearMounts();
/** @var IMountManager $manager */
$manager = \OC::$server->get(IMountManager::class);
$manager->removeMount('/' . $this->user);
$this->storageMock = null;
}
@ -47,13 +52,8 @@ class HelperStorageTest extends \Test\TestCase {
$this->storageMock = null;
}
\OC\Files\Filesystem::tearDown();
\OC\Files\Filesystem::mount($this->storage, [], '/');
\OC_User::setUserId('');
$user = \OC::$server->getUserManager()->get($this->user);
if ($user !== null) {
$user->delete();
}
\OC::$server->getConfig()->deleteAllUserValues($this->user);
parent::tearDown();

View File

@ -49,6 +49,8 @@ class SubAdminTest extends \Test\TestCase {
private $groups;
protected function setUp(): void {
parent::setUp();
$this->users = [];
$this->groups = [];

View File

@ -25,14 +25,21 @@ namespace Test;
use DOMDocument;
use DOMNode;
use OC\Command\QueueBus;
use OC\Files\Config\MountProviderCollection;
use OC\Files\Filesystem;
use OC\Files\Mount\CacheMountProvider;
use OC\Files\Mount\LocalHomeMountProvider;
use OC\Files\Mount\RootMountProvider;
use OC\Files\SetupManager;
use OC\Template\Base;
use OCP\Command\IBus;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Defaults;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface;
abstract class TestCase extends \PHPUnit\Framework\TestCase {
/** @var \OC\Command\QueueBus */
@ -276,6 +283,22 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
self::tearDownAfterClassCleanStrayHooks();
self::tearDownAfterClassCleanStrayLocks();
/** @var SetupManager $setupManager */
$setupManager = \OC::$server->get(SetupManager::class);
$setupManager->tearDown();
/** @var MountProviderCollection $mountProviderCollection */
$mountProviderCollection = \OC::$server->get(MountProviderCollection::class);
$mountProviderCollection->clearProviders();
/** @var IConfig $config */
$config = \OC::$server->get(IConfig::class);
$mountProviderCollection->registerProvider(new CacheMountProvider($config));
$mountProviderCollection->registerHomeProvider(new LocalHomeMountProvider());
$mountProviderCollection->registerRootProvider(new RootMountProvider($config, \OC::$server->get(LoggerInterface::class)));
$setupManager->setupRoot();
parent::tearDownAfterClass();
}

View File

@ -9,12 +9,13 @@
namespace Test\Traits;
use OC\Encryption\EncryptionWrapper;
use OC\Files\Filesystem;
use OC\Files\SetupManager;
use OC\Memcache\ArrayCache;
use OCA\Encryption\AppInfo\Application;
use OCA\Encryption\KeyManager;
use OCA\Encryption\Users\Setup;
use OCP\Encryption\IManager;
use OCP\IUserManager;
/**
* Enables encryption
@ -31,6 +32,11 @@ trait EncryptionTrait {
private $originalEncryptionModule;
/** @var IUserManager */
private $userManager;
/** @var SetupManager */
private $setupManager;
/**
* @var \OCP\IConfig
*/
@ -47,18 +53,20 @@ trait EncryptionTrait {
// needed for fully logout
\OC::$server->getUserSession()->setUser(null);
Filesystem::tearDown();
$this->setupManager->tearDown();
\OC_User::setUserId($user);
$this->postLogin();
\OC_Util::setupFS($user);
if (\OC::$server->getUserManager()->userExists($user)) {
if ($this->userManager->userExists($user)) {
\OC::$server->getUserFolder($user);
}
}
protected function setupForUser($name, $password) {
\OC_Util::tearDownFS();
\OC_Util::setupFS($name);
$this->setupManager->tearDown();
$this->setupManager->setupForUser($this->userManager->get($name));
$container = $this->encryptionApp->getContainer();
/** @var KeyManager $keyManager */
$keyManager = $container->query(KeyManager::class);
@ -86,6 +94,9 @@ trait EncryptionTrait {
$this->markTestSkipped('Encryption not ready');
}
$this->userManager = \OC::$server->get(IUserManager::class);
$this->setupManager = \OC::$server->get(SetupManager::class);
\OC_App::loadApp('encryption');
$this->encryptionApp = new Application([], $isReady);

View File

@ -8,6 +8,21 @@
namespace Test\Traits;
use OC\User\User;
use OCP\IUser;
class DummyUser extends User {
private string $uid;
public function __construct(string $uid) {
$this->uid = $uid;
}
public function getUID(): string {
return $this->uid;
}
}
/**
* Allow creating users in a temporary backend
*/
@ -17,8 +32,9 @@ trait UserTrait {
*/
protected $userBackend;
protected function createUser($name, $password) {
protected function createUser($name, $password): IUser {
$this->userBackend->createUser($name, $password);
return new DummyUser($name);
}
protected function setUpUserTrait() {