@@ -30,82 +30,82 @@ |
||
| 30 | 30 | |
| 31 | 31 | class TemplateManagerTest extends TestCase { |
| 32 | 32 | |
| 33 | - private IRootFolder $rootFolder; |
|
| 34 | - private Coordinator $bootstrapCoordinator; |
|
| 35 | - |
|
| 36 | - private TemplateManager $templateManager; |
|
| 37 | - |
|
| 38 | - protected function setUp(): void { |
|
| 39 | - parent::setUp(); |
|
| 40 | - |
|
| 41 | - $l10n = $this->createMock(IL10N::class); |
|
| 42 | - $l10n->method('t') |
|
| 43 | - ->willReturnCallback(fn ($string, $params) => sprintf($string, ...$params)); |
|
| 44 | - $l10nFactory = $this->createMock(IFactory::class); |
|
| 45 | - $l10nFactory->method('get') |
|
| 46 | - ->willReturn($l10n); |
|
| 47 | - $database = $this->createMock(IDBConnection::class); |
|
| 48 | - $database->method('supports4ByteText')->willReturn(true); |
|
| 49 | - $config = $this->createMock(IConfig::class); |
|
| 50 | - $logger = new NullLogger(); |
|
| 51 | - |
|
| 52 | - $filenameValidator = new FilenameValidator( |
|
| 53 | - $l10nFactory, |
|
| 54 | - $database, |
|
| 55 | - $config, |
|
| 56 | - $logger, |
|
| 57 | - ); |
|
| 58 | - |
|
| 59 | - $serverContainer = $this->createMock(IServerContainer::class); |
|
| 60 | - $eventDispatcher = $this->createMock(IEventDispatcher::class); |
|
| 61 | - $this->bootstrapCoordinator = $this->createMock(Coordinator::class); |
|
| 62 | - $this->bootstrapCoordinator->method('getRegistrationContext') |
|
| 63 | - ->willReturn(new RegistrationContext($logger)); |
|
| 64 | - $this->rootFolder = $this->createMock(IRootFolder::class); |
|
| 65 | - $user = $this->createMock(IUser::class); |
|
| 66 | - $user->method('getUID')->willReturn('user1'); |
|
| 67 | - $userSession = $this->createMock(\OCP\IUserSession::class); |
|
| 68 | - $userSession->method('getUser') |
|
| 69 | - ->willReturn($user); |
|
| 70 | - $userManager = $this->createMock(\OCP\IUserManager::class); |
|
| 71 | - $previewManager = $this->createMock(IPreview::class); |
|
| 72 | - |
|
| 73 | - $this->templateManager = new TemplateManager( |
|
| 74 | - $serverContainer, |
|
| 75 | - $eventDispatcher, |
|
| 76 | - $this->bootstrapCoordinator, |
|
| 77 | - $this->rootFolder, |
|
| 78 | - $userSession, |
|
| 79 | - $userManager, |
|
| 80 | - $previewManager, |
|
| 81 | - $config, |
|
| 82 | - $l10nFactory, |
|
| 83 | - $logger, |
|
| 84 | - $filenameValidator |
|
| 85 | - ); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - public function testCreateFromTemplateShoudValidateFilename(): void { |
|
| 89 | - $this->expectException(GenericFileException::class); |
|
| 90 | - |
|
| 91 | - $fileDirectory = '/'; |
|
| 92 | - $filePath = $fileDirectory . str_repeat('a', 251); |
|
| 93 | - |
|
| 94 | - $userFolder = $this->createMock(Folder::class); |
|
| 95 | - $userFolder->method('get') |
|
| 96 | - ->willReturnCallback(function ($path) use ($filePath, $fileDirectory) { |
|
| 97 | - if ($path === $filePath) { |
|
| 98 | - throw new NotFoundException(); |
|
| 99 | - } |
|
| 100 | - return $this->createMock(Folder::class); |
|
| 101 | - }); |
|
| 102 | - $userFolder->method('nodeExists') |
|
| 103 | - ->willReturnCallback(function ($path) use ($filePath, $fileDirectory) { |
|
| 104 | - return $path === $fileDirectory; |
|
| 105 | - }); |
|
| 106 | - $this->rootFolder->method('getUserFolder') |
|
| 107 | - ->willReturn($userFolder); |
|
| 108 | - |
|
| 109 | - $this->templateManager->createFromTemplate($filePath); |
|
| 110 | - } |
|
| 33 | + private IRootFolder $rootFolder; |
|
| 34 | + private Coordinator $bootstrapCoordinator; |
|
| 35 | + |
|
| 36 | + private TemplateManager $templateManager; |
|
| 37 | + |
|
| 38 | + protected function setUp(): void { |
|
| 39 | + parent::setUp(); |
|
| 40 | + |
|
| 41 | + $l10n = $this->createMock(IL10N::class); |
|
| 42 | + $l10n->method('t') |
|
| 43 | + ->willReturnCallback(fn ($string, $params) => sprintf($string, ...$params)); |
|
| 44 | + $l10nFactory = $this->createMock(IFactory::class); |
|
| 45 | + $l10nFactory->method('get') |
|
| 46 | + ->willReturn($l10n); |
|
| 47 | + $database = $this->createMock(IDBConnection::class); |
|
| 48 | + $database->method('supports4ByteText')->willReturn(true); |
|
| 49 | + $config = $this->createMock(IConfig::class); |
|
| 50 | + $logger = new NullLogger(); |
|
| 51 | + |
|
| 52 | + $filenameValidator = new FilenameValidator( |
|
| 53 | + $l10nFactory, |
|
| 54 | + $database, |
|
| 55 | + $config, |
|
| 56 | + $logger, |
|
| 57 | + ); |
|
| 58 | + |
|
| 59 | + $serverContainer = $this->createMock(IServerContainer::class); |
|
| 60 | + $eventDispatcher = $this->createMock(IEventDispatcher::class); |
|
| 61 | + $this->bootstrapCoordinator = $this->createMock(Coordinator::class); |
|
| 62 | + $this->bootstrapCoordinator->method('getRegistrationContext') |
|
| 63 | + ->willReturn(new RegistrationContext($logger)); |
|
| 64 | + $this->rootFolder = $this->createMock(IRootFolder::class); |
|
| 65 | + $user = $this->createMock(IUser::class); |
|
| 66 | + $user->method('getUID')->willReturn('user1'); |
|
| 67 | + $userSession = $this->createMock(\OCP\IUserSession::class); |
|
| 68 | + $userSession->method('getUser') |
|
| 69 | + ->willReturn($user); |
|
| 70 | + $userManager = $this->createMock(\OCP\IUserManager::class); |
|
| 71 | + $previewManager = $this->createMock(IPreview::class); |
|
| 72 | + |
|
| 73 | + $this->templateManager = new TemplateManager( |
|
| 74 | + $serverContainer, |
|
| 75 | + $eventDispatcher, |
|
| 76 | + $this->bootstrapCoordinator, |
|
| 77 | + $this->rootFolder, |
|
| 78 | + $userSession, |
|
| 79 | + $userManager, |
|
| 80 | + $previewManager, |
|
| 81 | + $config, |
|
| 82 | + $l10nFactory, |
|
| 83 | + $logger, |
|
| 84 | + $filenameValidator |
|
| 85 | + ); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + public function testCreateFromTemplateShoudValidateFilename(): void { |
|
| 89 | + $this->expectException(GenericFileException::class); |
|
| 90 | + |
|
| 91 | + $fileDirectory = '/'; |
|
| 92 | + $filePath = $fileDirectory . str_repeat('a', 251); |
|
| 93 | + |
|
| 94 | + $userFolder = $this->createMock(Folder::class); |
|
| 95 | + $userFolder->method('get') |
|
| 96 | + ->willReturnCallback(function ($path) use ($filePath, $fileDirectory) { |
|
| 97 | + if ($path === $filePath) { |
|
| 98 | + throw new NotFoundException(); |
|
| 99 | + } |
|
| 100 | + return $this->createMock(Folder::class); |
|
| 101 | + }); |
|
| 102 | + $userFolder->method('nodeExists') |
|
| 103 | + ->willReturnCallback(function ($path) use ($filePath, $fileDirectory) { |
|
| 104 | + return $path === $fileDirectory; |
|
| 105 | + }); |
|
| 106 | + $this->rootFolder->method('getUserFolder') |
|
| 107 | + ->willReturn($userFolder); |
|
| 108 | + |
|
| 109 | + $this->templateManager->createFromTemplate($filePath); |
|
| 110 | + } |
|
| 111 | 111 | } |