@@ -45,245 +45,245 @@ |
||
45 | 45 | * @package OCA\Files\Tests\Controller |
46 | 46 | */ |
47 | 47 | class ViewControllerTest extends TestCase { |
48 | - private ContainerInterface&MockObject $container; |
|
49 | - private IAppManager&MockObject $appManager; |
|
50 | - private ICacheFactory&MockObject $cacheFactory; |
|
51 | - private IConfig&MockObject $config; |
|
52 | - private IEventDispatcher $eventDispatcher; |
|
53 | - private IEventLogger&MockObject $eventLogger; |
|
54 | - private IInitialState&MockObject $initialState; |
|
55 | - private IL10N&MockObject $l10n; |
|
56 | - private IRequest&MockObject $request; |
|
57 | - private IRootFolder&MockObject $rootFolder; |
|
58 | - private ITemplateManager&MockObject $templateManager; |
|
59 | - private IURLGenerator $urlGenerator; |
|
60 | - private IUser&MockObject $user; |
|
61 | - private IUserSession&MockObject $userSession; |
|
62 | - private LoggerInterface&MockObject $logger; |
|
63 | - private UserConfig&MockObject $userConfig; |
|
64 | - private ViewConfig&MockObject $viewConfig; |
|
65 | - private Router $router; |
|
66 | - |
|
67 | - private ViewController&MockObject $viewController; |
|
68 | - |
|
69 | - protected function setUp(): void { |
|
70 | - parent::setUp(); |
|
71 | - $this->appManager = $this->createMock(IAppManager::class); |
|
72 | - $this->config = $this->createMock(IConfig::class); |
|
73 | - $this->eventDispatcher = $this->createMock(IEventDispatcher::class); |
|
74 | - $this->initialState = $this->createMock(IInitialState::class); |
|
75 | - $this->l10n = $this->createMock(IL10N::class); |
|
76 | - $this->request = $this->createMock(IRequest::class); |
|
77 | - $this->rootFolder = $this->createMock(IRootFolder::class); |
|
78 | - $this->templateManager = $this->createMock(ITemplateManager::class); |
|
79 | - $this->userConfig = $this->createMock(UserConfig::class); |
|
80 | - $this->userSession = $this->createMock(IUserSession::class); |
|
81 | - $this->viewConfig = $this->createMock(ViewConfig::class); |
|
82 | - |
|
83 | - $this->user = $this->getMockBuilder(IUser::class)->getMock(); |
|
84 | - $this->user->expects($this->any()) |
|
85 | - ->method('getUID') |
|
86 | - ->willReturn('testuser1'); |
|
87 | - $this->userSession->expects($this->any()) |
|
88 | - ->method('getUser') |
|
89 | - ->willReturn($this->user); |
|
90 | - |
|
91 | - // Make sure we know the app is enabled |
|
92 | - $this->appManager->expects($this->any()) |
|
93 | - ->method('cleanAppId') |
|
94 | - ->willReturnArgument(0); |
|
95 | - $this->appManager->expects($this->any()) |
|
96 | - ->method('getAppPath') |
|
97 | - ->willReturnCallback(fn (string $appid): string => \OC::$SERVERROOT . '/apps/' . $appid); |
|
98 | - $this->appManager->expects($this->any()) |
|
99 | - ->method('isAppLoaded') |
|
100 | - ->willReturn(true); |
|
101 | - |
|
102 | - $this->cacheFactory = $this->createMock(ICacheFactory::class); |
|
103 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
104 | - $this->eventLogger = $this->createMock(IEventLogger::class); |
|
105 | - $this->container = $this->createMock(ContainerInterface::class); |
|
106 | - $this->router = new Router( |
|
107 | - $this->logger, |
|
108 | - $this->request, |
|
109 | - $this->config, |
|
110 | - $this->eventLogger, |
|
111 | - $this->container, |
|
112 | - $this->appManager, |
|
113 | - ); |
|
114 | - |
|
115 | - // Create a real URLGenerator instance to generate URLs |
|
116 | - $this->urlGenerator = new URLGenerator( |
|
117 | - $this->config, |
|
118 | - $this->userSession, |
|
119 | - $this->cacheFactory, |
|
120 | - $this->request, |
|
121 | - $this->router |
|
122 | - ); |
|
123 | - |
|
124 | - $filenameValidator = $this->createMock(FilenameValidator::class); |
|
125 | - $this->viewController = $this->getMockBuilder(ViewController::class) |
|
126 | - ->setConstructorArgs([ |
|
127 | - 'files', |
|
128 | - $this->request, |
|
129 | - $this->urlGenerator, |
|
130 | - $this->l10n, |
|
131 | - $this->config, |
|
132 | - $this->eventDispatcher, |
|
133 | - $this->userSession, |
|
134 | - $this->appManager, |
|
135 | - $this->rootFolder, |
|
136 | - $this->initialState, |
|
137 | - $this->templateManager, |
|
138 | - $this->userConfig, |
|
139 | - $this->viewConfig, |
|
140 | - $filenameValidator, |
|
141 | - ]) |
|
142 | - ->onlyMethods([ |
|
143 | - 'getStorageInfo', |
|
144 | - ]) |
|
145 | - ->getMock(); |
|
146 | - } |
|
147 | - |
|
148 | - public function testIndexWithRegularBrowser(): void { |
|
149 | - $this->viewController |
|
150 | - ->expects($this->any()) |
|
151 | - ->method('getStorageInfo') |
|
152 | - ->willReturn([ |
|
153 | - 'used' => 123, |
|
154 | - 'quota' => 100, |
|
155 | - 'total' => 100, |
|
156 | - 'relative' => 123, |
|
157 | - 'owner' => 'MyName', |
|
158 | - 'ownerDisplayName' => 'MyDisplayName', |
|
159 | - ]); |
|
160 | - |
|
161 | - $this->config |
|
162 | - ->method('getUserValue') |
|
163 | - ->willReturnMap([ |
|
164 | - [$this->user->getUID(), 'files', 'file_sorting', 'name', 'name'], |
|
165 | - [$this->user->getUID(), 'files', 'file_sorting_direction', 'asc', 'asc'], |
|
166 | - [$this->user->getUID(), 'files', 'files_sorting_configs', '{}', '{}'], |
|
167 | - [$this->user->getUID(), 'files', 'show_hidden', false, false], |
|
168 | - [$this->user->getUID(), 'files', 'crop_image_previews', true, true], |
|
169 | - [$this->user->getUID(), 'files', 'show_grid', true], |
|
170 | - ]); |
|
171 | - |
|
172 | - $baseFolderFiles = $this->getMockBuilder(Folder::class)->getMock(); |
|
173 | - |
|
174 | - $this->rootFolder->expects($this->any()) |
|
175 | - ->method('getUserFolder') |
|
176 | - ->with('testuser1') |
|
177 | - ->willReturn($baseFolderFiles); |
|
178 | - |
|
179 | - $this->config |
|
180 | - ->expects($this->any()) |
|
181 | - ->method('getAppValue') |
|
182 | - ->willReturnArgument(2); |
|
183 | - |
|
184 | - $expected = new TemplateResponse( |
|
185 | - 'files', |
|
186 | - 'index', |
|
187 | - ); |
|
188 | - $policy = new ContentSecurityPolicy(); |
|
189 | - $policy->addAllowedWorkerSrcDomain('\'self\''); |
|
190 | - $policy->addAllowedFrameDomain('\'self\''); |
|
191 | - $expected->setContentSecurityPolicy($policy); |
|
192 | - |
|
193 | - $this->assertEquals($expected, $this->viewController->index('MyDir', 'MyView')); |
|
194 | - } |
|
195 | - |
|
196 | - public static function dataTestShortRedirect(): array { |
|
197 | - // openfile is true by default |
|
198 | - // opendetails is undefined by default |
|
199 | - // both will be evaluated as truthy |
|
200 | - return [ |
|
201 | - [null, null, '/index.php/apps/files/files/123456?openfile=true'], |
|
202 | - ['', null, '/index.php/apps/files/files/123456?openfile=true'], |
|
203 | - [null, '', '/index.php/apps/files/files/123456?openfile=true&opendetails=true'], |
|
204 | - ['', '', '/index.php/apps/files/files/123456?openfile=true&opendetails=true'], |
|
205 | - ['false', '', '/index.php/apps/files/files/123456?openfile=false'], |
|
206 | - [null, 'false', '/index.php/apps/files/files/123456?openfile=true&opendetails=false'], |
|
207 | - ['true', 'false', '/index.php/apps/files/files/123456?openfile=true&opendetails=false'], |
|
208 | - ['false', 'true', '/index.php/apps/files/files/123456?openfile=false&opendetails=true'], |
|
209 | - ['false', 'false', '/index.php/apps/files/files/123456?openfile=false&opendetails=false'], |
|
210 | - ]; |
|
211 | - } |
|
212 | - |
|
213 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTestShortRedirect')] |
|
214 | - public function testShortRedirect(?string $openfile, ?string $opendetails, string $result): void { |
|
215 | - $this->appManager->expects($this->any()) |
|
216 | - ->method('isEnabledForUser') |
|
217 | - ->with('files') |
|
218 | - ->willReturn(true); |
|
219 | - |
|
220 | - $baseFolderFiles = $this->getMockBuilder(Folder::class)->getMock(); |
|
221 | - $this->rootFolder->expects($this->any()) |
|
222 | - ->method('getUserFolder') |
|
223 | - ->with('testuser1') |
|
224 | - ->willReturn($baseFolderFiles); |
|
225 | - |
|
226 | - $parentNode = $this->getMockBuilder(Folder::class)->getMock(); |
|
227 | - $parentNode->expects($this->once()) |
|
228 | - ->method('getPath') |
|
229 | - ->willReturn('testuser1/files/Folder'); |
|
230 | - |
|
231 | - $node = $this->getMockBuilder(File::class)->getMock(); |
|
232 | - $node->expects($this->once()) |
|
233 | - ->method('getParent') |
|
234 | - ->willReturn($parentNode); |
|
235 | - |
|
236 | - $baseFolderFiles->expects($this->any()) |
|
237 | - ->method('getFirstNodeById') |
|
238 | - ->with(123456) |
|
239 | - ->willReturn($node); |
|
240 | - |
|
241 | - $response = $this->viewController->showFile('123456', $opendetails, $openfile); |
|
242 | - $this->assertStringContainsString($result, $response->getHeaders()['Location']); |
|
243 | - } |
|
244 | - |
|
245 | - public function testShowFileRouteWithTrashedFile(): void { |
|
246 | - $this->appManager->expects($this->exactly(2)) |
|
247 | - ->method('isEnabledForUser') |
|
248 | - ->willReturn(true); |
|
249 | - |
|
250 | - $parentNode = $this->createMock(Folder::class); |
|
251 | - $parentNode->expects($this->once()) |
|
252 | - ->method('getPath') |
|
253 | - ->willReturn('testuser1/files_trashbin/files/test.d1462861890/sub'); |
|
254 | - |
|
255 | - $baseFolderFiles = $this->createMock(Folder::class); |
|
256 | - $baseFolderTrash = $this->createMock(Folder::class); |
|
257 | - |
|
258 | - $this->rootFolder->expects($this->any()) |
|
259 | - ->method('getUserFolder') |
|
260 | - ->with('testuser1') |
|
261 | - ->willReturn($baseFolderFiles); |
|
262 | - $this->rootFolder->expects($this->once()) |
|
263 | - ->method('get') |
|
264 | - ->with('testuser1/files_trashbin/files/') |
|
265 | - ->willReturn($baseFolderTrash); |
|
266 | - |
|
267 | - $baseFolderFiles->expects($this->any()) |
|
268 | - ->method('getFirstNodeById') |
|
269 | - ->with(123) |
|
270 | - ->willReturn(null); |
|
271 | - |
|
272 | - $node = $this->createMock(File::class); |
|
273 | - $node->expects($this->once()) |
|
274 | - ->method('getParent') |
|
275 | - ->willReturn($parentNode); |
|
276 | - |
|
277 | - $baseFolderTrash->expects($this->once()) |
|
278 | - ->method('getFirstNodeById') |
|
279 | - ->with(123) |
|
280 | - ->willReturn($node); |
|
281 | - $baseFolderTrash->expects($this->once()) |
|
282 | - ->method('getRelativePath') |
|
283 | - ->with('testuser1/files_trashbin/files/test.d1462861890/sub') |
|
284 | - ->willReturn('/test.d1462861890/sub'); |
|
285 | - |
|
286 | - $expected = new RedirectResponse('/index.php/apps/files/trashbin/123?dir=/test.d1462861890/sub'); |
|
287 | - $this->assertEquals($expected, $this->viewController->index('', '', '123')); |
|
288 | - } |
|
48 | + private ContainerInterface&MockObject $container; |
|
49 | + private IAppManager&MockObject $appManager; |
|
50 | + private ICacheFactory&MockObject $cacheFactory; |
|
51 | + private IConfig&MockObject $config; |
|
52 | + private IEventDispatcher $eventDispatcher; |
|
53 | + private IEventLogger&MockObject $eventLogger; |
|
54 | + private IInitialState&MockObject $initialState; |
|
55 | + private IL10N&MockObject $l10n; |
|
56 | + private IRequest&MockObject $request; |
|
57 | + private IRootFolder&MockObject $rootFolder; |
|
58 | + private ITemplateManager&MockObject $templateManager; |
|
59 | + private IURLGenerator $urlGenerator; |
|
60 | + private IUser&MockObject $user; |
|
61 | + private IUserSession&MockObject $userSession; |
|
62 | + private LoggerInterface&MockObject $logger; |
|
63 | + private UserConfig&MockObject $userConfig; |
|
64 | + private ViewConfig&MockObject $viewConfig; |
|
65 | + private Router $router; |
|
66 | + |
|
67 | + private ViewController&MockObject $viewController; |
|
68 | + |
|
69 | + protected function setUp(): void { |
|
70 | + parent::setUp(); |
|
71 | + $this->appManager = $this->createMock(IAppManager::class); |
|
72 | + $this->config = $this->createMock(IConfig::class); |
|
73 | + $this->eventDispatcher = $this->createMock(IEventDispatcher::class); |
|
74 | + $this->initialState = $this->createMock(IInitialState::class); |
|
75 | + $this->l10n = $this->createMock(IL10N::class); |
|
76 | + $this->request = $this->createMock(IRequest::class); |
|
77 | + $this->rootFolder = $this->createMock(IRootFolder::class); |
|
78 | + $this->templateManager = $this->createMock(ITemplateManager::class); |
|
79 | + $this->userConfig = $this->createMock(UserConfig::class); |
|
80 | + $this->userSession = $this->createMock(IUserSession::class); |
|
81 | + $this->viewConfig = $this->createMock(ViewConfig::class); |
|
82 | + |
|
83 | + $this->user = $this->getMockBuilder(IUser::class)->getMock(); |
|
84 | + $this->user->expects($this->any()) |
|
85 | + ->method('getUID') |
|
86 | + ->willReturn('testuser1'); |
|
87 | + $this->userSession->expects($this->any()) |
|
88 | + ->method('getUser') |
|
89 | + ->willReturn($this->user); |
|
90 | + |
|
91 | + // Make sure we know the app is enabled |
|
92 | + $this->appManager->expects($this->any()) |
|
93 | + ->method('cleanAppId') |
|
94 | + ->willReturnArgument(0); |
|
95 | + $this->appManager->expects($this->any()) |
|
96 | + ->method('getAppPath') |
|
97 | + ->willReturnCallback(fn (string $appid): string => \OC::$SERVERROOT . '/apps/' . $appid); |
|
98 | + $this->appManager->expects($this->any()) |
|
99 | + ->method('isAppLoaded') |
|
100 | + ->willReturn(true); |
|
101 | + |
|
102 | + $this->cacheFactory = $this->createMock(ICacheFactory::class); |
|
103 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
104 | + $this->eventLogger = $this->createMock(IEventLogger::class); |
|
105 | + $this->container = $this->createMock(ContainerInterface::class); |
|
106 | + $this->router = new Router( |
|
107 | + $this->logger, |
|
108 | + $this->request, |
|
109 | + $this->config, |
|
110 | + $this->eventLogger, |
|
111 | + $this->container, |
|
112 | + $this->appManager, |
|
113 | + ); |
|
114 | + |
|
115 | + // Create a real URLGenerator instance to generate URLs |
|
116 | + $this->urlGenerator = new URLGenerator( |
|
117 | + $this->config, |
|
118 | + $this->userSession, |
|
119 | + $this->cacheFactory, |
|
120 | + $this->request, |
|
121 | + $this->router |
|
122 | + ); |
|
123 | + |
|
124 | + $filenameValidator = $this->createMock(FilenameValidator::class); |
|
125 | + $this->viewController = $this->getMockBuilder(ViewController::class) |
|
126 | + ->setConstructorArgs([ |
|
127 | + 'files', |
|
128 | + $this->request, |
|
129 | + $this->urlGenerator, |
|
130 | + $this->l10n, |
|
131 | + $this->config, |
|
132 | + $this->eventDispatcher, |
|
133 | + $this->userSession, |
|
134 | + $this->appManager, |
|
135 | + $this->rootFolder, |
|
136 | + $this->initialState, |
|
137 | + $this->templateManager, |
|
138 | + $this->userConfig, |
|
139 | + $this->viewConfig, |
|
140 | + $filenameValidator, |
|
141 | + ]) |
|
142 | + ->onlyMethods([ |
|
143 | + 'getStorageInfo', |
|
144 | + ]) |
|
145 | + ->getMock(); |
|
146 | + } |
|
147 | + |
|
148 | + public function testIndexWithRegularBrowser(): void { |
|
149 | + $this->viewController |
|
150 | + ->expects($this->any()) |
|
151 | + ->method('getStorageInfo') |
|
152 | + ->willReturn([ |
|
153 | + 'used' => 123, |
|
154 | + 'quota' => 100, |
|
155 | + 'total' => 100, |
|
156 | + 'relative' => 123, |
|
157 | + 'owner' => 'MyName', |
|
158 | + 'ownerDisplayName' => 'MyDisplayName', |
|
159 | + ]); |
|
160 | + |
|
161 | + $this->config |
|
162 | + ->method('getUserValue') |
|
163 | + ->willReturnMap([ |
|
164 | + [$this->user->getUID(), 'files', 'file_sorting', 'name', 'name'], |
|
165 | + [$this->user->getUID(), 'files', 'file_sorting_direction', 'asc', 'asc'], |
|
166 | + [$this->user->getUID(), 'files', 'files_sorting_configs', '{}', '{}'], |
|
167 | + [$this->user->getUID(), 'files', 'show_hidden', false, false], |
|
168 | + [$this->user->getUID(), 'files', 'crop_image_previews', true, true], |
|
169 | + [$this->user->getUID(), 'files', 'show_grid', true], |
|
170 | + ]); |
|
171 | + |
|
172 | + $baseFolderFiles = $this->getMockBuilder(Folder::class)->getMock(); |
|
173 | + |
|
174 | + $this->rootFolder->expects($this->any()) |
|
175 | + ->method('getUserFolder') |
|
176 | + ->with('testuser1') |
|
177 | + ->willReturn($baseFolderFiles); |
|
178 | + |
|
179 | + $this->config |
|
180 | + ->expects($this->any()) |
|
181 | + ->method('getAppValue') |
|
182 | + ->willReturnArgument(2); |
|
183 | + |
|
184 | + $expected = new TemplateResponse( |
|
185 | + 'files', |
|
186 | + 'index', |
|
187 | + ); |
|
188 | + $policy = new ContentSecurityPolicy(); |
|
189 | + $policy->addAllowedWorkerSrcDomain('\'self\''); |
|
190 | + $policy->addAllowedFrameDomain('\'self\''); |
|
191 | + $expected->setContentSecurityPolicy($policy); |
|
192 | + |
|
193 | + $this->assertEquals($expected, $this->viewController->index('MyDir', 'MyView')); |
|
194 | + } |
|
195 | + |
|
196 | + public static function dataTestShortRedirect(): array { |
|
197 | + // openfile is true by default |
|
198 | + // opendetails is undefined by default |
|
199 | + // both will be evaluated as truthy |
|
200 | + return [ |
|
201 | + [null, null, '/index.php/apps/files/files/123456?openfile=true'], |
|
202 | + ['', null, '/index.php/apps/files/files/123456?openfile=true'], |
|
203 | + [null, '', '/index.php/apps/files/files/123456?openfile=true&opendetails=true'], |
|
204 | + ['', '', '/index.php/apps/files/files/123456?openfile=true&opendetails=true'], |
|
205 | + ['false', '', '/index.php/apps/files/files/123456?openfile=false'], |
|
206 | + [null, 'false', '/index.php/apps/files/files/123456?openfile=true&opendetails=false'], |
|
207 | + ['true', 'false', '/index.php/apps/files/files/123456?openfile=true&opendetails=false'], |
|
208 | + ['false', 'true', '/index.php/apps/files/files/123456?openfile=false&opendetails=true'], |
|
209 | + ['false', 'false', '/index.php/apps/files/files/123456?openfile=false&opendetails=false'], |
|
210 | + ]; |
|
211 | + } |
|
212 | + |
|
213 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestShortRedirect')] |
|
214 | + public function testShortRedirect(?string $openfile, ?string $opendetails, string $result): void { |
|
215 | + $this->appManager->expects($this->any()) |
|
216 | + ->method('isEnabledForUser') |
|
217 | + ->with('files') |
|
218 | + ->willReturn(true); |
|
219 | + |
|
220 | + $baseFolderFiles = $this->getMockBuilder(Folder::class)->getMock(); |
|
221 | + $this->rootFolder->expects($this->any()) |
|
222 | + ->method('getUserFolder') |
|
223 | + ->with('testuser1') |
|
224 | + ->willReturn($baseFolderFiles); |
|
225 | + |
|
226 | + $parentNode = $this->getMockBuilder(Folder::class)->getMock(); |
|
227 | + $parentNode->expects($this->once()) |
|
228 | + ->method('getPath') |
|
229 | + ->willReturn('testuser1/files/Folder'); |
|
230 | + |
|
231 | + $node = $this->getMockBuilder(File::class)->getMock(); |
|
232 | + $node->expects($this->once()) |
|
233 | + ->method('getParent') |
|
234 | + ->willReturn($parentNode); |
|
235 | + |
|
236 | + $baseFolderFiles->expects($this->any()) |
|
237 | + ->method('getFirstNodeById') |
|
238 | + ->with(123456) |
|
239 | + ->willReturn($node); |
|
240 | + |
|
241 | + $response = $this->viewController->showFile('123456', $opendetails, $openfile); |
|
242 | + $this->assertStringContainsString($result, $response->getHeaders()['Location']); |
|
243 | + } |
|
244 | + |
|
245 | + public function testShowFileRouteWithTrashedFile(): void { |
|
246 | + $this->appManager->expects($this->exactly(2)) |
|
247 | + ->method('isEnabledForUser') |
|
248 | + ->willReturn(true); |
|
249 | + |
|
250 | + $parentNode = $this->createMock(Folder::class); |
|
251 | + $parentNode->expects($this->once()) |
|
252 | + ->method('getPath') |
|
253 | + ->willReturn('testuser1/files_trashbin/files/test.d1462861890/sub'); |
|
254 | + |
|
255 | + $baseFolderFiles = $this->createMock(Folder::class); |
|
256 | + $baseFolderTrash = $this->createMock(Folder::class); |
|
257 | + |
|
258 | + $this->rootFolder->expects($this->any()) |
|
259 | + ->method('getUserFolder') |
|
260 | + ->with('testuser1') |
|
261 | + ->willReturn($baseFolderFiles); |
|
262 | + $this->rootFolder->expects($this->once()) |
|
263 | + ->method('get') |
|
264 | + ->with('testuser1/files_trashbin/files/') |
|
265 | + ->willReturn($baseFolderTrash); |
|
266 | + |
|
267 | + $baseFolderFiles->expects($this->any()) |
|
268 | + ->method('getFirstNodeById') |
|
269 | + ->with(123) |
|
270 | + ->willReturn(null); |
|
271 | + |
|
272 | + $node = $this->createMock(File::class); |
|
273 | + $node->expects($this->once()) |
|
274 | + ->method('getParent') |
|
275 | + ->willReturn($parentNode); |
|
276 | + |
|
277 | + $baseFolderTrash->expects($this->once()) |
|
278 | + ->method('getFirstNodeById') |
|
279 | + ->with(123) |
|
280 | + ->willReturn($node); |
|
281 | + $baseFolderTrash->expects($this->once()) |
|
282 | + ->method('getRelativePath') |
|
283 | + ->with('testuser1/files_trashbin/files/test.d1462861890/sub') |
|
284 | + ->willReturn('/test.d1462861890/sub'); |
|
285 | + |
|
286 | + $expected = new RedirectResponse('/index.php/apps/files/trashbin/123?dir=/test.d1462861890/sub'); |
|
287 | + $this->assertEquals($expected, $this->viewController->index('', '', '123')); |
|
288 | + } |
|
289 | 289 | } |
@@ -14,33 +14,33 @@ |
||
14 | 14 | |
15 | 15 | class AdvancedCapabilitiesTest extends TestCase { |
16 | 16 | |
17 | - protected SettingsService&MockObject $service; |
|
18 | - protected AdvancedCapabilities $capabilities; |
|
19 | - |
|
20 | - protected function setUp(): void { |
|
21 | - parent::setUp(); |
|
22 | - $this->service = $this->createMock(SettingsService::class); |
|
23 | - $this->capabilities = new AdvancedCapabilities($this->service); |
|
24 | - } |
|
25 | - |
|
26 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataGetCapabilities')] |
|
27 | - public function testGetCapabilities(bool $wcf): void { |
|
28 | - $this->service |
|
29 | - ->expects(self::once()) |
|
30 | - ->method('hasFilesWindowsSupport') |
|
31 | - ->willReturn($wcf); |
|
32 | - |
|
33 | - self::assertEqualsCanonicalizing(['files' => [ 'windows_compatible_filenames' => $wcf ]], $this->capabilities->getCapabilities()); |
|
34 | - } |
|
35 | - |
|
36 | - public static function dataGetCapabilities(): array { |
|
37 | - return [ |
|
38 | - 'WCF enabled' => [ |
|
39 | - true, |
|
40 | - ], |
|
41 | - 'WCF disabled' => [ |
|
42 | - false, |
|
43 | - ], |
|
44 | - ]; |
|
45 | - } |
|
17 | + protected SettingsService&MockObject $service; |
|
18 | + protected AdvancedCapabilities $capabilities; |
|
19 | + |
|
20 | + protected function setUp(): void { |
|
21 | + parent::setUp(); |
|
22 | + $this->service = $this->createMock(SettingsService::class); |
|
23 | + $this->capabilities = new AdvancedCapabilities($this->service); |
|
24 | + } |
|
25 | + |
|
26 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetCapabilities')] |
|
27 | + public function testGetCapabilities(bool $wcf): void { |
|
28 | + $this->service |
|
29 | + ->expects(self::once()) |
|
30 | + ->method('hasFilesWindowsSupport') |
|
31 | + ->willReturn($wcf); |
|
32 | + |
|
33 | + self::assertEqualsCanonicalizing(['files' => [ 'windows_compatible_filenames' => $wcf ]], $this->capabilities->getCapabilities()); |
|
34 | + } |
|
35 | + |
|
36 | + public static function dataGetCapabilities(): array { |
|
37 | + return [ |
|
38 | + 'WCF enabled' => [ |
|
39 | + true, |
|
40 | + ], |
|
41 | + 'WCF disabled' => [ |
|
42 | + false, |
|
43 | + ], |
|
44 | + ]; |
|
45 | + } |
|
46 | 46 | } |
@@ -29,93 +29,93 @@ |
||
29 | 29 | * @package OCA\Files |
30 | 30 | */ |
31 | 31 | class TagServiceTest extends \Test\TestCase { |
32 | - private string $user; |
|
33 | - private IUserSession&MockObject $userSession; |
|
34 | - private IManager&MockObject $activityManager; |
|
35 | - private Folder $root; |
|
36 | - private TagService&MockObject $tagService; |
|
37 | - private ITags $tagger; |
|
38 | - |
|
39 | - protected function setUp(): void { |
|
40 | - parent::setUp(); |
|
41 | - $this->user = static::getUniqueID('user'); |
|
42 | - $this->activityManager = $this->createMock(IManager::class); |
|
43 | - Server::get(IUserManager::class)->createUser($this->user, 'test'); |
|
44 | - \OC_User::setUserId($this->user); |
|
45 | - \OC_Util::setupFS($this->user); |
|
46 | - $user = $this->createMock(IUser::class); |
|
47 | - /** |
|
48 | - * @var IUserSession |
|
49 | - */ |
|
50 | - $this->userSession = $this->createMock(IUserSession::class); |
|
51 | - $this->userSession->expects($this->any()) |
|
52 | - ->method('getUser') |
|
53 | - ->withAnyParameters() |
|
54 | - ->willReturn($user); |
|
55 | - |
|
56 | - $this->root = Server::get(IRootFolder::class)->getUserFolder($this->user); |
|
57 | - |
|
58 | - $this->tagger = Server::get(ITagManager::class)->load('files'); |
|
59 | - $this->tagService = $this->getTagService(); |
|
60 | - } |
|
61 | - |
|
62 | - protected function getTagService(array $methods = []): TagService&MockObject { |
|
63 | - return $this->getMockBuilder(TagService::class) |
|
64 | - ->setConstructorArgs([ |
|
65 | - $this->userSession, |
|
66 | - $this->activityManager, |
|
67 | - $this->tagger, |
|
68 | - $this->root, |
|
69 | - ]) |
|
70 | - ->onlyMethods($methods) |
|
71 | - ->getMock(); |
|
72 | - } |
|
73 | - |
|
74 | - protected function tearDown(): void { |
|
75 | - \OC_User::setUserId(''); |
|
76 | - $user = Server::get(IUserManager::class)->get($this->user); |
|
77 | - if ($user !== null) { |
|
78 | - $user->delete(); |
|
79 | - } |
|
80 | - |
|
81 | - parent::tearDown(); |
|
82 | - } |
|
83 | - |
|
84 | - public function testUpdateFileTags(): void { |
|
85 | - $tag1 = 'tag1'; |
|
86 | - $tag2 = 'tag2'; |
|
87 | - |
|
88 | - $subdir = $this->root->newFolder('subdir'); |
|
89 | - $testFile = $subdir->newFile('test.txt'); |
|
90 | - $testFile->putContent('test contents'); |
|
91 | - |
|
92 | - $fileId = $testFile->getId(); |
|
93 | - |
|
94 | - // set tags |
|
95 | - $this->tagService->updateFileTags('subdir/test.txt', [$tag1, $tag2]); |
|
96 | - |
|
97 | - $this->assertEquals([$fileId], $this->tagger->getIdsForTag($tag1)); |
|
98 | - $this->assertEquals([$fileId], $this->tagger->getIdsForTag($tag2)); |
|
99 | - |
|
100 | - // remove tag |
|
101 | - $this->tagService->updateFileTags('subdir/test.txt', [$tag2]); |
|
102 | - $this->assertEquals([], $this->tagger->getIdsForTag($tag1)); |
|
103 | - $this->assertEquals([$fileId], $this->tagger->getIdsForTag($tag2)); |
|
104 | - |
|
105 | - // clear tags |
|
106 | - $this->tagService->updateFileTags('subdir/test.txt', []); |
|
107 | - $this->assertEquals([], $this->tagger->getIdsForTag($tag1)); |
|
108 | - $this->assertEquals([], $this->tagger->getIdsForTag($tag2)); |
|
109 | - |
|
110 | - // non-existing file |
|
111 | - $caught = false; |
|
112 | - try { |
|
113 | - $this->tagService->updateFileTags('subdir/unexist.txt', [$tag1]); |
|
114 | - } catch (NotFoundException $e) { |
|
115 | - $caught = true; |
|
116 | - } |
|
117 | - $this->assertTrue($caught); |
|
118 | - |
|
119 | - $subdir->delete(); |
|
120 | - } |
|
32 | + private string $user; |
|
33 | + private IUserSession&MockObject $userSession; |
|
34 | + private IManager&MockObject $activityManager; |
|
35 | + private Folder $root; |
|
36 | + private TagService&MockObject $tagService; |
|
37 | + private ITags $tagger; |
|
38 | + |
|
39 | + protected function setUp(): void { |
|
40 | + parent::setUp(); |
|
41 | + $this->user = static::getUniqueID('user'); |
|
42 | + $this->activityManager = $this->createMock(IManager::class); |
|
43 | + Server::get(IUserManager::class)->createUser($this->user, 'test'); |
|
44 | + \OC_User::setUserId($this->user); |
|
45 | + \OC_Util::setupFS($this->user); |
|
46 | + $user = $this->createMock(IUser::class); |
|
47 | + /** |
|
48 | + * @var IUserSession |
|
49 | + */ |
|
50 | + $this->userSession = $this->createMock(IUserSession::class); |
|
51 | + $this->userSession->expects($this->any()) |
|
52 | + ->method('getUser') |
|
53 | + ->withAnyParameters() |
|
54 | + ->willReturn($user); |
|
55 | + |
|
56 | + $this->root = Server::get(IRootFolder::class)->getUserFolder($this->user); |
|
57 | + |
|
58 | + $this->tagger = Server::get(ITagManager::class)->load('files'); |
|
59 | + $this->tagService = $this->getTagService(); |
|
60 | + } |
|
61 | + |
|
62 | + protected function getTagService(array $methods = []): TagService&MockObject { |
|
63 | + return $this->getMockBuilder(TagService::class) |
|
64 | + ->setConstructorArgs([ |
|
65 | + $this->userSession, |
|
66 | + $this->activityManager, |
|
67 | + $this->tagger, |
|
68 | + $this->root, |
|
69 | + ]) |
|
70 | + ->onlyMethods($methods) |
|
71 | + ->getMock(); |
|
72 | + } |
|
73 | + |
|
74 | + protected function tearDown(): void { |
|
75 | + \OC_User::setUserId(''); |
|
76 | + $user = Server::get(IUserManager::class)->get($this->user); |
|
77 | + if ($user !== null) { |
|
78 | + $user->delete(); |
|
79 | + } |
|
80 | + |
|
81 | + parent::tearDown(); |
|
82 | + } |
|
83 | + |
|
84 | + public function testUpdateFileTags(): void { |
|
85 | + $tag1 = 'tag1'; |
|
86 | + $tag2 = 'tag2'; |
|
87 | + |
|
88 | + $subdir = $this->root->newFolder('subdir'); |
|
89 | + $testFile = $subdir->newFile('test.txt'); |
|
90 | + $testFile->putContent('test contents'); |
|
91 | + |
|
92 | + $fileId = $testFile->getId(); |
|
93 | + |
|
94 | + // set tags |
|
95 | + $this->tagService->updateFileTags('subdir/test.txt', [$tag1, $tag2]); |
|
96 | + |
|
97 | + $this->assertEquals([$fileId], $this->tagger->getIdsForTag($tag1)); |
|
98 | + $this->assertEquals([$fileId], $this->tagger->getIdsForTag($tag2)); |
|
99 | + |
|
100 | + // remove tag |
|
101 | + $this->tagService->updateFileTags('subdir/test.txt', [$tag2]); |
|
102 | + $this->assertEquals([], $this->tagger->getIdsForTag($tag1)); |
|
103 | + $this->assertEquals([$fileId], $this->tagger->getIdsForTag($tag2)); |
|
104 | + |
|
105 | + // clear tags |
|
106 | + $this->tagService->updateFileTags('subdir/test.txt', []); |
|
107 | + $this->assertEquals([], $this->tagger->getIdsForTag($tag1)); |
|
108 | + $this->assertEquals([], $this->tagger->getIdsForTag($tag2)); |
|
109 | + |
|
110 | + // non-existing file |
|
111 | + $caught = false; |
|
112 | + try { |
|
113 | + $this->tagService->updateFileTags('subdir/unexist.txt', [$tag1]); |
|
114 | + } catch (NotFoundException $e) { |
|
115 | + $caught = true; |
|
116 | + } |
|
117 | + $this->assertTrue($caught); |
|
118 | + |
|
119 | + $subdir->delete(); |
|
120 | + } |
|
121 | 121 | } |
@@ -11,85 +11,85 @@ |
||
11 | 11 | use OCA\Files\Helper; |
12 | 12 | |
13 | 13 | class HelperTest extends \Test\TestCase { |
14 | - private static function makeFileInfo($name, $size, $mtime, $isDir = false): FileInfo { |
|
15 | - return new FileInfo( |
|
16 | - '/' . $name, |
|
17 | - null, |
|
18 | - '/', |
|
19 | - [ |
|
20 | - 'name' => $name, |
|
21 | - 'size' => $size, |
|
22 | - 'mtime' => $mtime, |
|
23 | - 'type' => $isDir ? 'dir' : 'file', |
|
24 | - 'mimetype' => $isDir ? 'httpd/unix-directory' : 'application/octet-stream' |
|
25 | - ], |
|
26 | - null |
|
27 | - ); |
|
28 | - } |
|
14 | + private static function makeFileInfo($name, $size, $mtime, $isDir = false): FileInfo { |
|
15 | + return new FileInfo( |
|
16 | + '/' . $name, |
|
17 | + null, |
|
18 | + '/', |
|
19 | + [ |
|
20 | + 'name' => $name, |
|
21 | + 'size' => $size, |
|
22 | + 'mtime' => $mtime, |
|
23 | + 'type' => $isDir ? 'dir' : 'file', |
|
24 | + 'mimetype' => $isDir ? 'httpd/unix-directory' : 'application/octet-stream' |
|
25 | + ], |
|
26 | + null |
|
27 | + ); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Returns a file list for testing |
|
32 | - */ |
|
33 | - private static function getTestFileList(): array { |
|
34 | - return [ |
|
35 | - self::makeFileInfo('a.txt', 4, 2.3 * pow(10, 9)), |
|
36 | - self::makeFileInfo('q.txt', 5, 150), |
|
37 | - self::makeFileInfo('subdir2', 87, 128, true), |
|
38 | - self::makeFileInfo('b.txt', 2.2 * pow(10, 9), 800), |
|
39 | - self::makeFileInfo('o.txt', 12, 100), |
|
40 | - self::makeFileInfo('subdir', 88, 125, true), |
|
41 | - ]; |
|
42 | - } |
|
30 | + /** |
|
31 | + * Returns a file list for testing |
|
32 | + */ |
|
33 | + private static function getTestFileList(): array { |
|
34 | + return [ |
|
35 | + self::makeFileInfo('a.txt', 4, 2.3 * pow(10, 9)), |
|
36 | + self::makeFileInfo('q.txt', 5, 150), |
|
37 | + self::makeFileInfo('subdir2', 87, 128, true), |
|
38 | + self::makeFileInfo('b.txt', 2.2 * pow(10, 9), 800), |
|
39 | + self::makeFileInfo('o.txt', 12, 100), |
|
40 | + self::makeFileInfo('subdir', 88, 125, true), |
|
41 | + ]; |
|
42 | + } |
|
43 | 43 | |
44 | - public static function sortDataProvider(): array { |
|
45 | - return [ |
|
46 | - [ |
|
47 | - 'name', |
|
48 | - false, |
|
49 | - ['subdir', 'subdir2', 'a.txt', 'b.txt', 'o.txt', 'q.txt'], |
|
50 | - ], |
|
51 | - [ |
|
52 | - 'name', |
|
53 | - true, |
|
54 | - ['q.txt', 'o.txt', 'b.txt', 'a.txt', 'subdir2', 'subdir'], |
|
55 | - ], |
|
56 | - [ |
|
57 | - 'size', |
|
58 | - false, |
|
59 | - ['a.txt', 'q.txt', 'o.txt', 'subdir2', 'subdir', 'b.txt'], |
|
60 | - ], |
|
61 | - [ |
|
62 | - 'size', |
|
63 | - true, |
|
64 | - ['b.txt', 'subdir', 'subdir2', 'o.txt', 'q.txt', 'a.txt'], |
|
65 | - ], |
|
66 | - [ |
|
67 | - 'mtime', |
|
68 | - false, |
|
69 | - ['o.txt', 'subdir', 'subdir2', 'q.txt', 'b.txt', 'a.txt'], |
|
70 | - ], |
|
71 | - [ |
|
72 | - 'mtime', |
|
73 | - true, |
|
74 | - ['a.txt', 'b.txt', 'q.txt', 'subdir2', 'subdir', 'o.txt'], |
|
75 | - ], |
|
76 | - ]; |
|
77 | - } |
|
44 | + public static function sortDataProvider(): array { |
|
45 | + return [ |
|
46 | + [ |
|
47 | + 'name', |
|
48 | + false, |
|
49 | + ['subdir', 'subdir2', 'a.txt', 'b.txt', 'o.txt', 'q.txt'], |
|
50 | + ], |
|
51 | + [ |
|
52 | + 'name', |
|
53 | + true, |
|
54 | + ['q.txt', 'o.txt', 'b.txt', 'a.txt', 'subdir2', 'subdir'], |
|
55 | + ], |
|
56 | + [ |
|
57 | + 'size', |
|
58 | + false, |
|
59 | + ['a.txt', 'q.txt', 'o.txt', 'subdir2', 'subdir', 'b.txt'], |
|
60 | + ], |
|
61 | + [ |
|
62 | + 'size', |
|
63 | + true, |
|
64 | + ['b.txt', 'subdir', 'subdir2', 'o.txt', 'q.txt', 'a.txt'], |
|
65 | + ], |
|
66 | + [ |
|
67 | + 'mtime', |
|
68 | + false, |
|
69 | + ['o.txt', 'subdir', 'subdir2', 'q.txt', 'b.txt', 'a.txt'], |
|
70 | + ], |
|
71 | + [ |
|
72 | + 'mtime', |
|
73 | + true, |
|
74 | + ['a.txt', 'b.txt', 'q.txt', 'subdir2', 'subdir', 'o.txt'], |
|
75 | + ], |
|
76 | + ]; |
|
77 | + } |
|
78 | 78 | |
79 | - #[\PHPUnit\Framework\Attributes\DataProvider('sortDataProvider')] |
|
80 | - public function testSortByName(string $sort, bool $sortDescending, array $expectedOrder): void { |
|
81 | - if (($sort === 'mtime') && (PHP_INT_SIZE < 8)) { |
|
82 | - $this->markTestSkipped('Skip mtime sorting on 32bit'); |
|
83 | - } |
|
84 | - $files = self::getTestFileList(); |
|
85 | - $files = Helper::sortFiles($files, $sort, $sortDescending); |
|
86 | - $fileNames = []; |
|
87 | - foreach ($files as $fileInfo) { |
|
88 | - $fileNames[] = $fileInfo->getName(); |
|
89 | - } |
|
90 | - $this->assertEquals( |
|
91 | - $expectedOrder, |
|
92 | - $fileNames |
|
93 | - ); |
|
94 | - } |
|
79 | + #[\PHPUnit\Framework\Attributes\DataProvider('sortDataProvider')] |
|
80 | + public function testSortByName(string $sort, bool $sortDescending, array $expectedOrder): void { |
|
81 | + if (($sort === 'mtime') && (PHP_INT_SIZE < 8)) { |
|
82 | + $this->markTestSkipped('Skip mtime sorting on 32bit'); |
|
83 | + } |
|
84 | + $files = self::getTestFileList(); |
|
85 | + $files = Helper::sortFiles($files, $sort, $sortDescending); |
|
86 | + $fileNames = []; |
|
87 | + foreach ($files as $fileInfo) { |
|
88 | + $fileNames[] = $fileInfo->getName(); |
|
89 | + } |
|
90 | + $this->assertEquals( |
|
91 | + $expectedOrder, |
|
92 | + $fileNames |
|
93 | + ); |
|
94 | + } |
|
95 | 95 | } |
@@ -28,162 +28,162 @@ |
||
28 | 28 | * @package OCA\Files\Tests\Activity |
29 | 29 | */ |
30 | 30 | class ProviderTest extends TestCase { |
31 | - protected IFactory&MockObject $l10nFactory; |
|
32 | - protected IURLGenerator&MockObject $url; |
|
33 | - protected IManager&MockObject $activityManager; |
|
34 | - protected IUserManager&MockObject $userManager; |
|
35 | - protected IRootFolder&MockObject $rootFolder; |
|
36 | - protected ICloudIdManager&MockObject $cloudIdManager; |
|
37 | - protected IContactsManager&MockObject $contactsManager; |
|
38 | - protected IEventMerger&MockObject $eventMerger; |
|
39 | - |
|
40 | - protected function setUp(): void { |
|
41 | - parent::setUp(); |
|
42 | - |
|
43 | - $this->l10nFactory = $this->createMock(IFactory::class); |
|
44 | - $this->url = $this->createMock(IURLGenerator::class); |
|
45 | - $this->activityManager = $this->createMock(IManager::class); |
|
46 | - $this->userManager = $this->createMock(IUserManager::class); |
|
47 | - $this->rootFolder = $this->createMock(IRootFolder::class); |
|
48 | - $this->cloudIdManager = $this->createMock(ICloudIdManager::class); |
|
49 | - $this->contactsManager = $this->createMock(IContactsManager::class); |
|
50 | - $this->eventMerger = $this->createMock(IEventMerger::class); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * @param string[] $methods |
|
55 | - * @return Provider|MockObject |
|
56 | - */ |
|
57 | - protected function getProvider(array $methods = []) { |
|
58 | - if (!empty($methods)) { |
|
59 | - return $this->getMockBuilder(Provider::class) |
|
60 | - ->setConstructorArgs([ |
|
61 | - $this->l10nFactory, |
|
62 | - $this->url, |
|
63 | - $this->activityManager, |
|
64 | - $this->userManager, |
|
65 | - $this->rootFolder, |
|
66 | - $this->cloudIdManager, |
|
67 | - $this->contactsManager, |
|
68 | - $this->eventMerger, |
|
69 | - ]) |
|
70 | - ->onlyMethods($methods) |
|
71 | - ->getMock(); |
|
72 | - } |
|
73 | - return new Provider( |
|
74 | - $this->l10nFactory, |
|
75 | - $this->url, |
|
76 | - $this->activityManager, |
|
77 | - $this->userManager, |
|
78 | - $this->rootFolder, |
|
79 | - $this->cloudIdManager, |
|
80 | - $this->contactsManager, |
|
81 | - $this->eventMerger |
|
82 | - ); |
|
83 | - } |
|
84 | - |
|
85 | - public static function dataGetFile(): array { |
|
86 | - return [ |
|
87 | - [[42 => '/FortyTwo.txt'], null, '42', 'FortyTwo.txt', 'FortyTwo.txt'], |
|
88 | - [['23' => '/Twenty/Three.txt'], null, '23', 'Three.txt', 'Twenty/Three.txt'], |
|
89 | - ['/Foo/Bar.txt', 128, '128', 'Bar.txt', 'Foo/Bar.txt'], // Legacy from ownCloud 8.2 and before |
|
90 | - ]; |
|
91 | - } |
|
92 | - |
|
93 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataGetFile')] |
|
94 | - public function testGetFile(array|string $parameter, ?int $eventId, string $id, string $name, string $path): void { |
|
95 | - $provider = $this->getProvider(); |
|
96 | - |
|
97 | - if ($eventId !== null) { |
|
98 | - $event = $this->createMock(IEvent::class); |
|
99 | - $event->expects($this->once()) |
|
100 | - ->method('getObjectId') |
|
101 | - ->willReturn($eventId); |
|
102 | - } else { |
|
103 | - $event = null; |
|
104 | - } |
|
105 | - |
|
106 | - $this->url->expects($this->once()) |
|
107 | - ->method('linkToRouteAbsolute') |
|
108 | - ->with('files.viewcontroller.showFile', ['fileid' => $id]) |
|
109 | - ->willReturn('link-' . $id); |
|
110 | - |
|
111 | - $result = self::invokePrivate($provider, 'getFile', [$parameter, $event]); |
|
112 | - |
|
113 | - $this->assertSame('file', $result['type']); |
|
114 | - $this->assertSame($id, $result['id']); |
|
115 | - $this->assertSame($name, $result['name']); |
|
116 | - $this->assertSame($path, $result['path']); |
|
117 | - $this->assertSame('link-' . $id, $result['link']); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - public function testGetFileThrows(): void { |
|
122 | - $this->expectException(UnknownActivityException::class); |
|
123 | - |
|
124 | - $provider = $this->getProvider(); |
|
125 | - self::invokePrivate($provider, 'getFile', ['/Foo/Bar.txt', null]); |
|
126 | - } |
|
127 | - |
|
128 | - public static function dataGetUser(): array { |
|
129 | - return [ |
|
130 | - ['test', 'Test user', null, ['type' => 'user', 'id' => 'test', 'name' => 'Test user']], |
|
131 | - ['test@http://localhost', null, ['user' => 'test', 'displayId' => 'test@localhost', 'remote' => 'localhost', 'name' => null], ['type' => 'user', 'id' => 'test', 'name' => 'test@localhost', 'server' => 'localhost']], |
|
132 | - ['test@http://localhost', null, ['user' => 'test', 'displayId' => 'test@localhost', 'remote' => 'localhost', 'name' => 'Remote user'], ['type' => 'user', 'id' => 'test', 'name' => 'Remote user (test@localhost)', 'server' => 'localhost']], |
|
133 | - ['test', null, null, ['type' => 'user', 'id' => 'test', 'name' => 'test']], |
|
134 | - ]; |
|
135 | - } |
|
136 | - |
|
137 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataGetUser')] |
|
138 | - public function testGetUser(string $uid, ?string $userDisplayName, ?array $cloudIdData, array $expected): void { |
|
139 | - $provider = $this->getProvider(); |
|
140 | - |
|
141 | - if ($userDisplayName !== null) { |
|
142 | - $this->userManager->expects($this->once()) |
|
143 | - ->method('getDisplayName') |
|
144 | - ->with($uid) |
|
145 | - ->willReturn($userDisplayName); |
|
146 | - } |
|
147 | - if ($cloudIdData !== null) { |
|
148 | - $this->cloudIdManager->expects($this->once()) |
|
149 | - ->method('isValidCloudId') |
|
150 | - ->willReturn(true); |
|
151 | - |
|
152 | - $cloudId = $this->createMock(ICloudId::class); |
|
153 | - $cloudId->expects($this->once()) |
|
154 | - ->method('getUser') |
|
155 | - ->willReturn($cloudIdData['user']); |
|
156 | - $cloudId->expects($this->once()) |
|
157 | - ->method('getDisplayId') |
|
158 | - ->willReturn($cloudIdData['displayId']); |
|
159 | - $cloudId->expects($this->once()) |
|
160 | - ->method('getRemote') |
|
161 | - ->willReturn($cloudIdData['remote']); |
|
162 | - |
|
163 | - $this->cloudIdManager->expects($this->once()) |
|
164 | - ->method('resolveCloudId') |
|
165 | - ->with($uid) |
|
166 | - ->willReturn($cloudId); |
|
167 | - |
|
168 | - if ($cloudIdData['name'] !== null) { |
|
169 | - $this->contactsManager->expects($this->once()) |
|
170 | - ->method('search') |
|
171 | - ->with($cloudIdData['displayId'], ['CLOUD']) |
|
172 | - ->willReturn([ |
|
173 | - [ |
|
174 | - 'CLOUD' => $cloudIdData['displayId'], |
|
175 | - 'FN' => $cloudIdData['name'], |
|
176 | - ] |
|
177 | - ]); |
|
178 | - } else { |
|
179 | - $this->contactsManager->expects($this->once()) |
|
180 | - ->method('search') |
|
181 | - ->with($cloudIdData['displayId'], ['CLOUD']) |
|
182 | - ->willReturn([]); |
|
183 | - } |
|
184 | - } |
|
185 | - |
|
186 | - $result = self::invokePrivate($provider, 'getUser', [$uid]); |
|
187 | - $this->assertEquals($expected, $result); |
|
188 | - } |
|
31 | + protected IFactory&MockObject $l10nFactory; |
|
32 | + protected IURLGenerator&MockObject $url; |
|
33 | + protected IManager&MockObject $activityManager; |
|
34 | + protected IUserManager&MockObject $userManager; |
|
35 | + protected IRootFolder&MockObject $rootFolder; |
|
36 | + protected ICloudIdManager&MockObject $cloudIdManager; |
|
37 | + protected IContactsManager&MockObject $contactsManager; |
|
38 | + protected IEventMerger&MockObject $eventMerger; |
|
39 | + |
|
40 | + protected function setUp(): void { |
|
41 | + parent::setUp(); |
|
42 | + |
|
43 | + $this->l10nFactory = $this->createMock(IFactory::class); |
|
44 | + $this->url = $this->createMock(IURLGenerator::class); |
|
45 | + $this->activityManager = $this->createMock(IManager::class); |
|
46 | + $this->userManager = $this->createMock(IUserManager::class); |
|
47 | + $this->rootFolder = $this->createMock(IRootFolder::class); |
|
48 | + $this->cloudIdManager = $this->createMock(ICloudIdManager::class); |
|
49 | + $this->contactsManager = $this->createMock(IContactsManager::class); |
|
50 | + $this->eventMerger = $this->createMock(IEventMerger::class); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * @param string[] $methods |
|
55 | + * @return Provider|MockObject |
|
56 | + */ |
|
57 | + protected function getProvider(array $methods = []) { |
|
58 | + if (!empty($methods)) { |
|
59 | + return $this->getMockBuilder(Provider::class) |
|
60 | + ->setConstructorArgs([ |
|
61 | + $this->l10nFactory, |
|
62 | + $this->url, |
|
63 | + $this->activityManager, |
|
64 | + $this->userManager, |
|
65 | + $this->rootFolder, |
|
66 | + $this->cloudIdManager, |
|
67 | + $this->contactsManager, |
|
68 | + $this->eventMerger, |
|
69 | + ]) |
|
70 | + ->onlyMethods($methods) |
|
71 | + ->getMock(); |
|
72 | + } |
|
73 | + return new Provider( |
|
74 | + $this->l10nFactory, |
|
75 | + $this->url, |
|
76 | + $this->activityManager, |
|
77 | + $this->userManager, |
|
78 | + $this->rootFolder, |
|
79 | + $this->cloudIdManager, |
|
80 | + $this->contactsManager, |
|
81 | + $this->eventMerger |
|
82 | + ); |
|
83 | + } |
|
84 | + |
|
85 | + public static function dataGetFile(): array { |
|
86 | + return [ |
|
87 | + [[42 => '/FortyTwo.txt'], null, '42', 'FortyTwo.txt', 'FortyTwo.txt'], |
|
88 | + [['23' => '/Twenty/Three.txt'], null, '23', 'Three.txt', 'Twenty/Three.txt'], |
|
89 | + ['/Foo/Bar.txt', 128, '128', 'Bar.txt', 'Foo/Bar.txt'], // Legacy from ownCloud 8.2 and before |
|
90 | + ]; |
|
91 | + } |
|
92 | + |
|
93 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetFile')] |
|
94 | + public function testGetFile(array|string $parameter, ?int $eventId, string $id, string $name, string $path): void { |
|
95 | + $provider = $this->getProvider(); |
|
96 | + |
|
97 | + if ($eventId !== null) { |
|
98 | + $event = $this->createMock(IEvent::class); |
|
99 | + $event->expects($this->once()) |
|
100 | + ->method('getObjectId') |
|
101 | + ->willReturn($eventId); |
|
102 | + } else { |
|
103 | + $event = null; |
|
104 | + } |
|
105 | + |
|
106 | + $this->url->expects($this->once()) |
|
107 | + ->method('linkToRouteAbsolute') |
|
108 | + ->with('files.viewcontroller.showFile', ['fileid' => $id]) |
|
109 | + ->willReturn('link-' . $id); |
|
110 | + |
|
111 | + $result = self::invokePrivate($provider, 'getFile', [$parameter, $event]); |
|
112 | + |
|
113 | + $this->assertSame('file', $result['type']); |
|
114 | + $this->assertSame($id, $result['id']); |
|
115 | + $this->assertSame($name, $result['name']); |
|
116 | + $this->assertSame($path, $result['path']); |
|
117 | + $this->assertSame('link-' . $id, $result['link']); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + public function testGetFileThrows(): void { |
|
122 | + $this->expectException(UnknownActivityException::class); |
|
123 | + |
|
124 | + $provider = $this->getProvider(); |
|
125 | + self::invokePrivate($provider, 'getFile', ['/Foo/Bar.txt', null]); |
|
126 | + } |
|
127 | + |
|
128 | + public static function dataGetUser(): array { |
|
129 | + return [ |
|
130 | + ['test', 'Test user', null, ['type' => 'user', 'id' => 'test', 'name' => 'Test user']], |
|
131 | + ['test@http://localhost', null, ['user' => 'test', 'displayId' => 'test@localhost', 'remote' => 'localhost', 'name' => null], ['type' => 'user', 'id' => 'test', 'name' => 'test@localhost', 'server' => 'localhost']], |
|
132 | + ['test@http://localhost', null, ['user' => 'test', 'displayId' => 'test@localhost', 'remote' => 'localhost', 'name' => 'Remote user'], ['type' => 'user', 'id' => 'test', 'name' => 'Remote user (test@localhost)', 'server' => 'localhost']], |
|
133 | + ['test', null, null, ['type' => 'user', 'id' => 'test', 'name' => 'test']], |
|
134 | + ]; |
|
135 | + } |
|
136 | + |
|
137 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetUser')] |
|
138 | + public function testGetUser(string $uid, ?string $userDisplayName, ?array $cloudIdData, array $expected): void { |
|
139 | + $provider = $this->getProvider(); |
|
140 | + |
|
141 | + if ($userDisplayName !== null) { |
|
142 | + $this->userManager->expects($this->once()) |
|
143 | + ->method('getDisplayName') |
|
144 | + ->with($uid) |
|
145 | + ->willReturn($userDisplayName); |
|
146 | + } |
|
147 | + if ($cloudIdData !== null) { |
|
148 | + $this->cloudIdManager->expects($this->once()) |
|
149 | + ->method('isValidCloudId') |
|
150 | + ->willReturn(true); |
|
151 | + |
|
152 | + $cloudId = $this->createMock(ICloudId::class); |
|
153 | + $cloudId->expects($this->once()) |
|
154 | + ->method('getUser') |
|
155 | + ->willReturn($cloudIdData['user']); |
|
156 | + $cloudId->expects($this->once()) |
|
157 | + ->method('getDisplayId') |
|
158 | + ->willReturn($cloudIdData['displayId']); |
|
159 | + $cloudId->expects($this->once()) |
|
160 | + ->method('getRemote') |
|
161 | + ->willReturn($cloudIdData['remote']); |
|
162 | + |
|
163 | + $this->cloudIdManager->expects($this->once()) |
|
164 | + ->method('resolveCloudId') |
|
165 | + ->with($uid) |
|
166 | + ->willReturn($cloudId); |
|
167 | + |
|
168 | + if ($cloudIdData['name'] !== null) { |
|
169 | + $this->contactsManager->expects($this->once()) |
|
170 | + ->method('search') |
|
171 | + ->with($cloudIdData['displayId'], ['CLOUD']) |
|
172 | + ->willReturn([ |
|
173 | + [ |
|
174 | + 'CLOUD' => $cloudIdData['displayId'], |
|
175 | + 'FN' => $cloudIdData['name'], |
|
176 | + ] |
|
177 | + ]); |
|
178 | + } else { |
|
179 | + $this->contactsManager->expects($this->once()) |
|
180 | + ->method('search') |
|
181 | + ->with($cloudIdData['displayId'], ['CLOUD']) |
|
182 | + ->willReturn([]); |
|
183 | + } |
|
184 | + } |
|
185 | + |
|
186 | + $result = self::invokePrivate($provider, 'getUser', [$uid]); |
|
187 | + $this->assertEquals($expected, $result); |
|
188 | + } |
|
189 | 189 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | } |
92 | 92 | |
93 | 93 | #[\PHPUnit\Framework\Attributes\DataProvider('dataGetFile')] |
94 | - public function testGetFile(array|string $parameter, ?int $eventId, string $id, string $name, string $path): void { |
|
94 | + public function testGetFile(array | string $parameter, ?int $eventId, string $id, string $name, string $path): void { |
|
95 | 95 | $provider = $this->getProvider(); |
96 | 96 | |
97 | 97 | if ($eventId !== null) { |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | $this->url->expects($this->once()) |
107 | 107 | ->method('linkToRouteAbsolute') |
108 | 108 | ->with('files.viewcontroller.showFile', ['fileid' => $id]) |
109 | - ->willReturn('link-' . $id); |
|
109 | + ->willReturn('link-'.$id); |
|
110 | 110 | |
111 | 111 | $result = self::invokePrivate($provider, 'getFile', [$parameter, $event]); |
112 | 112 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | $this->assertSame($id, $result['id']); |
115 | 115 | $this->assertSame($name, $result['name']); |
116 | 116 | $this->assertSame($path, $result['path']); |
117 | - $this->assertSame('link-' . $id, $result['link']); |
|
117 | + $this->assertSame('link-'.$id, $result['link']); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 |
@@ -14,69 +14,69 @@ |
||
14 | 14 | use Test\TestCase; |
15 | 15 | |
16 | 16 | class GenericTest extends TestCase { |
17 | - public static function dataSettings(): array { |
|
18 | - return [ |
|
19 | - [FavoriteAction::class], |
|
20 | - [FileChanged::class], |
|
21 | - [FileChanged::class], |
|
22 | - ]; |
|
23 | - } |
|
17 | + public static function dataSettings(): array { |
|
18 | + return [ |
|
19 | + [FavoriteAction::class], |
|
20 | + [FileChanged::class], |
|
21 | + [FileChanged::class], |
|
22 | + ]; |
|
23 | + } |
|
24 | 24 | |
25 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
26 | - public function testImplementsInterface(string $settingClass): void { |
|
27 | - $setting = Server::get($settingClass); |
|
28 | - $this->assertInstanceOf(ISetting::class, $setting); |
|
29 | - } |
|
25 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
26 | + public function testImplementsInterface(string $settingClass): void { |
|
27 | + $setting = Server::get($settingClass); |
|
28 | + $this->assertInstanceOf(ISetting::class, $setting); |
|
29 | + } |
|
30 | 30 | |
31 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
32 | - public function testGetIdentifier(string $settingClass): void { |
|
33 | - /** @var ISetting $setting */ |
|
34 | - $setting = Server::get($settingClass); |
|
35 | - $this->assertIsString($setting->getIdentifier()); |
|
36 | - } |
|
31 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
32 | + public function testGetIdentifier(string $settingClass): void { |
|
33 | + /** @var ISetting $setting */ |
|
34 | + $setting = Server::get($settingClass); |
|
35 | + $this->assertIsString($setting->getIdentifier()); |
|
36 | + } |
|
37 | 37 | |
38 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
39 | - public function testGetName(string $settingClass): void { |
|
40 | - /** @var ISetting $setting */ |
|
41 | - $setting = Server::get($settingClass); |
|
42 | - $this->assertIsString($setting->getName()); |
|
43 | - } |
|
38 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
39 | + public function testGetName(string $settingClass): void { |
|
40 | + /** @var ISetting $setting */ |
|
41 | + $setting = Server::get($settingClass); |
|
42 | + $this->assertIsString($setting->getName()); |
|
43 | + } |
|
44 | 44 | |
45 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
46 | - public function testGetPriority(string $settingClass): void { |
|
47 | - /** @var ISetting $setting */ |
|
48 | - $setting = Server::get($settingClass); |
|
49 | - $priority = $setting->getPriority(); |
|
50 | - $this->assertIsInt($setting->getPriority()); |
|
51 | - $this->assertGreaterThanOrEqual(0, $priority); |
|
52 | - $this->assertLessThanOrEqual(100, $priority); |
|
53 | - } |
|
45 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
46 | + public function testGetPriority(string $settingClass): void { |
|
47 | + /** @var ISetting $setting */ |
|
48 | + $setting = Server::get($settingClass); |
|
49 | + $priority = $setting->getPriority(); |
|
50 | + $this->assertIsInt($setting->getPriority()); |
|
51 | + $this->assertGreaterThanOrEqual(0, $priority); |
|
52 | + $this->assertLessThanOrEqual(100, $priority); |
|
53 | + } |
|
54 | 54 | |
55 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
56 | - public function testCanChangeStream(string $settingClass): void { |
|
57 | - /** @var ISetting $setting */ |
|
58 | - $setting = Server::get($settingClass); |
|
59 | - $this->assertIsBool($setting->canChangeStream()); |
|
60 | - } |
|
55 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
56 | + public function testCanChangeStream(string $settingClass): void { |
|
57 | + /** @var ISetting $setting */ |
|
58 | + $setting = Server::get($settingClass); |
|
59 | + $this->assertIsBool($setting->canChangeStream()); |
|
60 | + } |
|
61 | 61 | |
62 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
63 | - public function testIsDefaultEnabledStream(string $settingClass): void { |
|
64 | - /** @var ISetting $setting */ |
|
65 | - $setting = Server::get($settingClass); |
|
66 | - $this->assertIsBool($setting->isDefaultEnabledStream()); |
|
67 | - } |
|
62 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
63 | + public function testIsDefaultEnabledStream(string $settingClass): void { |
|
64 | + /** @var ISetting $setting */ |
|
65 | + $setting = Server::get($settingClass); |
|
66 | + $this->assertIsBool($setting->isDefaultEnabledStream()); |
|
67 | + } |
|
68 | 68 | |
69 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
70 | - public function testCanChangeMail(string $settingClass): void { |
|
71 | - /** @var ISetting $setting */ |
|
72 | - $setting = Server::get($settingClass); |
|
73 | - $this->assertIsBool($setting->canChangeMail()); |
|
74 | - } |
|
69 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
70 | + public function testCanChangeMail(string $settingClass): void { |
|
71 | + /** @var ISetting $setting */ |
|
72 | + $setting = Server::get($settingClass); |
|
73 | + $this->assertIsBool($setting->canChangeMail()); |
|
74 | + } |
|
75 | 75 | |
76 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
77 | - public function testIsDefaultEnabledMail(string $settingClass): void { |
|
78 | - /** @var ISetting $setting */ |
|
79 | - $setting = Server::get($settingClass); |
|
80 | - $this->assertIsBool($setting->isDefaultEnabledMail()); |
|
81 | - } |
|
76 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataSettings')] |
|
77 | + public function testIsDefaultEnabledMail(string $settingClass): void { |
|
78 | + /** @var ISetting $setting */ |
|
79 | + $setting = Server::get($settingClass); |
|
80 | + $this->assertIsBool($setting->isDefaultEnabledMail()); |
|
81 | + } |
|
82 | 82 | } |
@@ -20,62 +20,62 @@ |
||
20 | 20 | * @group DB |
21 | 21 | */ |
22 | 22 | class GenericTest extends TestCase { |
23 | - public static function dataFilters(): array { |
|
24 | - return [ |
|
25 | - [Favorites::class], |
|
26 | - [FileChanges::class], |
|
27 | - ]; |
|
28 | - } |
|
23 | + public static function dataFilters(): array { |
|
24 | + return [ |
|
25 | + [Favorites::class], |
|
26 | + [FileChanges::class], |
|
27 | + ]; |
|
28 | + } |
|
29 | 29 | |
30 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
31 | - public function testImplementsInterface(string $filterClass): void { |
|
32 | - $filter = Server::get($filterClass); |
|
33 | - $this->assertInstanceOf(IFilter::class, $filter); |
|
34 | - } |
|
30 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
31 | + public function testImplementsInterface(string $filterClass): void { |
|
32 | + $filter = Server::get($filterClass); |
|
33 | + $this->assertInstanceOf(IFilter::class, $filter); |
|
34 | + } |
|
35 | 35 | |
36 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
37 | - public function testGetIdentifier(string $filterClass): void { |
|
38 | - /** @var IFilter $filter */ |
|
39 | - $filter = Server::get($filterClass); |
|
40 | - $this->assertIsString($filter->getIdentifier()); |
|
41 | - } |
|
36 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
37 | + public function testGetIdentifier(string $filterClass): void { |
|
38 | + /** @var IFilter $filter */ |
|
39 | + $filter = Server::get($filterClass); |
|
40 | + $this->assertIsString($filter->getIdentifier()); |
|
41 | + } |
|
42 | 42 | |
43 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
44 | - public function testGetName(string $filterClass): void { |
|
45 | - /** @var IFilter $filter */ |
|
46 | - $filter = Server::get($filterClass); |
|
47 | - $this->assertIsString($filter->getName()); |
|
48 | - } |
|
43 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
44 | + public function testGetName(string $filterClass): void { |
|
45 | + /** @var IFilter $filter */ |
|
46 | + $filter = Server::get($filterClass); |
|
47 | + $this->assertIsString($filter->getName()); |
|
48 | + } |
|
49 | 49 | |
50 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
51 | - public function testGetPriority(string $filterClass): void { |
|
52 | - /** @var IFilter $filter */ |
|
53 | - $filter = Server::get($filterClass); |
|
54 | - $priority = $filter->getPriority(); |
|
55 | - $this->assertIsInt($filter->getPriority()); |
|
56 | - $this->assertGreaterThanOrEqual(0, $priority); |
|
57 | - $this->assertLessThanOrEqual(100, $priority); |
|
58 | - } |
|
50 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
51 | + public function testGetPriority(string $filterClass): void { |
|
52 | + /** @var IFilter $filter */ |
|
53 | + $filter = Server::get($filterClass); |
|
54 | + $priority = $filter->getPriority(); |
|
55 | + $this->assertIsInt($filter->getPriority()); |
|
56 | + $this->assertGreaterThanOrEqual(0, $priority); |
|
57 | + $this->assertLessThanOrEqual(100, $priority); |
|
58 | + } |
|
59 | 59 | |
60 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
61 | - public function testGetIcon(string $filterClass): void { |
|
62 | - /** @var IFilter $filter */ |
|
63 | - $filter = Server::get($filterClass); |
|
64 | - $this->assertIsString($filter->getIcon()); |
|
65 | - $this->assertStringStartsWith('http', $filter->getIcon()); |
|
66 | - } |
|
60 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
61 | + public function testGetIcon(string $filterClass): void { |
|
62 | + /** @var IFilter $filter */ |
|
63 | + $filter = Server::get($filterClass); |
|
64 | + $this->assertIsString($filter->getIcon()); |
|
65 | + $this->assertStringStartsWith('http', $filter->getIcon()); |
|
66 | + } |
|
67 | 67 | |
68 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
69 | - public function testFilterTypes(string $filterClass): void { |
|
70 | - /** @var IFilter $filter */ |
|
71 | - $filter = Server::get($filterClass); |
|
72 | - $this->assertIsArray($filter->filterTypes([])); |
|
73 | - } |
|
68 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
69 | + public function testFilterTypes(string $filterClass): void { |
|
70 | + /** @var IFilter $filter */ |
|
71 | + $filter = Server::get($filterClass); |
|
72 | + $this->assertIsArray($filter->filterTypes([])); |
|
73 | + } |
|
74 | 74 | |
75 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
76 | - public function testAllowedApps(string $filterClass): void { |
|
77 | - /** @var IFilter $filter */ |
|
78 | - $filter = Server::get($filterClass); |
|
79 | - $this->assertIsArray($filter->allowedApps()); |
|
80 | - } |
|
75 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilters')] |
|
76 | + public function testAllowedApps(string $filterClass): void { |
|
77 | + /** @var IFilter $filter */ |
|
78 | + $filter = Server::get($filterClass); |
|
79 | + $this->assertIsArray($filter->allowedApps()); |
|
80 | + } |
|
81 | 81 | } |
@@ -32,365 +32,365 @@ |
||
32 | 32 | * @package OCA\Provisioning_API\Tests |
33 | 33 | */ |
34 | 34 | class AppConfigControllerTest extends TestCase { |
35 | - private IAppConfig&MockObject $appConfig; |
|
36 | - private IUserSession&MockObject $userSession; |
|
37 | - private IL10N&MockObject $l10n; |
|
38 | - private IManager&MockObject $settingManager; |
|
39 | - private IGroupManager&MockObject $groupManager; |
|
40 | - private IAppManager $appManager; |
|
41 | - |
|
42 | - protected function setUp(): void { |
|
43 | - parent::setUp(); |
|
44 | - |
|
45 | - $this->appConfig = $this->createMock(AppConfig::class); |
|
46 | - $this->userSession = $this->createMock(IUserSession::class); |
|
47 | - $this->l10n = $this->createMock(IL10N::class); |
|
48 | - $this->settingManager = $this->createMock(IManager::class); |
|
49 | - $this->groupManager = $this->createMock(IGroupManager::class); |
|
50 | - $this->appManager = Server::get(IAppManager::class); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * @param string[] $methods |
|
55 | - * @return AppConfigController|MockObject |
|
56 | - */ |
|
57 | - protected function getInstance(array $methods = []) { |
|
58 | - $request = $this->createMock(IRequest::class); |
|
59 | - |
|
60 | - if (empty($methods)) { |
|
61 | - return new AppConfigController( |
|
62 | - 'provisioning_api', |
|
63 | - $request, |
|
64 | - $this->appConfig, |
|
65 | - $this->userSession, |
|
66 | - $this->l10n, |
|
67 | - $this->groupManager, |
|
68 | - $this->settingManager, |
|
69 | - $this->appManager, |
|
70 | - ); |
|
71 | - } else { |
|
72 | - return $this->getMockBuilder(AppConfigController::class) |
|
73 | - ->setConstructorArgs([ |
|
74 | - 'provisioning_api', |
|
75 | - $request, |
|
76 | - $this->appConfig, |
|
77 | - $this->userSession, |
|
78 | - $this->l10n, |
|
79 | - $this->groupManager, |
|
80 | - $this->settingManager, |
|
81 | - $this->appManager, |
|
82 | - ]) |
|
83 | - ->onlyMethods($methods) |
|
84 | - ->getMock(); |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - public function testGetApps(): void { |
|
89 | - $this->appConfig->expects($this->once()) |
|
90 | - ->method('getApps') |
|
91 | - ->willReturn(['apps']); |
|
92 | - |
|
93 | - $result = $this->getInstance()->getApps(); |
|
94 | - $this->assertInstanceOf(DataResponse::class, $result); |
|
95 | - $this->assertSame(Http::STATUS_OK, $result->getStatus()); |
|
96 | - $this->assertEquals(['data' => ['apps']], $result->getData()); |
|
97 | - } |
|
98 | - |
|
99 | - public static function dataGetKeys(): array { |
|
100 | - return [ |
|
101 | - ['app1 ', null, new \InvalidArgumentException('error'), Http::STATUS_FORBIDDEN], |
|
102 | - ['app2', ['keys'], null, Http::STATUS_OK], |
|
103 | - ]; |
|
104 | - } |
|
105 | - |
|
106 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataGetKeys')] |
|
107 | - public function testGetKeys(string $app, ?array $keys, ?\Throwable $throws, int $status): void { |
|
108 | - $api = $this->getInstance(['verifyAppId']); |
|
109 | - if ($throws instanceof \Exception) { |
|
110 | - $api->expects($this->once()) |
|
111 | - ->method('verifyAppId') |
|
112 | - ->with($app) |
|
113 | - ->willThrowException($throws); |
|
114 | - |
|
115 | - $this->appConfig->expects($this->never()) |
|
116 | - ->method('getKeys'); |
|
117 | - } else { |
|
118 | - $api->expects($this->once()) |
|
119 | - ->method('verifyAppId') |
|
120 | - ->with($app); |
|
121 | - |
|
122 | - $this->appConfig->expects($this->once()) |
|
123 | - ->method('getKeys') |
|
124 | - ->with($app) |
|
125 | - ->willReturn($keys); |
|
126 | - } |
|
127 | - |
|
128 | - $result = $api->getKeys($app); |
|
129 | - $this->assertInstanceOf(DataResponse::class, $result); |
|
130 | - $this->assertSame($status, $result->getStatus()); |
|
131 | - if ($throws instanceof \Exception) { |
|
132 | - $this->assertEquals(['data' => ['message' => $throws->getMessage()]], $result->getData()); |
|
133 | - } else { |
|
134 | - $this->assertEquals(['data' => $keys], $result->getData()); |
|
135 | - } |
|
136 | - } |
|
137 | - |
|
138 | - public static function dataGetValue(): array { |
|
139 | - return [ |
|
140 | - ['app1', 'key', 'default', null, new \InvalidArgumentException('error'), Http::STATUS_FORBIDDEN], |
|
141 | - ['app2', 'key', 'default', 'return', null, Http::STATUS_OK], |
|
142 | - ]; |
|
143 | - } |
|
144 | - |
|
145 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataGetValue')] |
|
146 | - public function testGetValue(string $app, string $key, string $default, ?string $return, ?\Throwable $throws, int $status): void { |
|
147 | - $api = $this->getInstance(['verifyAppId']); |
|
148 | - if ($throws instanceof \Exception) { |
|
149 | - $api->expects($this->once()) |
|
150 | - ->method('verifyAppId') |
|
151 | - ->with($app) |
|
152 | - ->willThrowException($throws); |
|
153 | - } else { |
|
154 | - $api->expects($this->once()) |
|
155 | - ->method('verifyAppId') |
|
156 | - ->with($app); |
|
157 | - |
|
158 | - $this->appConfig->expects($this->once()) |
|
159 | - ->method('getValueMixed') |
|
160 | - ->with($app, $key, $default) |
|
161 | - ->willReturn($return); |
|
162 | - } |
|
163 | - |
|
164 | - $result = $api->getValue($app, $key, $default); |
|
165 | - $this->assertInstanceOf(DataResponse::class, $result); |
|
166 | - $this->assertSame($status, $result->getStatus()); |
|
167 | - if ($throws instanceof \Exception) { |
|
168 | - $this->assertEquals(['data' => ['message' => $throws->getMessage()]], $result->getData()); |
|
169 | - } else { |
|
170 | - $this->assertEquals(['data' => $return], $result->getData()); |
|
171 | - } |
|
172 | - } |
|
173 | - |
|
174 | - public static function dataSetValue(): array { |
|
175 | - return [ |
|
176 | - ['app1', 'key', 'default', new \InvalidArgumentException('error1'), null, Http::STATUS_FORBIDDEN], |
|
177 | - ['app2', 'key', 'default', null, new \InvalidArgumentException('error2'), Http::STATUS_FORBIDDEN], |
|
178 | - ['app2', 'key', 'default', null, null, Http::STATUS_OK], |
|
179 | - ['app2', 'key', '1', null, null, Http::STATUS_OK, IAppConfig::VALUE_BOOL], |
|
180 | - ['app2', 'key', '42', null, null, Http::STATUS_OK, IAppConfig::VALUE_INT], |
|
181 | - ['app2', 'key', '4.2', null, null, Http::STATUS_OK, IAppConfig::VALUE_FLOAT], |
|
182 | - ['app2', 'key', '42', null, null, Http::STATUS_OK, IAppConfig::VALUE_STRING], |
|
183 | - ['app2', 'key', 'secret', null, null, Http::STATUS_OK, IAppConfig::VALUE_STRING | IAppConfig::VALUE_SENSITIVE], |
|
184 | - ['app2', 'key', json_encode([4, 2]), null, null, Http::STATUS_OK, IAppConfig::VALUE_ARRAY], |
|
185 | - ['app2', 'key', json_encode([4, 2]), null, null, Http::STATUS_OK, new AppConfigUnknownKeyException()], |
|
186 | - ]; |
|
187 | - } |
|
188 | - |
|
189 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataSetValue')] |
|
190 | - public function testSetValue(string $app, string $key, string $value, ?\Throwable $appThrows, ?\Throwable $keyThrows, int $status, int|\Throwable $type = IAppConfig::VALUE_MIXED): void { |
|
191 | - $adminUser = $this->createMock(IUser::class); |
|
192 | - $adminUser->expects($this->once()) |
|
193 | - ->method('getUid') |
|
194 | - ->willReturn('admin'); |
|
195 | - |
|
196 | - $this->userSession->expects($this->once()) |
|
197 | - ->method('getUser') |
|
198 | - ->willReturn($adminUser); |
|
199 | - $this->groupManager->expects($this->once()) |
|
200 | - ->method('isAdmin') |
|
201 | - ->with('admin') |
|
202 | - ->willReturn(true); |
|
203 | - $api = $this->getInstance(['verifyAppId', 'verifyConfigKey']); |
|
204 | - if ($appThrows instanceof \Exception) { |
|
205 | - $api->expects($this->once()) |
|
206 | - ->method('verifyAppId') |
|
207 | - ->with($app) |
|
208 | - ->willThrowException($appThrows); |
|
209 | - |
|
210 | - $api->expects($this->never()) |
|
211 | - ->method('verifyConfigKey'); |
|
212 | - $this->appConfig->expects($this->never()) |
|
213 | - ->method('setValueMixed'); |
|
214 | - } elseif ($keyThrows instanceof \Exception) { |
|
215 | - $api->expects($this->once()) |
|
216 | - ->method('verifyAppId') |
|
217 | - ->with($app); |
|
218 | - $api->expects($this->once()) |
|
219 | - ->method('verifyConfigKey') |
|
220 | - ->with($app, $key) |
|
221 | - ->willThrowException($keyThrows); |
|
222 | - |
|
223 | - $this->appConfig->expects($this->never()) |
|
224 | - ->method('setValueMixed'); |
|
225 | - } else { |
|
226 | - $api->expects($this->once()) |
|
227 | - ->method('verifyAppId') |
|
228 | - ->with($app); |
|
229 | - $api->expects($this->once()) |
|
230 | - ->method('verifyConfigKey') |
|
231 | - ->with($app, $key); |
|
232 | - |
|
233 | - if ($type instanceof \Throwable) { |
|
234 | - $this->appConfig->expects($this->once()) |
|
235 | - ->method('getDetails') |
|
236 | - ->with($app, $key) |
|
237 | - ->willThrowException($type); |
|
238 | - } else { |
|
239 | - $this->appConfig->expects($this->once()) |
|
240 | - ->method('getDetails') |
|
241 | - ->with($app, $key) |
|
242 | - ->willReturn([ |
|
243 | - 'app' => $app, |
|
244 | - 'key' => $key, |
|
245 | - 'value' => '', // |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | } |
188 | 188 | |
189 | 189 | #[\PHPUnit\Framework\Attributes\DataProvider('dataSetValue')] |
190 | - public function testSetValue(string $app, string $key, string $value, ?\Throwable $appThrows, ?\Throwable $keyThrows, int $status, int|\Throwable $type = IAppConfig::VALUE_MIXED): void { |
|
190 | + public function testSetValue(string $app, string $key, string $value, ?\Throwable $appThrows, ?\Throwable $keyThrows, int $status, int | \Throwable $type = IAppConfig::VALUE_MIXED): void { |
|
191 | 191 | $adminUser = $this->createMock(IUser::class); |
192 | 192 | $adminUser->expects($this->once()) |
193 | 193 | ->method('getUid') |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | 'value' => '', // |
@@ -26,523 +26,523 @@ |
||
26 | 26 | use Psr\Log\LoggerInterface; |
27 | 27 | |
28 | 28 | class GroupsControllerTest extends \Test\TestCase { |
29 | - protected IRequest&MockObject $request; |
|
30 | - protected IUserManager&MockObject $userManager; |
|
31 | - protected IConfig&MockObject $config; |
|
32 | - protected Manager&MockObject $groupManager; |
|
33 | - protected IUserSession&MockObject $userSession; |
|
34 | - protected IAccountManager&MockObject $accountManager; |
|
35 | - protected ISubAdmin&MockObject $subAdminManager; |
|
36 | - protected IFactory&MockObject $l10nFactory; |
|
37 | - protected LoggerInterface&MockObject $logger; |
|
38 | - protected GroupsController&MockObject $api; |
|
39 | - |
|
40 | - private IRootFolder $rootFolder; |
|
41 | - |
|
42 | - |
|
43 | - protected function setUp(): void { |
|
44 | - parent::setUp(); |
|
45 | - |
|
46 | - $this->request = $this->createMock(IRequest::class); |
|
47 | - $this->userManager = $this->createMock(IUserManager::class); |
|
48 | - $this->config = $this->createMock(IConfig::class); |
|
49 | - $this->groupManager = $this->createMock(Manager::class); |
|
50 | - $this->userSession = $this->createMock(IUserSession::class); |
|
51 | - $this->accountManager = $this->createMock(IAccountManager::class); |
|
52 | - $this->subAdminManager = $this->createMock(ISubAdmin::class); |
|
53 | - $this->l10nFactory = $this->createMock(IFactory::class); |
|
54 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
55 | - $this->rootFolder = $this->createMock(IRootFolder::class); |
|
56 | - |
|
57 | - $this->groupManager |
|
58 | - ->method('getSubAdmin') |
|
59 | - ->willReturn($this->subAdminManager); |
|
60 | - |
|
61 | - $this->api = $this->getMockBuilder(GroupsController::class) |
|
62 | - ->setConstructorArgs([ |
|
63 | - 'provisioning_api', |
|
64 | - $this->request, |
|
65 | - $this->userManager, |
|
66 | - $this->config, |
|
67 | - $this->groupManager, |
|
68 | - $this->userSession, |
|
69 | - $this->accountManager, |
|
70 | - $this->subAdminManager, |
|
71 | - $this->l10nFactory, |
|
72 | - $this->rootFolder, |
|
73 | - $this->logger |
|
74 | - ]) |
|
75 | - ->onlyMethods(['fillStorageInfo']) |
|
76 | - ->getMock(); |
|
77 | - } |
|
78 | - |
|
79 | - private function createGroup(string $gid): IGroup&MockObject { |
|
80 | - $group = $this->createMock(IGroup::class); |
|
81 | - $group |
|
82 | - ->method('getGID') |
|
83 | - ->willReturn($gid); |
|
84 | - $group |
|
85 | - ->method('getDisplayName') |
|
86 | - ->willReturn($gid . '-name'); |
|
87 | - $group |
|
88 | - ->method('count') |
|
89 | - ->willReturn(123); |
|
90 | - $group |
|
91 | - ->method('countDisabled') |
|
92 | - ->willReturn(11); |
|
93 | - $group |
|
94 | - ->method('canAddUser') |
|
95 | - ->willReturn(true); |
|
96 | - $group |
|
97 | - ->method('canRemoveUser') |
|
98 | - ->willReturn(true); |
|
99 | - |
|
100 | - return $group; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @param string $uid |
|
105 | - * @return IUser&MockObject |
|
106 | - */ |
|
107 | - private function createUser($uid) { |
|
108 | - $user = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock(); |
|
109 | - $user |
|
110 | - ->method('getUID') |
|
111 | - ->willReturn($uid); |
|
112 | - $backendMock = $this->createMock(UserInterface::class); |
|
113 | - $user |
|
114 | - ->method('getBackend') |
|
115 | - ->willReturn($backendMock); |
|
116 | - return $user; |
|
117 | - } |
|
118 | - |
|
119 | - private function asUser() { |
|
120 | - $user = $this->createUser('user'); |
|
121 | - $this->userSession |
|
122 | - ->method('getUser') |
|
123 | - ->willReturn($user); |
|
124 | - } |
|
125 | - |
|
126 | - private function asAdmin() { |
|
127 | - $user = $this->createUser('admin'); |
|
128 | - $this->userSession |
|
129 | - ->method('getUser') |
|
130 | - ->willReturn($user); |
|
131 | - |
|
132 | - $this->groupManager |
|
133 | - ->method('isAdmin') |
|
134 | - ->with('admin') |
|
135 | - ->willReturn(true); |
|
136 | - } |
|
137 | - |
|
138 | - private function asSubAdminOfGroup($group) { |
|
139 | - $user = $this->createUser('subAdmin'); |
|
140 | - $this->userSession |
|
141 | - ->method('getUser') |
|
142 | - ->willReturn($user); |
|
143 | - |
|
144 | - $this->subAdminManager |
|
145 | - ->method('isSubAdminOfGroup') |
|
146 | - ->willReturnCallback(function ($_user, $_group) use ($user, $group) { |
|
147 | - if ($_user === $user && $_group === $group) { |
|
148 | - return true; |
|
149 | - } |
|
150 | - return false; |
|
151 | - }); |
|
152 | - } |
|
153 | - |
|
154 | - public static function dataGetGroups(): array { |
|
155 | - return [ |
|
156 | - [null, 0, 0], |
|
157 | - ['foo', 0, 0], |
|
158 | - [null, 1, 0], |
|
159 | - [null, 0, 2], |
|
160 | - ['foo', 1, 2], |
|
161 | - ]; |
|
162 | - } |
|
163 | - |
|
164 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataGetGroups')] |
|
165 | - public function testGetGroups(?string $search, int $limit, int $offset): void { |
|
166 | - $groups = [$this->createGroup('group1'), $this->createGroup('group2')]; |
|
167 | - |
|
168 | - $search = $search === null ? '' : $search; |
|
169 | - |
|
170 | - $this->groupManager |
|
171 | - ->expects($this->once()) |
|
172 | - ->method('search') |
|
173 | - ->with($search, $limit, $offset) |
|
174 | - ->willReturn($groups); |
|
175 | - |
|
176 | - $result = $this->api->getGroups($search, $limit, $offset); |
|
177 | - $this->assertEquals(['groups' => ['group1', 'group2']], $result->getData()); |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * |
|
182 | - * @param string|null $search |
|
183 | - * @param int|null $limit |
|
184 | - * @param int|null $offset |
|
185 | - */ |
|
186 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataGetGroups')] |
|
187 | - public function testGetGroupsDetails($search, $limit, $offset): void { |
|
188 | - $groups = [$this->createGroup('group1'), $this->createGroup('group2')]; |
|
189 | - |
|
190 | - $search = $search === null ? '' : $search; |
|
191 | - |
|
192 | - $this->groupManager |
|
193 | - ->expects($this->once()) |
|
194 | - ->method('search') |
|
195 | - ->with($search, $limit, $offset) |
|
196 | - ->willReturn($groups); |
|
197 | - |
|
198 | - $result = $this->api->getGroupsDetails($search, $limit, $offset); |
|
199 | - $this->assertEquals(['groups' => [ |
|
200 | - [ |
|
201 | - 'id' => 'group1', |
|
202 | - 'displayname' => 'group1-name', |
|
203 | - 'usercount' => 123, |
|
204 | - 'disabled' => 11, |
|
205 | - 'canAdd' => true, |
|
206 | - 'canRemove' => true |
|
207 | - ], |
|
208 | - [ |
|
209 | - 'id' => 'group2', |
|
210 | - 'displayname' => 'group2-name', |
|
211 | - 'usercount' => 123, |
|
212 | - 'disabled' => 11, |
|
213 | - 'canAdd' => true, |
|
214 | - 'canRemove' => true |
|
215 | - ] |
|
216 | - ]], $result->getData()); |
|
217 | - } |
|
218 | - |
|
219 | - public function testGetGroupAsSubadmin(): void { |
|
220 | - $group = $this->createGroup('group'); |
|
221 | - $this->asSubAdminOfGroup($group); |
|
222 | - |
|
223 | - $this->groupManager |
|
224 | - ->method('get') |
|
225 | - ->with('group') |
|
226 | - ->willReturn($group); |
|
227 | - $this->groupManager |
|
228 | - ->method('groupExists') |
|
229 | - ->with('group') |
|
230 | - ->willReturn(true); |
|
231 | - $group |
|
232 | - ->method('getUsers') |
|
233 | - ->willReturn([ |
|
234 | - $this->createUser('user1'), |
|
235 | - $this->createUser('user2') |
|
236 | - ]); |
|
237 | - |
|
238 | - $result = $this->api->getGroup('group'); |
|
239 | - |
|
240 | - $this->assertEquals(['users' => ['user1', 'user2']], $result->getData()); |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - public function testGetGroupAsIrrelevantSubadmin(): void { |
|
245 | - $this->expectException(OCSException::class); |
|
246 | - $this->expectExceptionCode(403); |
|
247 | - |
|
248 | - $group = $this->createGroup('group'); |
|
249 | - $otherGroup = $this->createGroup('otherGroup'); |
|
250 | - $this->asSubAdminOfGroup($otherGroup); |
|
251 | - |
|
252 | - $this->groupManager |
|
253 | - ->method('get') |
|
254 | - ->with('group') |
|
255 | - ->willReturn($group); |
|
256 | - $this->groupManager |
|
257 | - ->method('groupExists') |
|
258 | - ->with('group') |
|
259 | - ->willReturn(true); |
|
260 | - |
|
261 | - $this->api->getGroup('group'); |
|
262 | - } |
|
263 | - |
|
264 | - public function testGetGroupAsAdmin(): void { |
|
265 | - $group = $this->createGroup('group'); |
|
266 | - $this->asAdmin(); |
|
267 | - |
|
268 | - $this->groupManager |
|
269 | - ->method('get') |
|
270 | - ->with('group') |
|
271 | - ->willReturn($group); |
|
272 | - $this->groupManager |
|
273 | - ->method('groupExists') |
|
274 | - ->with('group') |
|
275 | - ->willReturn(true); |
|
276 | - $group |
|
277 | - ->method('getUsers') |
|
278 | - ->willReturn([ |
|
279 | - $this->createUser('user1'), |
|
280 | - $this->createUser('user2') |
|
281 | - ]); |
|
282 | - |
|
283 | - $result = $this->api->getGroup('group'); |
|
284 | - |
|
285 | - $this->assertEquals(['users' => ['user1', 'user2']], $result->getData()); |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - public function testGetGroupNonExisting(): void { |
|
290 | - $this->expectException(OCSException::class); |
|
291 | - $this->expectExceptionMessage('The requested group could not be found'); |
|
292 | - $this->expectExceptionCode(404); |
|
293 | - |
|
294 | - $this->asUser(); |
|
295 | - |
|
296 | - $this->api->getGroup($this->getUniqueID()); |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - public function testGetSubAdminsOfGroupsNotExists(): void { |
|
301 | - $this->expectException(OCSException::class); |
|
302 | - $this->expectExceptionMessage('Group does not exist'); |
|
303 | - $this->expectExceptionCode(101); |
|
304 | - |
|
305 | - $this->api->getSubAdminsOfGroup('NonExistingGroup'); |
|
306 | - } |
|
307 | - |
|
308 | - public function testGetSubAdminsOfGroup(): void { |
|
309 | - $group = $this->createGroup('GroupWithSubAdmins'); |
|
310 | - $this->groupManager |
|
311 | - ->method('get') |
|
312 | - ->with('GroupWithSubAdmins') |
|
313 | - ->willReturn($group); |
|
314 | - |
|
315 | - $this->subAdminManager |
|
316 | - ->expects($this->once()) |
|
317 | - ->method('getGroupsSubAdmins') |
|
318 | - ->with($group) |
|
319 | - ->willReturn([ |
|
320 | - $this->createUser('SubAdmin1'), |
|
321 | - $this->createUser('SubAdmin2'), |
|
322 | - ]); |
|
323 | - |
|
324 | - $result = $this->api->getSubAdminsOfGroup('GroupWithSubAdmins'); |
|
325 | - $this->assertEquals(['SubAdmin1', 'SubAdmin2'], $result->getData()); |
|
326 | - } |
|
327 | - |
|
328 | - public function testGetSubAdminsOfGroupEmptyList(): void { |
|
329 | - $group = $this->createGroup('GroupWithOutSubAdmins'); |
|
330 | - $this->groupManager |
|
331 | - ->method('get') |
|
332 | - ->with('GroupWithOutSubAdmins') |
|
333 | - ->willReturn($group); |
|
334 | - |
|
335 | - $this->subAdminManager |
|
336 | - ->expects($this->once()) |
|
337 | - ->method('getGroupsSubAdmins') |
|
338 | - ->with($group) |
|
339 | - ->willReturn([ |
|
340 | - ]); |
|
341 | - |
|
342 | - $result = $this->api->getSubAdminsOfGroup('GroupWithOutSubAdmins'); |
|
343 | - $this->assertEquals([], $result->getData()); |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - public function testAddGroupEmptyGroup(): void { |
|
348 | - $this->expectException(OCSException::class); |
|
349 | - $this->expectExceptionMessage('Invalid group name'); |
|
350 | - $this->expectExceptionCode(101); |
|
351 | - |
|
352 | - $this->api->addGroup(''); |
|
353 | - } |
|
354 | - |
|
355 | - |
|
356 | - public function testAddGroupExistingGroup(): void { |
|
357 | - $this->expectException(OCSException::class); |
|
358 | - $this->expectExceptionCode(102); |
|
359 | - |
|
360 | - $this->groupManager |
|
361 | - ->method('groupExists') |
|
362 | - ->with('ExistingGroup') |
|
363 | - ->willReturn(true); |
|
364 | - |
|
365 | - $this->api->addGroup('ExistingGroup'); |
|
366 | - } |
|
367 | - |
|
368 | - public function testAddGroup(): void { |
|
369 | - $this->groupManager |
|
370 | - ->method('groupExists') |
|
371 | - ->with('NewGroup') |
|
372 | - ->willReturn(false); |
|
373 | - |
|
374 | - $group = $this->createGroup('NewGroup'); |
|
375 | - $this->groupManager |
|
376 | - ->expects($this->once()) |
|
377 | - ->method('createGroup') |
|
378 | - ->with('NewGroup') |
|
379 | - ->willReturn($group); |
|
380 | - |
|
381 | - $this->api->addGroup('NewGroup'); |
|
382 | - } |
|
383 | - |
|
384 | - public function testAddGroupWithSpecialChar(): void { |
|
385 | - $this->groupManager |
|
386 | - ->method('groupExists') |
|
387 | - ->with('Iñtërnâtiônàlizætiøn') |
|
388 | - ->willReturn(false); |
|
389 | - |
|
390 | - $group = $this->createGroup('Iñtërnâtiônàlizætiøn'); |
|
391 | - $this->groupManager |
|
392 | - ->expects($this->once()) |
|
393 | - ->method('createGroup') |
|
394 | - ->with('Iñtërnâtiônàlizætiøn') |
|
395 | - ->willReturn($group); |
|
396 | - |
|
397 | - $this->api->addGroup('Iñtërnâtiônàlizætiøn'); |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - public function testDeleteGroupNonExisting(): void { |
|
402 | - $this->expectException(OCSException::class); |
|
403 | - $this->expectExceptionCode(101); |
|
404 | - |
|
405 | - $this->api->deleteGroup('NonExistingGroup'); |
|
406 | - } |
|
407 | - |
|
408 | - |
|
409 | - public function testDeleteAdminGroup(): void { |
|
410 | - $this->expectException(OCSException::class); |
|
411 | - $this->expectExceptionCode(102); |
|
412 | - |
|
413 | - $this->groupManager |
|
414 | - ->method('groupExists') |
|
415 | - ->with('admin') |
|
416 | - ->willReturn('true'); |
|
417 | - |
|
418 | - $this->api->deleteGroup('admin'); |
|
419 | - } |
|
420 | - |
|
421 | - public function testDeleteGroup(): void { |
|
422 | - $this->groupManager |
|
423 | - ->method('groupExists') |
|
424 | - ->with('ExistingGroup') |
|
425 | - ->willReturn('true'); |
|
426 | - |
|
427 | - $group = $this->createGroup('ExistingGroup'); |
|
428 | - $this->groupManager |
|
429 | - ->method('get') |
|
430 | - ->with('ExistingGroup') |
|
431 | - ->willReturn($group); |
|
432 | - $group |
|
433 | - ->expects($this->once()) |
|
434 | - ->method('delete') |
|
435 | - ->willReturn(true); |
|
436 | - |
|
437 | - $this->api->deleteGroup('ExistingGroup'); |
|
438 | - } |
|
439 | - |
|
440 | - public function testDeleteGroupEncoding(): void { |
|
441 | - $this->groupManager |
|
442 | - ->method('groupExists') |
|
443 | - ->with('ExistingGroup A/B') |
|
444 | - ->willReturn('true'); |
|
445 | - |
|
446 | - $group = $this->createGroup('ExistingGroup'); |
|
447 | - $this->groupManager |
|
448 | - ->method('get') |
|
449 | - ->with('ExistingGroup A/B') |
|
450 | - ->willReturn($group); |
|
451 | - $group |
|
452 | - ->expects($this->once()) |
|
453 | - ->method('delete') |
|
454 | - ->willReturn(true); |
|
455 | - |
|
456 | - $this->api->deleteGroup(urlencode('ExistingGroup A/B')); |
|
457 | - } |
|
458 | - |
|
459 | - public function testGetGroupUsersDetails(): void { |
|
460 | - $gid = 'ncg1'; |
|
461 | - |
|
462 | - $this->asAdmin(); |
|
463 | - |
|
464 | - $users = [ |
|
465 | - 'ncu1' => $this->createUser('ncu1'), # regular |
|
466 | - 'ncu2' => $this->createUser('ncu2'), # the zombie |
|
467 | - ]; |
|
468 | - $users['ncu2']->expects($this->atLeastOnce()) |
|
469 | - ->method('getHome') |
|
470 | - ->willThrowException(new NoUserException()); |
|
471 | - |
|
472 | - $this->userManager->expects($this->any()) |
|
473 | - ->method('get') |
|
474 | - ->willReturnCallback(function (string $uid) use ($users) { |
|
475 | - return $users[$uid] ?? null; |
|
476 | - }); |
|
477 | - |
|
478 | - $group = $this->createGroup($gid); |
|
479 | - $group->expects($this->once()) |
|
480 | - ->method('searchUsers') |
|
481 | - ->with('', null, 0) |
|
482 | - ->willReturn(array_values($users)); |
|
483 | - |
|
484 | - $this->groupManager |
|
485 | - ->method('get') |
|
486 | - ->with($gid) |
|
487 | - ->willReturn($group); |
|
488 | - $this->groupManager->expects($this->any()) |
|
489 | - ->method('getUserGroups') |
|
490 | - ->willReturn([$group]); |
|
491 | - |
|
492 | - /** @var MockObject */ |
|
493 | - $this->subAdminManager->expects($this->any()) |
|
494 | - ->method('isSubAdminOfGroup') |
|
495 | - ->willReturn(false); |
|
496 | - $this->subAdminManager->expects($this->any()) |
|
497 | - ->method('getSubAdminsGroups') |
|
498 | - ->willReturn([]); |
|
499 | - |
|
500 | - |
|
501 | - $this->api->getGroupUsersDetails($gid); |
|
502 | - } |
|
503 | - |
|
504 | - public function testGetGroupUsersDetailsEncoded(): void { |
|
505 | - $gid = 'Department A/B C/D'; |
|
506 | - |
|
507 | - $this->asAdmin(); |
|
508 | - |
|
509 | - $users = [ |
|
510 | - 'ncu1' => $this->createUser('ncu1'), # regular |
|
511 | - 'ncu2' => $this->createUser('ncu2'), # the zombie |
|
512 | - ]; |
|
513 | - $users['ncu2']->expects($this->atLeastOnce()) |
|
514 | - ->method('getHome') |
|
515 | - ->willThrowException(new NoUserException()); |
|
516 | - |
|
517 | - $this->userManager->expects($this->any()) |
|
518 | - ->method('get') |
|
519 | - ->willReturnCallback(function (string $uid) use ($users) { |
|
520 | - return $users[$uid] ?? null; |
|
521 | - }); |
|
522 | - |
|
523 | - $group = $this->createGroup($gid); |
|
524 | - $group->expects($this->once()) |
|
525 | - ->method('searchUsers') |
|
526 | - ->with('', null, 0) |
|
527 | - ->willReturn(array_values($users)); |
|
528 | - |
|
529 | - $this->groupManager |
|
530 | - ->method('get') |
|
531 | - ->with($gid) |
|
532 | - ->willReturn($group); |
|
533 | - $this->groupManager->expects($this->any()) |
|
534 | - ->method('getUserGroups') |
|
535 | - ->willReturn([$group]); |
|
536 | - |
|
537 | - /** @var MockObject */ |
|
538 | - $this->subAdminManager->expects($this->any()) |
|
539 | - ->method('isSubAdminOfGroup') |
|
540 | - ->willReturn(false); |
|
541 | - $this->subAdminManager->expects($this->any()) |
|
542 | - ->method('getSubAdminsGroups') |
|
543 | - ->willReturn([]); |
|
544 | - |
|
545 | - |
|
546 | - $this->api->getGroupUsersDetails(urlencode($gid)); |
|
547 | - } |
|
29 | + protected IRequest&MockObject $request; |
|
30 | + protected IUserManager&MockObject $userManager; |
|
31 | + protected IConfig&MockObject $config; |
|
32 | + protected Manager&MockObject $groupManager; |
|
33 | + protected IUserSession&MockObject $userSession; |
|
34 | + protected IAccountManager&MockObject $accountManager; |
|
35 | + protected ISubAdmin&MockObject $subAdminManager; |
|
36 | + protected IFactory&MockObject $l10nFactory; |
|
37 | + protected LoggerInterface&MockObject $logger; |
|
38 | + protected GroupsController&MockObject $api; |
|
39 | + |
|
40 | + private IRootFolder $rootFolder; |
|
41 | + |
|
42 | + |
|
43 | + protected function setUp(): void { |
|
44 | + parent::setUp(); |
|
45 | + |
|
46 | + $this->request = $this->createMock(IRequest::class); |
|
47 | + $this->userManager = $this->createMock(IUserManager::class); |
|
48 | + $this->config = $this->createMock(IConfig::class); |
|
49 | + $this->groupManager = $this->createMock(Manager::class); |
|
50 | + $this->userSession = $this->createMock(IUserSession::class); |
|
51 | + $this->accountManager = $this->createMock(IAccountManager::class); |
|
52 | + $this->subAdminManager = $this->createMock(ISubAdmin::class); |
|
53 | + $this->l10nFactory = $this->createMock(IFactory::class); |
|
54 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
55 | + $this->rootFolder = $this->createMock(IRootFolder::class); |
|
56 | + |
|
57 | + $this->groupManager |
|
58 | + ->method('getSubAdmin') |
|
59 | + ->willReturn($this->subAdminManager); |
|
60 | + |
|
61 | + $this->api = $this->getMockBuilder(GroupsController::class) |
|
62 | + ->setConstructorArgs([ |
|
63 | + 'provisioning_api', |
|
64 | + $this->request, |
|
65 | + $this->userManager, |
|
66 | + $this->config, |
|
67 | + $this->groupManager, |
|
68 | + $this->userSession, |
|
69 | + $this->accountManager, |
|
70 | + $this->subAdminManager, |
|
71 | + $this->l10nFactory, |
|
72 | + $this->rootFolder, |
|
73 | + $this->logger |
|
74 | + ]) |
|
75 | + ->onlyMethods(['fillStorageInfo']) |
|
76 | + ->getMock(); |
|
77 | + } |
|
78 | + |
|
79 | + private function createGroup(string $gid): IGroup&MockObject { |
|
80 | + $group = $this->createMock(IGroup::class); |
|
81 | + $group |
|
82 | + ->method('getGID') |
|
83 | + ->willReturn($gid); |
|
84 | + $group |
|
85 | + ->method('getDisplayName') |
|
86 | + ->willReturn($gid . '-name'); |
|
87 | + $group |
|
88 | + ->method('count') |
|
89 | + ->willReturn(123); |
|
90 | + $group |
|
91 | + ->method('countDisabled') |
|
92 | + ->willReturn(11); |
|
93 | + $group |
|
94 | + ->method('canAddUser') |
|
95 | + ->willReturn(true); |
|
96 | + $group |
|
97 | + ->method('canRemoveUser') |
|
98 | + ->willReturn(true); |
|
99 | + |
|
100 | + return $group; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @param string $uid |
|
105 | + * @return IUser&MockObject |
|
106 | + */ |
|
107 | + private function createUser($uid) { |
|
108 | + $user = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock(); |
|
109 | + $user |
|
110 | + ->method('getUID') |
|
111 | + ->willReturn($uid); |
|
112 | + $backendMock = $this->createMock(UserInterface::class); |
|
113 | + $user |
|
114 | + ->method('getBackend') |
|
115 | + ->willReturn($backendMock); |
|
116 | + return $user; |
|
117 | + } |
|
118 | + |
|
119 | + private function asUser() { |
|
120 | + $user = $this->createUser('user'); |
|
121 | + $this->userSession |
|
122 | + ->method('getUser') |
|
123 | + ->willReturn($user); |
|
124 | + } |
|
125 | + |
|
126 | + private function asAdmin() { |
|
127 | + $user = $this->createUser('admin'); |
|
128 | + $this->userSession |
|
129 | + ->method('getUser') |
|
130 | + ->willReturn($user); |
|
131 | + |
|
132 | + $this->groupManager |
|
133 | + ->method('isAdmin') |
|
134 | + ->with('admin') |
|
135 | + ->willReturn(true); |
|
136 | + } |
|
137 | + |
|
138 | + private function asSubAdminOfGroup($group) { |
|
139 | + $user = $this->createUser('subAdmin'); |
|
140 | + $this->userSession |
|
141 | + ->method('getUser') |
|
142 | + ->willReturn($user); |
|
143 | + |
|
144 | + $this->subAdminManager |
|
145 | + ->method('isSubAdminOfGroup') |
|
146 | + ->willReturnCallback(function ($_user, $_group) use ($user, $group) { |
|
147 | + if ($_user === $user && $_group === $group) { |
|
148 | + return true; |
|
149 | + } |
|
150 | + return false; |
|
151 | + }); |
|
152 | + } |
|
153 | + |
|
154 | + public static function dataGetGroups(): array { |
|
155 | + return [ |
|
156 | + [null, 0, 0], |
|
157 | + ['foo', 0, 0], |
|
158 | + [null, 1, 0], |
|
159 | + [null, 0, 2], |
|
160 | + ['foo', 1, 2], |
|
161 | + ]; |
|
162 | + } |
|
163 | + |
|
164 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetGroups')] |
|
165 | + public function testGetGroups(?string $search, int $limit, int $offset): void { |
|
166 | + $groups = [$this->createGroup('group1'), $this->createGroup('group2')]; |
|
167 | + |
|
168 | + $search = $search === null ? '' : $search; |
|
169 | + |
|
170 | + $this->groupManager |
|
171 | + ->expects($this->once()) |
|
172 | + ->method('search') |
|
173 | + ->with($search, $limit, $offset) |
|
174 | + ->willReturn($groups); |
|
175 | + |
|
176 | + $result = $this->api->getGroups($search, $limit, $offset); |
|
177 | + $this->assertEquals(['groups' => ['group1', 'group2']], $result->getData()); |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * |
|
182 | + * @param string|null $search |
|
183 | + * @param int|null $limit |
|
184 | + * @param int|null $offset |
|
185 | + */ |
|
186 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetGroups')] |
|
187 | + public function testGetGroupsDetails($search, $limit, $offset): void { |
|
188 | + $groups = [$this->createGroup('group1'), $this->createGroup('group2')]; |
|
189 | + |
|
190 | + $search = $search === null ? '' : $search; |
|
191 | + |
|
192 | + $this->groupManager |
|
193 | + ->expects($this->once()) |
|
194 | + ->method('search') |
|
195 | + ->with($search, $limit, $offset) |
|
196 | + ->willReturn($groups); |
|
197 | + |
|
198 | + $result = $this->api->getGroupsDetails($search, $limit, $offset); |
|
199 | + $this->assertEquals(['groups' => [ |
|
200 | + [ |
|
201 | + 'id' => 'group1', |
|
202 | + 'displayname' => 'group1-name', |
|
203 | + 'usercount' => 123, |
|
204 | + 'disabled' => 11, |
|
205 | + 'canAdd' => true, |
|
206 | + 'canRemove' => true |
|
207 | + ], |
|
208 | + [ |
|
209 | + 'id' => 'group2', |
|
210 | + 'displayname' => 'group2-name', |
|
211 | + 'usercount' => 123, |
|
212 | + 'disabled' => 11, |
|
213 | + 'canAdd' => true, |
|
214 | + 'canRemove' => true |
|
215 | + ] |
|
216 | + ]], $result->getData()); |
|
217 | + } |
|
218 | + |
|
219 | + public function testGetGroupAsSubadmin(): void { |
|
220 | + $group = $this->createGroup('group'); |
|
221 | + $this->asSubAdminOfGroup($group); |
|
222 | + |
|
223 | + $this->groupManager |
|
224 | + ->method('get') |
|
225 | + ->with('group') |
|
226 | + ->willReturn($group); |
|
227 | + $this->groupManager |
|
228 | + ->method('groupExists') |
|
229 | + ->with('group') |
|
230 | + ->willReturn(true); |
|
231 | + $group |
|
232 | + ->method('getUsers') |
|
233 | + ->willReturn([ |
|
234 | + $this->createUser('user1'), |
|
235 | + $this->createUser('user2') |
|
236 | + ]); |
|
237 | + |
|
238 | + $result = $this->api->getGroup('group'); |
|
239 | + |
|
240 | + $this->assertEquals(['users' => ['user1', 'user2']], $result->getData()); |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + public function testGetGroupAsIrrelevantSubadmin(): void { |
|
245 | + $this->expectException(OCSException::class); |
|
246 | + $this->expectExceptionCode(403); |
|
247 | + |
|
248 | + $group = $this->createGroup('group'); |
|
249 | + $otherGroup = $this->createGroup('otherGroup'); |
|
250 | + $this->asSubAdminOfGroup($otherGroup); |
|
251 | + |
|
252 | + $this->groupManager |
|
253 | + ->method('get') |
|
254 | + ->with('group') |
|
255 | + ->willReturn($group); |
|
256 | + $this->groupManager |
|
257 | + ->method('groupExists') |
|
258 | + ->with('group') |
|
259 | + ->willReturn(true); |
|
260 | + |
|
261 | + $this->api->getGroup('group'); |
|
262 | + } |
|
263 | + |
|
264 | + public function testGetGroupAsAdmin(): void { |
|
265 | + $group = $this->createGroup('group'); |
|
266 | + $this->asAdmin(); |
|
267 | + |
|
268 | + $this->groupManager |
|
269 | + ->method('get') |
|
270 | + ->with('group') |
|
271 | + ->willReturn($group); |
|
272 | + $this->groupManager |
|
273 | + ->method('groupExists') |
|
274 | + ->with('group') |
|
275 | + ->willReturn(true); |
|
276 | + $group |
|
277 | + ->method('getUsers') |
|
278 | + ->willReturn([ |
|
279 | + $this->createUser('user1'), |
|
280 | + $this->createUser('user2') |
|
281 | + ]); |
|
282 | + |
|
283 | + $result = $this->api->getGroup('group'); |
|
284 | + |
|
285 | + $this->assertEquals(['users' => ['user1', 'user2']], $result->getData()); |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + public function testGetGroupNonExisting(): void { |
|
290 | + $this->expectException(OCSException::class); |
|
291 | + $this->expectExceptionMessage('The requested group could not be found'); |
|
292 | + $this->expectExceptionCode(404); |
|
293 | + |
|
294 | + $this->asUser(); |
|
295 | + |
|
296 | + $this->api->getGroup($this->getUniqueID()); |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + public function testGetSubAdminsOfGroupsNotExists(): void { |
|
301 | + $this->expectException(OCSException::class); |
|
302 | + $this->expectExceptionMessage('Group does not exist'); |
|
303 | + $this->expectExceptionCode(101); |
|
304 | + |
|
305 | + $this->api->getSubAdminsOfGroup('NonExistingGroup'); |
|
306 | + } |
|
307 | + |
|
308 | + public function testGetSubAdminsOfGroup(): void { |
|
309 | + $group = $this->createGroup('GroupWithSubAdmins'); |
|
310 | + $this->groupManager |
|
311 | + ->method('get') |
|
312 | + ->with('GroupWithSubAdmins') |
|
313 | + ->willReturn($group); |
|
314 | + |
|
315 | + $this->subAdminManager |
|
316 | + ->expects($this->once()) |
|
317 | + ->method('getGroupsSubAdmins') |
|
318 | + ->with($group) |
|
319 | + ->willReturn([ |
|
320 | + $this->createUser('SubAdmin1'), |
|
321 | + $this->createUser('SubAdmin2'), |
|
322 | + ]); |
|
323 | + |
|
324 | + $result = $this->api->getSubAdminsOfGroup('GroupWithSubAdmins'); |
|
325 | + $this->assertEquals(['SubAdmin1', 'SubAdmin2'], $result->getData()); |
|
326 | + } |
|
327 | + |
|
328 | + public function testGetSubAdminsOfGroupEmptyList(): void { |
|
329 | + $group = $this->createGroup('GroupWithOutSubAdmins'); |
|
330 | + $this->groupManager |
|
331 | + ->method('get') |
|
332 | + ->with('GroupWithOutSubAdmins') |
|
333 | + ->willReturn($group); |
|
334 | + |
|
335 | + $this->subAdminManager |
|
336 | + ->expects($this->once()) |
|
337 | + ->method('getGroupsSubAdmins') |
|
338 | + ->with($group) |
|
339 | + ->willReturn([ |
|
340 | + ]); |
|
341 | + |
|
342 | + $result = $this->api->getSubAdminsOfGroup('GroupWithOutSubAdmins'); |
|
343 | + $this->assertEquals([], $result->getData()); |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + public function testAddGroupEmptyGroup(): void { |
|
348 | + $this->expectException(OCSException::class); |
|
349 | + $this->expectExceptionMessage('Invalid group name'); |
|
350 | + $this->expectExceptionCode(101); |
|
351 | + |
|
352 | + $this->api->addGroup(''); |
|
353 | + } |
|
354 | + |
|
355 | + |
|
356 | + public function testAddGroupExistingGroup(): void { |
|
357 | + $this->expectException(OCSException::class); |
|
358 | + $this->expectExceptionCode(102); |
|
359 | + |
|
360 | + $this->groupManager |
|
361 | + ->method('groupExists') |
|
362 | + ->with('ExistingGroup') |
|
363 | + ->willReturn(true); |
|
364 | + |
|
365 | + $this->api->addGroup('ExistingGroup'); |
|
366 | + } |
|
367 | + |
|
368 | + public function testAddGroup(): void { |
|
369 | + $this->groupManager |
|
370 | + ->method('groupExists') |
|
371 | + ->with('NewGroup') |
|
372 | + ->willReturn(false); |
|
373 | + |
|
374 | + $group = $this->createGroup('NewGroup'); |
|
375 | + $this->groupManager |
|
376 | + ->expects($this->once()) |
|
377 | + ->method('createGroup') |
|
378 | + ->with('NewGroup') |
|
379 | + ->willReturn($group); |
|
380 | + |
|
381 | + $this->api->addGroup('NewGroup'); |
|
382 | + } |
|
383 | + |
|
384 | + public function testAddGroupWithSpecialChar(): void { |
|
385 | + $this->groupManager |
|
386 | + ->method('groupExists') |
|
387 | + ->with('Iñtërnâtiônàlizætiøn') |
|
388 | + ->willReturn(false); |
|
389 | + |
|
390 | + $group = $this->createGroup('Iñtërnâtiônàlizætiøn'); |
|
391 | + $this->groupManager |
|
392 | + ->expects($this->once()) |
|
393 | + ->method('createGroup') |
|
394 | + ->with('Iñtërnâtiônàlizætiøn') |
|
395 | + ->willReturn($group); |
|
396 | + |
|
397 | + $this->api->addGroup('Iñtërnâtiônàlizætiøn'); |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + public function testDeleteGroupNonExisting(): void { |
|
402 | + $this->expectException(OCSException::class); |
|
403 | + $this->expectExceptionCode(101); |
|
404 | + |
|
405 | + $this->api->deleteGroup('NonExistingGroup'); |
|
406 | + } |
|
407 | + |
|
408 | + |
|
409 | + public function testDeleteAdminGroup(): void { |
|
410 | + $this->expectException(OCSException::class); |
|
411 | + $this->expectExceptionCode(102); |
|
412 | + |
|
413 | + $this->groupManager |
|
414 | + ->method('groupExists') |
|
415 | + ->with('admin') |
|
416 | + ->willReturn('true'); |
|
417 | + |
|
418 | + $this->api->deleteGroup('admin'); |
|
419 | + } |
|
420 | + |
|
421 | + public function testDeleteGroup(): void { |
|
422 | + $this->groupManager |
|
423 | + ->method('groupExists') |
|
424 | + ->with('ExistingGroup') |
|
425 | + ->willReturn('true'); |
|
426 | + |
|
427 | + $group = $this->createGroup('ExistingGroup'); |
|
428 | + $this->groupManager |
|
429 | + ->method('get') |
|
430 | + ->with('ExistingGroup') |
|
431 | + ->willReturn($group); |
|
432 | + $group |
|
433 | + ->expects($this->once()) |
|
434 | + ->method('delete') |
|
435 | + ->willReturn(true); |
|
436 | + |
|
437 | + $this->api->deleteGroup('ExistingGroup'); |
|
438 | + } |
|
439 | + |
|
440 | + public function testDeleteGroupEncoding(): void { |
|
441 | + $this->groupManager |
|
442 | + ->method('groupExists') |
|
443 | + ->with('ExistingGroup A/B') |
|
444 | + ->willReturn('true'); |
|
445 | + |
|
446 | + $group = $this->createGroup('ExistingGroup'); |
|
447 | + $this->groupManager |
|
448 | + ->method('get') |
|
449 | + ->with('ExistingGroup A/B') |
|
450 | + ->willReturn($group); |
|
451 | + $group |
|
452 | + ->expects($this->once()) |
|
453 | + ->method('delete') |
|
454 | + ->willReturn(true); |
|
455 | + |
|
456 | + $this->api->deleteGroup(urlencode('ExistingGroup A/B')); |
|
457 | + } |
|
458 | + |
|
459 | + public function testGetGroupUsersDetails(): void { |
|
460 | + $gid = 'ncg1'; |
|
461 | + |
|
462 | + $this->asAdmin(); |
|
463 | + |
|
464 | + $users = [ |
|
465 | + 'ncu1' => $this->createUser('ncu1'), # regular |
|
466 | + 'ncu2' => $this->createUser('ncu2'), # the zombie |
|
467 | + ]; |
|
468 | + $users['ncu2']->expects($this->atLeastOnce()) |
|
469 | + ->method('getHome') |
|
470 | + ->willThrowException(new NoUserException()); |
|
471 | + |
|
472 | + $this->userManager->expects($this->any()) |
|
473 | + ->method('get') |
|
474 | + ->willReturnCallback(function (string $uid) use ($users) { |
|
475 | + return $users[$uid] ?? null; |
|
476 | + }); |
|
477 | + |
|
478 | + $group = $this->createGroup($gid); |
|
479 | + $group->expects($this->once()) |
|
480 | + ->method('searchUsers') |
|
481 | + ->with('', null, 0) |
|
482 | + ->willReturn(array_values($users)); |
|
483 | + |
|
484 | + $this->groupManager |
|
485 | + ->method('get') |
|
486 | + ->with($gid) |
|
487 | + ->willReturn($group); |
|
488 | + $this->groupManager->expects($this->any()) |
|
489 | + ->method('getUserGroups') |
|
490 | + ->willReturn([$group]); |
|
491 | + |
|
492 | + /** @var MockObject */ |
|
493 | + $this->subAdminManager->expects($this->any()) |
|
494 | + ->method('isSubAdminOfGroup') |
|
495 | + ->willReturn(false); |
|
496 | + $this->subAdminManager->expects($this->any()) |
|
497 | + ->method('getSubAdminsGroups') |
|
498 | + ->willReturn([]); |
|
499 | + |
|
500 | + |
|
501 | + $this->api->getGroupUsersDetails($gid); |
|
502 | + } |
|
503 | + |
|
504 | + public function testGetGroupUsersDetailsEncoded(): void { |
|
505 | + $gid = 'Department A/B C/D'; |
|
506 | + |
|
507 | + $this->asAdmin(); |
|
508 | + |
|
509 | + $users = [ |
|
510 | + 'ncu1' => $this->createUser('ncu1'), # regular |
|
511 | + 'ncu2' => $this->createUser('ncu2'), # the zombie |
|
512 | + ]; |
|
513 | + $users['ncu2']->expects($this->atLeastOnce()) |
|
514 | + ->method('getHome') |
|
515 | + ->willThrowException(new NoUserException()); |
|
516 | + |
|
517 | + $this->userManager->expects($this->any()) |
|
518 | + ->method('get') |
|
519 | + ->willReturnCallback(function (string $uid) use ($users) { |
|
520 | + return $users[$uid] ?? null; |
|
521 | + }); |
|
522 | + |
|
523 | + $group = $this->createGroup($gid); |
|
524 | + $group->expects($this->once()) |
|
525 | + ->method('searchUsers') |
|
526 | + ->with('', null, 0) |
|
527 | + ->willReturn(array_values($users)); |
|
528 | + |
|
529 | + $this->groupManager |
|
530 | + ->method('get') |
|
531 | + ->with($gid) |
|
532 | + ->willReturn($group); |
|
533 | + $this->groupManager->expects($this->any()) |
|
534 | + ->method('getUserGroups') |
|
535 | + ->willReturn([$group]); |
|
536 | + |
|
537 | + /** @var MockObject */ |
|
538 | + $this->subAdminManager->expects($this->any()) |
|
539 | + ->method('isSubAdminOfGroup') |
|
540 | + ->willReturn(false); |
|
541 | + $this->subAdminManager->expects($this->any()) |
|
542 | + ->method('getSubAdminsGroups') |
|
543 | + ->willReturn([]); |
|
544 | + |
|
545 | + |
|
546 | + $this->api->getGroupUsersDetails(urlencode($gid)); |
|
547 | + } |
|
548 | 548 | } |