root = $this->createMock(IRootFolder::class); $this->userMountCache = $this->createMock(IUserMountCache::class); $this->appDataFactory = $this->createMock(IAppDataFactory::class); $this->groupManager = $this->createMock(IGroupManager::class); $this->appConfig = $this->createMock(IAppConfig::class); $this->l10n = $this->createMock(IL10N::class); } private function getFolderService(?string $userId = '171'): FolderSErvice { $service = new FolderService( $this->root, $this->userMountCache, $this->appDataFactory, $this->groupManager, $this->appConfig, $this->l10n, $userId ); return $service; } public function testGetFolderAsUnauthenticatedWhenUserIdIsInvalid():void { $folder = $this->createMock(\OCP\Files\Folder::class); $folder->method('nodeExists') ->with($this->equalTo('unauthenticated')) ->willReturn(true); $folder->method('get')->willReturn($folder); $fakeFolder = new FakeFolder(); $fakeFolder->folder = $folder; $appData = $this->createMock(IAppData::class); $appData->method('getFolder')->willReturn($fakeFolder); $this->appDataFactory->method('get')->willReturn($appData); $service = $this->getFolderService(null); $service->getFolder(171); $this->assertTrue(true); } public function testGetFileWithInvalidNodeId():void { $this->userMountCache->method('getMountsForFileId')->wilLReturn([]); $folder = $this->createMock(\OCP\Files\Folder::class); $folder->method('isUpdateable')->willReturn(true); $this->root->method('getUserFolder')->willReturn($folder); $service = $this->getFolderService(); $this->expectExceptionMessage('Invalid node'); $service->getFileById(171); } public function testGetFolderWithValidNodeId():void { $this->userMountCache ->method('getMountsForFileId') ->willreturn([]); $node = $this->createMock(\OCP\Files\File::class); $folder = $this->createMock(\OCP\Files\Folder::class); $node->method('getParent') ->willReturn($folder); $this->root->method('getUserFolder') ->willReturn($node); $folder->method('nodeExists')->willReturn(true); $folder->method('get')->willReturn($folder); $fakeFolder = new FakeFolder(); $fakeFolder->folder = $folder; $appData = $this->createMock(IAppData::class); $appData->method('getFolder') ->willReturn($fakeFolder); $this->appDataFactory->method('get') ->willReturn($appData); $service = $this->getFolderService('1'); $actual = $service->getFolder(171); $this->assertInstanceOf(\OCP\Files\Folder::class, $actual); } }