diff --git a/apps/comments/lib/Search/CommentsSearchProvider.php b/apps/comments/lib/Search/CommentsSearchProvider.php index 4d316525f9bc6..8b9d9f1f46a70 100644 --- a/apps/comments/lib/Search/CommentsSearchProvider.php +++ b/apps/comments/lib/Search/CommentsSearchProvider.php @@ -53,10 +53,6 @@ public function getOrder(string $route, array $routeParameters): int { public function search(IUser $user, ISearchQuery $query): SearchResult { $userFolder = $this->rootFolder->getUserFolder($user->getUID()); - if ($userFolder === null) { - return SearchResult::complete($this->l10n->t('Comments'), []); - } - $result = []; $numComments = 50; $offset = 0; diff --git a/apps/comments/tests/Unit/Activity/ListenerTest.php b/apps/comments/tests/Unit/Activity/ListenerTest.php index 358fd1b3af2f4..882c7e903e096 100644 --- a/apps/comments/tests/Unit/Activity/ListenerTest.php +++ b/apps/comments/tests/Unit/Activity/ListenerTest.php @@ -17,8 +17,8 @@ use OCP\Files\Config\ICachedMountFileInfo; use OCP\Files\Config\IMountProviderCollection; use OCP\Files\Config\IUserMountCache; -use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Node; use OCP\IUser; use OCP\IUserSession; @@ -93,7 +93,7 @@ public function testCommentEvent(): void { $node = $this->createMock(Node::class); - $ownerFolder = $this->createMock(Folder::class); + $ownerFolder = $this->createMock(IUserFolder::class); $ownerFolder->expects($this->any()) ->method('getFirstNodeById') ->willReturn($node); diff --git a/apps/comments/tests/Unit/Controller/NotificationsTest.php b/apps/comments/tests/Unit/Controller/NotificationsTest.php index 5b1180f662b60..ed6e834629452 100644 --- a/apps/comments/tests/Unit/Controller/NotificationsTest.php +++ b/apps/comments/tests/Unit/Controller/NotificationsTest.php @@ -15,8 +15,8 @@ use OCP\Comments\IComment; use OCP\Comments\ICommentsManager; use OCP\Comments\NotFoundException; -use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Node; use OCP\IRequest; use OCP\IURLGenerator; @@ -99,7 +99,7 @@ public function testViewSuccess(): void { ->willReturn($comment); $file = $this->createMock(Node::class); - $folder = $this->createMock(Folder::class); + $folder = $this->createMock(IUserFolder::class); $user = $this->createMock(IUser::class); $this->rootFolder->expects($this->once()) @@ -176,7 +176,7 @@ public function testViewNoFile(): void { ->with('42') ->willReturn($comment); - $folder = $this->createMock(Folder::class); + $folder = $this->createMock(IUserFolder::class); $this->rootFolder->expects($this->once()) ->method('getUserFolder') diff --git a/apps/comments/tests/Unit/Notification/NotifierTest.php b/apps/comments/tests/Unit/Notification/NotifierTest.php index cd2d1be14080d..01c6c4c869ef8 100644 --- a/apps/comments/tests/Unit/Notification/NotifierTest.php +++ b/apps/comments/tests/Unit/Notification/NotifierTest.php @@ -12,8 +12,8 @@ use OCP\Comments\IComment; use OCP\Comments\ICommentsManager; use OCP\Comments\NotFoundException; -use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Node; use OCP\IL10N; use OCP\IURLGenerator; @@ -80,7 +80,7 @@ public function testPrepareSuccess(): void { ->method('getPath') ->willReturn('/you/files/' . $fileName); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->folder->expects($this->once()) ->method('getUserFolder') ->with('you') @@ -196,7 +196,7 @@ public function testPrepareSuccessDeletedUser(): void { ->method('getPath') ->willReturn('/you/files/' . $fileName); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->folder->expects($this->once()) ->method('getUserFolder') ->with('you') @@ -491,7 +491,7 @@ public function testPrepareUnresolvableFileID(): void { $displayName = 'Huraga'; - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->folder->expects($this->once()) ->method('getUserFolder') ->with('you') diff --git a/apps/dav/lib/Files/RootCollection.php b/apps/dav/lib/Files/RootCollection.php index 2c01d1ff4baa2..5fb52289de7b3 100644 --- a/apps/dav/lib/Files/RootCollection.php +++ b/apps/dav/lib/Files/RootCollection.php @@ -7,7 +7,6 @@ */ namespace OCA\DAV\Files; -use OCP\Files\FileInfo; use OCP\Files\IRootFolder; use OCP\IUserSession; use OCP\Server; @@ -37,9 +36,6 @@ public function getChildForPrincipal(array $principalInfo) { return new SimpleCollection($name); } $userFolder = Server::get(IRootFolder::class)->getUserFolder($user->getUID()); - if (!($userFolder instanceof FileInfo)) { - throw new \Exception('Home does not exist'); - } return new FilesHome($principalInfo, $userFolder); } diff --git a/apps/dav/tests/unit/Controller/DirectControllerTest.php b/apps/dav/tests/unit/Controller/DirectControllerTest.php index 837adde1da7fd..16cb14baeb86c 100644 --- a/apps/dav/tests/unit/Controller/DirectControllerTest.php +++ b/apps/dav/tests/unit/Controller/DirectControllerTest.php @@ -19,6 +19,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\IRequest; use OCP\IURLGenerator; use OCP\Security\ISecureRandom; @@ -59,7 +60,7 @@ protected function setUp(): void { } public function testGetUrlNonExistingFileId(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with('awesomeUser') ->willReturn($userFolder); @@ -73,7 +74,7 @@ public function testGetUrlNonExistingFileId(): void { } public function testGetUrlForFolder(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with('awesomeUser') ->willReturn($userFolder); @@ -89,7 +90,7 @@ public function testGetUrlForFolder(): void { } public function testGetUrlValid(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with('awesomeUser') ->willReturn($userFolder); diff --git a/apps/dav/tests/unit/Direct/DirectFileTest.php b/apps/dav/tests/unit/Direct/DirectFileTest.php index f6f0f49fa8c37..e3b95cd4347c1 100644 --- a/apps/dav/tests/unit/Direct/DirectFileTest.php +++ b/apps/dav/tests/unit/Direct/DirectFileTest.php @@ -12,8 +12,8 @@ use OCA\DAV\Direct\DirectFile; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\File; -use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use PHPUnit\Framework\MockObject\MockObject; use Sabre\DAV\Exception\Forbidden; use Test\TestCase; @@ -21,7 +21,7 @@ class DirectFileTest extends TestCase { private Direct $direct; private IRootFolder&MockObject $rootFolder; - private Folder&MockObject $userFolder; + private IUserFolder&MockObject $userFolder; private File&MockObject $file; private IEventDispatcher&MockObject $eventDispatcher; private DirectFile $directFile; @@ -37,7 +37,7 @@ protected function setUp(): void { $this->rootFolder = $this->createMock(IRootFolder::class); - $this->userFolder = $this->createMock(Folder::class); + $this->userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with('directUser') ->willReturn($this->userFolder); diff --git a/apps/files/tests/Command/DeleteOrphanedFilesTest.php b/apps/files/tests/Command/DeleteOrphanedFilesTest.php index 13c7a36785ae6..7814242a84194 100644 --- a/apps/files/tests/Command/DeleteOrphanedFilesTest.php +++ b/apps/files/tests/Command/DeleteOrphanedFilesTest.php @@ -11,6 +11,7 @@ use OC\Files\View; use OCA\Files\Command\DeleteOrphanedFiles; use OCP\Files\IRootFolder; +use OCP\Files\NotFoundException; use OCP\Files\StorageNotAvailableException; use OCP\IDBConnection; use OCP\IUserManager; @@ -46,6 +47,13 @@ protected function setUp(): void { } protected function tearDown(): void { + // since we deleted the storage it might throw a (valid) StorageNotAvailableException + try { + $view = new View('/' . $this->user1 . '/files'); + $view->unlink('test'); + } catch (StorageNotAvailableException|NotFoundException $e) { + } + $userManager = Server::get(IUserManager::class); $user1 = $userManager->get($this->user1); if ($user1) { @@ -87,10 +95,10 @@ public function testClearFiles(): void { $this->loginAsUser($this->user1); - $view = new View('/' . $this->user1 . '/'); - $view->mkdir('files/test'); + $view = new View('/' . $this->user1 . '/files'); + $view->mkdir('test'); - $fileInfo = $view->getFileInfo('files/test'); + $fileInfo = $view->getFileInfo('test'); $storageId = $fileInfo->getStorage()->getId(); $numericStorageId = $fileInfo->getStorage()->getCache()->getNumericStorageId(); @@ -126,13 +134,5 @@ public function testClearFiles(): void { $this->assertCount(0, $this->getFile($fileInfo->getId()), 'Asserts that file gets cleaned up'); $this->assertEquals(0, $this->getMountsCount($numericStorageId), 'Asserts that mount gets cleaned up'); - - // Rescan folder to add back to cache before deleting - $rootFolder->getUserFolder($this->user1)->getStorage()->getScanner()->scan(''); - // since we deleted the storage it might throw a (valid) StorageNotAvailableException - try { - $view->unlink('files/test'); - } catch (StorageNotAvailableException $e) { - } } } diff --git a/apps/files/tests/Controller/ConversionApiControllerTest.php b/apps/files/tests/Controller/ConversionApiControllerTest.php index 659fbe1a9560d..a994d3374d725 100644 --- a/apps/files/tests/Controller/ConversionApiControllerTest.php +++ b/apps/files/tests/Controller/ConversionApiControllerTest.php @@ -14,8 +14,8 @@ use OCP\AppFramework\OCS\OCSNotFoundException; use OCP\Files\Conversion\IConversionManager; use OCP\Files\File; -use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\IL10N; use OCP\IRequest; use PHPUnit\Framework\MockObject\MockObject; @@ -33,7 +33,7 @@ class ConversionApiControllerTest extends TestCase { private IConversionManager&MockObject $fileConversionManager; private IRootFolder&MockObject $rootFolder; private File&MockObject $file; - private Folder&MockObject $userFolder; + private IUserFolder&MockObject $userFolder; private IL10N&MockObject $l10n; private string $user; @@ -46,7 +46,7 @@ protected function setUp(): void { $this->l10n = $this->createMock(IL10N::class); $this->user = 'userid'; - $this->userFolder = $this->createMock(Folder::class); + $this->userFolder = $this->createMock(IUserFolder::class); $this->rootFolder = $this->createMock(IRootFolder::class); $this->rootFolder->method('getUserFolder')->with($this->user)->willReturn($this->userFolder); diff --git a/apps/files/tests/Controller/ViewControllerTest.php b/apps/files/tests/Controller/ViewControllerTest.php index 631097cbc6019..733dcda1cc092 100644 --- a/apps/files/tests/Controller/ViewControllerTest.php +++ b/apps/files/tests/Controller/ViewControllerTest.php @@ -25,6 +25,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Template\ITemplateManager; use OCP\ICacheFactory; use OCP\IConfig; @@ -173,7 +174,7 @@ public function testIndexWithRegularBrowser(): void { [$this->user->getUID(), 'files', 'show_grid', true], ]); - $baseFolderFiles = $this->getMockBuilder(Folder::class)->getMock(); + $baseFolderFiles = $this->getMockBuilder(IUserFolder::class)->getMock(); $this->rootFolder->expects($this->any()) ->method('getUserFolder') @@ -221,7 +222,7 @@ public function testShortRedirect(?string $openfile, ?string $opendetails, strin ->with('files') ->willReturn(true); - $baseFolderFiles = $this->getMockBuilder(Folder::class)->getMock(); + $baseFolderFiles = $this->getMockBuilder(IUserFolder::class)->getMock(); $this->rootFolder->expects($this->any()) ->method('getUserFolder') ->with('testuser1') @@ -256,7 +257,7 @@ public function testShowFileRouteWithTrashedFile(): void { ->method('getPath') ->willReturn('testuser1/files_trashbin/files/test.d1462861890/sub'); - $baseFolderFiles = $this->createMock(Folder::class); + $baseFolderFiles = $this->createMock(IUserFolder::class); $baseFolderTrash = $this->createMock(Folder::class); $this->rootFolder->expects($this->any()) diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php index e0340b3ce0015..62c55c11b63fa 100644 --- a/apps/files_sharing/tests/ApiTest.php +++ b/apps/files_sharing/tests/ApiTest.php @@ -85,7 +85,7 @@ protected function setUp(): void { $mount = $this->view->getMount($this->filename); $mount->getStorage()->getScanner()->scan('', Scanner::SCAN_RECURSIVE); - $this->userFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1); + $this->userFolder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_FILES_SHARING_API_USER1); $this->appConfig = $this->createMock(IAppConfig::class); } diff --git a/apps/files_sharing/tests/ApplicationTest.php b/apps/files_sharing/tests/ApplicationTest.php index a6ff620722a5d..1379aa7428901 100644 --- a/apps/files_sharing/tests/ApplicationTest.php +++ b/apps/files_sharing/tests/ApplicationTest.php @@ -18,6 +18,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Storage\IStorage; use OCP\IUser; use OCP\IUserSession; @@ -78,7 +79,7 @@ public function testCheckDirectCanBeDownloaded( $file = $this->createMock(File::class); $file->method('getStorage')->willReturn($fileStorage); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userFolder->method('get')->willReturn($file); $user = $this->createMock(IUser::class); @@ -166,7 +167,7 @@ function (string $fileStorage) use ($nonSharedStorage, $secureSharedStorage) { $rootFolder->method('getStorage')->willReturn($nonSharedStorage); $rootFolder->method('getDirectoryListing')->willReturn([$folder]); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userFolder->method('get')->willReturn($rootFolder); $user = $this->createMock(IUser::class); diff --git a/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php b/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php index 2a2e1c2909667..61f94ac6852df 100644 --- a/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php +++ b/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php @@ -7,8 +7,8 @@ namespace OCA\Files_Sharing\Tests\Collaboration; use OCA\Files_Sharing\Collaboration\ShareRecipientSorter; -use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Node; use OCP\IUser; use OCP\IUserSession; @@ -42,8 +42,7 @@ protected function setUp(): void { public function testSort($data): void { $node = $this->createMock(Node::class); - /** @var Folder|\PHPUnit\Framework\MockObject\MockObject $folder */ - $folder = $this->createMock(Folder::class); + $folder = $this->createMock(IUserFolder::class); $this->rootFolder->expects($this->any()) ->method('getUserFolder') ->willReturn($folder); @@ -81,8 +80,7 @@ public function testSort($data): void { } public function testSortNoNodes(): void { - /** @var Folder|\PHPUnit\Framework\MockObject\MockObject $folder */ - $folder = $this->createMock(Folder::class); + $folder = $this->createMock(IUserFolder::class); $this->rootFolder->expects($this->any()) ->method('getUserFolder') ->willReturn($folder); diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php index 28caea90ceae8..241d5cf5edd19 100644 --- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php @@ -24,6 +24,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Mount\IMountPoint; use OCP\Files\Mount\IShareOwnerlessMount; use OCP\Files\NotFoundException; @@ -269,7 +270,7 @@ public function testDeleteShareLocked(): void { $share = $this->newShare(); $share->setNode($node); - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); + $userFolder = $this->getMockBuilder(IUserFolder::class)->getMock(); $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -434,7 +435,7 @@ public function testDeleteSharedWithMyGroup(): void { ->method('lock') ->with(ILockingProvider::LOCK_SHARED); - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); + $userFolder = $this->getMockBuilder(IUserFolder::class)->getMock(); $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -497,7 +498,7 @@ public function testDeleteSharedWithGroupIDontBelongTo(): void { ->method('lock') ->with(ILockingProvider::LOCK_SHARED); - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); + $userFolder = $this->getMockBuilder(IUserFolder::class)->getMock(); $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -533,7 +534,7 @@ public function testDeleteShareOwnerless(): void { ->method('getMountPoint') ->willReturn($mount); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userFolder->method('getById') ->with(2) ->willReturn([$file]); @@ -912,7 +913,7 @@ public function testGetShare(array $shareParams, array $result, bool $attributes ->with($share->getFullId(), 'currentUser') ->willReturn($share); - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $userFolder ->method('getRelativePath') ->willReturnArgument(0); @@ -978,7 +979,7 @@ public function testGetShareInvalidNode(): void { ->with('ocinternal:42', 'currentUser') ->willReturn($share); - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -1627,7 +1628,7 @@ function ($share) { } ); - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $userFolder->method('get') ->with('path') ->willReturn($this->mockSimpleNode(...$getSharesParameters['node'])); @@ -1697,7 +1698,7 @@ public function testCannotAccessLinkShare(): void { $share->method('getShareType')->willReturn(IShare::TYPE_LINK); $share->method('getNodeId')->willReturn(42); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -1714,7 +1715,7 @@ public function testCanAccessShareWithPermissions(int $permissions, bool $expect $file = $this->createMock(File::class); - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $userFolder->method('getFirstNodeById') ->with($share->getNodeId()) ->willReturn($file); @@ -1752,7 +1753,7 @@ public function testCanAccessShareAsGroupMember(string $group, bool $expected): $file = $this->createMock(File::class); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userFolder->method('getFirstNodeById') ->with($share->getNodeId()) ->willReturn($file); @@ -1813,7 +1814,7 @@ public function testCanAccessRoomShare( $share->method('getShareType')->willReturn(IShare::TYPE_ROOM); $share->method('getSharedWith')->willReturn('recipientRoom'); - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -1862,7 +1863,7 @@ public function testCreateShareInvalidPath(): void { $this->expectException(OCSNotFoundException::class); $this->expectExceptionMessage('Wrong path, file/folder does not exist'); - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->expects($this->once()) ->method('getUserFolder') ->with('currentUser') @@ -2190,10 +2191,11 @@ public function testCreateShareLinkNoLinksAllowed(): void { ['OCA\Files_Sharing\SharedStorage', false], ]); $path->method('getStorage')->willReturn($storage); - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); - $this->rootFolder->method('get')->with('valid-path')->willReturn($path); - $this->rootFolder->method('getById') + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('get')->with('valid-path')->willReturn($path); + $userFolder->method('getById') ->willReturn([]); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); @@ -2216,10 +2218,11 @@ public function testCreateShareLinkNoPublicUpload(): void { ['OCA\Files_Sharing\SharedStorage', false], ]); $path->method('getStorage')->willReturn($storage); - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); - $this->rootFolder->method('get')->with('valid-path')->willReturn($path); - $this->rootFolder->method('getById') + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('get')->with('valid-path')->willReturn($path); + $userFolder->method('getById') ->willReturn([]); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); $this->shareManager->method('shareApiAllowLinks')->willReturn(true); @@ -2243,10 +2246,11 @@ public function testCreateShareLinkPublicUploadFile(): void { $file->method('getId')->willReturn(42); $file->method('getStorage')->willReturn($storage); - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); - $this->rootFolder->method('get')->with('valid-path')->willReturn($file); - $this->rootFolder->method('getById') + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('get')->with('valid-path')->willReturn($file); + $userFolder->method('getById') ->willReturn([]); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); $this->shareManager->method('shareApiAllowLinks')->willReturn(true); @@ -2267,10 +2271,11 @@ public function testCreateShareLinkPublicUploadFolder(): void { ['OCA\Files_Sharing\SharedStorage', false], ]); $path->method('getStorage')->willReturn($storage); - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); - $this->rootFolder->method('get')->with('valid-path')->willReturn($path); - $this->rootFolder->method('getById') + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('get')->with('valid-path')->willReturn($path); + $userFolder->method('getById') ->willReturn([]); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); $this->shareManager->method('shareApiAllowLinks')->willReturn(true); @@ -2306,10 +2311,11 @@ public function testCreateShareLinkPassword(): void { ['OCA\Files_Sharing\SharedStorage', false], ]); $path->method('getStorage')->willReturn($storage); - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); - $this->rootFolder->method('get')->with('valid-path')->willReturn($path); - $this->rootFolder->method('getById') + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('get')->with('valid-path')->willReturn($path); + $userFolder->method('getById') ->willReturn([]); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); $this->shareManager->method('shareApiAllowLinks')->willReturn(true); @@ -2345,10 +2351,11 @@ public function testCreateShareLinkSendPasswordByTalk(): void { ['OCA\Files_Sharing\SharedStorage', false], ]); $path->method('getStorage')->willReturn($storage); - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); - $this->rootFolder->method('get')->with('valid-path')->willReturn($path); - $this->rootFolder->method('getById') + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('get')->with('valid-path')->willReturn($path); + $userFolder->method('getById') ->willReturn([]); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); $this->shareManager->method('shareApiAllowLinks')->willReturn(true); @@ -2392,10 +2399,11 @@ public function testCreateShareLinkSendPasswordByTalkWithTalkDisabled(): void { ]); $path->method('getStorage')->willReturn($storage); $path->method('getPath')->willReturn('valid-path'); - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); - $this->rootFolder->method('get')->with('valid-path')->willReturn($path); - $this->rootFolder->method('getById') + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('get')->with('valid-path')->willReturn($path); + $userFolder->method('getById') ->willReturn([]); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); $this->shareManager->method('shareApiAllowLinks')->willReturn(true); @@ -2430,10 +2438,11 @@ public function testCreateShareValidExpireDate(): void { ['OCA\Files_Sharing\SharedStorage', false], ]); $path->method('getStorage')->willReturn($storage); - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); - $this->rootFolder->method('get')->with('valid-path')->willReturn($path); - $this->rootFolder->method('getById') + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('get')->with('valid-path')->willReturn($path); + $userFolder->method('getById') ->willReturn([]); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); $this->shareManager->method('shareApiAllowLinks')->willReturn(true); @@ -2476,10 +2485,11 @@ public function testCreateShareInvalidExpireDate(): void { ['OCA\Files_Sharing\SharedStorage', false], ]); $path->method('getStorage')->willReturn($storage); - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); - $this->rootFolder->method('get')->with('valid-path')->willReturn($path); - $this->rootFolder->method('getById') + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('get')->with('valid-path')->willReturn($path); + $userFolder->method('getById') ->willReturn([]); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); $this->shareManager->method('shareApiAllowLinks')->willReturn(true); @@ -2835,7 +2845,7 @@ public function testCreateReshareOfFederatedMountNoDeletePermissions(): void { ])->onlyMethods(['formatShare']) ->getMock(); - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->expects($this->exactly(2)) ->method('getUserFolder') ->with('currentUser') @@ -4022,7 +4032,7 @@ public function testUpdateShareOwnerless(): void { ->method('getMountPoint') ->willReturn($mount); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userFolder->method('getById') ->with(2) ->willReturn([$file]); @@ -5000,20 +5010,19 @@ function ($user) { ->with('files_sharing.sharecontroller.showShare', ['token' => 'myToken']) ->willReturn('myLink'); - $this->rootFolder->method('getUserFolder') - ->with($this->currentUser) - ->willReturnSelf(); - $this->dateTimeZone->method('getTimezone')->willReturn(new \DateTimeZone('UTC')); - + $userFolder = $this->createMock(IUserFolder::class); if (!$exception) { - $this->rootFolder->method('getFirstNodeById') + $userFolder->method('getFirstNodeById') ->with($share->getNodeId()) ->willReturn($share->getNode()); - $this->rootFolder->method('getRelativePath') + $userFolder->method('getRelativePath') ->with($share->getNode()->getPath()) ->willReturnArgument(0); } + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); + $this->dateTimeZone->method('getTimezone')->willReturn(new \DateTimeZone('UTC')); + $cm = $this->createMock(\OCP\Contacts\IManager::class); $this->overwriteService(\OCP\Contacts\IManager::class, $cm); @@ -5193,17 +5202,14 @@ public function testFormatRoomShare(array $expects, bool $helperAvailable, array ->setNote('personal note') ->setId(42); - $this->rootFolder->method('getUserFolder') - ->with($this->currentUser) - ->willReturnSelf(); - - $this->rootFolder->method('getFirstNodeById') + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById') ->with($share->getNodeId()) ->willReturn($share->getNode()); - - $this->rootFolder->method('getRelativePath') + $userFolder->method('getRelativePath') ->with($share->getNode()->getPath()) ->willReturnArgument(0); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); if (!$helperAvailable) { $this->appManager->method('isEnabledForUser') @@ -5241,7 +5247,7 @@ public function testFormatRoomShare(array $expects, bool $helperAvailable, array */ private function getNonSharedUserFolder(): array { $node = $this->getMockBuilder(Folder::class)->getMock(); - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ @@ -5258,11 +5264,11 @@ private function getNonSharedUserFolder(): array { } /** - * @return list{Folder, File} + * @return list{IUserFolder, File} */ private function getNonSharedUserFile(): array { $node = $this->getMockBuilder(File::class)->getMock(); - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ @@ -5350,17 +5356,14 @@ public function testFormatShareWithFederatedShare(bool $isKnownServer, bool $isT $this->previewManager->method('isAvailable')->with($node)->willReturn(false); - $this->rootFolder->method('getUserFolder') - ->with($this->currentUser) - ->willReturnSelf(); - - $this->rootFolder->method('getFirstNodeById') + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById') ->with($share->getNodeId()) ->willReturn($node); - - $this->rootFolder->method('getRelativePath') + $userFolder->method('getRelativePath') ->with($node->getPath()) ->willReturnArgument(0); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); $serverName = 'remoteserver.com'; $this->trustedServers->method('isTrustedServer') @@ -5413,17 +5416,14 @@ public function testFormatShareWithFederatedShareWithAtInUsername(): void { $this->previewManager->method('isAvailable')->with($node)->willReturn(false); - $this->rootFolder->method('getUserFolder') - ->with($this->currentUser) - ->willReturnSelf(); - - $this->rootFolder->method('getFirstNodeById') + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById') ->with($share->getNodeId()) ->willReturn($node); - - $this->rootFolder->method('getRelativePath') + $userFolder->method('getRelativePath') ->with($node->getPath()) ->willReturnArgument(0); + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturn($userFolder); $serverName = 'remoteserver.com'; $this->trustedServers->method('isTrustedServer') @@ -5440,7 +5440,7 @@ public function testOwnerCanAlwaysDownload(): void { $share = $this->createMock(IShare::class); $node = $this->createMock(File::class); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $owner = $this->createMock(IUser::class); $share->method('getSharedBy')->willReturn('sharedByUser'); @@ -5462,7 +5462,7 @@ public function testParentHideDownloadEnforcedOnChild(): void { $share = $this->createMock(IShare::class); $node = $this->createMock(File::class); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $owner = $this->createMock(IUser::class); $storage = $this->createMock(SharedStorage::class); $originalShare = $this->createMock(IShare::class); @@ -5493,7 +5493,7 @@ public function testUserCanHideWhenParentAllows(): void { $share = $this->createMock(IShare::class); $node = $this->createMock(File::class); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $owner = $this->createMock(IUser::class); $storage = $this->createMock(SharedStorage::class); $originalShare = $this->createMock(IShare::class); @@ -5524,7 +5524,7 @@ public function testParentDownloadAttributeInherited(): void { $share = $this->createMock(IShare::class); $node = $this->createMock(File::class); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $owner = $this->createMock(IUser::class); $storage = $this->createMock(SharedStorage::class); $originalShare = $this->createMock(IShare::class); @@ -5562,7 +5562,7 @@ public function testFederatedStorageRespectsUserChoice(): void { $share = $this->createMock(IShare::class); $node = $this->createMock(File::class); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $owner = $this->createMock(IUser::class); $storage = $this->createMock(Storage::class); @@ -5591,7 +5591,7 @@ public function testUserAllowsDownloadWhenParentPermits(): void { $share = $this->createMock(IShare::class); $node = $this->createMock(File::class); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $owner = $this->createMock(IUser::class); $storage = $this->createMock(SharedStorage::class); $originalShare = $this->createMock(IShare::class); @@ -5622,7 +5622,7 @@ public function testWrapperStorageUnwrapped(): void { $share = $this->createMock(IShare::class); $node = $this->createMock(File::class); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $owner = $this->createMock(IUser::class); $wrapperStorage = $this->createMock(Wrapper::class); $innerStorage = $this->createMock(SharedStorage::class); diff --git a/apps/files_sharing/tests/External/ManagerTest.php b/apps/files_sharing/tests/External/ManagerTest.php index 31ce7155704ce..e45d132bfdfcd 100644 --- a/apps/files_sharing/tests/External/ManagerTest.php +++ b/apps/files_sharing/tests/External/ManagerTest.php @@ -21,9 +21,9 @@ use OCP\EventDispatcher\IEventDispatcher; use OCP\Federation\ICloudFederationFactory; use OCP\Federation\ICloudFederationProviderManager; -use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\Files\ISetupManager; +use OCP\Files\IUserFolder; use OCP\Files\NotFoundException; use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; @@ -90,8 +90,8 @@ protected function setUp(): void { $this->setupManager = $this->createMock(ISetupManager::class); $this->rootFolder = $this->createMock(IRootFolder::class); $this->rootFolder->method('getUserFolder') - ->willReturnCallback(function (string $userId): Folder { - $folder = $this->createMock(Folder::class); + ->willReturnCallback(function (string $userId): IUserFolder { + $folder = $this->createMock(IUserFolder::class); $folder->method('get') ->willReturn($folder); $folder->method('getNonExistingName') diff --git a/apps/files_sharing/tests/TestCase.php b/apps/files_sharing/tests/TestCase.php index 6b72ecb259cab..ce91ef910cf23 100644 --- a/apps/files_sharing/tests/TestCase.php +++ b/apps/files_sharing/tests/TestCase.php @@ -192,6 +192,7 @@ protected function loginHelper($user, $create = false, $password = false) { Storage::getGlobalCache()->clearCache(); Server::get(IUserSession::class)->setUser(null); Filesystem::tearDown(); + \OC_User::setIncognitoMode(false); Server::get(IUserSession::class)->login($user, $password); \OC::$server->getUserFolder($user); diff --git a/apps/files_trashbin/tests/Controller/PreviewControllerTest.php b/apps/files_trashbin/tests/Controller/PreviewControllerTest.php index bb951c9c8c7b1..ef36142555c8f 100644 --- a/apps/files_trashbin/tests/Controller/PreviewControllerTest.php +++ b/apps/files_trashbin/tests/Controller/PreviewControllerTest.php @@ -17,6 +17,7 @@ use OCP\Files\Folder; use OCP\Files\IMimeTypeDetector; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\SimpleFS\ISimpleFile; use OCP\IPreview; use OCP\IRequest; @@ -81,7 +82,7 @@ public function testInvalidHeight(): void { } public function testValidPreview(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userRoot = $this->createMock(Folder::class); $trash = $this->createMock(Folder::class); @@ -134,7 +135,7 @@ public function testValidPreview(): void { } public function testTrashFileNotFound(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userRoot = $this->createMock(Folder::class); $trash = $this->createMock(Folder::class); @@ -158,7 +159,7 @@ public function testTrashFileNotFound(): void { } public function testTrashFolder(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userRoot = $this->createMock(Folder::class); $trash = $this->createMock(Folder::class); diff --git a/apps/files_trashbin/tests/StorageTest.php b/apps/files_trashbin/tests/StorageTest.php index de8df1d293218..2e5912e758275 100644 --- a/apps/files_trashbin/tests/StorageTest.php +++ b/apps/files_trashbin/tests/StorageTest.php @@ -23,6 +23,7 @@ use OCP\Files\Cache\ICache; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Node; use OCP\Files\Storage\IStorage; use OCP\IUserManager; @@ -574,7 +575,7 @@ public function testShouldMoveToTrash(string $mountPoint, string $path, bool $us $logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); $eventDispatcher = $this->createMock(IEventDispatcher::class); $rootFolder = $this->createMock(IRootFolder::class); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $node = $this->getMockBuilder(Node::class)->disableOriginalConstructor()->getMock(); $trashManager = $this->createMock(ITrashManager::class); $event = $this->getMockBuilder(MoveToTrashEvent::class)->disableOriginalConstructor()->getMock(); diff --git a/apps/files_versions/lib/Storage.php b/apps/files_versions/lib/Storage.php index fe9f91534fa01..88f075e55d723 100644 --- a/apps/files_versions/lib/Storage.php +++ b/apps/files_versions/lib/Storage.php @@ -889,15 +889,11 @@ public static function expire($filename, $uid) { if ($softQuota) { $root = Server::get(IRootFolder::class); $userFolder = $root->getUserFolder($uid); - if (is_null($userFolder)) { - $availableSpace = 0; + $free = $quota - $userFolder->getSize(false); // remaining free space for user + if ($free > 0) { + $availableSpace = ($free * self::DEFAULTMAXSIZE / 100) - $versionsSize; // how much space can be used for versions } else { - $free = $quota - $userFolder->getSize(false); // remaining free space for user - if ($free > 0) { - $availableSpace = ($free * self::DEFAULTMAXSIZE / 100) - $versionsSize; // how much space can be used for versions - } else { - $availableSpace = $free - $versionsSize; - } + $availableSpace = $free - $versionsSize; } } else { $availableSpace = $quota; diff --git a/apps/files_versions/tests/Command/CleanupTest.php b/apps/files_versions/tests/Command/CleanupTest.php index 446b62f145d9d..c11a8805ad22a 100644 --- a/apps/files_versions/tests/Command/CleanupTest.php +++ b/apps/files_versions/tests/Command/CleanupTest.php @@ -12,8 +12,8 @@ use OCA\Files_Versions\Command\CleanUp; use OCA\Files_Versions\Db\VersionsMapper; use OCP\Files\Cache\ICache; -use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Storage\IStorage; use OCP\UserInterface; use PHPUnit\Framework\MockObject\MockObject; @@ -52,7 +52,7 @@ public function testDeleteVersions(bool $nodeExists): void { ->with('/testUser/files_versions') ->willReturn($nodeExists); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userHomeStorage = $this->createMock(IStorage::class); $userHomeStorageCache = $this->createMock(ICache::class); $this->rootFolder->expects($this->once()) diff --git a/apps/files_versions/tests/Controller/PreviewControllerTest.php b/apps/files_versions/tests/Controller/PreviewControllerTest.php index 542ea2b6b3485..7932f6399967c 100644 --- a/apps/files_versions/tests/Controller/PreviewControllerTest.php +++ b/apps/files_versions/tests/Controller/PreviewControllerTest.php @@ -15,6 +15,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\NotFoundException; use OCP\Files\SimpleFS\ISimpleFile; use OCP\IPreview; @@ -92,7 +93,7 @@ public function testInvalidVersion(): void { } public function testValidPreview(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userRoot = $this->createMock(Folder::class); $this->rootFolder->method('getUserFolder') @@ -130,7 +131,7 @@ public function testValidPreview(): void { } public function testVersionNotFound(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userRoot = $this->createMock(Folder::class); $this->rootFolder->method('getUserFolder') diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 47edd7bbcc739..a3af4fb8869df 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -502,6 +502,9 @@ + + info, false)]]> + @@ -1255,6 +1258,7 @@ + @@ -1272,6 +1276,7 @@ + @@ -2045,6 +2050,7 @@ + @@ -2212,6 +2218,7 @@ + @@ -3508,14 +3515,6 @@ __call(__FUNCTION__, func_get_args())]]> - - - - - - - - @@ -3886,9 +3885,6 @@ - - - diff --git a/core/Command/User/Info.php b/core/Command/User/Info.php index 4be0caefae355..03ec553e2313b 100644 --- a/core/Command/User/Info.php +++ b/core/Command/User/Info.php @@ -7,11 +7,13 @@ namespace OC\Core\Command\User; use OC\Core\Command\Base; +use OC\User\NoUserException; +use OCP\Files\IRootFolder; use OCP\Files\ISetupManager; -use OCP\Files\NotFoundException; use OCP\IGroupManager; use OCP\IUser; use OCP\IUserManager; +use OCP\Server; use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -84,20 +86,13 @@ private function formatLoginDate(int $timestamp): string { * @return array */ protected function getStorageInfo(IUser $user): array { - $this->setupManager->tearDown(); - $this->setupManager->setupForUser($user); + $root = Server::get(IRootFolder::class); try { - $storage = \OC_Helper::getStorageInfo('/'); - } catch (NotFoundException $e) { + $userFolder = $root->getUserFolder($user->getUID()); + return $userFolder->getUserQuota(); + } catch (NoUserException) { return []; } - return [ - 'free' => $storage['free'], - 'used' => $storage['used'], - 'total' => $storage['total'], - 'relative' => $storage['relative'], - 'quota' => $storage['quota'], - ]; } /** diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 93f5def20a52a..6d5615786adce 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -484,6 +484,7 @@ 'OCP\\Files\\IMimeTypeLoader' => $baseDir . '/lib/public/Files/IMimeTypeLoader.php', 'OCP\\Files\\IRootFolder' => $baseDir . '/lib/public/Files/IRootFolder.php', 'OCP\\Files\\ISetupManager' => $baseDir . '/lib/public/Files/ISetupManager.php', + 'OCP\\Files\\IUserFolder' => $baseDir . '/lib/public/Files/IUserFolder.php', 'OCP\\Files\\InvalidCharacterInPathException' => $baseDir . '/lib/public/Files/InvalidCharacterInPathException.php', 'OCP\\Files\\InvalidContentException' => $baseDir . '/lib/public/Files/InvalidContentException.php', 'OCP\\Files\\InvalidDirectoryException' => $baseDir . '/lib/public/Files/InvalidDirectoryException.php', @@ -1765,6 +1766,7 @@ 'OC\\Files\\Node\\NonExistingFile' => $baseDir . '/lib/private/Files/Node/NonExistingFile.php', 'OC\\Files\\Node\\NonExistingFolder' => $baseDir . '/lib/private/Files/Node/NonExistingFolder.php', 'OC\\Files\\Node\\Root' => $baseDir . '/lib/private/Files/Node/Root.php', + 'OC\\Files\\Node\\UserFolder' => $baseDir . '/lib/private/Files/Node/UserFolder.php', 'OC\\Files\\Notify\\Change' => $baseDir . '/lib/private/Files/Notify/Change.php', 'OC\\Files\\Notify\\RenameChange' => $baseDir . '/lib/private/Files/Notify/RenameChange.php', 'OC\\Files\\ObjectStore\\AppdataPreviewObjectStoreStorage' => $baseDir . '/lib/private/Files/ObjectStore/AppdataPreviewObjectStoreStorage.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index bc27a12cf46b6..9462e28f4211a 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -525,6 +525,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\Files\\IMimeTypeLoader' => __DIR__ . '/../../..' . '/lib/public/Files/IMimeTypeLoader.php', 'OCP\\Files\\IRootFolder' => __DIR__ . '/../../..' . '/lib/public/Files/IRootFolder.php', 'OCP\\Files\\ISetupManager' => __DIR__ . '/../../..' . '/lib/public/Files/ISetupManager.php', + 'OCP\\Files\\IUserFolder' => __DIR__ . '/../../..' . '/lib/public/Files/IUserFolder.php', 'OCP\\Files\\InvalidCharacterInPathException' => __DIR__ . '/../../..' . '/lib/public/Files/InvalidCharacterInPathException.php', 'OCP\\Files\\InvalidContentException' => __DIR__ . '/../../..' . '/lib/public/Files/InvalidContentException.php', 'OCP\\Files\\InvalidDirectoryException' => __DIR__ . '/../../..' . '/lib/public/Files/InvalidDirectoryException.php', @@ -1806,6 +1807,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OC\\Files\\Node\\NonExistingFile' => __DIR__ . '/../../..' . '/lib/private/Files/Node/NonExistingFile.php', 'OC\\Files\\Node\\NonExistingFolder' => __DIR__ . '/../../..' . '/lib/private/Files/Node/NonExistingFolder.php', 'OC\\Files\\Node\\Root' => __DIR__ . '/../../..' . '/lib/private/Files/Node/Root.php', + 'OC\\Files\\Node\\UserFolder' => __DIR__ . '/../../..' . '/lib/private/Files/Node/UserFolder.php', 'OC\\Files\\Notify\\Change' => __DIR__ . '/../../..' . '/lib/private/Files/Notify/Change.php', 'OC\\Files\\Notify\\RenameChange' => __DIR__ . '/../../..' . '/lib/private/Files/Notify/RenameChange.php', 'OC\\Files\\ObjectStore\\AppdataPreviewObjectStoreStorage' => __DIR__ . '/../../..' . '/lib/private/Files/ObjectStore/AppdataPreviewObjectStoreStorage.php', diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index f103a34c9e92d..e7168082e67e2 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -530,7 +530,7 @@ public function getOrCreateFolder(string $path, int $maxRetries = 5): IFolder { return $folder; } } catch (NotFoundException) { - $folder = dirname($path) === '.' ? $this : $this->get(dirname($path)); + $folder = in_array(dirname($path), ['.','/']) ? $this : $this->get(dirname($path)); if (!($folder instanceof Folder)) { throw new NotPermittedException("Unable to create folder $path. Parent is not a directory."); } diff --git a/lib/private/Files/Node/LazyFolder.php b/lib/private/Files/Node/LazyFolder.php index 23858bb0679af..e3451a176b456 100644 --- a/lib/private/Files/Node/LazyFolder.php +++ b/lib/private/Files/Node/LazyFolder.php @@ -313,13 +313,6 @@ public function getName() { return $this->__call(__FUNCTION__, func_get_args()); } - /** - * @inheritDoc - */ - public function getUserFolder($userId) { - return $this->__call(__FUNCTION__, func_get_args()); - } - public function getMimetype(): string { if (isset($this->data['mimetype'])) { return $this->data['mimetype']; diff --git a/lib/private/Files/Node/LazyRoot.php b/lib/private/Files/Node/LazyRoot.php index 8920a2f68f67e..b99baacb0cd95 100644 --- a/lib/private/Files/Node/LazyRoot.php +++ b/lib/private/Files/Node/LazyRoot.php @@ -9,6 +9,7 @@ use OCP\Files\Cache\ICacheEntry; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Mount\IMountPoint; use OCP\Files\Node as INode; @@ -33,7 +34,7 @@ protected function getRootFolder(): IRootFolder { return $folder; } - public function getUserFolder($userId) { + public function getUserFolder(string $userId): IUserFolder { return $this->__call(__FUNCTION__, func_get_args()); } diff --git a/lib/private/Files/Node/LazyUserFolder.php b/lib/private/Files/Node/LazyUserFolder.php index 5ac74e2705e21..be5d46a53139c 100644 --- a/lib/private/Files/Node/LazyUserFolder.php +++ b/lib/private/Files/Node/LazyUserFolder.php @@ -8,18 +8,19 @@ */ namespace OC\Files\Node; +use OC\Files\View; use OCP\Constants; -use OCP\Files\File; use OCP\Files\FileInfo; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Mount\IMountManager; -use OCP\Files\NotFoundException; +use OCP\ICacheFactory; +use OCP\IConfig; use OCP\IUser; use OCP\Server; -use Psr\Log\LoggerInterface; -class LazyUserFolder extends LazyFolder { +class LazyUserFolder extends LazyFolder implements IUserFolder { private string $path; public function __construct( @@ -44,23 +45,18 @@ public function __construct( parent::__construct( $rootFolder, - function () use ($user): Folder { - try { - $node = $this->getRootFolder()->get($this->path); - if ($node instanceof File) { - $e = new \RuntimeException(); - Server::get(LoggerInterface::class)->error('User root storage is not a folder: ' . $this->path, [ - 'exception' => $e, - ]); - throw $e; - } - return $node; - } catch (NotFoundException $e) { - if (!$this->getRootFolder()->nodeExists('/' . $user->getUID())) { - $this->getRootFolder()->newFolder('/' . $user->getUID()); - } - return $this->getRootFolder()->newFolder($this->path); - } + function () use ($user): UserFolder { + $root = $this->getRootFolder(); + $realFolder = $root->getOrCreateFolder('/' . $user->getUID() . '/files', maxRetries: 1); + return new UserFolder( + $root, + new View(), + $realFolder->getPath(), + null, + Server::get(IConfig::class), + $user, + Server::get(ICacheFactory::class), + ); }, $data, ); @@ -76,4 +72,8 @@ public function getMountPoint() { } return $mountPoint; } + + public function getUserQuota(bool $useCache = true): array { + return $this->__call(__FUNCTION__, func_get_args()); + } } diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php index 0c121dc8b0527..471cda1a4369e 100644 --- a/lib/private/Files/Node/Root.php +++ b/lib/private/Files/Node/Root.php @@ -27,6 +27,7 @@ use OCP\Files\Config\IUserMountCache; use OCP\Files\Events\Node\FilesystemTornDownEvent; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Mount\IMountPoint; use OCP\Files\Node as INode; use OCP\Files\NotFoundException; @@ -34,6 +35,7 @@ use OCP\IAppConfig; use OCP\ICache; use OCP\ICacheFactory; +use OCP\IConfig; use OCP\IUser; use OCP\IUserManager; use OCP\Server; @@ -72,7 +74,7 @@ public function __construct( private LoggerInterface $logger, private IUserManager $userManager, IEventDispatcher $eventDispatcher, - ICacheFactory $cacheFactory, + private ICacheFactory $cacheFactory, IAppConfig $appConfig, ) { parent::__construct($this, $view, ''); @@ -298,12 +300,10 @@ public function getName() { /** * Returns a view to user's files folder * - * @param string $userId user ID - * @return \OCP\Files\Folder * @throws NoUserException * @throws NotPermittedException */ - public function getUserFolder($userId) { + public function getUserFolder(string $userId): IUserFolder { $userObject = $this->userManager->get($userId); if (is_null($userObject)) { @@ -325,17 +325,16 @@ public function getUserFolder($userId) { if (!$this->userFolderCache->hasKey($userId)) { if ($this->mountManager->getSetupManager()->isSetupComplete($userObject)) { - try { - $folder = $this->get('/' . $userId . '/files'); - if (!$folder instanceof \OCP\Files\Folder) { - throw new \Exception("Account folder for \"$userId\" exists as a file"); - } - } catch (NotFoundException $e) { - if (!$this->nodeExists('/' . $userId)) { - $this->newFolder('/' . $userId); - } - $folder = $this->newFolder('/' . $userId . '/files'); - } + $realFolder = $this->getOrCreateFolder('/' . $userId . '/files', maxRetries: 1); + $folder = new UserFolder( + $this, + $this->view, + $realFolder->getPath(), + null, + Server::get(IConfig::class), + $userObject, + $this->cacheFactory, + ); } else { $folder = new LazyUserFolder($this, $userObject, $this->mountManager, $this->useDefaultHomeFoldersPermissions); } diff --git a/lib/private/Files/Node/UserFolder.php b/lib/private/Files/Node/UserFolder.php new file mode 100644 index 0000000000000..a7b18e92e1ebf --- /dev/null +++ b/lib/private/Files/Node/UserFolder.php @@ -0,0 +1,92 @@ +cacheFactory->createLocal('storage_info'); + if ($useCache) { + $cached = $memcache->get($this->getPath()); + if ($cached) { + return $cached; + } + } + + $quotaIncludeExternalStorage = $this->config->getSystemValueBool('quota_include_external_storage'); + $rootInfo = $this->getFileInfo($quotaIncludeExternalStorage); + + /** @var int|float $used */ + $used = max($rootInfo->getSize(), 0.0); + /** @var int|float $quota */ + $quota = \OCP\Files\FileInfo::SPACE_UNLIMITED; + $mount = $rootInfo->getMountPoint(); + $storage = $mount->getStorage(); + if ($storage === null) { + throw new \RuntimeException('Storage returned from mount point is null.'); + } + + if ($storage->instanceOfStorage(Quota::class)) { + $quota = $storage->getQuota(); + } elseif ($quotaIncludeExternalStorage) { + $quota = $this->user->getQuotaBytes(); + } + + $free = $storage->free_space($rootInfo->getInternalPath()); + if (is_bool($free)) { + $free = 0.0; + } + + if ($free >= 0) { + $total = $free + $used; + } else { + $total = $free; //either unknown or unlimited + } + + $relative = $total > 0 + ? $used / $total + : 0; + $this->config->setUserValue($this->user->getUID(), 'files', 'lastSeenQuotaUsage', (string)$relative); + + $info = [ + 'free' => $free, + 'used' => $used, + 'quota' => $quota, + 'total' => $total, + ]; + $memcache->set($this->getPath(), $info, 5 * 60); + + return $info; + } + +} diff --git a/lib/private/User/User.php b/lib/private/User/User.php index 8de3486a9b99a..b1b0923e37381 100644 --- a/lib/private/User/User.php +++ b/lib/private/User/User.php @@ -15,6 +15,7 @@ use OCP\Comments\ICommentsManager; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\FileInfo; +use OCP\Files\IRootFolder; use OCP\Group\Events\BeforeUserRemovedEvent; use OCP\Group\Events\UserRemovedEvent; use OCP\IAvatarManager; @@ -573,7 +574,11 @@ public function setQuota($quota): void { $this->config->setUserValue($this->uid, 'files', 'quota', $quota); $this->triggerChange('quota', $quota, $oldQuota); } - \OC_Helper::clearStorageInfo('/' . $this->uid . '/files'); + + // Refresh the quota cache + $root = Server::get(IRootFolder::class); + $userFolder = $root->getUserFolder($this->uid); + $userFolder->getUserQuota(false); } public function getManagerUids(): array { diff --git a/lib/private/legacy/OC_Helper.php b/lib/private/legacy/OC_Helper.php index 3dc7470811dbc..4c31cf5a5e7b1 100644 --- a/lib/private/legacy/OC_Helper.php +++ b/lib/private/legacy/OC_Helper.php @@ -145,6 +145,7 @@ public static function findBinaryPath(string $program): ?string { * @psalm-suppress LessSpecificReturnStatement Legacy code outputs weird types - manually validated that they are correct * @return StorageInfo * @throws NotFoundException + * @deprecated 33.0.0 use \OCP\Files\IUserFolder::getUserQuota */ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoints = true, $useCache = true) { if (!self::$cacheFactory) { @@ -207,7 +208,7 @@ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoin // TODO: need a better way to get total space from storage if ($sourceStorage->instanceOfStorage('\OC\Files\Storage\Wrapper\Quota')) { - /** @var Quota $storage */ + /** @var Quota $sourceStorage */ $quota = $sourceStorage->getQuota(); } try { @@ -329,6 +330,9 @@ private static function getGlobalStorageInfo(int|float $quota, IUser $user, IMou ]; } + /** + * @deprecated 33.0.0 + */ public static function clearStorageInfo(string $absolutePath): void { /** @var ICacheFactory $cacheFactory */ $cacheFactory = Server::get(ICacheFactory::class); diff --git a/lib/public/Files/IRootFolder.php b/lib/public/Files/IRootFolder.php index fb8532f8c8153..494c7bb42ea10 100644 --- a/lib/public/Files/IRootFolder.php +++ b/lib/public/Files/IRootFolder.php @@ -1,14 +1,18 @@ expects($this->once()) ->method('getMimeType') ->willReturn('image/jpeg'); - $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder')->with('userid')->willReturn($userFolder); $userFolder->method('get')->willReturn($file); @@ -386,7 +387,7 @@ public function testPostAvatarFromFile(): void { */ public function testPostAvatarFromNoFile(): void { $file = $this->getMockBuilder('OCP\Files\Node')->getMock(); - $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder')->with('userid')->willReturn($userFolder); $userFolder ->method('get') @@ -408,7 +409,7 @@ public function testPostAvatarInvalidType(): void { $file->expects($this->exactly(2)) ->method('getMimeType') ->willReturn('text/plain'); - $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder')->with('userid')->willReturn($userFolder); $userFolder->method('get')->willReturn($file); @@ -425,7 +426,7 @@ public function testPostAvatarNotPermittedException(): void { $file->expects($this->once()) ->method('getMimeType') ->willReturn('image/jpeg'); - $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock(); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder')->with('userid')->willReturn($userFolder); $userFolder->method('get')->willReturn($file); diff --git a/tests/Core/Controller/PreviewControllerTest.php b/tests/Core/Controller/PreviewControllerTest.php index 5a6cd1fba0a53..a8ca55a392bb9 100644 --- a/tests/Core/Controller/PreviewControllerTest.php +++ b/tests/Core/Controller/PreviewControllerTest.php @@ -13,6 +13,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\NotFoundException; use OCP\Files\SimpleFS\ISimpleFile; use OCP\Files\Storage\ISharedStorage; @@ -72,7 +73,7 @@ public function testInvalidHeight(): void { } public function testFileNotFound(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with($this->equalTo($this->userId)) ->willReturn($userFolder); @@ -88,7 +89,7 @@ public function testFileNotFound(): void { } public function testNotAFile(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with($this->equalTo($this->userId)) ->willReturn($userFolder); @@ -105,7 +106,7 @@ public function testNotAFile(): void { } public function testNoPreviewAndNoIcon(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with($this->equalTo($this->userId)) ->willReturn($userFolder); @@ -126,7 +127,7 @@ public function testNoPreviewAndNoIcon(): void { } public function testNoPreview() { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with($this->equalTo($this->userId)) ->willReturn($userFolder); @@ -157,7 +158,7 @@ public function testNoPreview() { $this->assertEquals($expected, $res); } public function testFileWithoutReadPermission() { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with($this->equalTo($this->userId)) ->willReturn($userFolder); @@ -181,7 +182,7 @@ public function testFileWithoutReadPermission() { } public function testFileWithoutDownloadPermission() { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with($this->equalTo($this->userId)) ->willReturn($userFolder); @@ -221,7 +222,7 @@ public function testFileWithoutDownloadPermission() { } public function testFileWithoutDownloadPermissionButHeader() { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with($this->equalTo($this->userId)) ->willReturn($userFolder); @@ -274,7 +275,7 @@ public function testFileWithoutDownloadPermissionButHeader() { } public function testValidPreview(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with($this->equalTo($this->userId)) ->willReturn($userFolder); @@ -313,7 +314,7 @@ public function testValidPreview(): void { } public function testValidPreviewOfShare() { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder') ->with($this->equalTo($this->userId)) ->willReturn($userFolder); diff --git a/tests/lib/DirectEditing/ManagerTest.php b/tests/lib/DirectEditing/ManagerTest.php index f519aeb4ce1d2..100652e1cee99 100644 --- a/tests/lib/DirectEditing/ManagerTest.php +++ b/tests/lib/DirectEditing/ManagerTest.php @@ -17,6 +17,7 @@ use OCP\Encryption\IManager; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\IDBConnection; use OCP\IL10N; use OCP\IUser; @@ -107,10 +108,7 @@ class ManagerTest extends TestCase { * @var MockObject|IRootFolder */ private $rootFolder; - /** - * @var MockObject|Folder - */ - private $userFolder; + private IUserFolder&MockObject $userFolder; /** * @var MockObject|IL10N */ @@ -129,7 +127,7 @@ protected function setUp(): void { $this->connection = Server::get(IDBConnection::class); $this->userSession = $this->createMock(IUserSession::class); $this->rootFolder = $this->createMock(IRootFolder::class); - $this->userFolder = $this->createMock(Folder::class); + $this->userFolder = $this->createMock(IUserFolder::class); $this->l10n = $this->createMock(IL10N::class); $this->encryptionManager = $this->createMock(IManager::class); diff --git a/tests/lib/Files/Node/RootTest.php b/tests/lib/Files/Node/RootTest.php index 3821b6943b15b..0dee1a6dc1e79 100644 --- a/tests/lib/Files/Node/RootTest.php +++ b/tests/lib/Files/Node/RootTest.php @@ -10,7 +10,6 @@ use OC\Files\FileInfo; use OC\Files\Mount\Manager; -use OC\Files\Node\Folder; use OC\Files\Node\Root; use OC\Files\Storage\Storage; use OC\Files\View; @@ -19,6 +18,7 @@ use OCP\Cache\CappedMemoryCache; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\IUserMountCache; +use OCP\Files\IUserFolder; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; use OCP\IAppConfig; @@ -210,7 +210,7 @@ public function testGetUserFolder(): void { ->expects($this->once()) ->method('hasKey') ->willReturn(true); - $folder = $this->createMock(Folder::class); + $folder = $this->createMock(IUserFolder::class); $cappedMemoryCache ->expects($this->once()) ->method('get') diff --git a/tests/lib/Files/Template/TemplateManagerTest.php b/tests/lib/Files/Template/TemplateManagerTest.php index 431b032594c14..bba36eb18db73 100644 --- a/tests/lib/Files/Template/TemplateManagerTest.php +++ b/tests/lib/Files/Template/TemplateManagerTest.php @@ -17,6 +17,7 @@ use OCP\Files\Folder; use OCP\Files\GenericFileException; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\NotFoundException; use OCP\IConfig; use OCP\IDBConnection; @@ -93,7 +94,7 @@ public function testCreateFromTemplateShoudValidateFilename(): void { $fileDirectory = '/'; $filePath = $fileDirectory . str_repeat('a', 251); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userFolder->method('get') ->willReturnCallback(function ($path) use ($filePath, $fileDirectory) { if ($path === $filePath) { diff --git a/tests/lib/Repair/Owncloud/CleanPreviewsBackgroundJobTest.php b/tests/lib/Repair/Owncloud/CleanPreviewsBackgroundJobTest.php index fc88ee5d226e1..caadb221f188d 100644 --- a/tests/lib/Repair/Owncloud/CleanPreviewsBackgroundJobTest.php +++ b/tests/lib/Repair/Owncloud/CleanPreviewsBackgroundJobTest.php @@ -11,6 +11,7 @@ use OCP\BackgroundJob\IJobList; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; use OCP\IUserManager; @@ -48,7 +49,7 @@ public function setUp(): void { } public function testCleanupPreviewsUnfinished(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userRoot = $this->createMock(Folder::class); $thumbnailFolder = $this->createMock(Folder::class); @@ -96,7 +97,7 @@ public function testCleanupPreviewsUnfinished(): void { } public function testCleanupPreviewsFinished(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userRoot = $this->createMock(Folder::class); $thumbnailFolder = $this->createMock(Folder::class); @@ -161,7 +162,7 @@ public function testNoUserFolder(): void { } public function testNoThumbnailFolder(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userRoot = $this->createMock(Folder::class); $this->rootFolder->method('getUserFolder') @@ -189,7 +190,7 @@ public function testNoThumbnailFolder(): void { } public function testNotPermittedToDelete(): void { - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userRoot = $this->createMock(Folder::class); $thumbnailFolder = $this->createMock(Folder::class); diff --git a/tests/lib/Share20/DefaultShareProviderTest.php b/tests/lib/Share20/DefaultShareProviderTest.php index aa5454bbe384f..1ab4ac2336903 100644 --- a/tests/lib/Share20/DefaultShareProviderTest.php +++ b/tests/lib/Share20/DefaultShareProviderTest.php @@ -20,6 +20,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\IConfig; use OCP\IDBConnection; use OCP\IGroup; @@ -217,7 +218,7 @@ public function testGetShareByIdUserShare(): void { $shareOwner->method('getUID')->willReturn('shareOwner'); $ownerPath = $this->createMock(File::class); - $shareOwnerFolder = $this->createMock(Folder::class); + $shareOwnerFolder = $this->createMock(IUserFolder::class); $shareOwnerFolder->method('getFirstNodeById')->with(42)->willReturn($ownerPath); $this->rootFolder @@ -295,7 +296,7 @@ public function testGetShareByIdLazy2(): void { $ownerPath = $this->createMock(File::class); - $shareOwnerFolder = $this->createMock(Folder::class); + $shareOwnerFolder = $this->createMock(IUserFolder::class); $shareOwnerFolder->method('getFirstNodeById')->with(42)->willReturn($ownerPath); $this->rootFolder @@ -339,7 +340,7 @@ public function testGetShareByIdGroupShare(): void { $id = $qb->getLastInsertId(); $ownerPath = $this->createMock(Folder::class); - $shareOwnerFolder = $this->createMock(Folder::class); + $shareOwnerFolder = $this->createMock(IUserFolder::class); $shareOwnerFolder->method('getFirstNodeById')->with(42)->willReturn($ownerPath); $this->rootFolder @@ -379,8 +380,9 @@ public function testGetShareByIdUserGroupShare(): void { $node->method('getId')->willReturn(42); $node->method('getName')->willReturn('myTarget'); - $this->rootFolder->method('getUserFolder')->with('user0')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->willReturn($node); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->willReturn($node); + $this->rootFolder->method('getUserFolder')->with('user0')->willReturn($userFolder); $this->userManager->method('get')->willReturnMap([ ['user0', $user0], @@ -424,7 +426,7 @@ public function testGetShareByIdLinkShare(): void { $id = $qb->getLastInsertId(); $ownerPath = $this->createMock(Folder::class); - $shareOwnerFolder = $this->createMock(Folder::class); + $shareOwnerFolder = $this->createMock(IUserFolder::class); $shareOwnerFolder->method('getFirstNodeById')->with(42)->willReturn($ownerPath); $this->rootFolder @@ -647,7 +649,7 @@ public function testGetChildren(): void { $qb->executeStatement(); $ownerPath = $this->createMock(Folder::class); - $ownerFolder = $this->createMock(Folder::class); + $ownerFolder = $this->createMock(IUserFolder::class); $ownerFolder->method('getFirstNodeById')->willReturn($ownerPath); $this->rootFolder @@ -696,8 +698,8 @@ public function testCreateUserShare(): void { $path->method('getId')->willReturn(100); $path->method('getOwner')->willReturn($shareOwner); - $ownerFolder = $this->createMock(Folder::class); - $userFolder = $this->createMock(Folder::class); + $ownerFolder = $this->createMock(IUserFolder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder ->method('getUserFolder') ->willReturnMap([ @@ -768,8 +770,8 @@ public function testCreateGroupShare(): void { $path->method('getId')->willReturn(100); $path->method('getOwner')->willReturn($shareOwner); - $ownerFolder = $this->createMock(Folder::class); - $userFolder = $this->createMock(Folder::class); + $ownerFolder = $this->createMock(IUserFolder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder ->method('getUserFolder') ->willReturnMap([ @@ -838,8 +840,8 @@ public function testCreateLinkShare(): void { $path->method('getId')->willReturn(100); $path->method('getOwner')->willReturn($shareOwner); - $ownerFolder = $this->createMock(Folder::class); - $userFolder = $this->createMock(Folder::class); + $ownerFolder = $this->createMock(IUserFolder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder ->method('getUserFolder') ->willReturnMap([ @@ -905,8 +907,9 @@ public function testGetShareByToken(): void { $file = $this->createMock(File::class); - $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with(42)->willReturn($file); + $shareOwnerFolder = $this->createMock(IUserFolder::class); + $shareOwnerFolder->method('getFirstNodeById')->with(42)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturn($shareOwnerFolder); $share = $this->provider->getShareByToken('secrettoken'); $this->assertEquals($id, $share->getId()); @@ -944,8 +947,9 @@ public function testGetShareByTokenNullLabel(): void { $file = $this->createMock(File::class); - $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with(42)->willReturn($file); + $shareOwnerFolder = $this->createMock(IUserFolder::class); + $shareOwnerFolder->method('getFirstNodeById')->with(42)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturn($shareOwnerFolder); $share = $this->provider->getShareByToken('secrettoken'); $this->assertEquals($id, $share->getId()); @@ -1027,8 +1031,9 @@ public function testGetSharedWithUser($storageStringId, $fileName1, $fileName2): $this->assertEquals(1, $qb->executeStatement()); $file = $this->createMock(File::class); - $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with($fileId)->willReturn($file); + $shareOwnerFolder = $this->createMock(IUserFolder::class); + $shareOwnerFolder->method('getFirstNodeById')->with($fileId)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturn($shareOwnerFolder); $share = $this->provider->getSharedWith('sharedWith', IShare::TYPE_USER, null, 1, 0); $this->assertCount(1, $share); @@ -1228,8 +1233,9 @@ public function testGetSharedWithUserWithNode($storageStringId, $fileName1, $fil $file = $this->createMock(File::class); $file->method('getId')->willReturn($fileId2); - $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with($fileId2)->willReturn($file); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with($fileId2)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('user1')->willReturn($userFolder); $share = $this->provider->getSharedWith('user0', IShare::TYPE_USER, $file, -1, 0); $this->assertCount(1, $share); @@ -1269,8 +1275,9 @@ public function testGetSharedWithGroupWithNode($storageStringId, $fileName1, $fi $node = $this->createMock(Folder::class); $node->method('getId')->willReturn($fileId2); - $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with($fileId2)->willReturn($node); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with($fileId2)->willReturn($node); + $this->rootFolder->method('getUserFolder')->with('user1')->willReturn($userFolder); $share = $this->provider->getSharedWith('user0', IShare::TYPE_GROUP, $node, -1, 0); $this->assertCount(1, $share); @@ -1318,8 +1325,9 @@ public function testGetSharedWithWithDeletedFile($shareType, $trashed): void { $this->assertEquals(1, $qb->executeStatement()); $file = $this->createMock(File::class); - $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with($deletedFileId)->willReturn($file); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with($deletedFileId)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturn($userFolder); $groups = []; foreach (range(0, 100) as $i) { @@ -1430,8 +1438,9 @@ public function testGetSharesNode(): void { $file = $this->createMock(File::class); $file->method('getId')->willReturn(42); - $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with(42)->willReturn($file); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with(42)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturn($userFolder); $share = $this->provider->getSharesBy('sharedBy', IShare::TYPE_USER, $file, false, 1, 0); $this->assertCount(1, $share); @@ -1480,8 +1489,9 @@ public function testGetSharesReshare(): void { $file = $this->createMock(File::class); $file->method('getId')->willReturn(42); - $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with(42)->willReturn($file); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with(42)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturn($userFolder); $shares = $this->provider->getSharesBy('shareOwner', IShare::TYPE_USER, null, true, -1, 0); $this->assertCount(2, $shares); @@ -1540,8 +1550,9 @@ public function testDeleteFromSelfGroupNoCustomShare(): void { $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); - $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('user1')->willReturn($userFolder); $share = $this->provider->getShareById($id); @@ -1612,8 +1623,9 @@ public function testDeleteFromSelfGroupAlreadyCustomShare(): void { $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); - $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('user1')->willReturn($userFolder); $share = $this->provider->getShareById($id); @@ -1670,8 +1682,9 @@ public function testDeleteFromSelfGroupUserNotInGroup(): void { $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); - $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('user1')->willReturn($userFolder); $share = $this->provider->getShareById($id); @@ -1712,8 +1725,9 @@ public function testDeleteFromSelfGroupDoesNotExist(): void { $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); - $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('user1')->willReturn($userFolder); $share = $this->provider->getShareById($id); @@ -1750,8 +1764,9 @@ public function testDeleteFromSelfUser(): void { $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); - $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('user1')->willReturn($userFolder); $share = $this->provider->getShareById($id); @@ -1804,8 +1819,9 @@ public function testDeleteFromSelfUserNotRecipient(): void { $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); - $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('user1')->willReturn($userFolder); $share = $this->provider->getShareById($id); @@ -1841,8 +1857,9 @@ public function testDeleteFromSelfLink(): void { $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); - $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with(1)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('user1')->willReturn($userFolder); $share = $this->provider->getShareById($id); @@ -1872,9 +1889,9 @@ function ($userId) use ($users) { $file2 = $this->createMock(File::class); $file2->method('getId')->willReturn(43); - $folder1 = $this->createMock(Folder::class); + $folder1 = $this->createMock(IUserFolder::class); $folder1->method('getFirstNodeById')->with(42)->willReturn($file1); - $folder2 = $this->createMock(Folder::class); + $folder2 = $this->createMock(IUserFolder::class); $folder2->method('getFirstNodeById')->with(43)->willReturn($file2); $this->rootFolder->method('getUserFolder')->willReturnMap([ @@ -1929,9 +1946,9 @@ function ($userId) use ($users) { $file2 = $this->createMock(File::class); $file2->method('getId')->willReturn(43); - $folder1 = $this->createMock(Folder::class); + $folder1 = $this->createMock(IUserFolder::class); $folder1->method('getFirstNodeById')->with(42)->willReturn($file1); - $folder2 = $this->createMock(Folder::class); + $folder2 = $this->createMock(IUserFolder::class); $folder2->method('getFirstNodeById')->with(43)->willReturn($file2); $this->rootFolder->method('getUserFolder')->willReturnMap([ @@ -1995,9 +2012,9 @@ function ($userId) use ($users) { $file2 = $this->createMock(File::class); $file2->method('getId')->willReturn(43); - $folder1 = $this->createMock(Folder::class); + $folder1 = $this->createMock(IUserFolder::class); $folder1->method('getFirstNodeById')->with(42)->willReturn($file1); - $folder2 = $this->createMock(Folder::class); + $folder2 = $this->createMock(IUserFolder::class); $folder2->method('getFirstNodeById')->with(43)->willReturn($file2); $this->rootFolder->method('getUserFolder')->willReturnMap([ @@ -2066,9 +2083,9 @@ function ($groupId) use ($groups) { $file2 = $this->createMock(File::class); $file2->method('getId')->willReturn(43); - $folder1 = $this->createMock(Folder::class); + $folder1 = $this->createMock(IUserFolder::class); $folder1->method('getFirstNodeById')->with(42)->willReturn($file1); - $folder2 = $this->createMock(Folder::class); + $folder2 = $this->createMock(IUserFolder::class); $folder2->method('getFirstNodeById')->with(43)->willReturn($file2); $this->rootFolder->method('getUserFolder')->willReturnMap([ @@ -2145,9 +2162,9 @@ function ($groupId) use ($groups) { $file2 = $this->createMock(File::class); $file2->method('getId')->willReturn(43); - $folder1 = $this->createMock(Folder::class); + $folder1 = $this->createMock(IUserFolder::class); $folder1->method('getFirstNodeById')->with(42)->willReturn($file1); - $folder2 = $this->createMock(Folder::class); + $folder2 = $this->createMock(IUserFolder::class); $folder2->method('getFirstNodeById')->with(43)->willReturn($file2); $this->rootFolder->method('getUserFolder')->willReturnMap([ @@ -2223,8 +2240,9 @@ public function testMoveUserShare(): void { $file = $this->createMock(File::class); $file->method('getId')->willReturn(42); - $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->willReturn($file); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with(42)->willReturn($file); + $this->rootFolder->method('getUserFolder')->with('user1')->willReturn($userFolder); $share = $this->provider->getShareById($id, null); @@ -2259,8 +2277,9 @@ public function testMoveGroupShare(): void { $folder = $this->createMock(Folder::class); $folder->method('getId')->willReturn(42); - $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf(); - $this->rootFolder->method('getFirstNodeById')->willReturn($folder); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getFirstNodeById')->with(42)->willReturn($folder); + $this->rootFolder->method('getUserFolder')->with('user1')->willReturn($userFolder); $share = $this->provider->getShareById($id, 'user0'); @@ -2943,23 +2962,23 @@ public function testGetAllShares(): void { $id5 = $qb->getLastInsertId(); $ownerPath1 = $this->createMock(File::class); - $shareOwner1Folder = $this->createMock(Folder::class); + $shareOwner1Folder = $this->createMock(IUserFolder::class); $shareOwner1Folder->method('getFirstNodeById')->willReturn($ownerPath1); $ownerPath2 = $this->createMock(File::class); - $shareOwner2Folder = $this->createMock(Folder::class); + $shareOwner2Folder = $this->createMock(IUserFolder::class); $shareOwner2Folder->method('getFirstNodeById')->willReturn($ownerPath2); $ownerPath3 = $this->createMock(File::class); - $shareOwner3Folder = $this->createMock(Folder::class); + $shareOwner3Folder = $this->createMock(IUserFolder::class); $shareOwner3Folder->method('getFirstNodeById')->willReturn($ownerPath3); $ownerPath4 = $this->createMock(File::class); - $shareOwner4Folder = $this->createMock(Folder::class); + $shareOwner4Folder = $this->createMock(IUserFolder::class); $shareOwner4Folder->method('getFirstNodeById')->willReturn($ownerPath4); $ownerPath5 = $this->createMock(File::class); - $shareOwner5Folder = $this->createMock(Folder::class); + $shareOwner5Folder = $this->createMock(IUserFolder::class); $shareOwner5Folder->method('getFirstNodeById')->willReturn($ownerPath5); $this->rootFolder diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 9e895a3020c17..05dad7d267a3c 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -26,6 +26,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Mount\IMountManager; use OCP\Files\Mount\IMountPoint; use OCP\Files\Mount\IShareOwnerlessMount; @@ -497,7 +498,7 @@ public function testPromoteReshareFile(): void { $manager->expects($this->exactly(1))->method('updateShare')->with($reShare)->willReturn($reShare); $this->userManager->method('userExists')->willReturn(true); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder')->with('userA')->willReturn($userFolder); $userFolder->method('getFirstNodeById') ->with(42) @@ -588,7 +589,7 @@ public function testPromoteReshare(): void { }); $this->userManager->method('userExists')->willReturn(true); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder')->with('userA')->willReturn($userFolder); $userFolder->method('getFirstNodeById') ->willReturnCallback(function ($id) use ($subFolder, $otherFolder, $folder) { @@ -650,7 +651,7 @@ public function testPromoteReshareWhenUserHasAnotherShare(): void { $manager->expects($this->never())->method('updateShare'); $this->userManager->method('userExists')->willReturn(true); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder')->with('userA')->willReturn($userFolder); $userFolder->method('getFirstNodeById') ->with(42) @@ -732,7 +733,7 @@ public function testPromoteReshareOfUsersInGroupShare(): void { $manager->method('getSharedWith')->willReturn([]); $this->userManager->method('userExists')->willReturn(true); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $this->rootFolder->method('getUserFolder')->with('userA')->willReturn($userFolder); $userFolder->method('getFirstNodeById') ->with(42) @@ -1178,7 +1179,7 @@ public function testGeneralChecks(array $shareParams, ?string $exceptionMessage, ['group0', true], ]); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userFolder->expects($this->any()) ->method('getId') ->willReturn(42); @@ -1223,7 +1224,7 @@ public function testGeneralCheckShareRoot(): void { ['user1', true], ]); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $userFolder->method('isSubNode')->with($userFolder)->willReturn(false); $this->rootFolder->method('getUserFolder')->willReturn($userFolder); @@ -3747,8 +3748,9 @@ public function testUpdateShareUser(): void { Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListener, 'post'); $hookListener->expects($this->never())->method('post'); - $this->rootFolder->method('getUserFolder')->with('newUser')->willReturnSelf(); - $this->rootFolder->method('getRelativePath')->with('/newUser/files/myPath')->willReturn('/myPath'); + $userFolder = $this->createMock(IUserFolder::class); + $userFolder->method('getRelativePath')->with('/newUser/files/myPath')->willReturn('/myPath'); + $this->rootFolder->method('getUserFolder')->with('newUser')->willReturn($userFolder); $hookListener2 = $this->createMock(DummyShareManagerListener::class); Util::connectHook('OCP\Share', 'post_update_permissions', $hookListener2, 'post'); @@ -4873,7 +4875,7 @@ public function testGetAccessList(): void { $node->method('getId') ->willReturn(42); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $file = $this->createMock(File::class); $folder = $this->createMock(Folder::class); @@ -4972,7 +4974,7 @@ public function testGetAccessListWithCurrentAccess(): void { $node->method('getId') ->willReturn(42); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $file = $this->createMock(File::class); $owner = $this->createMock(IUser::class); diff --git a/tests/lib/TagsTest.php b/tests/lib/TagsTest.php index 1827870ca6e21..5437c6ce9b8d2 100644 --- a/tests/lib/TagsTest.php +++ b/tests/lib/TagsTest.php @@ -11,8 +11,8 @@ use OC\Tagging\TagMapper; use OC\TagManager; use OCP\EventDispatcher\IEventDispatcher; -use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\IUserFolder; use OCP\Files\Node; use OCP\IDBConnection; use OCP\ITagManager; @@ -55,7 +55,7 @@ protected function setUp(): void { ->expects($this->any()) ->method('getUser') ->willReturn($this->user); - $userFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(IUserFolder::class); $node = $this->createMock(Node::class); $this->rootFolder = $this->createMock(IRootFolder::class); $this->rootFolder diff --git a/tests/lib/User/UserTest.php b/tests/lib/User/UserTest.php index 750b99db4204e..d4e5b83e0c32a 100644 --- a/tests/lib/User/UserTest.php +++ b/tests/lib/User/UserTest.php @@ -16,6 +16,7 @@ use OCP\Comments\ICommentsManager; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\FileInfo; +use OCP\Files\IRootFolder; use OCP\Files\Storage\IStorageFactory; use OCP\IConfig; use OCP\IURLGenerator; @@ -659,8 +660,13 @@ public function testSetQuota(): void { '23 TB' ); + /* Overwrite IRootFolder to avoid crash about unknown user */ + $this->overwriteService(IRootFolder::class, $this->createMock(IRootFolder::class)); + $user = new User('foo', $backend, $this->dispatcher, $emitter, $config); $user->setQuota('23 TB'); + + $this->restoreService(IRootFolder::class); } public function testGetDefaultUnlimitedQuota(): void { @@ -738,8 +744,13 @@ public function testSetQuotaAddressNoChange(): void { $config->expects($this->never()) ->method('setUserValue'); + /* Overwrite IRootFolder to avoid crash about unknown user */ + $this->overwriteService(IRootFolder::class, $this->createMock(IRootFolder::class)); + $user = new User('foo', $backend, $this->dispatcher, $emitter, $config); $user->setQuota('23 TB'); + + $this->restoreService(IRootFolder::class); } public function testGetLastLogin(): void {