createMock(IL10N::class); $l10n->method('t') ->willReturnCallback(fn ($string, $params) => sprintf($string, ...$params)); $l10nFactory = $this->createMock(IFactory::class); $l10nFactory->method('get') ->willReturn($l10n); $database = $this->createMock(IDBConnection::class); $database->method('supports4ByteText')->willReturn(true); $config = $this->createMock(IConfig::class); $logger = new NullLogger(); $filenameValidator = new FilenameValidator( $l10nFactory, $database, $config, $logger, ); $serverContainer = $this->createMock(IServerContainer::class); $eventDispatcher = $this->createMock(IEventDispatcher::class); $this->bootstrapCoordinator = $this->createMock(Coordinator::class); $this->bootstrapCoordinator->method('getRegistrationContext') ->willReturn(new RegistrationContext($logger)); $this->rootFolder = $this->createMock(IRootFolder::class); $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('user1'); $userSession = $this->createMock(\OCP\IUserSession::class); $userSession->method('getUser') ->willReturn($user); $userManager = $this->createMock(\OCP\IUserManager::class); $previewManager = $this->createMock(IPreview::class); $this->templateManager = new TemplateManager( $serverContainer, $eventDispatcher, $this->bootstrapCoordinator, $this->rootFolder, $userSession, $userManager, $previewManager, $config, $l10nFactory, $logger, $filenameValidator ); } public function testCreateFromTemplateShoudValidateFilename(): void { $this->expectException(GenericFileException::class); $fileDirectory = '/'; $filePath = $fileDirectory . str_repeat('a', 251); $userFolder = $this->createMock(Folder::class); $userFolder->method('get') ->willReturnCallback(function ($path) use ($filePath, $fileDirectory) { if ($path === $filePath) { throw new NotFoundException(); } return $this->createMock(Folder::class); }); $userFolder->method('nodeExists') ->willReturnCallback(function ($path) use ($filePath, $fileDirectory) { return $path === $fileDirectory; }); $this->rootFolder->method('getUserFolder') ->willReturn($userFolder); $this->templateManager->createFromTemplate($filePath); } }