Completed
Push — master ( d03f6d...56f3d1 )
by Joas
20:52 queued 17s
created
apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php 2 patches
Indentation   +679 added lines, -679 removed lines patch added patch discarded remove patch
@@ -40,683 +40,683 @@
 block discarded – undo
40 40
  */
41 41
 class FilesPluginTest extends TestCase {
42 42
 
43
-	private Tree&MockObject $tree;
44
-	private Server&MockObject $server;
45
-	private IConfig&MockObject $config;
46
-	private IRequest&MockObject $request;
47
-	private IPreview&MockObject $previewManager;
48
-	private IUserSession&MockObject $userSession;
49
-	private IFilenameValidator&MockObject $filenameValidator;
50
-	private IAccountManager&MockObject $accountManager;
51
-	private FilesPlugin $plugin;
52
-
53
-	protected function setUp(): void {
54
-		parent::setUp();
55
-		$this->server = $this->createMock(Server::class);
56
-		$this->tree = $this->createMock(Tree::class);
57
-		$this->config = $this->createMock(IConfig::class);
58
-		$this->config->expects($this->any())->method('getSystemValue')
59
-			->with($this->equalTo('data-fingerprint'), $this->equalTo(''))
60
-			->willReturn('my_fingerprint');
61
-		$this->request = $this->createMock(IRequest::class);
62
-		$this->previewManager = $this->createMock(IPreview::class);
63
-		$this->userSession = $this->createMock(IUserSession::class);
64
-		$this->filenameValidator = $this->createMock(IFilenameValidator::class);
65
-		$this->accountManager = $this->createMock(IAccountManager::class);
66
-
67
-		$this->plugin = new FilesPlugin(
68
-			$this->tree,
69
-			$this->config,
70
-			$this->request,
71
-			$this->previewManager,
72
-			$this->userSession,
73
-			$this->filenameValidator,
74
-			$this->accountManager,
75
-		);
76
-
77
-		$response = $this->createMock(ResponseInterface::class);
78
-		$this->server->httpResponse = $response;
79
-		$this->server->xml = new Service();
80
-
81
-		$this->plugin->initialize($this->server);
82
-	}
83
-
84
-	private function createTestNode(string $class, string $path = '/dummypath'): MockObject {
85
-		$node = $this->createMock($class);
86
-
87
-		$node->expects($this->any())
88
-			->method('getId')
89
-			->willReturn(123);
90
-
91
-		$this->tree->expects($this->any())
92
-			->method('getNodeForPath')
93
-			->with($path)
94
-			->willReturn($node);
95
-
96
-		$node->expects($this->any())
97
-			->method('getFileId')
98
-			->willReturn('00000123instanceid');
99
-		$node->expects($this->any())
100
-			->method('getInternalFileId')
101
-			->willReturn('123');
102
-		$node->expects($this->any())
103
-			->method('getEtag')
104
-			->willReturn('"abc"');
105
-		$node->expects($this->any())
106
-			->method('getDavPermissions')
107
-			->willReturn('DWCKMSR');
108
-
109
-		$fileInfo = $this->createMock(FileInfo::class);
110
-		$fileInfo->expects($this->any())
111
-			->method('isReadable')
112
-			->willReturn(true);
113
-		$fileInfo->expects($this->any())
114
-			->method('getCreationTime')
115
-			->willReturn(123456789);
116
-
117
-		$node->expects($this->any())
118
-			->method('getFileInfo')
119
-			->willReturn($fileInfo);
120
-
121
-		return $node;
122
-	}
123
-
124
-	public function testGetPropertiesForFile(): void {
125
-		/** @var File&MockObject $node */
126
-		$node = $this->createTestNode(File::class);
127
-
128
-		$propFind = new PropFind(
129
-			'/dummyPath',
130
-			[
131
-				FilesPlugin::GETETAG_PROPERTYNAME,
132
-				FilesPlugin::FILEID_PROPERTYNAME,
133
-				FilesPlugin::INTERNAL_FILEID_PROPERTYNAME,
134
-				FilesPlugin::SIZE_PROPERTYNAME,
135
-				FilesPlugin::PERMISSIONS_PROPERTYNAME,
136
-				FilesPlugin::DOWNLOADURL_PROPERTYNAME,
137
-				FilesPlugin::OWNER_ID_PROPERTYNAME,
138
-				FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME,
139
-				FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME,
140
-				FilesPlugin::CREATIONDATE_PROPERTYNAME,
141
-			],
142
-			0
143
-		);
144
-
145
-		$user = $this->createMock(User::class);
146
-		$user
147
-			->expects($this->once())
148
-			->method('getUID')
149
-			->willReturn('foo');
150
-		$user
151
-			->expects($this->once())
152
-			->method('getDisplayName')
153
-			->willReturn('M. Foo');
154
-
155
-		$owner = $this->createMock(Account::class);
156
-		$this->accountManager->expects($this->once())
157
-			->method('getAccount')
158
-			->with($user)
159
-			->willReturn($owner);
160
-
161
-		$node->expects($this->once())
162
-			->method('getDirectDownload')
163
-			->willReturn(['url' => 'http://example.com/']);
164
-		$node->expects($this->exactly(2))
165
-			->method('getOwner')
166
-			->willReturn($user);
167
-
168
-		$displayNameProp = $this->createMock(AccountProperty::class);
169
-		$owner
170
-			->expects($this->once())
171
-			->method('getProperty')
172
-			->with(IAccountManager::PROPERTY_DISPLAYNAME)
173
-			->willReturn($displayNameProp);
174
-		$displayNameProp
175
-			->expects($this->once())
176
-			->method('getScope')
177
-			->willReturn(IAccountManager::SCOPE_PUBLISHED);
178
-
179
-		$this->plugin->handleGetProperties(
180
-			$propFind,
181
-			$node
182
-		);
183
-
184
-		$this->assertEquals('"abc"', $propFind->get(FilesPlugin::GETETAG_PROPERTYNAME));
185
-		$this->assertEquals('00000123instanceid', $propFind->get(FilesPlugin::FILEID_PROPERTYNAME));
186
-		$this->assertEquals('123', $propFind->get(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME));
187
-		$this->assertEquals('1973-11-29T21:33:09+00:00', $propFind->get(FilesPlugin::CREATIONDATE_PROPERTYNAME));
188
-		$this->assertEquals(0, $propFind->get(FilesPlugin::SIZE_PROPERTYNAME));
189
-		$this->assertEquals('DWCKMSR', $propFind->get(FilesPlugin::PERMISSIONS_PROPERTYNAME));
190
-		$this->assertEquals('http://example.com/', $propFind->get(FilesPlugin::DOWNLOADURL_PROPERTYNAME));
191
-		$this->assertEquals('foo', $propFind->get(FilesPlugin::OWNER_ID_PROPERTYNAME));
192
-		$this->assertEquals('M. Foo', $propFind->get(FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME));
193
-		$this->assertEquals('my_fingerprint', $propFind->get(FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME));
194
-		$this->assertEquals([], $propFind->get404Properties());
195
-	}
196
-
197
-	public function testGetDisplayNamePropertyWhenNotPublished(): void {
198
-		$node = $this->createTestNode(File::class);
199
-		$propFind = new PropFind(
200
-			'/dummyPath',
201
-			[
202
-				FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME,
203
-			],
204
-			0
205
-		);
206
-
207
-		$this->userSession->expects($this->once())
208
-			->method('getUser')
209
-			->willReturn(null);
210
-
211
-		$user = $this->createMock(User::class);
212
-
213
-		$user->expects($this->never())
214
-			->method('getDisplayName');
215
-
216
-		$owner = $this->createMock(Account::class);
217
-		$this->accountManager->expects($this->once())
218
-			->method('getAccount')
219
-			->with($user)
220
-			->willReturn($owner);
221
-
222
-		$node->expects($this->once())
223
-			->method('getOwner')
224
-			->willReturn($user);
225
-
226
-		$displayNameProp = $this->createMock(AccountProperty::class);
227
-		$owner
228
-			->expects($this->once())
229
-			->method('getProperty')
230
-			->with(IAccountManager::PROPERTY_DISPLAYNAME)
231
-			->willReturn($displayNameProp);
232
-		$displayNameProp
233
-			->expects($this->once())
234
-			->method('getScope')
235
-			->willReturn(IAccountManager::SCOPE_PRIVATE);
236
-
237
-		$this->plugin->handleGetProperties(
238
-			$propFind,
239
-			$node
240
-		);
241
-
242
-		$this->assertEquals(null, $propFind->get(FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME));
243
-	}
244
-
245
-	public function testGetDisplayNamePropertyWhenNotPublishedButLoggedIn(): void {
246
-		$node = $this->createTestNode(File::class);
247
-
248
-		$propFind = new PropFind(
249
-			'/dummyPath',
250
-			[
251
-				FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME,
252
-			],
253
-			0
254
-		);
255
-
256
-		$user = $this->createMock(User::class);
257
-
258
-		$node->expects($this->once())
259
-			->method('getOwner')
260
-			->willReturn($user);
261
-
262
-		$loggedInUser = $this->createMock(User::class);
263
-		$this->userSession->expects($this->once())
264
-			->method('getUser')
265
-			->willReturn($loggedInUser);
266
-
267
-		$user
268
-			->expects($this->once())
269
-			->method('getDisplayName')
270
-			->willReturn('M. Foo');
271
-
272
-		$this->accountManager->expects($this->never())
273
-			->method('getAccount');
274
-
275
-		$this->plugin->handleGetProperties(
276
-			$propFind,
277
-			$node
278
-		);
279
-
280
-		$this->assertEquals('M. Foo', $propFind->get(FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME));
281
-	}
282
-
283
-	public function testGetPropertiesStorageNotAvailable(): void {
284
-		/** @var File&MockObject $node */
285
-		$node = $this->createTestNode(File::class);
286
-
287
-		$propFind = new PropFind(
288
-			'/dummyPath',
289
-			[
290
-				FilesPlugin::DOWNLOADURL_PROPERTYNAME,
291
-			],
292
-			0
293
-		);
294
-
295
-		$node->expects($this->once())
296
-			->method('getDirectDownload')
297
-			->will($this->throwException(new StorageNotAvailableException()));
298
-
299
-		$this->plugin->handleGetProperties(
300
-			$propFind,
301
-			$node
302
-		);
303
-
304
-		$this->assertEquals(null, $propFind->get(FilesPlugin::DOWNLOADURL_PROPERTYNAME));
305
-	}
306
-
307
-	public function testGetPublicPermissions(): void {
308
-		/** @var IRequest&MockObject */
309
-		$request = $this->createMock(IRequest::class);
310
-		$this->plugin = new FilesPlugin(
311
-			$this->tree,
312
-			$this->config,
313
-			$request,
314
-			$this->previewManager,
315
-			$this->userSession,
316
-			$this->filenameValidator,
317
-			$this->accountManager,
318
-			true,
319
-		);
320
-		$this->plugin->initialize($this->server);
321
-
322
-		$propFind = new PropFind(
323
-			'/dummyPath',
324
-			[
325
-				FilesPlugin::PERMISSIONS_PROPERTYNAME,
326
-			],
327
-			0
328
-		);
329
-
330
-		/** @var File&MockObject $node */
331
-		$node = $this->createTestNode(File::class);
332
-		$node->expects($this->any())
333
-			->method('getDavPermissions')
334
-			->willReturn('DWCKMSR');
335
-
336
-		$this->plugin->handleGetProperties(
337
-			$propFind,
338
-			$node
339
-		);
340
-
341
-		$this->assertEquals('DWCKR', $propFind->get(FilesPlugin::PERMISSIONS_PROPERTYNAME));
342
-	}
343
-
344
-	public function testGetPropertiesForDirectory(): void {
345
-		/** @var Directory&MockObject $node */
346
-		$node = $this->createTestNode(Directory::class);
347
-
348
-		$propFind = new PropFind(
349
-			'/dummyPath',
350
-			[
351
-				FilesPlugin::GETETAG_PROPERTYNAME,
352
-				FilesPlugin::FILEID_PROPERTYNAME,
353
-				FilesPlugin::SIZE_PROPERTYNAME,
354
-				FilesPlugin::PERMISSIONS_PROPERTYNAME,
355
-				FilesPlugin::DOWNLOADURL_PROPERTYNAME,
356
-				FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME,
357
-			],
358
-			0
359
-		);
360
-
361
-		$node->expects($this->once())
362
-			->method('getSize')
363
-			->willReturn(1025);
364
-
365
-		$this->plugin->handleGetProperties(
366
-			$propFind,
367
-			$node
368
-		);
369
-
370
-		$this->assertEquals('"abc"', $propFind->get(FilesPlugin::GETETAG_PROPERTYNAME));
371
-		$this->assertEquals('00000123instanceid', $propFind->get(FilesPlugin::FILEID_PROPERTYNAME));
372
-		$this->assertEquals(1025, $propFind->get(FilesPlugin::SIZE_PROPERTYNAME));
373
-		$this->assertEquals('DWCKMSR', $propFind->get(FilesPlugin::PERMISSIONS_PROPERTYNAME));
374
-		$this->assertEquals(null, $propFind->get(FilesPlugin::DOWNLOADURL_PROPERTYNAME));
375
-		$this->assertEquals('my_fingerprint', $propFind->get(FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME));
376
-		$this->assertEquals([FilesPlugin::DOWNLOADURL_PROPERTYNAME], $propFind->get404Properties());
377
-	}
378
-
379
-	public function testGetPropertiesForRootDirectory(): void {
380
-		/** @var Directory&MockObject $node */
381
-		$node = $this->createMock(Directory::class);
382
-		$node->expects($this->any())->method('getPath')->willReturn('/');
383
-
384
-		$fileInfo = $this->createMock(FileInfo::class);
385
-		$fileInfo->expects($this->any())
386
-			->method('isReadable')
387
-			->willReturn(true);
388
-
389
-		$node->expects($this->any())
390
-			->method('getFileInfo')
391
-			->willReturn($fileInfo);
392
-
393
-		$propFind = new PropFind(
394
-			'/',
395
-			[
396
-				FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME,
397
-			],
398
-			0
399
-		);
400
-
401
-		$this->plugin->handleGetProperties(
402
-			$propFind,
403
-			$node
404
-		);
405
-
406
-		$this->assertEquals('my_fingerprint', $propFind->get(FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME));
407
-	}
408
-
409
-	public function testGetPropertiesWhenNoPermission(): void {
410
-		// No read permissions can be caused by files access control.
411
-		// But we still want to load the directory list, so this is okay for us.
412
-		// $this->expectException(\Sabre\DAV\Exception\NotFound::class);
413
-		/** @var Directory&MockObject $node */
414
-		$node = $this->createMock(Directory::class);
415
-		$node->expects($this->any())->method('getPath')->willReturn('/');
416
-
417
-		$fileInfo = $this->createMock(FileInfo::class);
418
-		$fileInfo->expects($this->any())
419
-			->method('isReadable')
420
-			->willReturn(false);
421
-
422
-		$node->expects($this->any())
423
-			->method('getFileInfo')
424
-			->willReturn($fileInfo);
425
-
426
-		$propFind = new PropFind(
427
-			'/test',
428
-			[
429
-				FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME,
430
-			],
431
-			0
432
-		);
433
-
434
-		$this->plugin->handleGetProperties(
435
-			$propFind,
436
-			$node
437
-		);
438
-
439
-		$this->addToAssertionCount(1);
440
-	}
441
-
442
-	public function testUpdateProps(): void {
443
-		$node = $this->createTestNode(File::class);
444
-
445
-		$testDate = 'Fri, 13 Feb 2015 00:01:02 GMT';
446
-		$testCreationDate = '2007-08-31T16:47+00:00';
447
-
448
-		$node->expects($this->once())
449
-			->method('touch')
450
-			->with($testDate);
451
-
452
-		$node->expects($this->once())
453
-			->method('setEtag')
454
-			->with('newetag')
455
-			->willReturn(true);
456
-
457
-		$node->expects($this->once())
458
-			->method('setCreationTime')
459
-			->with('1188578820');
460
-
461
-		// properties to set
462
-		$propPatch = new PropPatch([
463
-			FilesPlugin::GETETAG_PROPERTYNAME => 'newetag',
464
-			FilesPlugin::LASTMODIFIED_PROPERTYNAME => $testDate,
465
-			FilesPlugin::CREATIONDATE_PROPERTYNAME => $testCreationDate,
466
-		]);
467
-
468
-
469
-		$this->plugin->handleUpdateProperties(
470
-			'/dummypath',
471
-			$propPatch
472
-		);
473
-
474
-		$propPatch->commit();
475
-
476
-		$this->assertEmpty($propPatch->getRemainingMutations());
477
-
478
-		$result = $propPatch->getResult();
479
-		$this->assertEquals(200, $result[FilesPlugin::LASTMODIFIED_PROPERTYNAME]);
480
-		$this->assertEquals(200, $result[FilesPlugin::GETETAG_PROPERTYNAME]);
481
-		$this->assertEquals(200, $result[FilesPlugin::CREATIONDATE_PROPERTYNAME]);
482
-	}
483
-
484
-	public function testUpdatePropsForbidden(): void {
485
-		$propPatch = new PropPatch([
486
-			FilesPlugin::OWNER_ID_PROPERTYNAME => 'user2',
487
-			FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME => 'User Two',
488
-			FilesPlugin::FILEID_PROPERTYNAME => 12345,
489
-			FilesPlugin::PERMISSIONS_PROPERTYNAME => 'C',
490
-			FilesPlugin::SIZE_PROPERTYNAME => 123,
491
-			FilesPlugin::DOWNLOADURL_PROPERTYNAME => 'http://example.com/',
492
-		]);
493
-
494
-		$this->plugin->handleUpdateProperties(
495
-			'/dummypath',
496
-			$propPatch
497
-		);
498
-
499
-		$propPatch->commit();
500
-
501
-		$this->assertEmpty($propPatch->getRemainingMutations());
502
-
503
-		$result = $propPatch->getResult();
504
-		$this->assertEquals(403, $result[FilesPlugin::OWNER_ID_PROPERTYNAME]);
505
-		$this->assertEquals(403, $result[FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME]);
506
-		$this->assertEquals(403, $result[FilesPlugin::FILEID_PROPERTYNAME]);
507
-		$this->assertEquals(403, $result[FilesPlugin::PERMISSIONS_PROPERTYNAME]);
508
-		$this->assertEquals(403, $result[FilesPlugin::SIZE_PROPERTYNAME]);
509
-		$this->assertEquals(403, $result[FilesPlugin::DOWNLOADURL_PROPERTYNAME]);
510
-	}
511
-
512
-	/**
513
-	 * Test case from https://github.com/owncloud/core/issues/5251
514
-	 *
515
-	 * |-FolderA
516
-	 *  |-text.txt
517
-	 * |-test.txt
518
-	 *
519
-	 * FolderA is an incoming shared folder and there are no delete permissions.
520
-	 * Thus moving /FolderA/test.txt to /test.txt should fail already on that check
521
-	 *
522
-	 */
523
-	public function testMoveSrcNotDeletable(): void {
524
-		$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
525
-		$this->expectExceptionMessage('FolderA/test.txt cannot be deleted');
526
-
527
-		$fileInfoFolderATestTXT = $this->createMock(FileInfo::class);
528
-		$fileInfoFolderATestTXT->expects($this->once())
529
-			->method('isDeletable')
530
-			->willReturn(false);
531
-
532
-		$node = $this->createMock(Node::class);
533
-		$node->expects($this->atLeastOnce())
534
-			->method('getFileInfo')
535
-			->willReturn($fileInfoFolderATestTXT);
536
-
537
-		$this->tree->expects($this->atLeastOnce())
538
-			->method('getNodeForPath')
539
-			->willReturn($node);
540
-
541
-		$this->plugin->checkMove('FolderA/test.txt', 'test.txt');
542
-	}
543
-
544
-	public function testMoveSrcDeletable(): void {
545
-		$fileInfoFolderATestTXT = $this->createMock(FileInfo::class);
546
-		$fileInfoFolderATestTXT->expects($this->once())
547
-			->method('isDeletable')
548
-			->willReturn(true);
549
-
550
-		$node = $this->createMock(Node::class);
551
-		$node->expects($this->atLeastOnce())
552
-			->method('getFileInfo')
553
-			->willReturn($fileInfoFolderATestTXT);
554
-
555
-		$this->tree->expects($this->atLeastOnce())
556
-			->method('getNodeForPath')
557
-			->willReturn($node);
558
-
559
-		$this->plugin->checkMove('FolderA/test.txt', 'test.txt');
560
-	}
561
-
562
-	public function testMoveSrcNotExist(): void {
563
-		$this->expectException(\Sabre\DAV\Exception\NotFound::class);
564
-		$this->expectExceptionMessage('FolderA/test.txt does not exist');
565
-
566
-		$node = $this->createMock(Node::class);
567
-		$node->expects($this->atLeastOnce())
568
-			->method('getFileInfo')
569
-			->willReturn(null);
570
-
571
-		$this->tree->expects($this->atLeastOnce())
572
-			->method('getNodeForPath')
573
-			->willReturn($node);
574
-
575
-		$this->plugin->checkMove('FolderA/test.txt', 'test.txt');
576
-	}
577
-
578
-	public function testMoveDestinationInvalid(): void {
579
-		$this->expectException(InvalidPath::class);
580
-		$this->expectExceptionMessage('Mocked exception');
581
-
582
-		$fileInfoFolderATestTXT = $this->createMock(FileInfo::class);
583
-		$fileInfoFolderATestTXT->expects(self::any())
584
-			->method('isDeletable')
585
-			->willReturn(true);
586
-
587
-		$node = $this->createMock(Node::class);
588
-		$node->expects($this->atLeastOnce())
589
-			->method('getFileInfo')
590
-			->willReturn($fileInfoFolderATestTXT);
591
-
592
-		$this->tree->expects($this->atLeastOnce())
593
-			->method('getNodeForPath')
594
-			->willReturn($node);
595
-
596
-		$this->filenameValidator->expects(self::once())
597
-			->method('validateFilename')
598
-			->with('invalid\\path.txt')
599
-			->willThrowException(new InvalidPathException('Mocked exception'));
600
-
601
-		$this->plugin->checkMove('FolderA/test.txt', 'invalid\\path.txt');
602
-	}
603
-
604
-	public function testCopySrcNotExist(): void {
605
-		$this->expectException(\Sabre\DAV\Exception\NotFound::class);
606
-		$this->expectExceptionMessage('FolderA/test.txt does not exist');
607
-
608
-		$node = $this->createMock(Node::class);
609
-		$node->expects($this->atLeastOnce())
610
-			->method('getFileInfo')
611
-			->willReturn(null);
612
-
613
-		$this->tree->expects($this->atLeastOnce())
614
-			->method('getNodeForPath')
615
-			->willReturn($node);
616
-
617
-		$this->plugin->checkCopy('FolderA/test.txt', 'test.txt');
618
-	}
619
-
620
-	public function testCopyDestinationInvalid(): void {
621
-		$this->expectException(InvalidPath::class);
622
-		$this->expectExceptionMessage('Mocked exception');
623
-
624
-		$fileInfoFolderATestTXT = $this->createMock(FileInfo::class);
625
-		$node = $this->createMock(Node::class);
626
-		$node->expects($this->atLeastOnce())
627
-			->method('getFileInfo')
628
-			->willReturn($fileInfoFolderATestTXT);
629
-
630
-		$this->tree->expects($this->atLeastOnce())
631
-			->method('getNodeForPath')
632
-			->willReturn($node);
633
-
634
-		$this->filenameValidator->expects(self::once())
635
-			->method('validateFilename')
636
-			->with('invalid\\path.txt')
637
-			->willThrowException(new InvalidPathException('Mocked exception'));
638
-
639
-		$this->plugin->checkCopy('FolderA/test.txt', 'invalid\\path.txt');
640
-	}
641
-
642
-	public static function downloadHeadersProvider(): array {
643
-		return [
644
-			[
645
-				false,
646
-				'attachment; filename*=UTF-8\'\'somefile.xml; filename="somefile.xml"'
647
-			],
648
-			[
649
-				true,
650
-				'attachment; filename="somefile.xml"'
651
-			],
652
-		];
653
-	}
654
-
655
-	/**
656
-	 * @dataProvider downloadHeadersProvider
657
-	 */
658
-	public function testDownloadHeaders(bool $isClumsyAgent, string $contentDispositionHeader): void {
659
-		$request = $this->createMock(RequestInterface::class);
660
-		$response = $this->createMock(ResponseInterface::class);
661
-
662
-		$request
663
-			->expects($this->once())
664
-			->method('getPath')
665
-			->willReturn('test/somefile.xml');
666
-
667
-		$node = $this->createMock(File::class);
668
-		$node
669
-			->expects($this->once())
670
-			->method('getName')
671
-			->willReturn('somefile.xml');
672
-
673
-		$this->tree
674
-			->expects($this->once())
675
-			->method('getNodeForPath')
676
-			->with('test/somefile.xml')
677
-			->willReturn($node);
678
-
679
-		$this->request
680
-			->expects($this->once())
681
-			->method('isUserAgent')
682
-			->willReturn($isClumsyAgent);
683
-
684
-		$calls = [
685
-			['Content-Disposition', $contentDispositionHeader],
686
-			['X-Accel-Buffering', 'no'],
687
-		];
688
-		$response
689
-			->expects($this->exactly(count($calls)))
690
-			->method('addHeader')
691
-			->willReturnCallback(function () use (&$calls) {
692
-				$expected = array_shift($calls);
693
-				$this->assertSame($expected, func_get_args());
694
-			});
695
-
696
-		$this->plugin->httpGet($request, $response);
697
-	}
698
-
699
-	public function testHasPreview(): void {
700
-		/** @var Directory&MockObject $node */
701
-		$node = $this->createTestNode(Directory::class);
702
-
703
-		$propFind = new PropFind(
704
-			'/dummyPath',
705
-			[
706
-				FilesPlugin::HAS_PREVIEW_PROPERTYNAME
707
-			],
708
-			0
709
-		);
710
-
711
-		$this->previewManager->expects($this->once())
712
-			->method('isAvailable')
713
-			->willReturn(false);
714
-
715
-		$this->plugin->handleGetProperties(
716
-			$propFind,
717
-			$node
718
-		);
719
-
720
-		$this->assertEquals('false', $propFind->get(FilesPlugin::HAS_PREVIEW_PROPERTYNAME));
721
-	}
43
+    private Tree&MockObject $tree;
44
+    private Server&MockObject $server;
45
+    private IConfig&MockObject $config;
46
+    private IRequest&MockObject $request;
47
+    private IPreview&MockObject $previewManager;
48
+    private IUserSession&MockObject $userSession;
49
+    private IFilenameValidator&MockObject $filenameValidator;
50
+    private IAccountManager&MockObject $accountManager;
51
+    private FilesPlugin $plugin;
52
+
53
+    protected function setUp(): void {
54
+        parent::setUp();
55
+        $this->server = $this->createMock(Server::class);
56
+        $this->tree = $this->createMock(Tree::class);
57
+        $this->config = $this->createMock(IConfig::class);
58
+        $this->config->expects($this->any())->method('getSystemValue')
59
+            ->with($this->equalTo('data-fingerprint'), $this->equalTo(''))
60
+            ->willReturn('my_fingerprint');
61
+        $this->request = $this->createMock(IRequest::class);
62
+        $this->previewManager = $this->createMock(IPreview::class);
63
+        $this->userSession = $this->createMock(IUserSession::class);
64
+        $this->filenameValidator = $this->createMock(IFilenameValidator::class);
65
+        $this->accountManager = $this->createMock(IAccountManager::class);
66
+
67
+        $this->plugin = new FilesPlugin(
68
+            $this->tree,
69
+            $this->config,
70
+            $this->request,
71
+            $this->previewManager,
72
+            $this->userSession,
73
+            $this->filenameValidator,
74
+            $this->accountManager,
75
+        );
76
+
77
+        $response = $this->createMock(ResponseInterface::class);
78
+        $this->server->httpResponse = $response;
79
+        $this->server->xml = new Service();
80
+
81
+        $this->plugin->initialize($this->server);
82
+    }
83
+
84
+    private function createTestNode(string $class, string $path = '/dummypath'): MockObject {
85
+        $node = $this->createMock($class);
86
+
87
+        $node->expects($this->any())
88
+            ->method('getId')
89
+            ->willReturn(123);
90
+
91
+        $this->tree->expects($this->any())
92
+            ->method('getNodeForPath')
93
+            ->with($path)
94
+            ->willReturn($node);
95
+
96
+        $node->expects($this->any())
97
+            ->method('getFileId')
98
+            ->willReturn('00000123instanceid');
99
+        $node->expects($this->any())
100
+            ->method('getInternalFileId')
101
+            ->willReturn('123');
102
+        $node->expects($this->any())
103
+            ->method('getEtag')
104
+            ->willReturn('"abc"');
105
+        $node->expects($this->any())
106
+            ->method('getDavPermissions')
107
+            ->willReturn('DWCKMSR');
108
+
109
+        $fileInfo = $this->createMock(FileInfo::class);
110
+        $fileInfo->expects($this->any())
111
+            ->method('isReadable')
112
+            ->willReturn(true);
113
+        $fileInfo->expects($this->any())
114
+            ->method('getCreationTime')
115
+            ->willReturn(123456789);
116
+
117
+        $node->expects($this->any())
118
+            ->method('getFileInfo')
119
+            ->willReturn($fileInfo);
120
+
121
+        return $node;
122
+    }
123
+
124
+    public function testGetPropertiesForFile(): void {
125
+        /** @var File&MockObject $node */
126
+        $node = $this->createTestNode(File::class);
127
+
128
+        $propFind = new PropFind(
129
+            '/dummyPath',
130
+            [
131
+                FilesPlugin::GETETAG_PROPERTYNAME,
132
+                FilesPlugin::FILEID_PROPERTYNAME,
133
+                FilesPlugin::INTERNAL_FILEID_PROPERTYNAME,
134
+                FilesPlugin::SIZE_PROPERTYNAME,
135
+                FilesPlugin::PERMISSIONS_PROPERTYNAME,
136
+                FilesPlugin::DOWNLOADURL_PROPERTYNAME,
137
+                FilesPlugin::OWNER_ID_PROPERTYNAME,
138
+                FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME,
139
+                FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME,
140
+                FilesPlugin::CREATIONDATE_PROPERTYNAME,
141
+            ],
142
+            0
143
+        );
144
+
145
+        $user = $this->createMock(User::class);
146
+        $user
147
+            ->expects($this->once())
148
+            ->method('getUID')
149
+            ->willReturn('foo');
150
+        $user
151
+            ->expects($this->once())
152
+            ->method('getDisplayName')
153
+            ->willReturn('M. Foo');
154
+
155
+        $owner = $this->createMock(Account::class);
156
+        $this->accountManager->expects($this->once())
157
+            ->method('getAccount')
158
+            ->with($user)
159
+            ->willReturn($owner);
160
+
161
+        $node->expects($this->once())
162
+            ->method('getDirectDownload')
163
+            ->willReturn(['url' => 'http://example.com/']);
164
+        $node->expects($this->exactly(2))
165
+            ->method('getOwner')
166
+            ->willReturn($user);
167
+
168
+        $displayNameProp = $this->createMock(AccountProperty::class);
169
+        $owner
170
+            ->expects($this->once())
171
+            ->method('getProperty')
172
+            ->with(IAccountManager::PROPERTY_DISPLAYNAME)
173
+            ->willReturn($displayNameProp);
174
+        $displayNameProp
175
+            ->expects($this->once())
176
+            ->method('getScope')
177
+            ->willReturn(IAccountManager::SCOPE_PUBLISHED);
178
+
179
+        $this->plugin->handleGetProperties(
180
+            $propFind,
181
+            $node
182
+        );
183
+
184
+        $this->assertEquals('"abc"', $propFind->get(FilesPlugin::GETETAG_PROPERTYNAME));
185
+        $this->assertEquals('00000123instanceid', $propFind->get(FilesPlugin::FILEID_PROPERTYNAME));
186
+        $this->assertEquals('123', $propFind->get(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME));
187
+        $this->assertEquals('1973-11-29T21:33:09+00:00', $propFind->get(FilesPlugin::CREATIONDATE_PROPERTYNAME));
188
+        $this->assertEquals(0, $propFind->get(FilesPlugin::SIZE_PROPERTYNAME));
189
+        $this->assertEquals('DWCKMSR', $propFind->get(FilesPlugin::PERMISSIONS_PROPERTYNAME));
190
+        $this->assertEquals('http://example.com/', $propFind->get(FilesPlugin::DOWNLOADURL_PROPERTYNAME));
191
+        $this->assertEquals('foo', $propFind->get(FilesPlugin::OWNER_ID_PROPERTYNAME));
192
+        $this->assertEquals('M. Foo', $propFind->get(FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME));
193
+        $this->assertEquals('my_fingerprint', $propFind->get(FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME));
194
+        $this->assertEquals([], $propFind->get404Properties());
195
+    }
196
+
197
+    public function testGetDisplayNamePropertyWhenNotPublished(): void {
198
+        $node = $this->createTestNode(File::class);
199
+        $propFind = new PropFind(
200
+            '/dummyPath',
201
+            [
202
+                FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME,
203
+            ],
204
+            0
205
+        );
206
+
207
+        $this->userSession->expects($this->once())
208
+            ->method('getUser')
209
+            ->willReturn(null);
210
+
211
+        $user = $this->createMock(User::class);
212
+
213
+        $user->expects($this->never())
214
+            ->method('getDisplayName');
215
+
216
+        $owner = $this->createMock(Account::class);
217
+        $this->accountManager->expects($this->once())
218
+            ->method('getAccount')
219
+            ->with($user)
220
+            ->willReturn($owner);
221
+
222
+        $node->expects($this->once())
223
+            ->method('getOwner')
224
+            ->willReturn($user);
225
+
226
+        $displayNameProp = $this->createMock(AccountProperty::class);
227
+        $owner
228
+            ->expects($this->once())
229
+            ->method('getProperty')
230
+            ->with(IAccountManager::PROPERTY_DISPLAYNAME)
231
+            ->willReturn($displayNameProp);
232
+        $displayNameProp
233
+            ->expects($this->once())
234
+            ->method('getScope')
235
+            ->willReturn(IAccountManager::SCOPE_PRIVATE);
236
+
237
+        $this->plugin->handleGetProperties(
238
+            $propFind,
239
+            $node
240
+        );
241
+
242
+        $this->assertEquals(null, $propFind->get(FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME));
243
+    }
244
+
245
+    public function testGetDisplayNamePropertyWhenNotPublishedButLoggedIn(): void {
246
+        $node = $this->createTestNode(File::class);
247
+
248
+        $propFind = new PropFind(
249
+            '/dummyPath',
250
+            [
251
+                FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME,
252
+            ],
253
+            0
254
+        );
255
+
256
+        $user = $this->createMock(User::class);
257
+
258
+        $node->expects($this->once())
259
+            ->method('getOwner')
260
+            ->willReturn($user);
261
+
262
+        $loggedInUser = $this->createMock(User::class);
263
+        $this->userSession->expects($this->once())
264
+            ->method('getUser')
265
+            ->willReturn($loggedInUser);
266
+
267
+        $user
268
+            ->expects($this->once())
269
+            ->method('getDisplayName')
270
+            ->willReturn('M. Foo');
271
+
272
+        $this->accountManager->expects($this->never())
273
+            ->method('getAccount');
274
+
275
+        $this->plugin->handleGetProperties(
276
+            $propFind,
277
+            $node
278
+        );
279
+
280
+        $this->assertEquals('M. Foo', $propFind->get(FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME));
281
+    }
282
+
283
+    public function testGetPropertiesStorageNotAvailable(): void {
284
+        /** @var File&MockObject $node */
285
+        $node = $this->createTestNode(File::class);
286
+
287
+        $propFind = new PropFind(
288
+            '/dummyPath',
289
+            [
290
+                FilesPlugin::DOWNLOADURL_PROPERTYNAME,
291
+            ],
292
+            0
293
+        );
294
+
295
+        $node->expects($this->once())
296
+            ->method('getDirectDownload')
297
+            ->will($this->throwException(new StorageNotAvailableException()));
298
+
299
+        $this->plugin->handleGetProperties(
300
+            $propFind,
301
+            $node
302
+        );
303
+
304
+        $this->assertEquals(null, $propFind->get(FilesPlugin::DOWNLOADURL_PROPERTYNAME));
305
+    }
306
+
307
+    public function testGetPublicPermissions(): void {
308
+        /** @var IRequest&MockObject */
309
+        $request = $this->createMock(IRequest::class);
310
+        $this->plugin = new FilesPlugin(
311
+            $this->tree,
312
+            $this->config,
313
+            $request,
314
+            $this->previewManager,
315
+            $this->userSession,
316
+            $this->filenameValidator,
317
+            $this->accountManager,
318
+            true,
319
+        );
320
+        $this->plugin->initialize($this->server);
321
+
322
+        $propFind = new PropFind(
323
+            '/dummyPath',
324
+            [
325
+                FilesPlugin::PERMISSIONS_PROPERTYNAME,
326
+            ],
327
+            0
328
+        );
329
+
330
+        /** @var File&MockObject $node */
331
+        $node = $this->createTestNode(File::class);
332
+        $node->expects($this->any())
333
+            ->method('getDavPermissions')
334
+            ->willReturn('DWCKMSR');
335
+
336
+        $this->plugin->handleGetProperties(
337
+            $propFind,
338
+            $node
339
+        );
340
+
341
+        $this->assertEquals('DWCKR', $propFind->get(FilesPlugin::PERMISSIONS_PROPERTYNAME));
342
+    }
343
+
344
+    public function testGetPropertiesForDirectory(): void {
345
+        /** @var Directory&MockObject $node */
346
+        $node = $this->createTestNode(Directory::class);
347
+
348
+        $propFind = new PropFind(
349
+            '/dummyPath',
350
+            [
351
+                FilesPlugin::GETETAG_PROPERTYNAME,
352
+                FilesPlugin::FILEID_PROPERTYNAME,
353
+                FilesPlugin::SIZE_PROPERTYNAME,
354
+                FilesPlugin::PERMISSIONS_PROPERTYNAME,
355
+                FilesPlugin::DOWNLOADURL_PROPERTYNAME,
356
+                FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME,
357
+            ],
358
+            0
359
+        );
360
+
361
+        $node->expects($this->once())
362
+            ->method('getSize')
363
+            ->willReturn(1025);
364
+
365
+        $this->plugin->handleGetProperties(
366
+            $propFind,
367
+            $node
368
+        );
369
+
370
+        $this->assertEquals('"abc"', $propFind->get(FilesPlugin::GETETAG_PROPERTYNAME));
371
+        $this->assertEquals('00000123instanceid', $propFind->get(FilesPlugin::FILEID_PROPERTYNAME));
372
+        $this->assertEquals(1025, $propFind->get(FilesPlugin::SIZE_PROPERTYNAME));
373
+        $this->assertEquals('DWCKMSR', $propFind->get(FilesPlugin::PERMISSIONS_PROPERTYNAME));
374
+        $this->assertEquals(null, $propFind->get(FilesPlugin::DOWNLOADURL_PROPERTYNAME));
375
+        $this->assertEquals('my_fingerprint', $propFind->get(FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME));
376
+        $this->assertEquals([FilesPlugin::DOWNLOADURL_PROPERTYNAME], $propFind->get404Properties());
377
+    }
378
+
379
+    public function testGetPropertiesForRootDirectory(): void {
380
+        /** @var Directory&MockObject $node */
381
+        $node = $this->createMock(Directory::class);
382
+        $node->expects($this->any())->method('getPath')->willReturn('/');
383
+
384
+        $fileInfo = $this->createMock(FileInfo::class);
385
+        $fileInfo->expects($this->any())
386
+            ->method('isReadable')
387
+            ->willReturn(true);
388
+
389
+        $node->expects($this->any())
390
+            ->method('getFileInfo')
391
+            ->willReturn($fileInfo);
392
+
393
+        $propFind = new PropFind(
394
+            '/',
395
+            [
396
+                FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME,
397
+            ],
398
+            0
399
+        );
400
+
401
+        $this->plugin->handleGetProperties(
402
+            $propFind,
403
+            $node
404
+        );
405
+
406
+        $this->assertEquals('my_fingerprint', $propFind->get(FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME));
407
+    }
408
+
409
+    public function testGetPropertiesWhenNoPermission(): void {
410
+        // No read permissions can be caused by files access control.
411
+        // But we still want to load the directory list, so this is okay for us.
412
+        // $this->expectException(\Sabre\DAV\Exception\NotFound::class);
413
+        /** @var Directory&MockObject $node */
414
+        $node = $this->createMock(Directory::class);
415
+        $node->expects($this->any())->method('getPath')->willReturn('/');
416
+
417
+        $fileInfo = $this->createMock(FileInfo::class);
418
+        $fileInfo->expects($this->any())
419
+            ->method('isReadable')
420
+            ->willReturn(false);
421
+
422
+        $node->expects($this->any())
423
+            ->method('getFileInfo')
424
+            ->willReturn($fileInfo);
425
+
426
+        $propFind = new PropFind(
427
+            '/test',
428
+            [
429
+                FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME,
430
+            ],
431
+            0
432
+        );
433
+
434
+        $this->plugin->handleGetProperties(
435
+            $propFind,
436
+            $node
437
+        );
438
+
439
+        $this->addToAssertionCount(1);
440
+    }
441
+
442
+    public function testUpdateProps(): void {
443
+        $node = $this->createTestNode(File::class);
444
+
445
+        $testDate = 'Fri, 13 Feb 2015 00:01:02 GMT';
446
+        $testCreationDate = '2007-08-31T16:47+00:00';
447
+
448
+        $node->expects($this->once())
449
+            ->method('touch')
450
+            ->with($testDate);
451
+
452
+        $node->expects($this->once())
453
+            ->method('setEtag')
454
+            ->with('newetag')
455
+            ->willReturn(true);
456
+
457
+        $node->expects($this->once())
458
+            ->method('setCreationTime')
459
+            ->with('1188578820');
460
+
461
+        // properties to set
462
+        $propPatch = new PropPatch([
463
+            FilesPlugin::GETETAG_PROPERTYNAME => 'newetag',
464
+            FilesPlugin::LASTMODIFIED_PROPERTYNAME => $testDate,
465
+            FilesPlugin::CREATIONDATE_PROPERTYNAME => $testCreationDate,
466
+        ]);
467
+
468
+
469
+        $this->plugin->handleUpdateProperties(
470
+            '/dummypath',
471
+            $propPatch
472
+        );
473
+
474
+        $propPatch->commit();
475
+
476
+        $this->assertEmpty($propPatch->getRemainingMutations());
477
+
478
+        $result = $propPatch->getResult();
479
+        $this->assertEquals(200, $result[FilesPlugin::LASTMODIFIED_PROPERTYNAME]);
480
+        $this->assertEquals(200, $result[FilesPlugin::GETETAG_PROPERTYNAME]);
481
+        $this->assertEquals(200, $result[FilesPlugin::CREATIONDATE_PROPERTYNAME]);
482
+    }
483
+
484
+    public function testUpdatePropsForbidden(): void {
485
+        $propPatch = new PropPatch([
486
+            FilesPlugin::OWNER_ID_PROPERTYNAME => 'user2',
487
+            FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME => 'User Two',
488
+            FilesPlugin::FILEID_PROPERTYNAME => 12345,
489
+            FilesPlugin::PERMISSIONS_PROPERTYNAME => 'C',
490
+            FilesPlugin::SIZE_PROPERTYNAME => 123,
491
+            FilesPlugin::DOWNLOADURL_PROPERTYNAME => 'http://example.com/',
492
+        ]);
493
+
494
+        $this->plugin->handleUpdateProperties(
495
+            '/dummypath',
496
+            $propPatch
497
+        );
498
+
499
+        $propPatch->commit();
500
+
501
+        $this->assertEmpty($propPatch->getRemainingMutations());
502
+
503
+        $result = $propPatch->getResult();
504
+        $this->assertEquals(403, $result[FilesPlugin::OWNER_ID_PROPERTYNAME]);
505
+        $this->assertEquals(403, $result[FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME]);
506
+        $this->assertEquals(403, $result[FilesPlugin::FILEID_PROPERTYNAME]);
507
+        $this->assertEquals(403, $result[FilesPlugin::PERMISSIONS_PROPERTYNAME]);
508
+        $this->assertEquals(403, $result[FilesPlugin::SIZE_PROPERTYNAME]);
509
+        $this->assertEquals(403, $result[FilesPlugin::DOWNLOADURL_PROPERTYNAME]);
510
+    }
511
+
512
+    /**
513
+     * Test case from https://github.com/owncloud/core/issues/5251
514
+     *
515
+     * |-FolderA
516
+     *  |-text.txt
517
+     * |-test.txt
518
+     *
519
+     * FolderA is an incoming shared folder and there are no delete permissions.
520
+     * Thus moving /FolderA/test.txt to /test.txt should fail already on that check
521
+     *
522
+     */
523
+    public function testMoveSrcNotDeletable(): void {
524
+        $this->expectException(\Sabre\DAV\Exception\Forbidden::class);
525
+        $this->expectExceptionMessage('FolderA/test.txt cannot be deleted');
526
+
527
+        $fileInfoFolderATestTXT = $this->createMock(FileInfo::class);
528
+        $fileInfoFolderATestTXT->expects($this->once())
529
+            ->method('isDeletable')
530
+            ->willReturn(false);
531
+
532
+        $node = $this->createMock(Node::class);
533
+        $node->expects($this->atLeastOnce())
534
+            ->method('getFileInfo')
535
+            ->willReturn($fileInfoFolderATestTXT);
536
+
537
+        $this->tree->expects($this->atLeastOnce())
538
+            ->method('getNodeForPath')
539
+            ->willReturn($node);
540
+
541
+        $this->plugin->checkMove('FolderA/test.txt', 'test.txt');
542
+    }
543
+
544
+    public function testMoveSrcDeletable(): void {
545
+        $fileInfoFolderATestTXT = $this->createMock(FileInfo::class);
546
+        $fileInfoFolderATestTXT->expects($this->once())
547
+            ->method('isDeletable')
548
+            ->willReturn(true);
549
+
550
+        $node = $this->createMock(Node::class);
551
+        $node->expects($this->atLeastOnce())
552
+            ->method('getFileInfo')
553
+            ->willReturn($fileInfoFolderATestTXT);
554
+
555
+        $this->tree->expects($this->atLeastOnce())
556
+            ->method('getNodeForPath')
557
+            ->willReturn($node);
558
+
559
+        $this->plugin->checkMove('FolderA/test.txt', 'test.txt');
560
+    }
561
+
562
+    public function testMoveSrcNotExist(): void {
563
+        $this->expectException(\Sabre\DAV\Exception\NotFound::class);
564
+        $this->expectExceptionMessage('FolderA/test.txt does not exist');
565
+
566
+        $node = $this->createMock(Node::class);
567
+        $node->expects($this->atLeastOnce())
568
+            ->method('getFileInfo')
569
+            ->willReturn(null);
570
+
571
+        $this->tree->expects($this->atLeastOnce())
572
+            ->method('getNodeForPath')
573
+            ->willReturn($node);
574
+
575
+        $this->plugin->checkMove('FolderA/test.txt', 'test.txt');
576
+    }
577
+
578
+    public function testMoveDestinationInvalid(): void {
579
+        $this->expectException(InvalidPath::class);
580
+        $this->expectExceptionMessage('Mocked exception');
581
+
582
+        $fileInfoFolderATestTXT = $this->createMock(FileInfo::class);
583
+        $fileInfoFolderATestTXT->expects(self::any())
584
+            ->method('isDeletable')
585
+            ->willReturn(true);
586
+
587
+        $node = $this->createMock(Node::class);
588
+        $node->expects($this->atLeastOnce())
589
+            ->method('getFileInfo')
590
+            ->willReturn($fileInfoFolderATestTXT);
591
+
592
+        $this->tree->expects($this->atLeastOnce())
593
+            ->method('getNodeForPath')
594
+            ->willReturn($node);
595
+
596
+        $this->filenameValidator->expects(self::once())
597
+            ->method('validateFilename')
598
+            ->with('invalid\\path.txt')
599
+            ->willThrowException(new InvalidPathException('Mocked exception'));
600
+
601
+        $this->plugin->checkMove('FolderA/test.txt', 'invalid\\path.txt');
602
+    }
603
+
604
+    public function testCopySrcNotExist(): void {
605
+        $this->expectException(\Sabre\DAV\Exception\NotFound::class);
606
+        $this->expectExceptionMessage('FolderA/test.txt does not exist');
607
+
608
+        $node = $this->createMock(Node::class);
609
+        $node->expects($this->atLeastOnce())
610
+            ->method('getFileInfo')
611
+            ->willReturn(null);
612
+
613
+        $this->tree->expects($this->atLeastOnce())
614
+            ->method('getNodeForPath')
615
+            ->willReturn($node);
616
+
617
+        $this->plugin->checkCopy('FolderA/test.txt', 'test.txt');
618
+    }
619
+
620
+    public function testCopyDestinationInvalid(): void {
621
+        $this->expectException(InvalidPath::class);
622
+        $this->expectExceptionMessage('Mocked exception');
623
+
624
+        $fileInfoFolderATestTXT = $this->createMock(FileInfo::class);
625
+        $node = $this->createMock(Node::class);
626
+        $node->expects($this->atLeastOnce())
627
+            ->method('getFileInfo')
628
+            ->willReturn($fileInfoFolderATestTXT);
629
+
630
+        $this->tree->expects($this->atLeastOnce())
631
+            ->method('getNodeForPath')
632
+            ->willReturn($node);
633
+
634
+        $this->filenameValidator->expects(self::once())
635
+            ->method('validateFilename')
636
+            ->with('invalid\\path.txt')
637
+            ->willThrowException(new InvalidPathException('Mocked exception'));
638
+
639
+        $this->plugin->checkCopy('FolderA/test.txt', 'invalid\\path.txt');
640
+    }
641
+
642
+    public static function downloadHeadersProvider(): array {
643
+        return [
644
+            [
645
+                false,
646
+                'attachment; filename*=UTF-8\'\'somefile.xml; filename="somefile.xml"'
647
+            ],
648
+            [
649
+                true,
650
+                'attachment; filename="somefile.xml"'
651
+            ],
652
+        ];
653
+    }
654
+
655
+    /**
656
+     * @dataProvider downloadHeadersProvider
657
+     */
658
+    public function testDownloadHeaders(bool $isClumsyAgent, string $contentDispositionHeader): void {
659
+        $request = $this->createMock(RequestInterface::class);
660
+        $response = $this->createMock(ResponseInterface::class);
661
+
662
+        $request
663
+            ->expects($this->once())
664
+            ->method('getPath')
665
+            ->willReturn('test/somefile.xml');
666
+
667
+        $node = $this->createMock(File::class);
668
+        $node
669
+            ->expects($this->once())
670
+            ->method('getName')
671
+            ->willReturn('somefile.xml');
672
+
673
+        $this->tree
674
+            ->expects($this->once())
675
+            ->method('getNodeForPath')
676
+            ->with('test/somefile.xml')
677
+            ->willReturn($node);
678
+
679
+        $this->request
680
+            ->expects($this->once())
681
+            ->method('isUserAgent')
682
+            ->willReturn($isClumsyAgent);
683
+
684
+        $calls = [
685
+            ['Content-Disposition', $contentDispositionHeader],
686
+            ['X-Accel-Buffering', 'no'],
687
+        ];
688
+        $response
689
+            ->expects($this->exactly(count($calls)))
690
+            ->method('addHeader')
691
+            ->willReturnCallback(function () use (&$calls) {
692
+                $expected = array_shift($calls);
693
+                $this->assertSame($expected, func_get_args());
694
+            });
695
+
696
+        $this->plugin->httpGet($request, $response);
697
+    }
698
+
699
+    public function testHasPreview(): void {
700
+        /** @var Directory&MockObject $node */
701
+        $node = $this->createTestNode(Directory::class);
702
+
703
+        $propFind = new PropFind(
704
+            '/dummyPath',
705
+            [
706
+                FilesPlugin::HAS_PREVIEW_PROPERTYNAME
707
+            ],
708
+            0
709
+        );
710
+
711
+        $this->previewManager->expects($this->once())
712
+            ->method('isAvailable')
713
+            ->willReturn(false);
714
+
715
+        $this->plugin->handleGetProperties(
716
+            $propFind,
717
+            $node
718
+        );
719
+
720
+        $this->assertEquals('false', $propFind->get(FilesPlugin::HAS_PREVIEW_PROPERTYNAME));
721
+    }
722 722
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -688,7 +688,7 @@
 block discarded – undo
688 688
 		$response
689 689
 			->expects($this->exactly(count($calls)))
690 690
 			->method('addHeader')
691
-			->willReturnCallback(function () use (&$calls) {
691
+			->willReturnCallback(function() use (&$calls) {
692 692
 				$expected = array_shift($calls);
693 693
 				$this->assertSame($expected, func_get_args());
694 694
 			});
Please login to merge, or discard this patch.
apps/dav/tests/unit/Connector/Sabre/PropfindCompressionPluginTest.php 1 patch
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -14,85 +14,85 @@
 block discarded – undo
14 14
 use Test\TestCase;
15 15
 
16 16
 class PropfindCompressionPluginTest extends TestCase {
17
-	private PropfindCompressionPlugin $plugin;
17
+    private PropfindCompressionPlugin $plugin;
18 18
 
19
-	protected function setUp(): void {
20
-		parent::setUp();
19
+    protected function setUp(): void {
20
+        parent::setUp();
21 21
 
22
-		$this->plugin = new PropfindCompressionPlugin();
23
-	}
22
+        $this->plugin = new PropfindCompressionPlugin();
23
+    }
24 24
 
25
-	public function testNoHeader(): void {
26
-		$request = $this->createMock(Request::class);
27
-		$response = $this->createMock(Response::class);
25
+    public function testNoHeader(): void {
26
+        $request = $this->createMock(Request::class);
27
+        $response = $this->createMock(Response::class);
28 28
 
29
-		$request->method('getHeader')
30
-			->with('Accept-Encoding')
31
-			->willReturn(null);
29
+        $request->method('getHeader')
30
+            ->with('Accept-Encoding')
31
+            ->willReturn(null);
32 32
 
33
-		$response->expects($this->never())
34
-			->method($this->anything());
33
+        $response->expects($this->never())
34
+            ->method($this->anything());
35 35
 
36
-		$result = $this->plugin->compressResponse($request, $response);
37
-		$this->assertSame($response, $result);
38
-	}
36
+        $result = $this->plugin->compressResponse($request, $response);
37
+        $this->assertSame($response, $result);
38
+    }
39 39
 
40
-	public function testHeaderButNoGzip(): void {
41
-		$request = $this->createMock(Request::class);
42
-		$response = $this->createMock(Response::class);
40
+    public function testHeaderButNoGzip(): void {
41
+        $request = $this->createMock(Request::class);
42
+        $response = $this->createMock(Response::class);
43 43
 
44
-		$request->method('getHeader')
45
-			->with('Accept-Encoding')
46
-			->willReturn('deflate');
44
+        $request->method('getHeader')
45
+            ->with('Accept-Encoding')
46
+            ->willReturn('deflate');
47 47
 
48
-		$response->expects($this->never())
49
-			->method($this->anything());
48
+        $response->expects($this->never())
49
+            ->method($this->anything());
50 50
 
51
-		$result = $this->plugin->compressResponse($request, $response);
52
-		$this->assertSame($response, $result);
53
-	}
51
+        $result = $this->plugin->compressResponse($request, $response);
52
+        $this->assertSame($response, $result);
53
+    }
54 54
 
55
-	public function testHeaderGzipButNoStringBody(): void {
56
-		$request = $this->createMock(Request::class);
57
-		$response = $this->createMock(Response::class);
55
+    public function testHeaderGzipButNoStringBody(): void {
56
+        $request = $this->createMock(Request::class);
57
+        $response = $this->createMock(Response::class);
58 58
 
59
-		$request->method('getHeader')
60
-			->with('Accept-Encoding')
61
-			->willReturn('deflate');
59
+        $request->method('getHeader')
60
+            ->with('Accept-Encoding')
61
+            ->willReturn('deflate');
62 62
 
63
-		$response->method('getBody')
64
-			->willReturn(5);
63
+        $response->method('getBody')
64
+            ->willReturn(5);
65 65
 
66
-		$result = $this->plugin->compressResponse($request, $response);
67
-		$this->assertSame($response, $result);
68
-	}
66
+        $result = $this->plugin->compressResponse($request, $response);
67
+        $this->assertSame($response, $result);
68
+    }
69 69
 
70 70
 
71
-	public function testProperGzip(): void {
72
-		$request = $this->createMock(Request::class);
73
-		$response = $this->createMock(Response::class);
71
+    public function testProperGzip(): void {
72
+        $request = $this->createMock(Request::class);
73
+        $response = $this->createMock(Response::class);
74 74
 
75
-		$request->method('getHeader')
76
-			->with('Accept-Encoding')
77
-			->willReturn('gzip, deflate');
75
+        $request->method('getHeader')
76
+            ->with('Accept-Encoding')
77
+            ->willReturn('gzip, deflate');
78 78
 
79
-		$response->method('getBody')
80
-			->willReturn('my gzip test');
79
+        $response->method('getBody')
80
+            ->willReturn('my gzip test');
81 81
 
82
-		$response->expects($this->once())
83
-			->method('setHeader')
84
-			->with(
85
-				$this->equalTo('Content-Encoding'),
86
-				$this->equalTo('gzip')
87
-			);
88
-		$response->expects($this->once())
89
-			->method('setBody')
90
-			->with($this->callback(function ($data) {
91
-				$orig = gzdecode($data);
92
-				return $orig === 'my gzip test';
93
-			}));
82
+        $response->expects($this->once())
83
+            ->method('setHeader')
84
+            ->with(
85
+                $this->equalTo('Content-Encoding'),
86
+                $this->equalTo('gzip')
87
+            );
88
+        $response->expects($this->once())
89
+            ->method('setBody')
90
+            ->with($this->callback(function ($data) {
91
+                $orig = gzdecode($data);
92
+                return $orig === 'my gzip test';
93
+            }));
94 94
 
95
-		$result = $this->plugin->compressResponse($request, $response);
96
-		$this->assertSame($response, $result);
97
-	}
95
+        $result = $this->plugin->compressResponse($request, $response);
96
+        $this->assertSame($response, $result);
97
+    }
98 98
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/Connector/LegacyPublicAuthTest.php 2 patches
Indentation   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -25,206 +25,206 @@
 block discarded – undo
25 25
  * @package OCA\DAV\Tests\unit\Connector
26 26
  */
27 27
 class LegacyPublicAuthTest extends \Test\TestCase {
28
-	private ISession&MockObject $session;
29
-	private IRequest&MockObject $request;
30
-	private IManager&MockObject $shareManager;
31
-	private IThrottler&MockObject $throttler;
32
-	private LegacyPublicAuth $auth;
33
-	private string|false $oldUser;
28
+    private ISession&MockObject $session;
29
+    private IRequest&MockObject $request;
30
+    private IManager&MockObject $shareManager;
31
+    private IThrottler&MockObject $throttler;
32
+    private LegacyPublicAuth $auth;
33
+    private string|false $oldUser;
34 34
 
35
-	protected function setUp(): void {
36
-		parent::setUp();
35
+    protected function setUp(): void {
36
+        parent::setUp();
37 37
 
38
-		$this->session = $this->createMock(ISession::class);
39
-		$this->request = $this->createMock(IRequest::class);
40
-		$this->shareManager = $this->createMock(IManager::class);
41
-		$this->throttler = $this->createMock(IThrottler::class);
38
+        $this->session = $this->createMock(ISession::class);
39
+        $this->request = $this->createMock(IRequest::class);
40
+        $this->shareManager = $this->createMock(IManager::class);
41
+        $this->throttler = $this->createMock(IThrottler::class);
42 42
 
43
-		$this->auth = new LegacyPublicAuth(
44
-			$this->request,
45
-			$this->shareManager,
46
-			$this->session,
47
-			$this->throttler
48
-		);
43
+        $this->auth = new LegacyPublicAuth(
44
+            $this->request,
45
+            $this->shareManager,
46
+            $this->session,
47
+            $this->throttler
48
+        );
49 49
 
50
-		// Store current user
51
-		$this->oldUser = \OC_User::getUser();
52
-	}
50
+        // Store current user
51
+        $this->oldUser = \OC_User::getUser();
52
+    }
53 53
 
54
-	protected function tearDown(): void {
55
-		\OC_User::setIncognitoMode(false);
54
+    protected function tearDown(): void {
55
+        \OC_User::setIncognitoMode(false);
56 56
 
57
-		// Set old user
58
-		\OC_User::setUserId($this->oldUser);
59
-		if ($this->oldUser !== false) {
60
-			\OC_Util::setupFS($this->oldUser);
61
-		}
57
+        // Set old user
58
+        \OC_User::setUserId($this->oldUser);
59
+        if ($this->oldUser !== false) {
60
+            \OC_Util::setupFS($this->oldUser);
61
+        }
62 62
 
63
-		parent::tearDown();
64
-	}
63
+        parent::tearDown();
64
+    }
65 65
 
66
-	public function testNoShare(): void {
67
-		$this->shareManager->expects($this->once())
68
-			->method('getShareByToken')
69
-			->willThrowException(new ShareNotFound());
66
+    public function testNoShare(): void {
67
+        $this->shareManager->expects($this->once())
68
+            ->method('getShareByToken')
69
+            ->willThrowException(new ShareNotFound());
70 70
 
71
-		$result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
71
+        $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
72 72
 
73
-		$this->assertFalse($result);
74
-	}
73
+        $this->assertFalse($result);
74
+    }
75 75
 
76
-	public function testShareNoPassword(): void {
77
-		$share = $this->createMock(IShare::class);
78
-		$share->method('getPassword')->willReturn(null);
76
+    public function testShareNoPassword(): void {
77
+        $share = $this->createMock(IShare::class);
78
+        $share->method('getPassword')->willReturn(null);
79 79
 
80
-		$this->shareManager->expects($this->once())
81
-			->method('getShareByToken')
82
-			->willReturn($share);
80
+        $this->shareManager->expects($this->once())
81
+            ->method('getShareByToken')
82
+            ->willReturn($share);
83 83
 
84
-		$result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
84
+        $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
85 85
 
86
-		$this->assertTrue($result);
87
-	}
86
+        $this->assertTrue($result);
87
+    }
88 88
 
89
-	public function testSharePasswordFancyShareType(): void {
90
-		$share = $this->createMock(IShare::class);
91
-		$share->method('getPassword')->willReturn('password');
92
-		$share->method('getShareType')->willReturn(42);
89
+    public function testSharePasswordFancyShareType(): void {
90
+        $share = $this->createMock(IShare::class);
91
+        $share->method('getPassword')->willReturn('password');
92
+        $share->method('getShareType')->willReturn(42);
93 93
 
94
-		$this->shareManager->expects($this->once())
95
-			->method('getShareByToken')
96
-			->willReturn($share);
94
+        $this->shareManager->expects($this->once())
95
+            ->method('getShareByToken')
96
+            ->willReturn($share);
97 97
 
98
-		$result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
98
+        $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
99 99
 
100
-		$this->assertFalse($result);
101
-	}
100
+        $this->assertFalse($result);
101
+    }
102 102
 
103 103
 
104
-	public function testSharePasswordRemote(): void {
105
-		$share = $this->createMock(IShare::class);
106
-		$share->method('getPassword')->willReturn('password');
107
-		$share->method('getShareType')->willReturn(IShare::TYPE_REMOTE);
104
+    public function testSharePasswordRemote(): void {
105
+        $share = $this->createMock(IShare::class);
106
+        $share->method('getPassword')->willReturn('password');
107
+        $share->method('getShareType')->willReturn(IShare::TYPE_REMOTE);
108 108
 
109
-		$this->shareManager->expects($this->once())
110
-			->method('getShareByToken')
111
-			->willReturn($share);
109
+        $this->shareManager->expects($this->once())
110
+            ->method('getShareByToken')
111
+            ->willReturn($share);
112 112
 
113
-		$result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
113
+        $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
114 114
 
115
-		$this->assertTrue($result);
116
-	}
115
+        $this->assertTrue($result);
116
+    }
117 117
 
118
-	public function testSharePasswordLinkValidPassword(): void {
119
-		$share = $this->createMock(IShare::class);
120
-		$share->method('getPassword')->willReturn('password');
121
-		$share->method('getShareType')->willReturn(IShare::TYPE_LINK);
118
+    public function testSharePasswordLinkValidPassword(): void {
119
+        $share = $this->createMock(IShare::class);
120
+        $share->method('getPassword')->willReturn('password');
121
+        $share->method('getShareType')->willReturn(IShare::TYPE_LINK);
122 122
 
123
-		$this->shareManager->expects($this->once())
124
-			->method('getShareByToken')
125
-			->willReturn($share);
123
+        $this->shareManager->expects($this->once())
124
+            ->method('getShareByToken')
125
+            ->willReturn($share);
126 126
 
127
-		$this->shareManager->expects($this->once())
128
-			->method('checkPassword')->with(
129
-				$this->equalTo($share),
130
-				$this->equalTo('password')
131
-			)->willReturn(true);
127
+        $this->shareManager->expects($this->once())
128
+            ->method('checkPassword')->with(
129
+                $this->equalTo($share),
130
+                $this->equalTo('password')
131
+            )->willReturn(true);
132 132
 
133
-		$result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
133
+        $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
134 134
 
135
-		$this->assertTrue($result);
136
-	}
135
+        $this->assertTrue($result);
136
+    }
137 137
 
138
-	public function testSharePasswordMailValidPassword(): void {
139
-		$share = $this->createMock(IShare::class);
140
-		$share->method('getPassword')->willReturn('password');
141
-		$share->method('getShareType')->willReturn(IShare::TYPE_EMAIL);
138
+    public function testSharePasswordMailValidPassword(): void {
139
+        $share = $this->createMock(IShare::class);
140
+        $share->method('getPassword')->willReturn('password');
141
+        $share->method('getShareType')->willReturn(IShare::TYPE_EMAIL);
142 142
 
143
-		$this->shareManager->expects($this->once())
144
-			->method('getShareByToken')
145
-			->willReturn($share);
143
+        $this->shareManager->expects($this->once())
144
+            ->method('getShareByToken')
145
+            ->willReturn($share);
146 146
 
147
-		$this->shareManager->expects($this->once())
148
-			->method('checkPassword')->with(
149
-				$this->equalTo($share),
150
-				$this->equalTo('password')
151
-			)->willReturn(true);
147
+        $this->shareManager->expects($this->once())
148
+            ->method('checkPassword')->with(
149
+                $this->equalTo($share),
150
+                $this->equalTo('password')
151
+            )->willReturn(true);
152 152
 
153
-		$result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
153
+        $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
154 154
 
155
-		$this->assertTrue($result);
156
-	}
155
+        $this->assertTrue($result);
156
+    }
157 157
 
158
-	public function testInvalidSharePasswordLinkValidSession(): void {
159
-		$share = $this->createMock(IShare::class);
160
-		$share->method('getPassword')->willReturn('password');
161
-		$share->method('getShareType')->willReturn(IShare::TYPE_LINK);
162
-		$share->method('getId')->willReturn('42');
158
+    public function testInvalidSharePasswordLinkValidSession(): void {
159
+        $share = $this->createMock(IShare::class);
160
+        $share->method('getPassword')->willReturn('password');
161
+        $share->method('getShareType')->willReturn(IShare::TYPE_LINK);
162
+        $share->method('getId')->willReturn('42');
163 163
 
164
-		$this->shareManager->expects($this->once())
165
-			->method('getShareByToken')
166
-			->willReturn($share);
164
+        $this->shareManager->expects($this->once())
165
+            ->method('getShareByToken')
166
+            ->willReturn($share);
167 167
 
168
-		$this->shareManager->method('checkPassword')
169
-			->with(
170
-				$this->equalTo($share),
171
-				$this->equalTo('password')
172
-			)->willReturn(false);
168
+        $this->shareManager->method('checkPassword')
169
+            ->with(
170
+                $this->equalTo($share),
171
+                $this->equalTo('password')
172
+            )->willReturn(false);
173 173
 
174
-		$this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
175
-		$this->session->method('get')->with('public_link_authenticated')->willReturn('42');
174
+        $this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
175
+        $this->session->method('get')->with('public_link_authenticated')->willReturn('42');
176 176
 
177
-		$result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
177
+        $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
178 178
 
179
-		$this->assertTrue($result);
180
-	}
179
+        $this->assertTrue($result);
180
+    }
181 181
 
182
-	public function testSharePasswordLinkInvalidSession(): void {
183
-		$share = $this->createMock(IShare::class);
184
-		$share->method('getPassword')->willReturn('password');
185
-		$share->method('getShareType')->willReturn(IShare::TYPE_LINK);
186
-		$share->method('getId')->willReturn('42');
182
+    public function testSharePasswordLinkInvalidSession(): void {
183
+        $share = $this->createMock(IShare::class);
184
+        $share->method('getPassword')->willReturn('password');
185
+        $share->method('getShareType')->willReturn(IShare::TYPE_LINK);
186
+        $share->method('getId')->willReturn('42');
187 187
 
188
-		$this->shareManager->expects($this->once())
189
-			->method('getShareByToken')
190
-			->willReturn($share);
188
+        $this->shareManager->expects($this->once())
189
+            ->method('getShareByToken')
190
+            ->willReturn($share);
191 191
 
192
-		$this->shareManager->method('checkPassword')
193
-			->with(
194
-				$this->equalTo($share),
195
-				$this->equalTo('password')
196
-			)->willReturn(false);
192
+        $this->shareManager->method('checkPassword')
193
+            ->with(
194
+                $this->equalTo($share),
195
+                $this->equalTo('password')
196
+            )->willReturn(false);
197 197
 
198
-		$this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
199
-		$this->session->method('get')->with('public_link_authenticated')->willReturn('43');
198
+        $this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
199
+        $this->session->method('get')->with('public_link_authenticated')->willReturn('43');
200 200
 
201
-		$result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
201
+        $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
202 202
 
203
-		$this->assertFalse($result);
204
-	}
203
+        $this->assertFalse($result);
204
+    }
205 205
 
206 206
 
207
-	public function testSharePasswordMailInvalidSession(): void {
208
-		$share = $this->createMock(IShare::class);
209
-		$share->method('getPassword')->willReturn('password');
210
-		$share->method('getShareType')->willReturn(IShare::TYPE_EMAIL);
211
-		$share->method('getId')->willReturn('42');
207
+    public function testSharePasswordMailInvalidSession(): void {
208
+        $share = $this->createMock(IShare::class);
209
+        $share->method('getPassword')->willReturn('password');
210
+        $share->method('getShareType')->willReturn(IShare::TYPE_EMAIL);
211
+        $share->method('getId')->willReturn('42');
212 212
 
213
-		$this->shareManager->expects($this->once())
214
-			->method('getShareByToken')
215
-			->willReturn($share);
213
+        $this->shareManager->expects($this->once())
214
+            ->method('getShareByToken')
215
+            ->willReturn($share);
216 216
 
217
-		$this->shareManager->method('checkPassword')
218
-			->with(
219
-				$this->equalTo($share),
220
-				$this->equalTo('password')
221
-			)->willReturn(false);
217
+        $this->shareManager->method('checkPassword')
218
+            ->with(
219
+                $this->equalTo($share),
220
+                $this->equalTo('password')
221
+            )->willReturn(false);
222 222
 
223
-		$this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
224
-		$this->session->method('get')->with('public_link_authenticated')->willReturn('43');
223
+        $this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
224
+        $this->session->method('get')->with('public_link_authenticated')->willReturn('43');
225 225
 
226
-		$result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
226
+        $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
227 227
 
228
-		$this->assertFalse($result);
229
-	}
228
+        $this->assertFalse($result);
229
+    }
230 230
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
30 30
 	private IManager&MockObject $shareManager;
31 31
 	private IThrottler&MockObject $throttler;
32 32
 	private LegacyPublicAuth $auth;
33
-	private string|false $oldUser;
33
+	private string | false $oldUser;
34 34
 
35 35
 	protected function setUp(): void {
36 36
 		parent::setUp();
Please login to merge, or discard this patch.
apps/dav/tests/unit/Direct/DirectHomeTest.php 1 patch
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -25,136 +25,136 @@
 block discarded – undo
25 25
 use Test\TestCase;
26 26
 
27 27
 class DirectHomeTest extends TestCase {
28
-	private DirectMapper&MockObject $directMapper;
29
-	private IRootFolder&MockObject $rootFolder;
30
-	private ITimeFactory&MockObject $timeFactory;
31
-	private IThrottler&MockObject $throttler;
32
-	private IRequest&MockObject $request;
33
-	private IEventDispatcher&MockObject $eventDispatcher;
34
-	private DirectHome $directHome;
28
+    private DirectMapper&MockObject $directMapper;
29
+    private IRootFolder&MockObject $rootFolder;
30
+    private ITimeFactory&MockObject $timeFactory;
31
+    private IThrottler&MockObject $throttler;
32
+    private IRequest&MockObject $request;
33
+    private IEventDispatcher&MockObject $eventDispatcher;
34
+    private DirectHome $directHome;
35 35
 
36
-	protected function setUp(): void {
37
-		parent::setUp();
36
+    protected function setUp(): void {
37
+        parent::setUp();
38 38
 
39
-		$this->directMapper = $this->createMock(DirectMapper::class);
40
-		$this->rootFolder = $this->createMock(IRootFolder::class);
41
-		$this->timeFactory = $this->createMock(ITimeFactory::class);
42
-		$this->throttler = $this->createMock(IThrottler::class);
43
-		$this->request = $this->createMock(IRequest::class);
44
-		$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
39
+        $this->directMapper = $this->createMock(DirectMapper::class);
40
+        $this->rootFolder = $this->createMock(IRootFolder::class);
41
+        $this->timeFactory = $this->createMock(ITimeFactory::class);
42
+        $this->throttler = $this->createMock(IThrottler::class);
43
+        $this->request = $this->createMock(IRequest::class);
44
+        $this->eventDispatcher = $this->createMock(IEventDispatcher::class);
45 45
 
46
-		$this->timeFactory->method('getTime')
47
-			->willReturn(42);
46
+        $this->timeFactory->method('getTime')
47
+            ->willReturn(42);
48 48
 
49
-		$this->request->method('getRemoteAddress')
50
-			->willReturn('1.2.3.4');
51
-
52
-
53
-		$this->directHome = new DirectHome(
54
-			$this->rootFolder,
55
-			$this->directMapper,
56
-			$this->timeFactory,
57
-			$this->throttler,
58
-			$this->request,
59
-			$this->eventDispatcher
60
-		);
61
-	}
62
-
63
-	public function testCreateFile(): void {
64
-		$this->expectException(Forbidden::class);
65
-
66
-		$this->directHome->createFile('foo', 'bar');
67
-	}
68
-
69
-	public function testCreateDirectory(): void {
70
-		$this->expectException(Forbidden::class);
71
-
72
-		$this->directHome->createDirectory('foo');
73
-	}
74
-
75
-	public function testGetChildren(): void {
76
-		$this->expectException(MethodNotAllowed::class);
77
-
78
-		$this->directHome->getChildren();
79
-	}
80
-
81
-	public function testChildExists(): void {
82
-		$this->assertFalse($this->directHome->childExists('foo'));
83
-	}
84
-
85
-	public function testDelete(): void {
86
-		$this->expectException(Forbidden::class);
87
-
88
-		$this->directHome->delete();
89
-	}
90
-
91
-	public function testGetName(): void {
92
-		$this->assertSame('direct', $this->directHome->getName());
93
-	}
94
-
95
-	public function testSetName(): void {
96
-		$this->expectException(Forbidden::class);
97
-
98
-		$this->directHome->setName('foo');
99
-	}
100
-
101
-	public function testGetLastModified(): void {
102
-		$this->assertSame(0, $this->directHome->getLastModified());
103
-	}
104
-
105
-	public function testGetChildValid(): void {
106
-		$direct = Direct::fromParams([
107
-			'expiration' => 100,
108
-		]);
109
-
110
-		$this->directMapper->method('getByToken')
111
-			->with('longtoken')
112
-			->willReturn($direct);
113
-
114
-		$this->throttler->expects($this->never())
115
-			->method($this->anything());
116
-
117
-		$result = $this->directHome->getChild('longtoken');
118
-		$this->assertInstanceOf(DirectFile::class, $result);
119
-	}
120
-
121
-	public function testGetChildExpired(): void {
122
-		$direct = Direct::fromParams([
123
-			'expiration' => 41,
124
-		]);
125
-
126
-		$this->directMapper->method('getByToken')
127
-			->with('longtoken')
128
-			->willReturn($direct);
49
+        $this->request->method('getRemoteAddress')
50
+            ->willReturn('1.2.3.4');
51
+
52
+
53
+        $this->directHome = new DirectHome(
54
+            $this->rootFolder,
55
+            $this->directMapper,
56
+            $this->timeFactory,
57
+            $this->throttler,
58
+            $this->request,
59
+            $this->eventDispatcher
60
+        );
61
+    }
62
+
63
+    public function testCreateFile(): void {
64
+        $this->expectException(Forbidden::class);
65
+
66
+        $this->directHome->createFile('foo', 'bar');
67
+    }
68
+
69
+    public function testCreateDirectory(): void {
70
+        $this->expectException(Forbidden::class);
71
+
72
+        $this->directHome->createDirectory('foo');
73
+    }
74
+
75
+    public function testGetChildren(): void {
76
+        $this->expectException(MethodNotAllowed::class);
77
+
78
+        $this->directHome->getChildren();
79
+    }
80
+
81
+    public function testChildExists(): void {
82
+        $this->assertFalse($this->directHome->childExists('foo'));
83
+    }
84
+
85
+    public function testDelete(): void {
86
+        $this->expectException(Forbidden::class);
87
+
88
+        $this->directHome->delete();
89
+    }
90
+
91
+    public function testGetName(): void {
92
+        $this->assertSame('direct', $this->directHome->getName());
93
+    }
94
+
95
+    public function testSetName(): void {
96
+        $this->expectException(Forbidden::class);
97
+
98
+        $this->directHome->setName('foo');
99
+    }
100
+
101
+    public function testGetLastModified(): void {
102
+        $this->assertSame(0, $this->directHome->getLastModified());
103
+    }
104
+
105
+    public function testGetChildValid(): void {
106
+        $direct = Direct::fromParams([
107
+            'expiration' => 100,
108
+        ]);
109
+
110
+        $this->directMapper->method('getByToken')
111
+            ->with('longtoken')
112
+            ->willReturn($direct);
113
+
114
+        $this->throttler->expects($this->never())
115
+            ->method($this->anything());
116
+
117
+        $result = $this->directHome->getChild('longtoken');
118
+        $this->assertInstanceOf(DirectFile::class, $result);
119
+    }
120
+
121
+    public function testGetChildExpired(): void {
122
+        $direct = Direct::fromParams([
123
+            'expiration' => 41,
124
+        ]);
125
+
126
+        $this->directMapper->method('getByToken')
127
+            ->with('longtoken')
128
+            ->willReturn($direct);
129 129
 
130
-		$this->throttler->expects($this->never())
131
-			->method($this->anything());
130
+        $this->throttler->expects($this->never())
131
+            ->method($this->anything());
132 132
 
133
-		$this->expectException(NotFound::class);
133
+        $this->expectException(NotFound::class);
134 134
 
135
-		$this->directHome->getChild('longtoken');
136
-	}
135
+        $this->directHome->getChild('longtoken');
136
+    }
137 137
 
138
-	public function testGetChildInvalid(): void {
139
-		$this->directMapper->method('getByToken')
140
-			->with('longtoken')
141
-			->willThrowException(new DoesNotExistException('not found'));
138
+    public function testGetChildInvalid(): void {
139
+        $this->directMapper->method('getByToken')
140
+            ->with('longtoken')
141
+            ->willThrowException(new DoesNotExistException('not found'));
142 142
 
143
-		$this->throttler->expects($this->once())
144
-			->method('registerAttempt')
145
-			->with(
146
-				'directlink',
147
-				'1.2.3.4'
148
-			);
149
-		$this->throttler->expects($this->once())
150
-			->method('sleepDelayOrThrowOnMax')
151
-			->with(
152
-				'1.2.3.4',
153
-				'directlink'
154
-			);
143
+        $this->throttler->expects($this->once())
144
+            ->method('registerAttempt')
145
+            ->with(
146
+                'directlink',
147
+                '1.2.3.4'
148
+            );
149
+        $this->throttler->expects($this->once())
150
+            ->method('sleepDelayOrThrowOnMax')
151
+            ->with(
152
+                '1.2.3.4',
153
+                'directlink'
154
+            );
155 155
 
156
-		$this->expectException(NotFound::class);
156
+        $this->expectException(NotFound::class);
157 157
 
158
-		$this->directHome->getChild('longtoken');
159
-	}
158
+        $this->directHome->getChild('longtoken');
159
+    }
160 160
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/Direct/DirectFileTest.php 1 patch
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -19,93 +19,93 @@
 block discarded – undo
19 19
 use Test\TestCase;
20 20
 
21 21
 class DirectFileTest extends TestCase {
22
-	private Direct $direct;
23
-	private IRootFolder&MockObject $rootFolder;
24
-	private Folder&MockObject $userFolder;
25
-	private File&MockObject $file;
26
-	private IEventDispatcher&MockObject $eventDispatcher;
27
-	private DirectFile $directFile;
22
+    private Direct $direct;
23
+    private IRootFolder&MockObject $rootFolder;
24
+    private Folder&MockObject $userFolder;
25
+    private File&MockObject $file;
26
+    private IEventDispatcher&MockObject $eventDispatcher;
27
+    private DirectFile $directFile;
28 28
 
29
-	protected function setUp(): void {
30
-		parent::setUp();
29
+    protected function setUp(): void {
30
+        parent::setUp();
31 31
 
32
-		$this->direct = Direct::fromParams([
33
-			'userId' => 'directUser',
34
-			'token' => 'directToken',
35
-			'fileId' => 42,
36
-		]);
32
+        $this->direct = Direct::fromParams([
33
+            'userId' => 'directUser',
34
+            'token' => 'directToken',
35
+            'fileId' => 42,
36
+        ]);
37 37
 
38
-		$this->rootFolder = $this->createMock(IRootFolder::class);
38
+        $this->rootFolder = $this->createMock(IRootFolder::class);
39 39
 
40
-		$this->userFolder = $this->createMock(Folder::class);
41
-		$this->rootFolder->method('getUserFolder')
42
-			->with('directUser')
43
-			->willReturn($this->userFolder);
40
+        $this->userFolder = $this->createMock(Folder::class);
41
+        $this->rootFolder->method('getUserFolder')
42
+            ->with('directUser')
43
+            ->willReturn($this->userFolder);
44 44
 
45
-		$this->file = $this->createMock(File::class);
46
-		$this->userFolder->method('getFirstNodeById')
47
-			->with(42)
48
-			->willReturn($this->file);
45
+        $this->file = $this->createMock(File::class);
46
+        $this->userFolder->method('getFirstNodeById')
47
+            ->with(42)
48
+            ->willReturn($this->file);
49 49
 
50
-		$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
50
+        $this->eventDispatcher = $this->createMock(IEventDispatcher::class);
51 51
 
52
-		$this->directFile = new DirectFile($this->direct, $this->rootFolder, $this->eventDispatcher);
53
-	}
52
+        $this->directFile = new DirectFile($this->direct, $this->rootFolder, $this->eventDispatcher);
53
+    }
54 54
 
55
-	public function testPut(): void {
56
-		$this->expectException(Forbidden::class);
55
+    public function testPut(): void {
56
+        $this->expectException(Forbidden::class);
57 57
 
58
-		$this->directFile->put('foo');
59
-	}
58
+        $this->directFile->put('foo');
59
+    }
60 60
 
61
-	public function testGet(): void {
62
-		$this->file->expects($this->once())
63
-			->method('fopen')
64
-			->with('rb');
65
-		$this->directFile->get();
66
-	}
61
+    public function testGet(): void {
62
+        $this->file->expects($this->once())
63
+            ->method('fopen')
64
+            ->with('rb');
65
+        $this->directFile->get();
66
+    }
67 67
 
68
-	public function testGetContentType(): void {
69
-		$this->file->method('getMimeType')
70
-			->willReturn('direct/type');
68
+    public function testGetContentType(): void {
69
+        $this->file->method('getMimeType')
70
+            ->willReturn('direct/type');
71 71
 
72
-		$this->assertSame('direct/type', $this->directFile->getContentType());
73
-	}
72
+        $this->assertSame('direct/type', $this->directFile->getContentType());
73
+    }
74 74
 
75
-	public function testGetETag(): void {
76
-		$this->file->method('getEtag')
77
-			->willReturn('directEtag');
75
+    public function testGetETag(): void {
76
+        $this->file->method('getEtag')
77
+            ->willReturn('directEtag');
78 78
 
79
-		$this->assertSame('directEtag', $this->directFile->getETag());
80
-	}
79
+        $this->assertSame('directEtag', $this->directFile->getETag());
80
+    }
81 81
 
82
-	public function testGetSize(): void {
83
-		$this->file->method('getSize')
84
-			->willReturn(42);
82
+    public function testGetSize(): void {
83
+        $this->file->method('getSize')
84
+            ->willReturn(42);
85 85
 
86
-		$this->assertSame(42, $this->directFile->getSize());
87
-	}
86
+        $this->assertSame(42, $this->directFile->getSize());
87
+    }
88 88
 
89
-	public function testDelete(): void {
90
-		$this->expectException(Forbidden::class);
89
+    public function testDelete(): void {
90
+        $this->expectException(Forbidden::class);
91 91
 
92
-		$this->directFile->delete();
93
-	}
92
+        $this->directFile->delete();
93
+    }
94 94
 
95
-	public function testGetName(): void {
96
-		$this->assertSame('directToken', $this->directFile->getName());
97
-	}
95
+    public function testGetName(): void {
96
+        $this->assertSame('directToken', $this->directFile->getName());
97
+    }
98 98
 
99
-	public function testSetName(): void {
100
-		$this->expectException(Forbidden::class);
99
+    public function testSetName(): void {
100
+        $this->expectException(Forbidden::class);
101 101
 
102
-		$this->directFile->setName('foobar');
103
-	}
102
+        $this->directFile->setName('foobar');
103
+    }
104 104
 
105
-	public function testGetLastModified(): void {
106
-		$this->file->method('getMTime')
107
-			->willReturn(42);
105
+    public function testGetLastModified(): void {
106
+        $this->file->method('getMTime')
107
+            ->willReturn(42);
108 108
 
109
-		$this->assertSame(42, $this->directFile->getLastModified());
110
-	}
109
+        $this->assertSame(42, $this->directFile->getLastModified());
110
+    }
111 111
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/Provisioning/Apple/AppleProvisioningNodeTest.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -14,57 +14,57 @@
 block discarded – undo
14 14
 use Test\TestCase;
15 15
 
16 16
 class AppleProvisioningNodeTest extends TestCase {
17
-	private ITimeFactory&MockObject $timeFactory;
18
-	private AppleProvisioningNode $node;
17
+    private ITimeFactory&MockObject $timeFactory;
18
+    private AppleProvisioningNode $node;
19 19
 
20
-	protected function setUp(): void {
21
-		parent::setUp();
20
+    protected function setUp(): void {
21
+        parent::setUp();
22 22
 
23
-		$this->timeFactory = $this->createMock(ITimeFactory::class);
24
-		$this->node = new AppleProvisioningNode($this->timeFactory);
25
-	}
23
+        $this->timeFactory = $this->createMock(ITimeFactory::class);
24
+        $this->node = new AppleProvisioningNode($this->timeFactory);
25
+    }
26 26
 
27
-	public function testGetName(): void {
28
-		$this->assertEquals('apple-provisioning.mobileconfig', $this->node->getName());
29
-	}
27
+    public function testGetName(): void {
28
+        $this->assertEquals('apple-provisioning.mobileconfig', $this->node->getName());
29
+    }
30 30
 
31
-	public function testSetName(): void {
32
-		$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
33
-		$this->expectExceptionMessage('Renaming apple-provisioning.mobileconfig is forbidden');
31
+    public function testSetName(): void {
32
+        $this->expectException(\Sabre\DAV\Exception\Forbidden::class);
33
+        $this->expectExceptionMessage('Renaming apple-provisioning.mobileconfig is forbidden');
34 34
 
35
-		$this->node->setName('foo');
36
-	}
35
+        $this->node->setName('foo');
36
+    }
37 37
 
38
-	public function testGetLastModified(): void {
39
-		$this->assertEquals(null, $this->node->getLastModified());
40
-	}
38
+    public function testGetLastModified(): void {
39
+        $this->assertEquals(null, $this->node->getLastModified());
40
+    }
41 41
 
42 42
 
43
-	public function testDelete(): void {
44
-		$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
45
-		$this->expectExceptionMessage('apple-provisioning.mobileconfig may not be deleted');
43
+    public function testDelete(): void {
44
+        $this->expectException(\Sabre\DAV\Exception\Forbidden::class);
45
+        $this->expectExceptionMessage('apple-provisioning.mobileconfig may not be deleted');
46 46
 
47
-		$this->node->delete();
48
-	}
47
+        $this->node->delete();
48
+    }
49 49
 
50
-	public function testGetProperties(): void {
51
-		$this->timeFactory->expects($this->once())
52
-			->method('getDateTime')
53
-			->willReturn(new \DateTime('2000-01-01'));
50
+    public function testGetProperties(): void {
51
+        $this->timeFactory->expects($this->once())
52
+            ->method('getDateTime')
53
+            ->willReturn(new \DateTime('2000-01-01'));
54 54
 
55
-		$this->assertEquals([
56
-			'{DAV:}getcontentlength' => 42,
57
-			'{DAV:}getlastmodified' => 'Sat, 01 Jan 2000 00:00:00 +0000',
58
-		], $this->node->getProperties([]));
59
-	}
55
+        $this->assertEquals([
56
+            '{DAV:}getcontentlength' => 42,
57
+            '{DAV:}getlastmodified' => 'Sat, 01 Jan 2000 00:00:00 +0000',
58
+        ], $this->node->getProperties([]));
59
+    }
60 60
 
61 61
 
62
-	public function testGetPropPatch(): void {
63
-		$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
64
-		$this->expectExceptionMessage('apple-provisioning.mobileconfig\'s properties may not be altered.');
62
+    public function testGetPropPatch(): void {
63
+        $this->expectException(\Sabre\DAV\Exception\Forbidden::class);
64
+        $this->expectExceptionMessage('apple-provisioning.mobileconfig\'s properties may not be altered.');
65 65
 
66
-		$propPatch = $this->createMock(PropPatch::class);
66
+        $propPatch = $this->createMock(PropPatch::class);
67 67
 
68
-		$this->node->propPatch($propPatch);
69
-	}
68
+        $this->node->propPatch($propPatch);
69
+    }
70 70
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/Provisioning/Apple/AppleProvisioningPluginTest.php 2 patches
Indentation   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -21,145 +21,145 @@  discard block
 block discarded – undo
21 21
 use Test\TestCase;
22 22
 
23 23
 class AppleProvisioningPluginTest extends TestCase {
24
-	protected Server&MockObject $server;
25
-	protected IUserSession&MockObject $userSession;
26
-	protected IURLGenerator&MockObject $urlGenerator;
27
-	protected ThemingDefaults&MockObject $themingDefaults;
28
-	protected IRequest&MockObject $request;
29
-	protected IL10N&MockObject $l10n;
30
-	protected RequestInterface&MockObject $sabreRequest;
31
-	protected ResponseInterface&MockObject $sabreResponse;
32
-	protected AppleProvisioningPlugin $plugin;
33
-
34
-	protected function setUp(): void {
35
-		parent::setUp();
36
-
37
-		$this->server = $this->createMock(Server::class);
38
-		$this->userSession = $this->createMock(IUserSession::class);
39
-		$this->urlGenerator = $this->createMock(IURLGenerator::class);
40
-		$this->themingDefaults = $this->createMock(ThemingDefaults::class);
41
-		$this->request = $this->createMock(IRequest::class);
42
-		$this->l10n = $this->createMock(IL10N::class);
43
-
44
-		$this->plugin = new AppleProvisioningPlugin($this->userSession,
45
-			$this->urlGenerator,
46
-			$this->themingDefaults,
47
-			$this->request,
48
-			$this->l10n,
49
-			function () {
50
-				return 'generated-uuid';
51
-			}
52
-		);
53
-
54
-		$this->sabreRequest = $this->createMock(RequestInterface::class);
55
-		$this->sabreResponse = $this->createMock(ResponseInterface::class);
56
-	}
57
-
58
-	public function testInitialize(): void {
59
-		$server = $this->createMock(Server::class);
60
-
61
-		$plugin = new AppleProvisioningPlugin($this->userSession,
62
-			$this->urlGenerator, $this->themingDefaults, $this->request, $this->l10n,
63
-			function (): void {
64
-			});
65
-
66
-		$server->expects($this->once())
67
-			->method('on')
68
-			->with('method:GET', [$plugin, 'httpGet'], 90);
69
-
70
-		$plugin->initialize($server);
71
-	}
72
-
73
-	public function testHttpGetOnHttp(): void {
74
-		$this->sabreRequest->expects($this->once())
75
-			->method('getPath')
76
-			->with()
77
-			->willReturn('provisioning/apple-provisioning.mobileconfig');
78
-
79
-		$user = $this->createMock(IUser::class);
80
-		$this->userSession->expects($this->once())
81
-			->method('getUser')
82
-			->willReturn($user);
83
-
84
-		$this->request->expects($this->once())
85
-			->method('getServerProtocol')
86
-			->wilLReturn('http');
87
-
88
-		$this->themingDefaults->expects($this->once())
89
-			->method('getName')
90
-			->willReturn('InstanceName');
91
-
92
-		$this->l10n->expects($this->once())
93
-			->method('t')
94
-			->with('Your %s needs to be configured to use HTTPS in order to use CalDAV and CardDAV with iOS/macOS.', ['InstanceName'])
95
-			->willReturn('LocalizedErrorMessage');
96
-
97
-		$this->sabreResponse->expects($this->once())
98
-			->method('setStatus')
99
-			->with(200);
100
-		$this->sabreResponse->expects($this->once())
101
-			->method('setHeader')
102
-			->with('Content-Type', 'text/plain; charset=utf-8');
103
-		$this->sabreResponse->expects($this->once())
104
-			->method('setBody')
105
-			->with('LocalizedErrorMessage');
106
-
107
-		$returnValue = $this->plugin->httpGet($this->sabreRequest, $this->sabreResponse);
108
-
109
-		$this->assertFalse($returnValue);
110
-	}
111
-
112
-	public function testHttpGetOnHttps(): void {
113
-		$this->sabreRequest->expects($this->once())
114
-			->method('getPath')
115
-			->with()
116
-			->willReturn('provisioning/apple-provisioning.mobileconfig');
117
-
118
-		$user = $this->createMock(IUser::class);
119
-		$user->expects($this->once())
120
-			->method('getUID')
121
-			->willReturn('userName');
122
-
123
-		$this->userSession->expects($this->once())
124
-			->method('getUser')
125
-			->willReturn($user);
126
-
127
-		$this->request->expects($this->once())
128
-			->method('getServerProtocol')
129
-			->wilLReturn('https');
130
-
131
-		$this->urlGenerator->expects($this->once())
132
-			->method('getBaseUrl')
133
-			->willReturn('https://nextcloud.tld/nextcloud');
134
-
135
-		$this->themingDefaults->expects($this->once())
136
-			->method('getName')
137
-			->willReturn('InstanceName');
138
-
139
-		$this->l10n->expects($this->exactly(2))
140
-			->method('t')
141
-			->willReturnMap([
142
-				['Configures a CalDAV account', [], 'LocalizedConfiguresCalDAV'],
143
-				['Configures a CardDAV account', [], 'LocalizedConfiguresCardDAV'],
144
-			]);
145
-
146
-		$this->sabreResponse->expects($this->once())
147
-			->method('setStatus')
148
-			->with(200);
149
-
150
-		$calls = [
151
-			['Content-Disposition', 'attachment; filename="userName-apple-provisioning.mobileconfig"'],
152
-			['Content-Type', 'application/xml; charset=utf-8'],
153
-		];
154
-		$this->sabreResponse->expects($this->exactly(2))
155
-			->method('setHeader')
156
-			->willReturnCallback(function () use (&$calls) {
157
-				$expected = array_shift($calls);
158
-				$this->assertEquals($expected, func_get_args());
159
-			});
160
-		$this->sabreResponse->expects($this->once())
161
-			->method('setBody')
162
-			->with(<<<EOF
24
+    protected Server&MockObject $server;
25
+    protected IUserSession&MockObject $userSession;
26
+    protected IURLGenerator&MockObject $urlGenerator;
27
+    protected ThemingDefaults&MockObject $themingDefaults;
28
+    protected IRequest&MockObject $request;
29
+    protected IL10N&MockObject $l10n;
30
+    protected RequestInterface&MockObject $sabreRequest;
31
+    protected ResponseInterface&MockObject $sabreResponse;
32
+    protected AppleProvisioningPlugin $plugin;
33
+
34
+    protected function setUp(): void {
35
+        parent::setUp();
36
+
37
+        $this->server = $this->createMock(Server::class);
38
+        $this->userSession = $this->createMock(IUserSession::class);
39
+        $this->urlGenerator = $this->createMock(IURLGenerator::class);
40
+        $this->themingDefaults = $this->createMock(ThemingDefaults::class);
41
+        $this->request = $this->createMock(IRequest::class);
42
+        $this->l10n = $this->createMock(IL10N::class);
43
+
44
+        $this->plugin = new AppleProvisioningPlugin($this->userSession,
45
+            $this->urlGenerator,
46
+            $this->themingDefaults,
47
+            $this->request,
48
+            $this->l10n,
49
+            function () {
50
+                return 'generated-uuid';
51
+            }
52
+        );
53
+
54
+        $this->sabreRequest = $this->createMock(RequestInterface::class);
55
+        $this->sabreResponse = $this->createMock(ResponseInterface::class);
56
+    }
57
+
58
+    public function testInitialize(): void {
59
+        $server = $this->createMock(Server::class);
60
+
61
+        $plugin = new AppleProvisioningPlugin($this->userSession,
62
+            $this->urlGenerator, $this->themingDefaults, $this->request, $this->l10n,
63
+            function (): void {
64
+            });
65
+
66
+        $server->expects($this->once())
67
+            ->method('on')
68
+            ->with('method:GET', [$plugin, 'httpGet'], 90);
69
+
70
+        $plugin->initialize($server);
71
+    }
72
+
73
+    public function testHttpGetOnHttp(): void {
74
+        $this->sabreRequest->expects($this->once())
75
+            ->method('getPath')
76
+            ->with()
77
+            ->willReturn('provisioning/apple-provisioning.mobileconfig');
78
+
79
+        $user = $this->createMock(IUser::class);
80
+        $this->userSession->expects($this->once())
81
+            ->method('getUser')
82
+            ->willReturn($user);
83
+
84
+        $this->request->expects($this->once())
85
+            ->method('getServerProtocol')
86
+            ->wilLReturn('http');
87
+
88
+        $this->themingDefaults->expects($this->once())
89
+            ->method('getName')
90
+            ->willReturn('InstanceName');
91
+
92
+        $this->l10n->expects($this->once())
93
+            ->method('t')
94
+            ->with('Your %s needs to be configured to use HTTPS in order to use CalDAV and CardDAV with iOS/macOS.', ['InstanceName'])
95
+            ->willReturn('LocalizedErrorMessage');
96
+
97
+        $this->sabreResponse->expects($this->once())
98
+            ->method('setStatus')
99
+            ->with(200);
100
+        $this->sabreResponse->expects($this->once())
101
+            ->method('setHeader')
102
+            ->with('Content-Type', 'text/plain; charset=utf-8');
103
+        $this->sabreResponse->expects($this->once())
104
+            ->method('setBody')
105
+            ->with('LocalizedErrorMessage');
106
+
107
+        $returnValue = $this->plugin->httpGet($this->sabreRequest, $this->sabreResponse);
108
+
109
+        $this->assertFalse($returnValue);
110
+    }
111
+
112
+    public function testHttpGetOnHttps(): void {
113
+        $this->sabreRequest->expects($this->once())
114
+            ->method('getPath')
115
+            ->with()
116
+            ->willReturn('provisioning/apple-provisioning.mobileconfig');
117
+
118
+        $user = $this->createMock(IUser::class);
119
+        $user->expects($this->once())
120
+            ->method('getUID')
121
+            ->willReturn('userName');
122
+
123
+        $this->userSession->expects($this->once())
124
+            ->method('getUser')
125
+            ->willReturn($user);
126
+
127
+        $this->request->expects($this->once())
128
+            ->method('getServerProtocol')
129
+            ->wilLReturn('https');
130
+
131
+        $this->urlGenerator->expects($this->once())
132
+            ->method('getBaseUrl')
133
+            ->willReturn('https://nextcloud.tld/nextcloud');
134
+
135
+        $this->themingDefaults->expects($this->once())
136
+            ->method('getName')
137
+            ->willReturn('InstanceName');
138
+
139
+        $this->l10n->expects($this->exactly(2))
140
+            ->method('t')
141
+            ->willReturnMap([
142
+                ['Configures a CalDAV account', [], 'LocalizedConfiguresCalDAV'],
143
+                ['Configures a CardDAV account', [], 'LocalizedConfiguresCardDAV'],
144
+            ]);
145
+
146
+        $this->sabreResponse->expects($this->once())
147
+            ->method('setStatus')
148
+            ->with(200);
149
+
150
+        $calls = [
151
+            ['Content-Disposition', 'attachment; filename="userName-apple-provisioning.mobileconfig"'],
152
+            ['Content-Type', 'application/xml; charset=utf-8'],
153
+        ];
154
+        $this->sabreResponse->expects($this->exactly(2))
155
+            ->method('setHeader')
156
+            ->willReturnCallback(function () use (&$calls) {
157
+                $expected = array_shift($calls);
158
+                $this->assertEquals($expected, func_get_args());
159
+            });
160
+        $this->sabreResponse->expects($this->once())
161
+            ->method('setBody')
162
+            ->with(<<<EOF
163 163
 <?xml version="1.0" encoding="UTF-8"?>
164 164
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
165 165
 <plist version="1.0">
@@ -231,10 +231,10 @@  discard block
 block discarded – undo
231 231
 </plist>
232 232
 
233 233
 EOF
234
-			);
234
+            );
235 235
 
236
-		$returnValue = $this->plugin->httpGet($this->sabreRequest, $this->sabreResponse);
236
+        $returnValue = $this->plugin->httpGet($this->sabreRequest, $this->sabreResponse);
237 237
 
238
-		$this->assertFalse($returnValue);
239
-	}
238
+        $this->assertFalse($returnValue);
239
+    }
240 240
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 			$this->themingDefaults,
47 47
 			$this->request,
48 48
 			$this->l10n,
49
-			function () {
49
+			function() {
50 50
 				return 'generated-uuid';
51 51
 			}
52 52
 		);
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 
61 61
 		$plugin = new AppleProvisioningPlugin($this->userSession,
62 62
 			$this->urlGenerator, $this->themingDefaults, $this->request, $this->l10n,
63
-			function (): void {
63
+			function(): void {
64 64
 			});
65 65
 
66 66
 		$server->expects($this->once())
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 		];
154 154
 		$this->sabreResponse->expects($this->exactly(2))
155 155
 			->method('setHeader')
156
-			->willReturnCallback(function () use (&$calls) {
156
+			->willReturnCallback(function() use (&$calls) {
157 157
 				$expected = array_shift($calls);
158 158
 				$this->assertEquals($expected, func_get_args());
159 159
 			});
Please login to merge, or discard this patch.
apps/dav/tests/unit/DAV/BrowserErrorPagePluginTest.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -15,30 +15,30 @@
 block discarded – undo
15 15
 
16 16
 class BrowserErrorPagePluginTest extends \Test\TestCase {
17 17
 
18
-	/**
19
-	 * @dataProvider providesExceptions
20
-	 */
21
-	public function test(int $expectedCode, \Throwable $exception): void {
22
-		/** @var BrowserErrorPagePlugin&MockObject $plugin */
23
-		$plugin = $this->getMockBuilder(BrowserErrorPagePlugin::class)->onlyMethods(['sendResponse', 'generateBody'])->getMock();
24
-		$plugin->expects($this->once())->method('generateBody')->willReturn(':boom:');
25
-		$plugin->expects($this->once())->method('sendResponse');
26
-		/** @var \Sabre\DAV\Server&MockObject $server */
27
-		$server = $this->createMock('Sabre\DAV\Server');
28
-		$server->expects($this->once())->method('on');
29
-		$httpResponse = $this->createMock(Response::class);
30
-		$httpResponse->expects($this->once())->method('addHeaders');
31
-		$httpResponse->expects($this->once())->method('setStatus')->with($expectedCode);
32
-		$httpResponse->expects($this->once())->method('setBody')->with(':boom:');
33
-		$server->httpResponse = $httpResponse;
34
-		$plugin->initialize($server);
35
-		$plugin->logException($exception);
36
-	}
18
+    /**
19
+     * @dataProvider providesExceptions
20
+     */
21
+    public function test(int $expectedCode, \Throwable $exception): void {
22
+        /** @var BrowserErrorPagePlugin&MockObject $plugin */
23
+        $plugin = $this->getMockBuilder(BrowserErrorPagePlugin::class)->onlyMethods(['sendResponse', 'generateBody'])->getMock();
24
+        $plugin->expects($this->once())->method('generateBody')->willReturn(':boom:');
25
+        $plugin->expects($this->once())->method('sendResponse');
26
+        /** @var \Sabre\DAV\Server&MockObject $server */
27
+        $server = $this->createMock('Sabre\DAV\Server');
28
+        $server->expects($this->once())->method('on');
29
+        $httpResponse = $this->createMock(Response::class);
30
+        $httpResponse->expects($this->once())->method('addHeaders');
31
+        $httpResponse->expects($this->once())->method('setStatus')->with($expectedCode);
32
+        $httpResponse->expects($this->once())->method('setBody')->with(':boom:');
33
+        $server->httpResponse = $httpResponse;
34
+        $plugin->initialize($server);
35
+        $plugin->logException($exception);
36
+    }
37 37
 
38
-	public static function providesExceptions(): array {
39
-		return [
40
-			[ 404, new NotFound()],
41
-			[ 500, new \RuntimeException()],
42
-		];
43
-	}
38
+    public static function providesExceptions(): array {
39
+        return [
40
+            [ 404, new NotFound()],
41
+            [ 500, new \RuntimeException()],
42
+        ];
43
+    }
44 44
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,8 +37,8 @@
 block discarded – undo
37 37
 
38 38
 	public static function providesExceptions(): array {
39 39
 		return [
40
-			[ 404, new NotFound()],
41
-			[ 500, new \RuntimeException()],
40
+			[404, new NotFound()],
41
+			[500, new \RuntimeException()],
42 42
 		];
43 43
 	}
44 44
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/DAV/Sharing/BackendTest.php 2 patches
Indentation   +372 added lines, -372 removed lines patch added patch discarded remove patch
@@ -24,376 +24,376 @@
 block discarded – undo
24 24
 
25 25
 class BackendTest extends TestCase {
26 26
 
27
-	private IDBConnection&MockObject $db;
28
-	private IUserManager&MockObject $userManager;
29
-	private IGroupManager&MockObject $groupManager;
30
-	private Principal&MockObject $principalBackend;
31
-	private ICache&MockObject $shareCache;
32
-	private LoggerInterface&MockObject $logger;
33
-	private ICacheFactory&MockObject $cacheFactory;
34
-	private Service&MockObject $calendarService;
35
-	private CalendarSharingBackend $backend;
36
-
37
-	protected function setUp(): void {
38
-		parent::setUp();
39
-		$this->db = $this->createMock(IDBConnection::class);
40
-		$this->userManager = $this->createMock(IUserManager::class);
41
-		$this->groupManager = $this->createMock(IGroupManager::class);
42
-		$this->principalBackend = $this->createMock(Principal::class);
43
-		$this->cacheFactory = $this->createMock(ICacheFactory::class);
44
-		$this->shareCache = $this->createMock(ICache::class);
45
-		$this->logger = $this->createMock(LoggerInterface::class);
46
-		$this->calendarService = $this->createMock(Service::class);
47
-		$this->cacheFactory->expects(self::any())
48
-			->method('createInMemory')
49
-			->willReturn($this->shareCache);
50
-
51
-		$this->backend = new CalendarSharingBackend(
52
-			$this->userManager,
53
-			$this->groupManager,
54
-			$this->principalBackend,
55
-			$this->cacheFactory,
56
-			$this->calendarService,
57
-			$this->logger,
58
-		);
59
-	}
60
-
61
-	public function testUpdateShareCalendarBob(): void {
62
-		$shareable = $this->createConfiguredMock(IShareable::class, [
63
-			'getOwner' => 'principals/users/alice',
64
-			'getResourceId' => 42,
65
-		]);
66
-		$add = [
67
-			[
68
-				'href' => 'principal:principals/users/bob',
69
-				'readOnly' => true,
70
-			]
71
-		];
72
-		$principal = 'principals/users/bob';
73
-
74
-		$this->shareCache->expects(self::once())
75
-			->method('clear');
76
-		$this->principalBackend->expects(self::once())
77
-			->method('findByUri')
78
-			->willReturn($principal);
79
-		$this->userManager->expects(self::once())
80
-			->method('userExists')
81
-			->willReturn(true);
82
-		$this->groupManager->expects(self::never())
83
-			->method('groupExists');
84
-		$this->calendarService->expects(self::once())
85
-			->method('shareWith')
86
-			->with($shareable->getResourceId(), $principal, Backend::ACCESS_READ);
87
-
88
-		$this->backend->updateShares($shareable, $add, []);
89
-	}
90
-
91
-	public function testUpdateShareCalendarGroup(): void {
92
-		$shareable = $this->createConfiguredMock(IShareable::class, [
93
-			'getOwner' => 'principals/users/alice',
94
-			'getResourceId' => 42,
95
-		]);
96
-		$add = [
97
-			[
98
-				'href' => 'principal:principals/groups/bob',
99
-				'readOnly' => true,
100
-			]
101
-		];
102
-		$principal = 'principals/groups/bob';
103
-
104
-		$this->shareCache->expects(self::once())
105
-			->method('clear');
106
-		$this->principalBackend->expects(self::once())
107
-			->method('findByUri')
108
-			->willReturn($principal);
109
-		$this->userManager->expects(self::never())
110
-			->method('userExists');
111
-		$this->groupManager->expects(self::once())
112
-			->method('groupExists')
113
-			->willReturn(true);
114
-		$this->calendarService->expects(self::once())
115
-			->method('shareWith')
116
-			->with($shareable->getResourceId(), $principal, Backend::ACCESS_READ);
117
-
118
-		$this->backend->updateShares($shareable, $add, []);
119
-	}
120
-
121
-	public function testUpdateShareContactsBob(): void {
122
-		$shareable = $this->createConfiguredMock(IShareable::class, [
123
-			'getOwner' => 'principals/users/alice',
124
-			'getResourceId' => 42,
125
-		]);
126
-		$add = [
127
-			[
128
-				'href' => 'principal:principals/users/bob',
129
-				'readOnly' => true,
130
-			]
131
-		];
132
-		$principal = 'principals/users/bob';
133
-
134
-		$this->shareCache->expects(self::once())
135
-			->method('clear');
136
-		$this->principalBackend->expects(self::once())
137
-			->method('findByUri')
138
-			->willReturn($principal);
139
-		$this->userManager->expects(self::once())
140
-			->method('userExists')
141
-			->willReturn(true);
142
-		$this->groupManager->expects(self::never())
143
-			->method('groupExists');
144
-		$this->calendarService->expects(self::once())
145
-			->method('shareWith')
146
-			->with($shareable->getResourceId(), $principal, Backend::ACCESS_READ);
147
-
148
-		$this->backend->updateShares($shareable, $add, []);
149
-	}
150
-
151
-	public function testUpdateShareContactsGroup(): void {
152
-		$shareable = $this->createConfiguredMock(IShareable::class, [
153
-			'getOwner' => 'principals/users/alice',
154
-			'getResourceId' => 42,
155
-		]);
156
-		$add = [
157
-			[
158
-				'href' => 'principal:principals/groups/bob',
159
-				'readOnly' => true,
160
-			]
161
-		];
162
-		$principal = 'principals/groups/bob';
163
-
164
-		$this->shareCache->expects(self::once())
165
-			->method('clear');
166
-		$this->principalBackend->expects(self::once())
167
-			->method('findByUri')
168
-			->willReturn($principal);
169
-		$this->userManager->expects(self::never())
170
-			->method('userExists');
171
-		$this->groupManager->expects(self::once())
172
-			->method('groupExists')
173
-			->willReturn(true);
174
-		$this->calendarService->expects(self::once())
175
-			->method('shareWith')
176
-			->with($shareable->getResourceId(), $principal, Backend::ACCESS_READ);
177
-
178
-		$this->backend->updateShares($shareable, $add, []);
179
-	}
180
-
181
-	public function testUpdateShareCircle(): void {
182
-		$shareable = $this->createConfiguredMock(IShareable::class, [
183
-			'getOwner' => 'principals/users/alice',
184
-			'getResourceId' => 42,
185
-		]);
186
-		$add = [
187
-			[
188
-				'href' => 'principal:principals/circles/bob',
189
-				'readOnly' => true,
190
-			]
191
-		];
192
-		$principal = 'principals/groups/bob';
193
-
194
-		$this->shareCache->expects(self::once())
195
-			->method('clear');
196
-		$this->principalBackend->expects(self::once())
197
-			->method('findByUri')
198
-			->willReturn($principal);
199
-		$this->userManager->expects(self::never())
200
-			->method('userExists');
201
-		$this->groupManager->expects(self::once())
202
-			->method('groupExists')
203
-			->willReturn(true);
204
-		$this->calendarService->expects(self::once())
205
-			->method('shareWith')
206
-			->with($shareable->getResourceId(), $principal, Backend::ACCESS_READ);
207
-
208
-		$this->backend->updateShares($shareable, $add, []);
209
-	}
210
-
211
-	public function testUnshareBob(): void {
212
-		$shareable = $this->createConfiguredMock(IShareable::class, [
213
-			'getOwner' => 'principals/users/alice',
214
-			'getResourceId' => 42,
215
-		]);
216
-		$remove = [
217
-			'principal:principals/users/bob',
218
-		];
219
-		$principal = 'principals/users/bob';
220
-
221
-		$this->shareCache->expects(self::once())
222
-			->method('clear');
223
-		$this->principalBackend->expects(self::once())
224
-			->method('findByUri')
225
-			->willReturn($principal);
226
-		$this->calendarService->expects(self::once())
227
-			->method('deleteShare')
228
-			->with($shareable->getResourceId(), $principal);
229
-		$this->calendarService->expects(self::never())
230
-			->method('unshare');
231
-
232
-		$this->backend->updateShares($shareable, [], $remove);
233
-	}
234
-
235
-	public function testUnshareWithBobGroup(): void {
236
-		$shareable = $this->createConfiguredMock(IShareable::class, [
237
-			'getOwner' => 'principals/users/alice',
238
-			'getResourceId' => 42,
239
-		]);
240
-		$remove = [
241
-			'principal:principals/users/bob',
242
-		];
243
-		$oldShares = [
244
-			[
245
-				'href' => 'principal:principals/groups/bob',
246
-				'commonName' => 'bob',
247
-				'status' => 1,
248
-				'readOnly' => true,
249
-				'{http://owncloud.org/ns}principal' => 'principals/groups/bob',
250
-				'{http://owncloud.org/ns}group-share' => true,
251
-			]
252
-		];
253
-
254
-
255
-		$this->shareCache->expects(self::once())
256
-			->method('clear');
257
-		$this->principalBackend->expects(self::once())
258
-			->method('findByUri')
259
-			->willReturn('principals/users/bob');
260
-		$this->calendarService->expects(self::once())
261
-			->method('deleteShare')
262
-			->with($shareable->getResourceId(), 'principals/users/bob');
263
-		$this->calendarService->expects(self::never())
264
-			->method('unshare');
265
-
266
-		$this->backend->updateShares($shareable, [], $remove, $oldShares);
267
-	}
268
-
269
-	public function testGetShares(): void {
270
-		$resourceId = 42;
271
-		$principal = 'principals/groups/bob';
272
-		$rows = [
273
-			[
274
-				'principaluri' => $principal,
275
-				'access' => Backend::ACCESS_READ,
276
-			]
277
-		];
278
-		$expected = [
279
-			[
280
-				'href' => 'principal:principals/groups/bob',
281
-				'commonName' => 'bob',
282
-				'status' => 1,
283
-				'readOnly' => true,
284
-				'{http://owncloud.org/ns}principal' => $principal,
285
-				'{http://owncloud.org/ns}group-share' => true,
286
-			]
287
-		];
288
-
289
-
290
-		$this->shareCache->expects(self::once())
291
-			->method('get')
292
-			->with((string)$resourceId)
293
-			->willReturn(null);
294
-		$this->calendarService->expects(self::once())
295
-			->method('getShares')
296
-			->with($resourceId)
297
-			->willReturn($rows);
298
-		$this->principalBackend->expects(self::once())
299
-			->method('getPrincipalByPath')
300
-			->with($principal)
301
-			->willReturn(['uri' => $principal, '{DAV:}displayname' => 'bob']);
302
-		$this->shareCache->expects(self::once())
303
-			->method('set')
304
-			->with((string)$resourceId, $expected);
305
-
306
-		$result = $this->backend->getShares($resourceId);
307
-		$this->assertEquals($expected, $result);
308
-	}
309
-
310
-	public function testGetSharesAddressbooks(): void {
311
-		$service = $this->createMock(\OCA\DAV\CardDAV\Sharing\Service::class);
312
-		$backend = new ContactsSharingBackend(
313
-			$this->userManager,
314
-			$this->groupManager,
315
-			$this->principalBackend,
316
-			$this->cacheFactory,
317
-			$service,
318
-			$this->logger);
319
-		$resourceId = 42;
320
-		$principal = 'principals/groups/bob';
321
-		$rows = [
322
-			[
323
-				'principaluri' => $principal,
324
-				'access' => Backend::ACCESS_READ,
325
-			]
326
-		];
327
-		$expected = [
328
-			[
329
-				'href' => 'principal:principals/groups/bob',
330
-				'commonName' => 'bob',
331
-				'status' => 1,
332
-				'readOnly' => true,
333
-				'{http://owncloud.org/ns}principal' => $principal,
334
-				'{http://owncloud.org/ns}group-share' => true,
335
-			]
336
-		];
337
-
338
-		$this->shareCache->expects(self::once())
339
-			->method('get')
340
-			->with((string)$resourceId)
341
-			->willReturn(null);
342
-		$service->expects(self::once())
343
-			->method('getShares')
344
-			->with($resourceId)
345
-			->willReturn($rows);
346
-		$this->principalBackend->expects(self::once())
347
-			->method('getPrincipalByPath')
348
-			->with($principal)
349
-			->willReturn(['uri' => $principal, '{DAV:}displayname' => 'bob']);
350
-		$this->shareCache->expects(self::once())
351
-			->method('set')
352
-			->with((string)$resourceId, $expected);
353
-
354
-		$result = $backend->getShares($resourceId);
355
-		$this->assertEquals($expected, $result);
356
-	}
357
-
358
-	public function testPreloadShares(): void {
359
-		$resourceIds = [42, 99];
360
-		$rows = [
361
-			[
362
-				'resourceid' => 42,
363
-				'principaluri' => 'principals/groups/bob',
364
-				'access' => Backend::ACCESS_READ,
365
-			],
366
-			[
367
-				'resourceid' => 99,
368
-				'principaluri' => 'principals/users/carlos',
369
-				'access' => Backend::ACCESS_READ_WRITE,
370
-			]
371
-		];
372
-		$principalResults = [
373
-			['uri' => 'principals/groups/bob', '{DAV:}displayname' => 'bob'],
374
-			['uri' => 'principals/users/carlos', '{DAV:}displayname' => 'carlos'],
375
-		];
376
-
377
-		$this->shareCache->expects(self::exactly(2))
378
-			->method('get')
379
-			->willReturn(null);
380
-		$this->calendarService->expects(self::once())
381
-			->method('getSharesForIds')
382
-			->with($resourceIds)
383
-			->willReturn($rows);
384
-		$this->principalBackend->expects(self::exactly(2))
385
-			->method('getPrincipalByPath')
386
-			->willReturnCallback(function (string $principal) use ($principalResults) {
387
-				switch ($principal) {
388
-					case 'principals/groups/bob':
389
-						return $principalResults[0];
390
-					default:
391
-						return $principalResults[1];
392
-				}
393
-			});
394
-		$this->shareCache->expects(self::exactly(2))
395
-			->method('set');
396
-
397
-		$this->backend->preloadShares($resourceIds);
398
-	}
27
+    private IDBConnection&MockObject $db;
28
+    private IUserManager&MockObject $userManager;
29
+    private IGroupManager&MockObject $groupManager;
30
+    private Principal&MockObject $principalBackend;
31
+    private ICache&MockObject $shareCache;
32
+    private LoggerInterface&MockObject $logger;
33
+    private ICacheFactory&MockObject $cacheFactory;
34
+    private Service&MockObject $calendarService;
35
+    private CalendarSharingBackend $backend;
36
+
37
+    protected function setUp(): void {
38
+        parent::setUp();
39
+        $this->db = $this->createMock(IDBConnection::class);
40
+        $this->userManager = $this->createMock(IUserManager::class);
41
+        $this->groupManager = $this->createMock(IGroupManager::class);
42
+        $this->principalBackend = $this->createMock(Principal::class);
43
+        $this->cacheFactory = $this->createMock(ICacheFactory::class);
44
+        $this->shareCache = $this->createMock(ICache::class);
45
+        $this->logger = $this->createMock(LoggerInterface::class);
46
+        $this->calendarService = $this->createMock(Service::class);
47
+        $this->cacheFactory->expects(self::any())
48
+            ->method('createInMemory')
49
+            ->willReturn($this->shareCache);
50
+
51
+        $this->backend = new CalendarSharingBackend(
52
+            $this->userManager,
53
+            $this->groupManager,
54
+            $this->principalBackend,
55
+            $this->cacheFactory,
56
+            $this->calendarService,
57
+            $this->logger,
58
+        );
59
+    }
60
+
61
+    public function testUpdateShareCalendarBob(): void {
62
+        $shareable = $this->createConfiguredMock(IShareable::class, [
63
+            'getOwner' => 'principals/users/alice',
64
+            'getResourceId' => 42,
65
+        ]);
66
+        $add = [
67
+            [
68
+                'href' => 'principal:principals/users/bob',
69
+                'readOnly' => true,
70
+            ]
71
+        ];
72
+        $principal = 'principals/users/bob';
73
+
74
+        $this->shareCache->expects(self::once())
75
+            ->method('clear');
76
+        $this->principalBackend->expects(self::once())
77
+            ->method('findByUri')
78
+            ->willReturn($principal);
79
+        $this->userManager->expects(self::once())
80
+            ->method('userExists')
81
+            ->willReturn(true);
82
+        $this->groupManager->expects(self::never())
83
+            ->method('groupExists');
84
+        $this->calendarService->expects(self::once())
85
+            ->method('shareWith')
86
+            ->with($shareable->getResourceId(), $principal, Backend::ACCESS_READ);
87
+
88
+        $this->backend->updateShares($shareable, $add, []);
89
+    }
90
+
91
+    public function testUpdateShareCalendarGroup(): void {
92
+        $shareable = $this->createConfiguredMock(IShareable::class, [
93
+            'getOwner' => 'principals/users/alice',
94
+            'getResourceId' => 42,
95
+        ]);
96
+        $add = [
97
+            [
98
+                'href' => 'principal:principals/groups/bob',
99
+                'readOnly' => true,
100
+            ]
101
+        ];
102
+        $principal = 'principals/groups/bob';
103
+
104
+        $this->shareCache->expects(self::once())
105
+            ->method('clear');
106
+        $this->principalBackend->expects(self::once())
107
+            ->method('findByUri')
108
+            ->willReturn($principal);
109
+        $this->userManager->expects(self::never())
110
+            ->method('userExists');
111
+        $this->groupManager->expects(self::once())
112
+            ->method('groupExists')
113
+            ->willReturn(true);
114
+        $this->calendarService->expects(self::once())
115
+            ->method('shareWith')
116
+            ->with($shareable->getResourceId(), $principal, Backend::ACCESS_READ);
117
+
118
+        $this->backend->updateShares($shareable, $add, []);
119
+    }
120
+
121
+    public function testUpdateShareContactsBob(): void {
122
+        $shareable = $this->createConfiguredMock(IShareable::class, [
123
+            'getOwner' => 'principals/users/alice',
124
+            'getResourceId' => 42,
125
+        ]);
126
+        $add = [
127
+            [
128
+                'href' => 'principal:principals/users/bob',
129
+                'readOnly' => true,
130
+            ]
131
+        ];
132
+        $principal = 'principals/users/bob';
133
+
134
+        $this->shareCache->expects(self::once())
135
+            ->method('clear');
136
+        $this->principalBackend->expects(self::once())
137
+            ->method('findByUri')
138
+            ->willReturn($principal);
139
+        $this->userManager->expects(self::once())
140
+            ->method('userExists')
141
+            ->willReturn(true);
142
+        $this->groupManager->expects(self::never())
143
+            ->method('groupExists');
144
+        $this->calendarService->expects(self::once())
145
+            ->method('shareWith')
146
+            ->with($shareable->getResourceId(), $principal, Backend::ACCESS_READ);
147
+
148
+        $this->backend->updateShares($shareable, $add, []);
149
+    }
150
+
151
+    public function testUpdateShareContactsGroup(): void {
152
+        $shareable = $this->createConfiguredMock(IShareable::class, [
153
+            'getOwner' => 'principals/users/alice',
154
+            'getResourceId' => 42,
155
+        ]);
156
+        $add = [
157
+            [
158
+                'href' => 'principal:principals/groups/bob',
159
+                'readOnly' => true,
160
+            ]
161
+        ];
162
+        $principal = 'principals/groups/bob';
163
+
164
+        $this->shareCache->expects(self::once())
165
+            ->method('clear');
166
+        $this->principalBackend->expects(self::once())
167
+            ->method('findByUri')
168
+            ->willReturn($principal);
169
+        $this->userManager->expects(self::never())
170
+            ->method('userExists');
171
+        $this->groupManager->expects(self::once())
172
+            ->method('groupExists')
173
+            ->willReturn(true);
174
+        $this->calendarService->expects(self::once())
175
+            ->method('shareWith')
176
+            ->with($shareable->getResourceId(), $principal, Backend::ACCESS_READ);
177
+
178
+        $this->backend->updateShares($shareable, $add, []);
179
+    }
180
+
181
+    public function testUpdateShareCircle(): void {
182
+        $shareable = $this->createConfiguredMock(IShareable::class, [
183
+            'getOwner' => 'principals/users/alice',
184
+            'getResourceId' => 42,
185
+        ]);
186
+        $add = [
187
+            [
188
+                'href' => 'principal:principals/circles/bob',
189
+                'readOnly' => true,
190
+            ]
191
+        ];
192
+        $principal = 'principals/groups/bob';
193
+
194
+        $this->shareCache->expects(self::once())
195
+            ->method('clear');
196
+        $this->principalBackend->expects(self::once())
197
+            ->method('findByUri')
198
+            ->willReturn($principal);
199
+        $this->userManager->expects(self::never())
200
+            ->method('userExists');
201
+        $this->groupManager->expects(self::once())
202
+            ->method('groupExists')
203
+            ->willReturn(true);
204
+        $this->calendarService->expects(self::once())
205
+            ->method('shareWith')
206
+            ->with($shareable->getResourceId(), $principal, Backend::ACCESS_READ);
207
+
208
+        $this->backend->updateShares($shareable, $add, []);
209
+    }
210
+
211
+    public function testUnshareBob(): void {
212
+        $shareable = $this->createConfiguredMock(IShareable::class, [
213
+            'getOwner' => 'principals/users/alice',
214
+            'getResourceId' => 42,
215
+        ]);
216
+        $remove = [
217
+            'principal:principals/users/bob',
218
+        ];
219
+        $principal = 'principals/users/bob';
220
+
221
+        $this->shareCache->expects(self::once())
222
+            ->method('clear');
223
+        $this->principalBackend->expects(self::once())
224
+            ->method('findByUri')
225
+            ->willReturn($principal);
226
+        $this->calendarService->expects(self::once())
227
+            ->method('deleteShare')
228
+            ->with($shareable->getResourceId(), $principal);
229
+        $this->calendarService->expects(self::never())
230
+            ->method('unshare');
231
+
232
+        $this->backend->updateShares($shareable, [], $remove);
233
+    }
234
+
235
+    public function testUnshareWithBobGroup(): void {
236
+        $shareable = $this->createConfiguredMock(IShareable::class, [
237
+            'getOwner' => 'principals/users/alice',
238
+            'getResourceId' => 42,
239
+        ]);
240
+        $remove = [
241
+            'principal:principals/users/bob',
242
+        ];
243
+        $oldShares = [
244
+            [
245
+                'href' => 'principal:principals/groups/bob',
246
+                'commonName' => 'bob',
247
+                'status' => 1,
248
+                'readOnly' => true,
249
+                '{http://owncloud.org/ns}principal' => 'principals/groups/bob',
250
+                '{http://owncloud.org/ns}group-share' => true,
251
+            ]
252
+        ];
253
+
254
+
255
+        $this->shareCache->expects(self::once())
256
+            ->method('clear');
257
+        $this->principalBackend->expects(self::once())
258
+            ->method('findByUri')
259
+            ->willReturn('principals/users/bob');
260
+        $this->calendarService->expects(self::once())
261
+            ->method('deleteShare')
262
+            ->with($shareable->getResourceId(), 'principals/users/bob');
263
+        $this->calendarService->expects(self::never())
264
+            ->method('unshare');
265
+
266
+        $this->backend->updateShares($shareable, [], $remove, $oldShares);
267
+    }
268
+
269
+    public function testGetShares(): void {
270
+        $resourceId = 42;
271
+        $principal = 'principals/groups/bob';
272
+        $rows = [
273
+            [
274
+                'principaluri' => $principal,
275
+                'access' => Backend::ACCESS_READ,
276
+            ]
277
+        ];
278
+        $expected = [
279
+            [
280
+                'href' => 'principal:principals/groups/bob',
281
+                'commonName' => 'bob',
282
+                'status' => 1,
283
+                'readOnly' => true,
284
+                '{http://owncloud.org/ns}principal' => $principal,
285
+                '{http://owncloud.org/ns}group-share' => true,
286
+            ]
287
+        ];
288
+
289
+
290
+        $this->shareCache->expects(self::once())
291
+            ->method('get')
292
+            ->with((string)$resourceId)
293
+            ->willReturn(null);
294
+        $this->calendarService->expects(self::once())
295
+            ->method('getShares')
296
+            ->with($resourceId)
297
+            ->willReturn($rows);
298
+        $this->principalBackend->expects(self::once())
299
+            ->method('getPrincipalByPath')
300
+            ->with($principal)
301
+            ->willReturn(['uri' => $principal, '{DAV:}displayname' => 'bob']);
302
+        $this->shareCache->expects(self::once())
303
+            ->method('set')
304
+            ->with((string)$resourceId, $expected);
305
+
306
+        $result = $this->backend->getShares($resourceId);
307
+        $this->assertEquals($expected, $result);
308
+    }
309
+
310
+    public function testGetSharesAddressbooks(): void {
311
+        $service = $this->createMock(\OCA\DAV\CardDAV\Sharing\Service::class);
312
+        $backend = new ContactsSharingBackend(
313
+            $this->userManager,
314
+            $this->groupManager,
315
+            $this->principalBackend,
316
+            $this->cacheFactory,
317
+            $service,
318
+            $this->logger);
319
+        $resourceId = 42;
320
+        $principal = 'principals/groups/bob';
321
+        $rows = [
322
+            [
323
+                'principaluri' => $principal,
324
+                'access' => Backend::ACCESS_READ,
325
+            ]
326
+        ];
327
+        $expected = [
328
+            [
329
+                'href' => 'principal:principals/groups/bob',
330
+                'commonName' => 'bob',
331
+                'status' => 1,
332
+                'readOnly' => true,
333
+                '{http://owncloud.org/ns}principal' => $principal,
334
+                '{http://owncloud.org/ns}group-share' => true,
335
+            ]
336
+        ];
337
+
338
+        $this->shareCache->expects(self::once())
339
+            ->method('get')
340
+            ->with((string)$resourceId)
341
+            ->willReturn(null);
342
+        $service->expects(self::once())
343
+            ->method('getShares')
344
+            ->with($resourceId)
345
+            ->willReturn($rows);
346
+        $this->principalBackend->expects(self::once())
347
+            ->method('getPrincipalByPath')
348
+            ->with($principal)
349
+            ->willReturn(['uri' => $principal, '{DAV:}displayname' => 'bob']);
350
+        $this->shareCache->expects(self::once())
351
+            ->method('set')
352
+            ->with((string)$resourceId, $expected);
353
+
354
+        $result = $backend->getShares($resourceId);
355
+        $this->assertEquals($expected, $result);
356
+    }
357
+
358
+    public function testPreloadShares(): void {
359
+        $resourceIds = [42, 99];
360
+        $rows = [
361
+            [
362
+                'resourceid' => 42,
363
+                'principaluri' => 'principals/groups/bob',
364
+                'access' => Backend::ACCESS_READ,
365
+            ],
366
+            [
367
+                'resourceid' => 99,
368
+                'principaluri' => 'principals/users/carlos',
369
+                'access' => Backend::ACCESS_READ_WRITE,
370
+            ]
371
+        ];
372
+        $principalResults = [
373
+            ['uri' => 'principals/groups/bob', '{DAV:}displayname' => 'bob'],
374
+            ['uri' => 'principals/users/carlos', '{DAV:}displayname' => 'carlos'],
375
+        ];
376
+
377
+        $this->shareCache->expects(self::exactly(2))
378
+            ->method('get')
379
+            ->willReturn(null);
380
+        $this->calendarService->expects(self::once())
381
+            ->method('getSharesForIds')
382
+            ->with($resourceIds)
383
+            ->willReturn($rows);
384
+        $this->principalBackend->expects(self::exactly(2))
385
+            ->method('getPrincipalByPath')
386
+            ->willReturnCallback(function (string $principal) use ($principalResults) {
387
+                switch ($principal) {
388
+                    case 'principals/groups/bob':
389
+                        return $principalResults[0];
390
+                    default:
391
+                        return $principalResults[1];
392
+                }
393
+            });
394
+        $this->shareCache->expects(self::exactly(2))
395
+            ->method('set');
396
+
397
+        $this->backend->preloadShares($resourceIds);
398
+    }
399 399
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 
290 290
 		$this->shareCache->expects(self::once())
291 291
 			->method('get')
292
-			->with((string)$resourceId)
292
+			->with((string) $resourceId)
293 293
 			->willReturn(null);
294 294
 		$this->calendarService->expects(self::once())
295 295
 			->method('getShares')
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 			->willReturn(['uri' => $principal, '{DAV:}displayname' => 'bob']);
302 302
 		$this->shareCache->expects(self::once())
303 303
 			->method('set')
304
-			->with((string)$resourceId, $expected);
304
+			->with((string) $resourceId, $expected);
305 305
 
306 306
 		$result = $this->backend->getShares($resourceId);
307 307
 		$this->assertEquals($expected, $result);
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 
338 338
 		$this->shareCache->expects(self::once())
339 339
 			->method('get')
340
-			->with((string)$resourceId)
340
+			->with((string) $resourceId)
341 341
 			->willReturn(null);
342 342
 		$service->expects(self::once())
343 343
 			->method('getShares')
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
 			->willReturn(['uri' => $principal, '{DAV:}displayname' => 'bob']);
350 350
 		$this->shareCache->expects(self::once())
351 351
 			->method('set')
352
-			->with((string)$resourceId, $expected);
352
+			->with((string) $resourceId, $expected);
353 353
 
354 354
 		$result = $backend->getShares($resourceId);
355 355
 		$this->assertEquals($expected, $result);
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 			->willReturn($rows);
384 384
 		$this->principalBackend->expects(self::exactly(2))
385 385
 			->method('getPrincipalByPath')
386
-			->willReturnCallback(function (string $principal) use ($principalResults) {
386
+			->willReturnCallback(function(string $principal) use ($principalResults) {
387 387
 				switch ($principal) {
388 388
 					case 'principals/groups/bob':
389 389
 						return $principalResults[0];
Please login to merge, or discard this patch.