diff options
author | Robin Appelman <robin@icewind.nl> | 2022-02-23 18:29:08 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2022-03-04 16:29:59 +0100 |
commit | 1c468129afa2b2ec4a370a879f8eaffd22768baf (patch) | |
tree | 1c096e8c0a62371965104684e1f1bf2ef55eb2d4 /tests | |
parent | 5c0fe934988960ece3ac71d5a1dfc8df405413aa (diff) | |
download | nextcloud-server-1c468129afa2b2ec4a370a879f8eaffd22768baf.tar.gz nextcloud-server-1c468129afa2b2ec4a370a879f8eaffd22768baf.zip |
adjust tests to new fs setup
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Cache/FileCacheTest.php | 19 | ||||
-rw-r--r-- | tests/lib/Files/Cache/UpdaterLegacyTest.php | 6 | ||||
-rw-r--r-- | tests/lib/Files/Cache/UpdaterTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Files/Config/UserMountCacheTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Files/Mount/ManagerTest.php | 13 | ||||
-rw-r--r-- | tests/lib/Files/Node/FileTest.php | 25 | ||||
-rw-r--r-- | tests/lib/Files/Node/FolderTest.php | 44 | ||||
-rw-r--r-- | tests/lib/Files/Node/HookConnectorTest.php | 3 | ||||
-rw-r--r-- | tests/lib/Files/Node/IntegrationTest.php | 15 | ||||
-rw-r--r-- | tests/lib/Files/Node/NodeTest.php | 14 | ||||
-rw-r--r-- | tests/lib/Files/Node/RootTest.php | 22 | ||||
-rw-r--r-- | tests/lib/Files/PathVerificationTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Files/ViewTest.php | 16 | ||||
-rw-r--r-- | tests/lib/HelperStorageTest.php | 18 | ||||
-rw-r--r-- | tests/lib/SubAdminTest.php | 2 | ||||
-rw-r--r-- | tests/lib/TestCase.php | 23 | ||||
-rw-r--r-- | tests/lib/Traits/EncryptionTrait.php | 21 | ||||
-rw-r--r-- | tests/lib/Traits/UserTrait.php | 18 |
18 files changed, 179 insertions, 86 deletions
diff --git a/tests/lib/Cache/FileCacheTest.php b/tests/lib/Cache/FileCacheTest.php index a800fd005d9..41675b7c461 100644 --- a/tests/lib/Cache/FileCacheTest.php +++ b/tests/lib/Cache/FileCacheTest.php @@ -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(); } diff --git a/tests/lib/Files/Cache/UpdaterLegacyTest.php b/tests/lib/Files/Cache/UpdaterLegacyTest.php index 6d6cc08b3de..be0390db15e 100644 --- a/tests/lib/Files/Cache/UpdaterLegacyTest.php +++ b/tests/lib/Files/Cache/UpdaterLegacyTest.php @@ -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'); diff --git a/tests/lib/Files/Cache/UpdaterTest.php b/tests/lib/Files/Cache/UpdaterTest.php index 4c99b24d9d6..7e0f6866793 100644 --- a/tests/lib/Files/Cache/UpdaterTest.php +++ b/tests/lib/Files/Cache/UpdaterTest.php @@ -50,8 +50,6 @@ class UpdaterTest extends \Test\TestCase { } protected function tearDown(): void { - Filesystem::clearMounts(); - $this->logout(); parent::tearDown(); } diff --git a/tests/lib/Files/Config/UserMountCacheTest.php b/tests/lib/Files/Config/UserMountCacheTest.php index 321ed2196fd..0922dab3672 100644 --- a/tests/lib/Files/Config/UserMountCacheTest.php +++ b/tests/lib/Files/Config/UserMountCacheTest.php @@ -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) diff --git a/tests/lib/Files/Mount/ManagerTest.php b/tests/lib/Files/Mount/ManagerTest.php index 1e80ec17ea1..3fd994edd56 100644 --- a/tests/lib/Files/Mount/ManagerTest.php +++ b/tests/lib/Files/Mount/ManagerTest.php @@ -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('/')); diff --git a/tests/lib/Files/Node/FileTest.php b/tests/lib/Files/Node/FileTest.php index 6b5aaabbc28..c381fd9b2be 100644 --- a/tests/lib/Files/Node/FileTest.php +++ b/tests/lib/Files/Node/FileTest.php @@ -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'); diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php index 72bd15d3922..d604786905d 100644 --- a/tests/lib/Files/Node/FolderTest.php +++ b/tests/lib/Files/Node/FolderTest.php @@ -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') diff --git a/tests/lib/Files/Node/HookConnectorTest.php b/tests/lib/Files/Node/HookConnectorTest.php index 7990abad231..5e0b4017243 100644 --- a/tests/lib/Files/Node/HookConnectorTest.php +++ b/tests/lib/Files/Node/HookConnectorTest.php @@ -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); diff --git a/tests/lib/Files/Node/IntegrationTest.php b/tests/lib/Files/Node/IntegrationTest.php index 26cdf398d94..71e8793ad6f 100644 --- a/tests/lib/Files/Node/IntegrationTest.php +++ b/tests/lib/Files/Node/IntegrationTest.php @@ -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 { diff --git a/tests/lib/Files/Node/NodeTest.php b/tests/lib/Files/Node/NodeTest.php index 6ea5a6d7ffa..a60a20b99f3 100644 --- a/tests/lib/Files/Node/NodeTest.php +++ b/tests/lib/Files/Node/NodeTest.php @@ -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(); diff --git a/tests/lib/Files/Node/RootTest.php b/tests/lib/Files/Node/RootTest.php index 13fdcb65902..a7f7dc02e01 100644 --- a/tests/lib/Files/Node/RootTest.php +++ b/tests/lib/Files/Node/RootTest.php @@ -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()) diff --git a/tests/lib/Files/PathVerificationTest.php b/tests/lib/Files/PathVerificationTest.php index 18637daf9d7..3570acfaab4 100644 --- a/tests/lib/Files/PathVerificationTest.php +++ b/tests/lib/Files/PathVerificationTest.php @@ -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'); diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php index 15c9400864b..7b735720ff1 100644 --- a/tests/lib/Files/ViewTest.php +++ b/tests/lib/Files/ViewTest.php @@ -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'); diff --git a/tests/lib/HelperStorageTest.php b/tests/lib/HelperStorageTest.php index 4166d606366..6d7ea513d3f 100644 --- a/tests/lib/HelperStorageTest.php +++ b/tests/lib/HelperStorageTest.php @@ -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(); diff --git a/tests/lib/SubAdminTest.php b/tests/lib/SubAdminTest.php index a3a795ce392..907abf4b7d8 100644 --- a/tests/lib/SubAdminTest.php +++ b/tests/lib/SubAdminTest.php @@ -49,6 +49,8 @@ class SubAdminTest extends \Test\TestCase { private $groups; protected function setUp(): void { + parent::setUp(); + $this->users = []; $this->groups = []; diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php index b5dcd76faf9..256fb95a85b 100644 --- a/tests/lib/TestCase.php +++ b/tests/lib/TestCase.php @@ -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(); } diff --git a/tests/lib/Traits/EncryptionTrait.php b/tests/lib/Traits/EncryptionTrait.php index 6b74f7ca8ee..9cb64c12d00 100644 --- a/tests/lib/Traits/EncryptionTrait.php +++ b/tests/lib/Traits/EncryptionTrait.php @@ -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); diff --git a/tests/lib/Traits/UserTrait.php b/tests/lib/Traits/UserTrait.php index 229087a5200..3f7cfe419db 100644 --- a/tests/lib/Traits/UserTrait.php +++ b/tests/lib/Traits/UserTrait.php @@ -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() { |