Completed
Push — master ( 5d14f8...2337bd )
by Robin
27:19 queued 16s
created
apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php 1 patch
Indentation   +435 added lines, -435 removed lines patch added patch discarded remove patch
@@ -28,439 +28,439 @@
 block discarded – undo
28 28
  * @package OCA\Files_Sharing\Tests\API
29 29
  */
30 30
 class ShareesAPIControllerTest extends TestCase {
31
-	/** @var ShareesAPIController */
32
-	protected $sharees;
33
-
34
-	/** @var string */
35
-	protected $uid;
36
-
37
-	/** @var IRequest|MockObject */
38
-	protected $request;
39
-
40
-	/** @var IManager|MockObject */
41
-	protected $shareManager;
42
-
43
-	/** @var ISearch|MockObject */
44
-	protected $collaboratorSearch;
45
-
46
-	/** @var IConfig|MockObject */
47
-	protected $config;
48
-
49
-	protected function setUp(): void {
50
-		parent::setUp();
51
-
52
-		$this->uid = 'test123';
53
-		$this->request = $this->createMock(IRequest::class);
54
-		$this->shareManager = $this->createMock(IManager::class);
55
-		$this->config = $this->createMock(IConfig::class);
56
-
57
-		/** @var IURLGenerator|MockObject $urlGeneratorMock */
58
-		$urlGeneratorMock = $this->createMock(IURLGenerator::class);
59
-
60
-		$this->collaboratorSearch = $this->createMock(ISearch::class);
61
-
62
-		$this->sharees = new ShareesAPIController(
63
-			'files_sharing',
64
-			$this->request,
65
-			$this->uid,
66
-			$this->config,
67
-			$urlGeneratorMock,
68
-			$this->shareManager,
69
-			$this->collaboratorSearch
70
-		);
71
-	}
72
-
73
-	public static function dataSearch(): array {
74
-		$noRemote = [IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_EMAIL];
75
-		$allTypes = [IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_REMOTE, IShare::TYPE_REMOTE_GROUP, IShare::TYPE_EMAIL];
76
-
77
-		return [
78
-			[[], '', 'yes', false, true, true, true, $noRemote, false, true, true],
79
-
80
-			// Test itemType
81
-			[[
82
-				'search' => '',
83
-			], '', 'yes', false, true, true, true, $noRemote, false, true, true],
84
-			[[
85
-				'search' => 'foobar',
86
-			], '', 'yes', false, true, true, true, $noRemote, false, true, true],
87
-			[[
88
-				'search' => 0,
89
-			], '', 'yes', false, true, true, true, $noRemote, false, true, true],
90
-
91
-			// Test itemType
92
-			[[
93
-				'itemType' => '',
94
-			], '', 'yes', false, true, true, true, $noRemote, false, true, true],
95
-			[[
96
-				'itemType' => 'folder',
97
-			], '', 'yes', false, true, true, true, $allTypes, false, true, true],
98
-			[[
99
-				'itemType' => 0,
100
-			], '', 'yes', false, true, true , true, $noRemote, false, true, true],
101
-			// Test shareType
102
-			[[
103
-				'itemType' => 'call',
104
-			], '', 'yes', false, true, true, true, $noRemote, false, true, true],
105
-			[[
106
-				'itemType' => 'call',
107
-			], '', 'yes', false, true, true, true, [0, 4], false, true, false],
108
-			[[
109
-				'itemType' => 'folder',
110
-			], '', 'yes', false, true, true, true, $allTypes, false, true, true],
111
-			[[
112
-				'itemType' => 'folder',
113
-				'shareType' => 0,
114
-			], '', 'yes', false, true, true, false, [0], false, true, true],
115
-			[[
116
-				'itemType' => 'folder',
117
-				'shareType' => '0',
118
-			], '', 'yes', false, true, true, false, [0], false, true, true],
119
-			[[
120
-				'itemType' => 'folder',
121
-				'shareType' => 1,
122
-			], '', 'yes', false, true, true, false, [1], false, true, true],
123
-			[[
124
-				'itemType' => 'folder',
125
-				'shareType' => 12,
126
-			], '', 'yes', false, true, true, false, [], false, true, true],
127
-			[[
128
-				'itemType' => 'folder',
129
-				'shareType' => 'foobar',
130
-			], '', 'yes', false, true, true, true, $allTypes, false, true, true],
131
-
132
-			[[
133
-				'itemType' => 'folder',
134
-				'shareType' => [0, 1, 2],
135
-			], '', 'yes', false, false, false, false, [0, 1], false, true, true],
136
-			[[
137
-				'itemType' => 'folder',
138
-				'shareType' => [0, 1],
139
-			], '', 'yes', false, false, false, false, [0, 1], false, true, true],
140
-			[[
141
-				'itemType' => 'folder',
142
-				'shareType' => $allTypes,
143
-			], '', 'yes', false, true, true, true, $allTypes, false, true, true],
144
-			[[
145
-				'itemType' => 'folder',
146
-				'shareType' => $allTypes,
147
-			], '', 'yes', false, false, false, false, [0, 1], false, true, true],
148
-			[[
149
-				'itemType' => 'folder',
150
-				'shareType' => $allTypes,
151
-			], '', 'yes', false, true, false, false, [0, 6], false, true, false],
152
-			[[
153
-				'itemType' => 'folder',
154
-				'shareType' => $allTypes,
155
-			], '', 'yes', false, false, false, true, [0, 4], false, true, false],
156
-			[[
157
-				'itemType' => 'folder',
158
-				'shareType' => $allTypes,
159
-			], '', 'yes', false, true, true, false, [0, 6, 9], false, true, false],
160
-
161
-			// Test pagination
162
-			[[
163
-				'itemType' => 'folder',
164
-				'page' => 1,
165
-			], '', 'yes', false, true, true, true, $allTypes, false, true, true],
166
-			[[
167
-				'itemType' => 'folder',
168
-				'page' => 10,
169
-			], '', 'yes', false, true, true, true, $allTypes, false, true, true],
170
-
171
-			// Test perPage
172
-			[[
173
-				'itemType' => 'folder',
174
-				'perPage' => 1,
175
-			], '', 'yes', false, true, true, true, $allTypes, false, true, true],
176
-			[[
177
-				'itemType' => 'folder',
178
-				'perPage' => 10,
179
-			], '', 'yes', false, true, true, true, $allTypes, false, true, true],
180
-
181
-			// Test $shareWithGroupOnly setting
182
-			[[
183
-				'itemType' => 'folder',
184
-			], 'no', 'yes', false, true, true, true, $allTypes, false, true, true],
185
-			[[
186
-				'itemType' => 'folder',
187
-			], 'yes', 'yes', false, true, true, true, $allTypes, true, true, true],
188
-
189
-			// Test $shareeEnumeration setting
190
-			[[
191
-				'itemType' => 'folder',
192
-			], 'no', 'yes', false, true, true, true, $allTypes, false, true, true],
193
-			[[
194
-				'itemType' => 'folder',
195
-			], 'no', 'no', false, true, true, true, $allTypes, false, false, true],
196
-
197
-		];
198
-	}
199
-
200
-	/**
201
-	 *
202
-	 * @param array $getData
203
-	 * @param string $apiSetting
204
-	 * @param string $enumSetting
205
-	 * @param bool $remoteSharingEnabled
206
-	 * @param bool $isRemoteGroupSharingEnabled
207
-	 * @param bool $emailSharingEnabled
208
-	 * @param array $shareTypes
209
-	 * @param bool $shareWithGroupOnly
210
-	 * @param bool $shareeEnumeration
211
-	 * @param bool $allowGroupSharing
212
-	 * @throws OCSBadRequestException
213
-	 */
214
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataSearch')]
215
-	public function testSearch(
216
-		array $getData,
217
-		string $apiSetting,
218
-		string $enumSetting,
219
-		bool $sharingDisabledForUser,
220
-		bool $remoteSharingEnabled,
221
-		bool $isRemoteGroupSharingEnabled,
222
-		bool $emailSharingEnabled,
223
-		array $shareTypes,
224
-		bool $shareWithGroupOnly,
225
-		bool $shareeEnumeration,
226
-		bool $allowGroupSharing,
227
-	): void {
228
-		$search = $getData['search'] ?? '';
229
-		$itemType = $getData['itemType'] ?? 'irrelevant';
230
-		$page = $getData['page'] ?? 1;
231
-		$perPage = $getData['perPage'] ?? 200;
232
-		$shareType = $getData['shareType'] ?? null;
233
-
234
-		$globalConfig = $this->createMock(GlobalScaleIConfig::class);
235
-		$globalConfig->expects(self::once())
236
-			->method('isGlobalScaleEnabled')
237
-			->willReturn(true);
238
-		$this->overwriteService(GlobalScaleIConfig::class, $globalConfig);
239
-
240
-		/** @var IConfig|MockObject $config */
241
-		$config = $this->createMock(IConfig::class);
242
-
243
-		$this->shareManager->expects($this->once())
244
-			->method('allowGroupSharing')
245
-			->willReturn($allowGroupSharing);
246
-
247
-		/** @var string */
248
-		$uid = 'test123';
249
-		/** @var IRequest|MockObject $request */
250
-		$request = $this->createMock(IRequest::class);
251
-		/** @var IURLGenerator|MockObject $urlGenerator */
252
-		$urlGenerator = $this->createMock(IURLGenerator::class);
253
-
254
-		/** @var MockObject|ShareesAPIController $sharees */
255
-		$sharees = $this->getMockBuilder(ShareesAPIController::class)
256
-			->setConstructorArgs([
257
-				'files_sharing',
258
-				$request,
259
-				$uid,
260
-				$config,
261
-				$urlGenerator,
262
-				$this->shareManager,
263
-				$this->collaboratorSearch
264
-			])
265
-			->onlyMethods(['isRemoteSharingAllowed', 'isRemoteGroupSharingAllowed'])
266
-			->getMock();
267
-
268
-		$expectedShareTypes = $shareTypes;
269
-		sort($expectedShareTypes);
270
-
271
-		$this->collaboratorSearch->expects($this->once())
272
-			->method('search')
273
-			->with($search, $expectedShareTypes, $this->anything(), $perPage, $perPage * ($page - 1))
274
-			->willReturn([[], false]);
275
-
276
-		$sharees->expects($this->any())
277
-			->method('isRemoteSharingAllowed')
278
-			->with($itemType)
279
-			->willReturn($remoteSharingEnabled);
280
-
281
-
282
-		$sharees->expects($this->any())
283
-			->method('isRemoteGroupSharingAllowed')
284
-			->with($itemType)
285
-			->willReturn($isRemoteGroupSharingEnabled);
286
-
287
-		$this->shareManager->expects($this->any())
288
-			->method('sharingDisabledForUser')
289
-			->with($uid)
290
-			->willReturn($sharingDisabledForUser);
291
-
292
-		$this->shareManager->expects($this->any())
293
-			->method('shareProviderExists')
294
-			->willReturnCallback(function ($shareType) use ($emailSharingEnabled) {
295
-				if ($shareType === IShare::TYPE_EMAIL) {
296
-					return $emailSharingEnabled;
297
-				} else {
298
-					return false;
299
-				}
300
-			});
301
-
302
-		$this->assertInstanceOf(DataResponse::class, $sharees->search($search, $itemType, $page, $perPage, $shareType));
303
-	}
304
-
305
-	public static function dataSearchInvalid(): array {
306
-		return [
307
-			// Test invalid pagination
308
-			[[
309
-				'page' => 0,
310
-			], 'Invalid page'],
311
-			[[
312
-				'page' => '0',
313
-			], 'Invalid page'],
314
-			[[
315
-				'page' => -1,
316
-			], 'Invalid page'],
317
-
318
-			// Test invalid perPage
319
-			[[
320
-				'perPage' => 0,
321
-			], 'Invalid perPage argument'],
322
-			[[
323
-				'perPage' => '0',
324
-			], 'Invalid perPage argument'],
325
-			[[
326
-				'perPage' => -1,
327
-			], 'Invalid perPage argument'],
328
-		];
329
-	}
330
-
331
-	/**
332
-	 *
333
-	 * @param array $getData
334
-	 * @param string $message
335
-	 */
336
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataSearchInvalid')]
337
-	public function testSearchInvalid($getData, $message): void {
338
-		$page = $getData['page'] ?? 1;
339
-		$perPage = $getData['perPage'] ?? 200;
340
-
341
-		/** @var IConfig|MockObject $config */
342
-		$config = $this->createMock(IConfig::class);
343
-		$config->expects($this->never())
344
-			->method('getAppValue');
345
-
346
-		/** @var string */
347
-		$uid = 'test123';
348
-		/** @var IRequest|MockObject $request */
349
-		$request = $this->createMock(IRequest::class);
350
-		/** @var IURLGenerator|MockObject $urlGenerator */
351
-		$urlGenerator = $this->createMock(IURLGenerator::class);
352
-
353
-		/** @var MockObject|ShareesAPIController $sharees */
354
-		$sharees = $this->getMockBuilder('\OCA\Files_Sharing\Controller\ShareesAPIController')
355
-			->setConstructorArgs([
356
-				'files_sharing',
357
-				$request,
358
-				$uid,
359
-				$config,
360
-				$urlGenerator,
361
-				$this->shareManager,
362
-				$this->collaboratorSearch
363
-			])
364
-			->onlyMethods(['isRemoteSharingAllowed'])
365
-			->getMock();
366
-		$sharees->expects($this->never())
367
-			->method('isRemoteSharingAllowed');
368
-
369
-		$this->collaboratorSearch->expects($this->never())
370
-			->method('search');
371
-
372
-		try {
373
-			$sharees->search('', null, $page, $perPage, null);
374
-			$this->fail();
375
-		} catch (OCSBadRequestException $e) {
376
-			$this->assertEquals($message, $e->getMessage());
377
-		}
378
-	}
379
-
380
-	public static function dataIsRemoteSharingAllowed() {
381
-		return [
382
-			['file', true],
383
-			['folder', true],
384
-			['', false],
385
-			['contacts', false],
386
-		];
387
-	}
388
-
389
-	/**
390
-	 *
391
-	 * @param string $itemType
392
-	 * @param bool $expected
393
-	 */
394
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataIsRemoteSharingAllowed')]
395
-	public function testIsRemoteSharingAllowed($itemType, $expected): void {
396
-		$this->assertSame($expected, $this->invokePrivate($this->sharees, 'isRemoteSharingAllowed', [$itemType]));
397
-	}
398
-
399
-	public function testSearchSharingDisabled(): void {
400
-		$this->shareManager->expects($this->once())
401
-			->method('sharingDisabledForUser')
402
-			->with($this->uid)
403
-			->willReturn(true);
404
-
405
-		$this->config->expects($this->once())
406
-			->method('getSystemValueInt')
407
-			->with('sharing.minSearchStringLength', 0)
408
-			->willReturn(0);
409
-
410
-		$this->shareManager->expects($this->never())
411
-			->method('allowGroupSharing');
412
-
413
-		$this->assertInstanceOf(DataResponse::class, $this->sharees->search('', null, 1, 10, [], false));
414
-	}
415
-
416
-	public function testSearchNoItemType(): void {
417
-		$this->expectException(OCSBadRequestException::class);
418
-		$this->expectExceptionMessage('Missing itemType');
419
-
420
-		$this->sharees->search('', null, 1, 10, [], false);
421
-	}
422
-
423
-	public static function dataGetPaginationLink() {
424
-		return [
425
-			[1, '/ocs/v1.php', ['perPage' => 2], '<?perPage=2&page=2>; rel="next"'],
426
-			[10, '/ocs/v2.php', ['perPage' => 2], '<?perPage=2&page=11>; rel="next"'],
427
-		];
428
-	}
429
-
430
-	/**
431
-	 *
432
-	 * @param int $page
433
-	 * @param string $scriptName
434
-	 * @param array $params
435
-	 * @param array $expected
436
-	 */
437
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataGetPaginationLink')]
438
-	public function testGetPaginationLink($page, $scriptName, $params, $expected): void {
439
-		$this->request->expects($this->once())
440
-			->method('getScriptName')
441
-			->willReturn($scriptName);
442
-
443
-		$this->assertEquals($expected, $this->invokePrivate($this->sharees, 'getPaginationLink', [$page, $params]));
444
-	}
445
-
446
-	public static function dataIsV2() {
447
-		return [
448
-			['/ocs/v1.php', false],
449
-			['/ocs/v2.php', true],
450
-		];
451
-	}
452
-
453
-	/**
454
-	 *
455
-	 * @param string $scriptName
456
-	 * @param bool $expected
457
-	 */
458
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataIsV2')]
459
-	public function testIsV2($scriptName, $expected): void {
460
-		$this->request->expects($this->once())
461
-			->method('getScriptName')
462
-			->willReturn($scriptName);
463
-
464
-		$this->assertEquals($expected, $this->invokePrivate($this->sharees, 'isV2'));
465
-	}
31
+    /** @var ShareesAPIController */
32
+    protected $sharees;
33
+
34
+    /** @var string */
35
+    protected $uid;
36
+
37
+    /** @var IRequest|MockObject */
38
+    protected $request;
39
+
40
+    /** @var IManager|MockObject */
41
+    protected $shareManager;
42
+
43
+    /** @var ISearch|MockObject */
44
+    protected $collaboratorSearch;
45
+
46
+    /** @var IConfig|MockObject */
47
+    protected $config;
48
+
49
+    protected function setUp(): void {
50
+        parent::setUp();
51
+
52
+        $this->uid = 'test123';
53
+        $this->request = $this->createMock(IRequest::class);
54
+        $this->shareManager = $this->createMock(IManager::class);
55
+        $this->config = $this->createMock(IConfig::class);
56
+
57
+        /** @var IURLGenerator|MockObject $urlGeneratorMock */
58
+        $urlGeneratorMock = $this->createMock(IURLGenerator::class);
59
+
60
+        $this->collaboratorSearch = $this->createMock(ISearch::class);
61
+
62
+        $this->sharees = new ShareesAPIController(
63
+            'files_sharing',
64
+            $this->request,
65
+            $this->uid,
66
+            $this->config,
67
+            $urlGeneratorMock,
68
+            $this->shareManager,
69
+            $this->collaboratorSearch
70
+        );
71
+    }
72
+
73
+    public static function dataSearch(): array {
74
+        $noRemote = [IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_EMAIL];
75
+        $allTypes = [IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_REMOTE, IShare::TYPE_REMOTE_GROUP, IShare::TYPE_EMAIL];
76
+
77
+        return [
78
+            [[], '', 'yes', false, true, true, true, $noRemote, false, true, true],
79
+
80
+            // Test itemType
81
+            [[
82
+                'search' => '',
83
+            ], '', 'yes', false, true, true, true, $noRemote, false, true, true],
84
+            [[
85
+                'search' => 'foobar',
86
+            ], '', 'yes', false, true, true, true, $noRemote, false, true, true],
87
+            [[
88
+                'search' => 0,
89
+            ], '', 'yes', false, true, true, true, $noRemote, false, true, true],
90
+
91
+            // Test itemType
92
+            [[
93
+                'itemType' => '',
94
+            ], '', 'yes', false, true, true, true, $noRemote, false, true, true],
95
+            [[
96
+                'itemType' => 'folder',
97
+            ], '', 'yes', false, true, true, true, $allTypes, false, true, true],
98
+            [[
99
+                'itemType' => 0,
100
+            ], '', 'yes', false, true, true , true, $noRemote, false, true, true],
101
+            // Test shareType
102
+            [[
103
+                'itemType' => 'call',
104
+            ], '', 'yes', false, true, true, true, $noRemote, false, true, true],
105
+            [[
106
+                'itemType' => 'call',
107
+            ], '', 'yes', false, true, true, true, [0, 4], false, true, false],
108
+            [[
109
+                'itemType' => 'folder',
110
+            ], '', 'yes', false, true, true, true, $allTypes, false, true, true],
111
+            [[
112
+                'itemType' => 'folder',
113
+                'shareType' => 0,
114
+            ], '', 'yes', false, true, true, false, [0], false, true, true],
115
+            [[
116
+                'itemType' => 'folder',
117
+                'shareType' => '0',
118
+            ], '', 'yes', false, true, true, false, [0], false, true, true],
119
+            [[
120
+                'itemType' => 'folder',
121
+                'shareType' => 1,
122
+            ], '', 'yes', false, true, true, false, [1], false, true, true],
123
+            [[
124
+                'itemType' => 'folder',
125
+                'shareType' => 12,
126
+            ], '', 'yes', false, true, true, false, [], false, true, true],
127
+            [[
128
+                'itemType' => 'folder',
129
+                'shareType' => 'foobar',
130
+            ], '', 'yes', false, true, true, true, $allTypes, false, true, true],
131
+
132
+            [[
133
+                'itemType' => 'folder',
134
+                'shareType' => [0, 1, 2],
135
+            ], '', 'yes', false, false, false, false, [0, 1], false, true, true],
136
+            [[
137
+                'itemType' => 'folder',
138
+                'shareType' => [0, 1],
139
+            ], '', 'yes', false, false, false, false, [0, 1], false, true, true],
140
+            [[
141
+                'itemType' => 'folder',
142
+                'shareType' => $allTypes,
143
+            ], '', 'yes', false, true, true, true, $allTypes, false, true, true],
144
+            [[
145
+                'itemType' => 'folder',
146
+                'shareType' => $allTypes,
147
+            ], '', 'yes', false, false, false, false, [0, 1], false, true, true],
148
+            [[
149
+                'itemType' => 'folder',
150
+                'shareType' => $allTypes,
151
+            ], '', 'yes', false, true, false, false, [0, 6], false, true, false],
152
+            [[
153
+                'itemType' => 'folder',
154
+                'shareType' => $allTypes,
155
+            ], '', 'yes', false, false, false, true, [0, 4], false, true, false],
156
+            [[
157
+                'itemType' => 'folder',
158
+                'shareType' => $allTypes,
159
+            ], '', 'yes', false, true, true, false, [0, 6, 9], false, true, false],
160
+
161
+            // Test pagination
162
+            [[
163
+                'itemType' => 'folder',
164
+                'page' => 1,
165
+            ], '', 'yes', false, true, true, true, $allTypes, false, true, true],
166
+            [[
167
+                'itemType' => 'folder',
168
+                'page' => 10,
169
+            ], '', 'yes', false, true, true, true, $allTypes, false, true, true],
170
+
171
+            // Test perPage
172
+            [[
173
+                'itemType' => 'folder',
174
+                'perPage' => 1,
175
+            ], '', 'yes', false, true, true, true, $allTypes, false, true, true],
176
+            [[
177
+                'itemType' => 'folder',
178
+                'perPage' => 10,
179
+            ], '', 'yes', false, true, true, true, $allTypes, false, true, true],
180
+
181
+            // Test $shareWithGroupOnly setting
182
+            [[
183
+                'itemType' => 'folder',
184
+            ], 'no', 'yes', false, true, true, true, $allTypes, false, true, true],
185
+            [[
186
+                'itemType' => 'folder',
187
+            ], 'yes', 'yes', false, true, true, true, $allTypes, true, true, true],
188
+
189
+            // Test $shareeEnumeration setting
190
+            [[
191
+                'itemType' => 'folder',
192
+            ], 'no', 'yes', false, true, true, true, $allTypes, false, true, true],
193
+            [[
194
+                'itemType' => 'folder',
195
+            ], 'no', 'no', false, true, true, true, $allTypes, false, false, true],
196
+
197
+        ];
198
+    }
199
+
200
+    /**
201
+     *
202
+     * @param array $getData
203
+     * @param string $apiSetting
204
+     * @param string $enumSetting
205
+     * @param bool $remoteSharingEnabled
206
+     * @param bool $isRemoteGroupSharingEnabled
207
+     * @param bool $emailSharingEnabled
208
+     * @param array $shareTypes
209
+     * @param bool $shareWithGroupOnly
210
+     * @param bool $shareeEnumeration
211
+     * @param bool $allowGroupSharing
212
+     * @throws OCSBadRequestException
213
+     */
214
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataSearch')]
215
+    public function testSearch(
216
+        array $getData,
217
+        string $apiSetting,
218
+        string $enumSetting,
219
+        bool $sharingDisabledForUser,
220
+        bool $remoteSharingEnabled,
221
+        bool $isRemoteGroupSharingEnabled,
222
+        bool $emailSharingEnabled,
223
+        array $shareTypes,
224
+        bool $shareWithGroupOnly,
225
+        bool $shareeEnumeration,
226
+        bool $allowGroupSharing,
227
+    ): void {
228
+        $search = $getData['search'] ?? '';
229
+        $itemType = $getData['itemType'] ?? 'irrelevant';
230
+        $page = $getData['page'] ?? 1;
231
+        $perPage = $getData['perPage'] ?? 200;
232
+        $shareType = $getData['shareType'] ?? null;
233
+
234
+        $globalConfig = $this->createMock(GlobalScaleIConfig::class);
235
+        $globalConfig->expects(self::once())
236
+            ->method('isGlobalScaleEnabled')
237
+            ->willReturn(true);
238
+        $this->overwriteService(GlobalScaleIConfig::class, $globalConfig);
239
+
240
+        /** @var IConfig|MockObject $config */
241
+        $config = $this->createMock(IConfig::class);
242
+
243
+        $this->shareManager->expects($this->once())
244
+            ->method('allowGroupSharing')
245
+            ->willReturn($allowGroupSharing);
246
+
247
+        /** @var string */
248
+        $uid = 'test123';
249
+        /** @var IRequest|MockObject $request */
250
+        $request = $this->createMock(IRequest::class);
251
+        /** @var IURLGenerator|MockObject $urlGenerator */
252
+        $urlGenerator = $this->createMock(IURLGenerator::class);
253
+
254
+        /** @var MockObject|ShareesAPIController $sharees */
255
+        $sharees = $this->getMockBuilder(ShareesAPIController::class)
256
+            ->setConstructorArgs([
257
+                'files_sharing',
258
+                $request,
259
+                $uid,
260
+                $config,
261
+                $urlGenerator,
262
+                $this->shareManager,
263
+                $this->collaboratorSearch
264
+            ])
265
+            ->onlyMethods(['isRemoteSharingAllowed', 'isRemoteGroupSharingAllowed'])
266
+            ->getMock();
267
+
268
+        $expectedShareTypes = $shareTypes;
269
+        sort($expectedShareTypes);
270
+
271
+        $this->collaboratorSearch->expects($this->once())
272
+            ->method('search')
273
+            ->with($search, $expectedShareTypes, $this->anything(), $perPage, $perPage * ($page - 1))
274
+            ->willReturn([[], false]);
275
+
276
+        $sharees->expects($this->any())
277
+            ->method('isRemoteSharingAllowed')
278
+            ->with($itemType)
279
+            ->willReturn($remoteSharingEnabled);
280
+
281
+
282
+        $sharees->expects($this->any())
283
+            ->method('isRemoteGroupSharingAllowed')
284
+            ->with($itemType)
285
+            ->willReturn($isRemoteGroupSharingEnabled);
286
+
287
+        $this->shareManager->expects($this->any())
288
+            ->method('sharingDisabledForUser')
289
+            ->with($uid)
290
+            ->willReturn($sharingDisabledForUser);
291
+
292
+        $this->shareManager->expects($this->any())
293
+            ->method('shareProviderExists')
294
+            ->willReturnCallback(function ($shareType) use ($emailSharingEnabled) {
295
+                if ($shareType === IShare::TYPE_EMAIL) {
296
+                    return $emailSharingEnabled;
297
+                } else {
298
+                    return false;
299
+                }
300
+            });
301
+
302
+        $this->assertInstanceOf(DataResponse::class, $sharees->search($search, $itemType, $page, $perPage, $shareType));
303
+    }
304
+
305
+    public static function dataSearchInvalid(): array {
306
+        return [
307
+            // Test invalid pagination
308
+            [[
309
+                'page' => 0,
310
+            ], 'Invalid page'],
311
+            [[
312
+                'page' => '0',
313
+            ], 'Invalid page'],
314
+            [[
315
+                'page' => -1,
316
+            ], 'Invalid page'],
317
+
318
+            // Test invalid perPage
319
+            [[
320
+                'perPage' => 0,
321
+            ], 'Invalid perPage argument'],
322
+            [[
323
+                'perPage' => '0',
324
+            ], 'Invalid perPage argument'],
325
+            [[
326
+                'perPage' => -1,
327
+            ], 'Invalid perPage argument'],
328
+        ];
329
+    }
330
+
331
+    /**
332
+     *
333
+     * @param array $getData
334
+     * @param string $message
335
+     */
336
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataSearchInvalid')]
337
+    public function testSearchInvalid($getData, $message): void {
338
+        $page = $getData['page'] ?? 1;
339
+        $perPage = $getData['perPage'] ?? 200;
340
+
341
+        /** @var IConfig|MockObject $config */
342
+        $config = $this->createMock(IConfig::class);
343
+        $config->expects($this->never())
344
+            ->method('getAppValue');
345
+
346
+        /** @var string */
347
+        $uid = 'test123';
348
+        /** @var IRequest|MockObject $request */
349
+        $request = $this->createMock(IRequest::class);
350
+        /** @var IURLGenerator|MockObject $urlGenerator */
351
+        $urlGenerator = $this->createMock(IURLGenerator::class);
352
+
353
+        /** @var MockObject|ShareesAPIController $sharees */
354
+        $sharees = $this->getMockBuilder('\OCA\Files_Sharing\Controller\ShareesAPIController')
355
+            ->setConstructorArgs([
356
+                'files_sharing',
357
+                $request,
358
+                $uid,
359
+                $config,
360
+                $urlGenerator,
361
+                $this->shareManager,
362
+                $this->collaboratorSearch
363
+            ])
364
+            ->onlyMethods(['isRemoteSharingAllowed'])
365
+            ->getMock();
366
+        $sharees->expects($this->never())
367
+            ->method('isRemoteSharingAllowed');
368
+
369
+        $this->collaboratorSearch->expects($this->never())
370
+            ->method('search');
371
+
372
+        try {
373
+            $sharees->search('', null, $page, $perPage, null);
374
+            $this->fail();
375
+        } catch (OCSBadRequestException $e) {
376
+            $this->assertEquals($message, $e->getMessage());
377
+        }
378
+    }
379
+
380
+    public static function dataIsRemoteSharingAllowed() {
381
+        return [
382
+            ['file', true],
383
+            ['folder', true],
384
+            ['', false],
385
+            ['contacts', false],
386
+        ];
387
+    }
388
+
389
+    /**
390
+     *
391
+     * @param string $itemType
392
+     * @param bool $expected
393
+     */
394
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataIsRemoteSharingAllowed')]
395
+    public function testIsRemoteSharingAllowed($itemType, $expected): void {
396
+        $this->assertSame($expected, $this->invokePrivate($this->sharees, 'isRemoteSharingAllowed', [$itemType]));
397
+    }
398
+
399
+    public function testSearchSharingDisabled(): void {
400
+        $this->shareManager->expects($this->once())
401
+            ->method('sharingDisabledForUser')
402
+            ->with($this->uid)
403
+            ->willReturn(true);
404
+
405
+        $this->config->expects($this->once())
406
+            ->method('getSystemValueInt')
407
+            ->with('sharing.minSearchStringLength', 0)
408
+            ->willReturn(0);
409
+
410
+        $this->shareManager->expects($this->never())
411
+            ->method('allowGroupSharing');
412
+
413
+        $this->assertInstanceOf(DataResponse::class, $this->sharees->search('', null, 1, 10, [], false));
414
+    }
415
+
416
+    public function testSearchNoItemType(): void {
417
+        $this->expectException(OCSBadRequestException::class);
418
+        $this->expectExceptionMessage('Missing itemType');
419
+
420
+        $this->sharees->search('', null, 1, 10, [], false);
421
+    }
422
+
423
+    public static function dataGetPaginationLink() {
424
+        return [
425
+            [1, '/ocs/v1.php', ['perPage' => 2], '<?perPage=2&page=2>; rel="next"'],
426
+            [10, '/ocs/v2.php', ['perPage' => 2], '<?perPage=2&page=11>; rel="next"'],
427
+        ];
428
+    }
429
+
430
+    /**
431
+     *
432
+     * @param int $page
433
+     * @param string $scriptName
434
+     * @param array $params
435
+     * @param array $expected
436
+     */
437
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataGetPaginationLink')]
438
+    public function testGetPaginationLink($page, $scriptName, $params, $expected): void {
439
+        $this->request->expects($this->once())
440
+            ->method('getScriptName')
441
+            ->willReturn($scriptName);
442
+
443
+        $this->assertEquals($expected, $this->invokePrivate($this->sharees, 'getPaginationLink', [$page, $params]));
444
+    }
445
+
446
+    public static function dataIsV2() {
447
+        return [
448
+            ['/ocs/v1.php', false],
449
+            ['/ocs/v2.php', true],
450
+        ];
451
+    }
452
+
453
+    /**
454
+     *
455
+     * @param string $scriptName
456
+     * @param bool $expected
457
+     */
458
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataIsV2')]
459
+    public function testIsV2($scriptName, $expected): void {
460
+        $this->request->expects($this->once())
461
+            ->method('getScriptName')
462
+            ->willReturn($scriptName);
463
+
464
+        $this->assertEquals($expected, $this->invokePrivate($this->sharees, 'isV2'));
465
+    }
466 466
 }
Please login to merge, or discard this patch.
apps/files_sharing/tests/Controller/ShareControllerTest.php 2 patches
Indentation   +764 added lines, -764 removed lines patch added patch discarded remove patch
@@ -55,768 +55,768 @@
 block discarded – undo
55 55
  */
56 56
 class ShareControllerTest extends \Test\TestCase {
57 57
 
58
-	private string $user;
59
-	private string $oldUser;
60
-	private string $appName = 'files_sharing';
61
-	private ShareController $shareController;
62
-
63
-	private IL10N&MockObject $l10n;
64
-	private IConfig&MockObject $config;
65
-	private ISession&MockObject $session;
66
-	private Defaults&MockObject $defaults;
67
-	private IAppConfig&MockObject $appConfig;
68
-	private Manager&MockObject $shareManager;
69
-	private IPreview&MockObject $previewManager;
70
-	private IUserManager&MockObject $userManager;
71
-	private IInitialState&MockObject $initialState;
72
-	private IURLGenerator&MockObject $urlGenerator;
73
-	private ISecureRandom&MockObject $secureRandom;
74
-	private IAccountManager&MockObject $accountManager;
75
-	private IEventDispatcher&MockObject $eventDispatcher;
76
-	private FederatedShareProvider&MockObject $federatedShareProvider;
77
-	private IPublicShareTemplateFactory&MockObject $publicShareTemplateFactory;
78
-
79
-	protected function setUp(): void {
80
-		parent::setUp();
81
-		$this->appName = 'files_sharing';
82
-
83
-		$this->shareManager = $this->createMock(Manager::class);
84
-		$this->urlGenerator = $this->createMock(IURLGenerator::class);
85
-		$this->session = $this->createMock(ISession::class);
86
-		$this->previewManager = $this->createMock(IPreview::class);
87
-		$this->config = $this->createMock(IConfig::class);
88
-		$this->appConfig = $this->createMock(IAppConfig::class);
89
-		$this->userManager = $this->createMock(IUserManager::class);
90
-		$this->initialState = $this->createMock(IInitialState::class);
91
-		$this->federatedShareProvider = $this->createMock(FederatedShareProvider::class);
92
-		$this->federatedShareProvider->expects($this->any())
93
-			->method('isOutgoingServer2serverShareEnabled')->willReturn(true);
94
-		$this->federatedShareProvider->expects($this->any())
95
-			->method('isIncomingServer2serverShareEnabled')->willReturn(true);
96
-		$this->accountManager = $this->createMock(IAccountManager::class);
97
-		$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
98
-		$this->l10n = $this->createMock(IL10N::class);
99
-		$this->secureRandom = $this->createMock(ISecureRandom::class);
100
-		$this->defaults = $this->createMock(Defaults::class);
101
-		$this->publicShareTemplateFactory = $this->createMock(IPublicShareTemplateFactory::class);
102
-		$this->publicShareTemplateFactory
103
-			->expects($this->any())
104
-			->method('getProvider')
105
-			->willReturn(
106
-				new DefaultPublicShareTemplateProvider(
107
-					$this->userManager,
108
-					$this->accountManager,
109
-					$this->previewManager,
110
-					$this->federatedShareProvider,
111
-					$this->urlGenerator,
112
-					$this->eventDispatcher,
113
-					$this->l10n,
114
-					$this->defaults,
115
-					$this->config,
116
-					$this->createMock(IRequest::class),
117
-					$this->initialState,
118
-					$this->appConfig,
119
-				)
120
-			);
121
-
122
-		$this->shareController = new ShareController(
123
-			$this->appName,
124
-			$this->createMock(IRequest::class),
125
-			$this->config,
126
-			$this->urlGenerator,
127
-			$this->userManager,
128
-			$this->createMock(IManager::class),
129
-			$this->shareManager,
130
-			$this->session,
131
-			$this->previewManager,
132
-			$this->createMock(IRootFolder::class),
133
-			$this->federatedShareProvider,
134
-			$this->accountManager,
135
-			$this->eventDispatcher,
136
-			$this->l10n,
137
-			$this->secureRandom,
138
-			$this->defaults,
139
-			$this->publicShareTemplateFactory,
140
-		);
141
-
142
-
143
-		// Store current user
144
-		$this->oldUser = \OC_User::getUser();
145
-
146
-		// Create a dummy user
147
-		$this->user = Server::get(ISecureRandom::class)->generate(12, ISecureRandom::CHAR_LOWER);
148
-
149
-		Server::get(IUserManager::class)->createUser($this->user, $this->user);
150
-		\OC_Util::tearDownFS();
151
-		$this->loginAsUser($this->user);
152
-	}
153
-
154
-	protected function tearDown(): void {
155
-		\OC_Util::tearDownFS();
156
-		\OC_User::setUserId('');
157
-		Filesystem::tearDown();
158
-		$user = Server::get(IUserManager::class)->get($this->user);
159
-		if ($user !== null) {
160
-			$user->delete();
161
-		}
162
-		\OC_User::setIncognitoMode(false);
163
-
164
-		Server::get(ISession::class)->set('public_link_authenticated', '');
165
-
166
-		// Set old user
167
-		\OC_User::setUserId($this->oldUser);
168
-		\OC_Util::setupFS($this->oldUser);
169
-		parent::tearDown();
170
-	}
171
-
172
-	public function testShowShareInvalidToken(): void {
173
-		$this->shareController->setToken('invalidtoken');
174
-
175
-		$this->shareManager
176
-			->expects($this->once())
177
-			->method('getShareByToken')
178
-			->with('invalidtoken')
179
-			->willThrowException(new ShareNotFound());
180
-
181
-		$this->expectException(NotFoundException::class);
182
-
183
-		// Test without a not existing token
184
-		$this->shareController->showShare();
185
-	}
186
-
187
-	public function testShowShareNotAuthenticated(): void {
188
-		$this->shareController->setToken('validtoken');
189
-
190
-		$share = Server::get(\OCP\Share\IManager::class)->newShare();
191
-		$share->setPassword('password');
192
-
193
-		$this->shareManager
194
-			->expects($this->once())
195
-			->method('getShareByToken')
196
-			->with('validtoken')
197
-			->willReturn($share);
198
-
199
-		$this->expectException(NotFoundException::class);
200
-
201
-		// Test without a not existing token
202
-		$this->shareController->showShare();
203
-	}
204
-
205
-
206
-	public function testShowShare(): void {
207
-		$note = 'personal note';
208
-		$filename = 'file1.txt';
209
-
210
-		$this->shareController->setToken('token');
211
-
212
-		$owner = $this->createMock(IUser::class);
213
-		$owner->method('getDisplayName')->willReturn('ownerDisplay');
214
-		$owner->method('getUID')->willReturn('ownerUID');
215
-		$owner->method('isEnabled')->willReturn(true);
216
-
217
-		$initiator = $this->createMock(IUser::class);
218
-		$initiator->method('getDisplayName')->willReturn('initiatorDisplay');
219
-		$initiator->method('getUID')->willReturn('initiatorUID');
220
-		$initiator->method('isEnabled')->willReturn(true);
221
-
222
-		$file = $this->createMock(File::class);
223
-		$file->method('getName')->willReturn($filename);
224
-		$file->method('getMimetype')->willReturn('text/plain');
225
-		$file->method('getSize')->willReturn(33);
226
-		$file->method('isReadable')->willReturn(true);
227
-		$file->method('isShareable')->willReturn(true);
228
-		$file->method('getId')->willReturn(111);
229
-
230
-		$accountName = $this->createMock(IAccountProperty::class);
231
-		$accountName->method('getScope')
232
-			->willReturn(IAccountManager::SCOPE_PUBLISHED);
233
-		$account = $this->createMock(IAccount::class);
234
-		$account->method('getProperty')
235
-			->with(IAccountManager::PROPERTY_DISPLAYNAME)
236
-			->willReturn($accountName);
237
-		$this->accountManager->expects($this->once())
238
-			->method('getAccount')
239
-			->with($owner)
240
-			->willReturn($account);
241
-
242
-		/** @var Manager */
243
-		$manager = Server::get(Manager::class);
244
-		$share = $manager->newShare();
245
-		$share->setId(42)
246
-			->setPermissions(Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE)
247
-			->setPassword('password')
248
-			->setShareOwner('ownerUID')
249
-			->setSharedBy('initiatorUID')
250
-			->setNode($file)
251
-			->setNote($note)
252
-			->setTarget("/$filename")
253
-			->setToken('token');
254
-
255
-		$this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
256
-		$this->session->method('get')->with('public_link_authenticated')->willReturn('42');
257
-
258
-		$this->urlGenerator->expects(self::atLeast(2))
259
-			->method('linkToRouteAbsolute')
260
-			->willReturnMap([
261
-				// every file has the show show share url in the opengraph url prop
262
-				['files_sharing.sharecontroller.showShare', ['token' => 'token'], 'shareUrl'],
263
-				// this share is not an image to the default preview is used
264
-				['files_sharing.PublicPreview.getPreview', ['x' => 256, 'y' => 256, 'file' => $share->getTarget(), 'token' => 'token'], 'previewUrl'],
265
-			]);
266
-
267
-		$this->urlGenerator->expects($this->once())
268
-			->method('getAbsoluteURL')
269
-			->willReturnMap([
270
-				['/public.php/dav/files/token/?accept=zip', 'downloadUrl'],
271
-			]);
272
-
273
-		$this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true);
274
-
275
-		$this->config->method('getSystemValue')
276
-			->willReturnMap(
277
-				[
278
-					['max_filesize_animated_gifs_public_sharing', 10, 10],
279
-					['enable_previews', true, true],
280
-					['preview_max_x', 1024, 1024],
281
-					['preview_max_y', 1024, 1024],
282
-				]
283
-			);
284
-
285
-		$this->shareManager
286
-			->expects($this->once())
287
-			->method('getShareByToken')
288
-			->with('token')
289
-			->willReturn($share);
290
-
291
-		$this->userManager->method('get')->willReturnCallback(function (string $uid) use ($owner, $initiator) {
292
-			if ($uid === 'ownerUID') {
293
-				return $owner;
294
-			}
295
-			if ($uid === 'initiatorUID') {
296
-				return $initiator;
297
-			}
298
-			return null;
299
-		});
300
-
301
-		$this->eventDispatcher->method('dispatchTyped')->with(
302
-			$this->callback(function ($event) use ($share) {
303
-				if ($event instanceof BeforeTemplateRenderedEvent) {
304
-					return $event->getShare() === $share;
305
-				} else {
306
-					return true;
307
-				}
308
-			})
309
-		);
310
-
311
-		$this->l10n->expects($this->any())
312
-			->method('t')
313
-			->willReturnCallback(function ($text, $parameters) {
314
-				return vsprintf($text, $parameters);
315
-			});
316
-
317
-		$this->defaults->expects(self::any())
318
-			->method('getProductName')
319
-			->willReturn('Nextcloud');
320
-
321
-		// Ensure the correct initial state is setup
322
-		// Shared node is a file so this is a single file share:
323
-		$view = 'public-file-share';
324
-		// Set up initial state
325
-		$initialState = [];
326
-		$this->initialState->expects(self::any())
327
-			->method('provideInitialState')
328
-			->willReturnCallback(function ($key, $value) use (&$initialState): void {
329
-				$initialState[$key] = $value;
330
-			});
331
-		$expectedInitialState = [
332
-			'isPublic' => true,
333
-			'sharingToken' => 'token',
334
-			'sharePermissions' => (Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE),
335
-			'filename' => $filename,
336
-			'view' => $view,
337
-			'fileId' => 111,
338
-			'owner' => 'ownerUID',
339
-			'ownerDisplayName' => 'ownerDisplay',
340
-			'isFileRequest' => false,
341
-		];
342
-
343
-		$response = $this->shareController->showShare();
344
-
345
-		$this->assertEquals($expectedInitialState, $initialState);
346
-
347
-		$csp = new ContentSecurityPolicy();
348
-		$csp->addAllowedFrameDomain('\'self\'');
349
-		$expectedResponse = new PublicTemplateResponse('files', 'index');
350
-		$expectedResponse->setParams(['pageTitle' => $filename]);
351
-		$expectedResponse->setContentSecurityPolicy($csp);
352
-		$expectedResponse->setHeaderTitle($filename);
353
-		$expectedResponse->setHeaderDetails('shared by ownerDisplay');
354
-		$expectedResponse->setHeaderActions([
355
-			new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download', 'downloadUrl', 0, '33'),
356
-			new ExternalShareMenuAction($this->l10n->t('Add to your Nextcloud'), 'icon-external', 'owner', 'ownerDisplay', $filename),
357
-			new LinkMenuAction($this->l10n->t('Direct link'), 'icon-public', 'downloadUrl'),
358
-		]);
359
-
360
-		$this->assertEquals($expectedResponse, $response);
361
-	}
362
-
363
-	public function testShowFileDropShare(): void {
364
-		$filename = 'folder1';
365
-
366
-		$this->shareController->setToken('token');
367
-
368
-		$owner = $this->createMock(IUser::class);
369
-		$owner->method('getDisplayName')->willReturn('ownerDisplay');
370
-		$owner->method('getUID')->willReturn('ownerUID');
371
-		$owner->method('isEnabled')->willReturn(true);
372
-
373
-		$initiator = $this->createMock(IUser::class);
374
-		$initiator->method('getDisplayName')->willReturn('initiatorDisplay');
375
-		$initiator->method('getUID')->willReturn('initiatorUID');
376
-		$initiator->method('isEnabled')->willReturn(true);
377
-
378
-		$file = $this->createMock(Folder::class);
379
-		$file->method('isReadable')->willReturn(true);
380
-		$file->method('isShareable')->willReturn(true);
381
-		$file->method('getId')->willReturn(1234);
382
-		$file->method('getName')->willReturn($filename);
383
-
384
-		$accountName = $this->createMock(IAccountProperty::class);
385
-		$accountName->method('getScope')
386
-			->willReturn(IAccountManager::SCOPE_PUBLISHED);
387
-		$account = $this->createMock(IAccount::class);
388
-		$account->method('getProperty')
389
-			->with(IAccountManager::PROPERTY_DISPLAYNAME)
390
-			->willReturn($accountName);
391
-		$this->accountManager->expects($this->once())
392
-			->method('getAccount')
393
-			->with($owner)
394
-			->willReturn($account);
395
-
396
-		/** @var Manager */
397
-		$manager = Server::get(Manager::class);
398
-		$share = $manager->newShare();
399
-		$share->setId(42)
400
-			->setPermissions(Constants::PERMISSION_CREATE)
401
-			->setPassword('password')
402
-			->setShareOwner('ownerUID')
403
-			->setSharedBy('initiatorUID')
404
-			->setNote('The note')
405
-			->setLabel('A label')
406
-			->setNode($file)
407
-			->setTarget("/$filename")
408
-			->setToken('token');
409
-
410
-		$this->appConfig
411
-			->expects($this->once())
412
-			->method('getValueString')
413
-			->with('core', 'shareapi_public_link_disclaimertext', '')
414
-			->willReturn('My disclaimer text');
415
-
416
-		$this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
417
-		$this->session->method('get')->with('public_link_authenticated')->willReturn('42');
418
-
419
-		$this->urlGenerator->expects(self::atLeastOnce())
420
-			->method('linkToRouteAbsolute')
421
-			->willReturnMap([
422
-				// every file has the show show share url in the opengraph url prop
423
-				['files_sharing.sharecontroller.showShare', ['token' => 'token'], 'shareUrl'],
424
-				// there is no preview or folders so no other link for opengraph
425
-			]);
426
-
427
-		$this->config->method('getSystemValue')
428
-			->willReturnMap(
429
-				[
430
-					['max_filesize_animated_gifs_public_sharing', 10, 10],
431
-					['enable_previews', true, true],
432
-					['preview_max_x', 1024, 1024],
433
-					['preview_max_y', 1024, 1024],
434
-				]
435
-			);
436
-
437
-		$this->shareManager
438
-			->expects($this->once())
439
-			->method('getShareByToken')
440
-			->with('token')
441
-			->willReturn($share);
442
-
443
-		$this->userManager->method('get')->willReturnCallback(function (string $uid) use ($owner, $initiator) {
444
-			if ($uid === 'ownerUID') {
445
-				return $owner;
446
-			}
447
-			if ($uid === 'initiatorUID') {
448
-				return $initiator;
449
-			}
450
-			return null;
451
-		});
452
-
453
-		$this->eventDispatcher->method('dispatchTyped')->with(
454
-			$this->callback(function ($event) use ($share) {
455
-				if ($event instanceof BeforeTemplateRenderedEvent) {
456
-					return $event->getShare() === $share;
457
-				} else {
458
-					return true;
459
-				}
460
-			})
461
-		);
462
-
463
-		$this->l10n->expects($this->any())
464
-			->method('t')
465
-			->willReturnCallback(function ($text, $parameters) {
466
-				return vsprintf($text, $parameters);
467
-			});
468
-
469
-		// Set up initial state
470
-		$initialState = [];
471
-		$this->initialState->expects(self::any())
472
-			->method('provideInitialState')
473
-			->willReturnCallback(function ($key, $value) use (&$initialState): void {
474
-				$initialState[$key] = $value;
475
-			});
476
-		$expectedInitialState = [
477
-			'isPublic' => true,
478
-			'sharingToken' => 'token',
479
-			'sharePermissions' => Constants::PERMISSION_CREATE,
480
-			'filename' => $filename,
481
-			'view' => 'public-file-drop',
482
-			'disclaimer' => 'My disclaimer text',
483
-			'owner' => 'ownerUID',
484
-			'ownerDisplayName' => 'ownerDisplay',
485
-			'isFileRequest' => false,
486
-			'note' => 'The note',
487
-			'label' => 'A label',
488
-		];
489
-
490
-		$response = $this->shareController->showShare();
491
-
492
-		$this->assertEquals($expectedInitialState, $initialState);
493
-
494
-		$csp = new ContentSecurityPolicy();
495
-		$csp->addAllowedFrameDomain('\'self\'');
496
-		$expectedResponse = new PublicTemplateResponse('files', 'index');
497
-		$expectedResponse->setParams(['pageTitle' => 'A label']);
498
-		$expectedResponse->setContentSecurityPolicy($csp);
499
-		$expectedResponse->setHeaderTitle('A label');
500
-		$expectedResponse->setHeaderDetails('shared by ownerDisplay');
501
-		$expectedResponse->setHeaderActions([
502
-			new LinkMenuAction($this->l10n->t('Direct link'), 'icon-public', 'shareUrl'),
503
-		]);
504
-
505
-		$this->assertEquals($expectedResponse, $response);
506
-	}
507
-
508
-	public function testShowShareWithPrivateName(): void {
509
-		$note = 'personal note';
510
-		$filename = 'file1.txt';
511
-
512
-		$this->shareController->setToken('token');
513
-
514
-		$owner = $this->createMock(IUser::class);
515
-		$owner->method('getDisplayName')->willReturn('ownerDisplay');
516
-		$owner->method('getUID')->willReturn('ownerUID');
517
-		$owner->method('isEnabled')->willReturn(true);
518
-
519
-		$initiator = $this->createMock(IUser::class);
520
-		$initiator->method('getDisplayName')->willReturn('initiatorDisplay');
521
-		$initiator->method('getUID')->willReturn('initiatorUID');
522
-		$initiator->method('isEnabled')->willReturn(true);
523
-
524
-		$file = $this->createMock(File::class);
525
-		$file->method('getName')->willReturn($filename);
526
-		$file->method('getMimetype')->willReturn('text/plain');
527
-		$file->method('getSize')->willReturn(33);
528
-		$file->method('isReadable')->willReturn(true);
529
-		$file->method('isShareable')->willReturn(true);
530
-		$file->method('getId')->willReturn(111);
531
-
532
-		$accountName = $this->createMock(IAccountProperty::class);
533
-		$accountName->method('getScope')
534
-			->willReturn(IAccountManager::SCOPE_LOCAL);
535
-		$account = $this->createMock(IAccount::class);
536
-		$account->method('getProperty')
537
-			->with(IAccountManager::PROPERTY_DISPLAYNAME)
538
-			->willReturn($accountName);
539
-		$this->accountManager->expects($this->once())
540
-			->method('getAccount')
541
-			->with($owner)
542
-			->willReturn($account);
543
-
544
-		/** @var IShare */
545
-		$share = Server::get(Manager::class)->newShare();
546
-		$share->setId(42);
547
-		$share->setPassword('password')
548
-			->setShareOwner('ownerUID')
549
-			->setSharedBy('initiatorUID')
550
-			->setNode($file)
551
-			->setNote($note)
552
-			->setToken('token')
553
-			->setPermissions(Constants::PERMISSION_ALL & ~Constants::PERMISSION_SHARE)
554
-			->setTarget("/$filename");
555
-
556
-		$this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
557
-		$this->session->method('get')->with('public_link_authenticated')->willReturn('42');
558
-
559
-		$this->urlGenerator->expects(self::atLeast(2))
560
-			->method('linkToRouteAbsolute')
561
-			->willReturnMap([
562
-				// every file has the show show share url in the opengraph url prop
563
-				['files_sharing.sharecontroller.showShare', ['token' => 'token'], 'shareUrl'],
564
-				// this share is not an image to the default preview is used
565
-				['files_sharing.PublicPreview.getPreview', ['x' => 256, 'y' => 256, 'file' => $share->getTarget(), 'token' => 'token'], 'previewUrl'],
566
-			]);
567
-
568
-		$this->urlGenerator->expects($this->once())
569
-			->method('getAbsoluteURL')
570
-			->willReturnMap([
571
-				['/public.php/dav/files/token/?accept=zip', 'downloadUrl'],
572
-			]);
573
-
574
-		$this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true);
575
-
576
-		$this->config->method('getSystemValue')
577
-			->willReturnMap(
578
-				[
579
-					['max_filesize_animated_gifs_public_sharing', 10, 10],
580
-					['enable_previews', true, true],
581
-					['preview_max_x', 1024, 1024],
582
-					['preview_max_y', 1024, 1024],
583
-				]
584
-			);
585
-		$shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10);
586
-		$shareTmpl['previewEnabled'] = $this->config->getSystemValue('enable_previews', true);
587
-
588
-		$this->shareManager
589
-			->expects($this->once())
590
-			->method('getShareByToken')
591
-			->with('token')
592
-			->willReturn($share);
593
-
594
-		$this->userManager->method('get')->willReturnCallback(function (string $uid) use ($owner, $initiator) {
595
-			if ($uid === 'ownerUID') {
596
-				return $owner;
597
-			}
598
-			if ($uid === 'initiatorUID') {
599
-				return $initiator;
600
-			}
601
-			return null;
602
-		});
603
-
604
-		$this->eventDispatcher->method('dispatchTyped')->with(
605
-			$this->callback(function ($event) use ($share) {
606
-				if ($event instanceof BeforeTemplateRenderedEvent) {
607
-					return $event->getShare() === $share;
608
-				} else {
609
-					return true;
610
-				}
611
-			})
612
-		);
613
-
614
-		$this->l10n->expects($this->any())
615
-			->method('t')
616
-			->willReturnCallback(function ($text, $parameters) {
617
-				return vsprintf($text, $parameters);
618
-			});
619
-
620
-		$this->defaults->expects(self::any())
621
-			->method('getProductName')
622
-			->willReturn('Nextcloud');
623
-
624
-		$response = $this->shareController->showShare();
625
-
626
-		$csp = new ContentSecurityPolicy();
627
-		$csp->addAllowedFrameDomain('\'self\'');
628
-		$expectedResponse = new PublicTemplateResponse('files', 'index');
629
-		$expectedResponse->setParams(['pageTitle' => $filename]);
630
-		$expectedResponse->setContentSecurityPolicy($csp);
631
-		$expectedResponse->setHeaderTitle($filename);
632
-		$expectedResponse->setHeaderDetails('');
633
-		$expectedResponse->setHeaderActions([
634
-			new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download', 'downloadUrl', 0, '33'),
635
-			new ExternalShareMenuAction($this->l10n->t('Add to your Nextcloud'), 'icon-external', 'owner', 'ownerDisplay', $filename),
636
-			new LinkMenuAction($this->l10n->t('Direct link'), 'icon-public', 'downloadUrl'),
637
-		]);
638
-
639
-		$this->assertEquals($expectedResponse, $response);
640
-	}
641
-
642
-
643
-	public function testShowShareInvalid(): void {
644
-		$this->expectException(NotFoundException::class);
645
-
646
-		$filename = 'file1.txt';
647
-		$this->shareController->setToken('token');
648
-
649
-		$owner = $this->getMockBuilder(IUser::class)->getMock();
650
-		$owner->method('getDisplayName')->willReturn('ownerDisplay');
651
-		$owner->method('getUID')->willReturn('ownerUID');
652
-
653
-		$file = $this->getMockBuilder('OCP\Files\File')->getMock();
654
-		$file->method('getName')->willReturn($filename);
655
-		$file->method('getMimetype')->willReturn('text/plain');
656
-		$file->method('getSize')->willReturn(33);
657
-		$file->method('isShareable')->willReturn(false);
658
-		$file->method('isReadable')->willReturn(true);
659
-
660
-		$share = Server::get(\OCP\Share\IManager::class)->newShare();
661
-		$share->setId(42);
662
-		$share->setPassword('password')
663
-			->setShareOwner('ownerUID')
664
-			->setNode($file)
665
-			->setTarget("/$filename");
666
-
667
-		$this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
668
-		$this->session->method('get')->with('public_link_authenticated')->willReturn('42');
669
-
670
-		$this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true);
671
-
672
-		$this->config->method('getSystemValue')
673
-			->willReturnMap(
674
-				[
675
-					['max_filesize_animated_gifs_public_sharing', 10, 10],
676
-					['enable_previews', true, true],
677
-				]
678
-			);
679
-		$shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10);
680
-		$shareTmpl['previewEnabled'] = $this->config->getSystemValue('enable_previews', true);
681
-
682
-		$this->shareManager
683
-			->expects($this->once())
684
-			->method('getShareByToken')
685
-			->with('token')
686
-			->willReturn($share);
687
-
688
-		$this->userManager->method('get')->with('ownerUID')->willReturn($owner);
689
-
690
-		$this->shareController->showShare();
691
-	}
692
-
693
-	public function testDownloadShareWithCreateOnlyShare(): void {
694
-		$share = $this->getMockBuilder(IShare::class)->getMock();
695
-		$share->method('getPassword')->willReturn('password');
696
-		$share
697
-			->expects($this->once())
698
-			->method('getPermissions')
699
-			->willReturn(Constants::PERMISSION_CREATE);
700
-
701
-		$this->shareManager
702
-			->expects($this->once())
703
-			->method('getShareByToken')
704
-			->with('validtoken')
705
-			->willReturn($share);
706
-
707
-		// Test with a password protected share and no authentication
708
-		$response = $this->shareController->downloadShare('validtoken');
709
-		$expectedResponse = new DataResponse('Share has no read permission');
710
-		$this->assertEquals($expectedResponse, $response);
711
-	}
712
-
713
-	public function testDownloadShareWithoutDownloadPermission(): void {
714
-		$attributes = $this->createMock(IAttributes::class);
715
-		$attributes->expects(self::once())
716
-			->method('getAttribute')
717
-			->with('permissions', 'download')
718
-			->willReturn(false);
719
-
720
-		$share = $this->createMock(IShare::class);
721
-		$share->method('getPassword')->willReturn('password');
722
-		$share->expects(self::once())
723
-			->method('getPermissions')
724
-			->willReturn(Constants::PERMISSION_READ);
725
-		$share->expects(self::once())
726
-			->method('getAttributes')
727
-			->willReturn($attributes);
728
-
729
-		$this->shareManager
730
-			->expects(self::once())
731
-			->method('getShareByToken')
732
-			->with('validtoken')
733
-			->willReturn($share);
734
-
735
-		// Test with a password protected share and no authentication
736
-		$response = $this->shareController->downloadShare('validtoken');
737
-		$expectedResponse = new DataResponse('Share has no download permission');
738
-		$this->assertEquals($expectedResponse, $response);
739
-	}
740
-
741
-	public function testDisabledOwner(): void {
742
-		$this->shareController->setToken('token');
743
-
744
-		$owner = $this->getMockBuilder(IUser::class)->getMock();
745
-		$owner->method('isEnabled')->willReturn(false);
746
-
747
-		$initiator = $this->createMock(IUser::class);
748
-		$initiator->method('isEnabled')->willReturn(false);
749
-
750
-		/* @var MockObject|Folder $folder */
751
-		$folder = $this->createMock(Folder::class);
752
-
753
-		$share = Server::get(\OCP\Share\IManager::class)->newShare();
754
-		$share->setId(42);
755
-		$share->setPermissions(Constants::PERMISSION_CREATE)
756
-			->setShareOwner('ownerUID')
757
-			->setSharedBy('initiatorUID')
758
-			->setNode($folder)
759
-			->setTarget('/share');
760
-
761
-		$this->shareManager
762
-			->expects($this->once())
763
-			->method('getShareByToken')
764
-			->with('token')
765
-			->willReturn($share);
766
-
767
-		$this->userManager->method('get')->willReturnCallback(function (string $uid) use ($owner, $initiator) {
768
-			if ($uid === 'ownerUID') {
769
-				return $owner;
770
-			}
771
-			if ($uid === 'initiatorUID') {
772
-				return $initiator;
773
-			}
774
-			return null;
775
-		});
776
-
777
-		$this->expectException(NotFoundException::class);
778
-
779
-		$this->shareController->showShare();
780
-	}
781
-
782
-	public function testDisabledInitiator(): void {
783
-		$this->shareController->setToken('token');
784
-
785
-		$owner = $this->getMockBuilder(IUser::class)->getMock();
786
-		$owner->method('isEnabled')->willReturn(false);
787
-
788
-		$initiator = $this->createMock(IUser::class);
789
-		$initiator->method('isEnabled')->willReturn(true);
790
-
791
-		/* @var MockObject|Folder $folder */
792
-		$folder = $this->createMock(Folder::class);
793
-
794
-		$share = Server::get(\OCP\Share\IManager::class)->newShare();
795
-		$share->setId(42);
796
-		$share->setPermissions(Constants::PERMISSION_CREATE)
797
-			->setShareOwner('ownerUID')
798
-			->setSharedBy('initiatorUID')
799
-			->setNode($folder)
800
-			->setTarget('/share');
801
-
802
-		$this->shareManager
803
-			->expects($this->once())
804
-			->method('getShareByToken')
805
-			->with('token')
806
-			->willReturn($share);
807
-
808
-		$this->userManager->method('get')->willReturnCallback(function (string $uid) use ($owner, $initiator) {
809
-			if ($uid === 'ownerUID') {
810
-				return $owner;
811
-			}
812
-			if ($uid === 'initiatorUID') {
813
-				return $initiator;
814
-			}
815
-			return null;
816
-		});
817
-
818
-		$this->expectException(NotFoundException::class);
819
-
820
-		$this->shareController->showShare();
821
-	}
58
+    private string $user;
59
+    private string $oldUser;
60
+    private string $appName = 'files_sharing';
61
+    private ShareController $shareController;
62
+
63
+    private IL10N&MockObject $l10n;
64
+    private IConfig&MockObject $config;
65
+    private ISession&MockObject $session;
66
+    private Defaults&MockObject $defaults;
67
+    private IAppConfig&MockObject $appConfig;
68
+    private Manager&MockObject $shareManager;
69
+    private IPreview&MockObject $previewManager;
70
+    private IUserManager&MockObject $userManager;
71
+    private IInitialState&MockObject $initialState;
72
+    private IURLGenerator&MockObject $urlGenerator;
73
+    private ISecureRandom&MockObject $secureRandom;
74
+    private IAccountManager&MockObject $accountManager;
75
+    private IEventDispatcher&MockObject $eventDispatcher;
76
+    private FederatedShareProvider&MockObject $federatedShareProvider;
77
+    private IPublicShareTemplateFactory&MockObject $publicShareTemplateFactory;
78
+
79
+    protected function setUp(): void {
80
+        parent::setUp();
81
+        $this->appName = 'files_sharing';
82
+
83
+        $this->shareManager = $this->createMock(Manager::class);
84
+        $this->urlGenerator = $this->createMock(IURLGenerator::class);
85
+        $this->session = $this->createMock(ISession::class);
86
+        $this->previewManager = $this->createMock(IPreview::class);
87
+        $this->config = $this->createMock(IConfig::class);
88
+        $this->appConfig = $this->createMock(IAppConfig::class);
89
+        $this->userManager = $this->createMock(IUserManager::class);
90
+        $this->initialState = $this->createMock(IInitialState::class);
91
+        $this->federatedShareProvider = $this->createMock(FederatedShareProvider::class);
92
+        $this->federatedShareProvider->expects($this->any())
93
+            ->method('isOutgoingServer2serverShareEnabled')->willReturn(true);
94
+        $this->federatedShareProvider->expects($this->any())
95
+            ->method('isIncomingServer2serverShareEnabled')->willReturn(true);
96
+        $this->accountManager = $this->createMock(IAccountManager::class);
97
+        $this->eventDispatcher = $this->createMock(IEventDispatcher::class);
98
+        $this->l10n = $this->createMock(IL10N::class);
99
+        $this->secureRandom = $this->createMock(ISecureRandom::class);
100
+        $this->defaults = $this->createMock(Defaults::class);
101
+        $this->publicShareTemplateFactory = $this->createMock(IPublicShareTemplateFactory::class);
102
+        $this->publicShareTemplateFactory
103
+            ->expects($this->any())
104
+            ->method('getProvider')
105
+            ->willReturn(
106
+                new DefaultPublicShareTemplateProvider(
107
+                    $this->userManager,
108
+                    $this->accountManager,
109
+                    $this->previewManager,
110
+                    $this->federatedShareProvider,
111
+                    $this->urlGenerator,
112
+                    $this->eventDispatcher,
113
+                    $this->l10n,
114
+                    $this->defaults,
115
+                    $this->config,
116
+                    $this->createMock(IRequest::class),
117
+                    $this->initialState,
118
+                    $this->appConfig,
119
+                )
120
+            );
121
+
122
+        $this->shareController = new ShareController(
123
+            $this->appName,
124
+            $this->createMock(IRequest::class),
125
+            $this->config,
126
+            $this->urlGenerator,
127
+            $this->userManager,
128
+            $this->createMock(IManager::class),
129
+            $this->shareManager,
130
+            $this->session,
131
+            $this->previewManager,
132
+            $this->createMock(IRootFolder::class),
133
+            $this->federatedShareProvider,
134
+            $this->accountManager,
135
+            $this->eventDispatcher,
136
+            $this->l10n,
137
+            $this->secureRandom,
138
+            $this->defaults,
139
+            $this->publicShareTemplateFactory,
140
+        );
141
+
142
+
143
+        // Store current user
144
+        $this->oldUser = \OC_User::getUser();
145
+
146
+        // Create a dummy user
147
+        $this->user = Server::get(ISecureRandom::class)->generate(12, ISecureRandom::CHAR_LOWER);
148
+
149
+        Server::get(IUserManager::class)->createUser($this->user, $this->user);
150
+        \OC_Util::tearDownFS();
151
+        $this->loginAsUser($this->user);
152
+    }
153
+
154
+    protected function tearDown(): void {
155
+        \OC_Util::tearDownFS();
156
+        \OC_User::setUserId('');
157
+        Filesystem::tearDown();
158
+        $user = Server::get(IUserManager::class)->get($this->user);
159
+        if ($user !== null) {
160
+            $user->delete();
161
+        }
162
+        \OC_User::setIncognitoMode(false);
163
+
164
+        Server::get(ISession::class)->set('public_link_authenticated', '');
165
+
166
+        // Set old user
167
+        \OC_User::setUserId($this->oldUser);
168
+        \OC_Util::setupFS($this->oldUser);
169
+        parent::tearDown();
170
+    }
171
+
172
+    public function testShowShareInvalidToken(): void {
173
+        $this->shareController->setToken('invalidtoken');
174
+
175
+        $this->shareManager
176
+            ->expects($this->once())
177
+            ->method('getShareByToken')
178
+            ->with('invalidtoken')
179
+            ->willThrowException(new ShareNotFound());
180
+
181
+        $this->expectException(NotFoundException::class);
182
+
183
+        // Test without a not existing token
184
+        $this->shareController->showShare();
185
+    }
186
+
187
+    public function testShowShareNotAuthenticated(): void {
188
+        $this->shareController->setToken('validtoken');
189
+
190
+        $share = Server::get(\OCP\Share\IManager::class)->newShare();
191
+        $share->setPassword('password');
192
+
193
+        $this->shareManager
194
+            ->expects($this->once())
195
+            ->method('getShareByToken')
196
+            ->with('validtoken')
197
+            ->willReturn($share);
198
+
199
+        $this->expectException(NotFoundException::class);
200
+
201
+        // Test without a not existing token
202
+        $this->shareController->showShare();
203
+    }
204
+
205
+
206
+    public function testShowShare(): void {
207
+        $note = 'personal note';
208
+        $filename = 'file1.txt';
209
+
210
+        $this->shareController->setToken('token');
211
+
212
+        $owner = $this->createMock(IUser::class);
213
+        $owner->method('getDisplayName')->willReturn('ownerDisplay');
214
+        $owner->method('getUID')->willReturn('ownerUID');
215
+        $owner->method('isEnabled')->willReturn(true);
216
+
217
+        $initiator = $this->createMock(IUser::class);
218
+        $initiator->method('getDisplayName')->willReturn('initiatorDisplay');
219
+        $initiator->method('getUID')->willReturn('initiatorUID');
220
+        $initiator->method('isEnabled')->willReturn(true);
221
+
222
+        $file = $this->createMock(File::class);
223
+        $file->method('getName')->willReturn($filename);
224
+        $file->method('getMimetype')->willReturn('text/plain');
225
+        $file->method('getSize')->willReturn(33);
226
+        $file->method('isReadable')->willReturn(true);
227
+        $file->method('isShareable')->willReturn(true);
228
+        $file->method('getId')->willReturn(111);
229
+
230
+        $accountName = $this->createMock(IAccountProperty::class);
231
+        $accountName->method('getScope')
232
+            ->willReturn(IAccountManager::SCOPE_PUBLISHED);
233
+        $account = $this->createMock(IAccount::class);
234
+        $account->method('getProperty')
235
+            ->with(IAccountManager::PROPERTY_DISPLAYNAME)
236
+            ->willReturn($accountName);
237
+        $this->accountManager->expects($this->once())
238
+            ->method('getAccount')
239
+            ->with($owner)
240
+            ->willReturn($account);
241
+
242
+        /** @var Manager */
243
+        $manager = Server::get(Manager::class);
244
+        $share = $manager->newShare();
245
+        $share->setId(42)
246
+            ->setPermissions(Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE)
247
+            ->setPassword('password')
248
+            ->setShareOwner('ownerUID')
249
+            ->setSharedBy('initiatorUID')
250
+            ->setNode($file)
251
+            ->setNote($note)
252
+            ->setTarget("/$filename")
253
+            ->setToken('token');
254
+
255
+        $this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
256
+        $this->session->method('get')->with('public_link_authenticated')->willReturn('42');
257
+
258
+        $this->urlGenerator->expects(self::atLeast(2))
259
+            ->method('linkToRouteAbsolute')
260
+            ->willReturnMap([
261
+                // every file has the show show share url in the opengraph url prop
262
+                ['files_sharing.sharecontroller.showShare', ['token' => 'token'], 'shareUrl'],
263
+                // this share is not an image to the default preview is used
264
+                ['files_sharing.PublicPreview.getPreview', ['x' => 256, 'y' => 256, 'file' => $share->getTarget(), 'token' => 'token'], 'previewUrl'],
265
+            ]);
266
+
267
+        $this->urlGenerator->expects($this->once())
268
+            ->method('getAbsoluteURL')
269
+            ->willReturnMap([
270
+                ['/public.php/dav/files/token/?accept=zip', 'downloadUrl'],
271
+            ]);
272
+
273
+        $this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true);
274
+
275
+        $this->config->method('getSystemValue')
276
+            ->willReturnMap(
277
+                [
278
+                    ['max_filesize_animated_gifs_public_sharing', 10, 10],
279
+                    ['enable_previews', true, true],
280
+                    ['preview_max_x', 1024, 1024],
281
+                    ['preview_max_y', 1024, 1024],
282
+                ]
283
+            );
284
+
285
+        $this->shareManager
286
+            ->expects($this->once())
287
+            ->method('getShareByToken')
288
+            ->with('token')
289
+            ->willReturn($share);
290
+
291
+        $this->userManager->method('get')->willReturnCallback(function (string $uid) use ($owner, $initiator) {
292
+            if ($uid === 'ownerUID') {
293
+                return $owner;
294
+            }
295
+            if ($uid === 'initiatorUID') {
296
+                return $initiator;
297
+            }
298
+            return null;
299
+        });
300
+
301
+        $this->eventDispatcher->method('dispatchTyped')->with(
302
+            $this->callback(function ($event) use ($share) {
303
+                if ($event instanceof BeforeTemplateRenderedEvent) {
304
+                    return $event->getShare() === $share;
305
+                } else {
306
+                    return true;
307
+                }
308
+            })
309
+        );
310
+
311
+        $this->l10n->expects($this->any())
312
+            ->method('t')
313
+            ->willReturnCallback(function ($text, $parameters) {
314
+                return vsprintf($text, $parameters);
315
+            });
316
+
317
+        $this->defaults->expects(self::any())
318
+            ->method('getProductName')
319
+            ->willReturn('Nextcloud');
320
+
321
+        // Ensure the correct initial state is setup
322
+        // Shared node is a file so this is a single file share:
323
+        $view = 'public-file-share';
324
+        // Set up initial state
325
+        $initialState = [];
326
+        $this->initialState->expects(self::any())
327
+            ->method('provideInitialState')
328
+            ->willReturnCallback(function ($key, $value) use (&$initialState): void {
329
+                $initialState[$key] = $value;
330
+            });
331
+        $expectedInitialState = [
332
+            'isPublic' => true,
333
+            'sharingToken' => 'token',
334
+            'sharePermissions' => (Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE),
335
+            'filename' => $filename,
336
+            'view' => $view,
337
+            'fileId' => 111,
338
+            'owner' => 'ownerUID',
339
+            'ownerDisplayName' => 'ownerDisplay',
340
+            'isFileRequest' => false,
341
+        ];
342
+
343
+        $response = $this->shareController->showShare();
344
+
345
+        $this->assertEquals($expectedInitialState, $initialState);
346
+
347
+        $csp = new ContentSecurityPolicy();
348
+        $csp->addAllowedFrameDomain('\'self\'');
349
+        $expectedResponse = new PublicTemplateResponse('files', 'index');
350
+        $expectedResponse->setParams(['pageTitle' => $filename]);
351
+        $expectedResponse->setContentSecurityPolicy($csp);
352
+        $expectedResponse->setHeaderTitle($filename);
353
+        $expectedResponse->setHeaderDetails('shared by ownerDisplay');
354
+        $expectedResponse->setHeaderActions([
355
+            new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download', 'downloadUrl', 0, '33'),
356
+            new ExternalShareMenuAction($this->l10n->t('Add to your Nextcloud'), 'icon-external', 'owner', 'ownerDisplay', $filename),
357
+            new LinkMenuAction($this->l10n->t('Direct link'), 'icon-public', 'downloadUrl'),
358
+        ]);
359
+
360
+        $this->assertEquals($expectedResponse, $response);
361
+    }
362
+
363
+    public function testShowFileDropShare(): void {
364
+        $filename = 'folder1';
365
+
366
+        $this->shareController->setToken('token');
367
+
368
+        $owner = $this->createMock(IUser::class);
369
+        $owner->method('getDisplayName')->willReturn('ownerDisplay');
370
+        $owner->method('getUID')->willReturn('ownerUID');
371
+        $owner->method('isEnabled')->willReturn(true);
372
+
373
+        $initiator = $this->createMock(IUser::class);
374
+        $initiator->method('getDisplayName')->willReturn('initiatorDisplay');
375
+        $initiator->method('getUID')->willReturn('initiatorUID');
376
+        $initiator->method('isEnabled')->willReturn(true);
377
+
378
+        $file = $this->createMock(Folder::class);
379
+        $file->method('isReadable')->willReturn(true);
380
+        $file->method('isShareable')->willReturn(true);
381
+        $file->method('getId')->willReturn(1234);
382
+        $file->method('getName')->willReturn($filename);
383
+
384
+        $accountName = $this->createMock(IAccountProperty::class);
385
+        $accountName->method('getScope')
386
+            ->willReturn(IAccountManager::SCOPE_PUBLISHED);
387
+        $account = $this->createMock(IAccount::class);
388
+        $account->method('getProperty')
389
+            ->with(IAccountManager::PROPERTY_DISPLAYNAME)
390
+            ->willReturn($accountName);
391
+        $this->accountManager->expects($this->once())
392
+            ->method('getAccount')
393
+            ->with($owner)
394
+            ->willReturn($account);
395
+
396
+        /** @var Manager */
397
+        $manager = Server::get(Manager::class);
398
+        $share = $manager->newShare();
399
+        $share->setId(42)
400
+            ->setPermissions(Constants::PERMISSION_CREATE)
401
+            ->setPassword('password')
402
+            ->setShareOwner('ownerUID')
403
+            ->setSharedBy('initiatorUID')
404
+            ->setNote('The note')
405
+            ->setLabel('A label')
406
+            ->setNode($file)
407
+            ->setTarget("/$filename")
408
+            ->setToken('token');
409
+
410
+        $this->appConfig
411
+            ->expects($this->once())
412
+            ->method('getValueString')
413
+            ->with('core', 'shareapi_public_link_disclaimertext', '')
414
+            ->willReturn('My disclaimer text');
415
+
416
+        $this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
417
+        $this->session->method('get')->with('public_link_authenticated')->willReturn('42');
418
+
419
+        $this->urlGenerator->expects(self::atLeastOnce())
420
+            ->method('linkToRouteAbsolute')
421
+            ->willReturnMap([
422
+                // every file has the show show share url in the opengraph url prop
423
+                ['files_sharing.sharecontroller.showShare', ['token' => 'token'], 'shareUrl'],
424
+                // there is no preview or folders so no other link for opengraph
425
+            ]);
426
+
427
+        $this->config->method('getSystemValue')
428
+            ->willReturnMap(
429
+                [
430
+                    ['max_filesize_animated_gifs_public_sharing', 10, 10],
431
+                    ['enable_previews', true, true],
432
+                    ['preview_max_x', 1024, 1024],
433
+                    ['preview_max_y', 1024, 1024],
434
+                ]
435
+            );
436
+
437
+        $this->shareManager
438
+            ->expects($this->once())
439
+            ->method('getShareByToken')
440
+            ->with('token')
441
+            ->willReturn($share);
442
+
443
+        $this->userManager->method('get')->willReturnCallback(function (string $uid) use ($owner, $initiator) {
444
+            if ($uid === 'ownerUID') {
445
+                return $owner;
446
+            }
447
+            if ($uid === 'initiatorUID') {
448
+                return $initiator;
449
+            }
450
+            return null;
451
+        });
452
+
453
+        $this->eventDispatcher->method('dispatchTyped')->with(
454
+            $this->callback(function ($event) use ($share) {
455
+                if ($event instanceof BeforeTemplateRenderedEvent) {
456
+                    return $event->getShare() === $share;
457
+                } else {
458
+                    return true;
459
+                }
460
+            })
461
+        );
462
+
463
+        $this->l10n->expects($this->any())
464
+            ->method('t')
465
+            ->willReturnCallback(function ($text, $parameters) {
466
+                return vsprintf($text, $parameters);
467
+            });
468
+
469
+        // Set up initial state
470
+        $initialState = [];
471
+        $this->initialState->expects(self::any())
472
+            ->method('provideInitialState')
473
+            ->willReturnCallback(function ($key, $value) use (&$initialState): void {
474
+                $initialState[$key] = $value;
475
+            });
476
+        $expectedInitialState = [
477
+            'isPublic' => true,
478
+            'sharingToken' => 'token',
479
+            'sharePermissions' => Constants::PERMISSION_CREATE,
480
+            'filename' => $filename,
481
+            'view' => 'public-file-drop',
482
+            'disclaimer' => 'My disclaimer text',
483
+            'owner' => 'ownerUID',
484
+            'ownerDisplayName' => 'ownerDisplay',
485
+            'isFileRequest' => false,
486
+            'note' => 'The note',
487
+            'label' => 'A label',
488
+        ];
489
+
490
+        $response = $this->shareController->showShare();
491
+
492
+        $this->assertEquals($expectedInitialState, $initialState);
493
+
494
+        $csp = new ContentSecurityPolicy();
495
+        $csp->addAllowedFrameDomain('\'self\'');
496
+        $expectedResponse = new PublicTemplateResponse('files', 'index');
497
+        $expectedResponse->setParams(['pageTitle' => 'A label']);
498
+        $expectedResponse->setContentSecurityPolicy($csp);
499
+        $expectedResponse->setHeaderTitle('A label');
500
+        $expectedResponse->setHeaderDetails('shared by ownerDisplay');
501
+        $expectedResponse->setHeaderActions([
502
+            new LinkMenuAction($this->l10n->t('Direct link'), 'icon-public', 'shareUrl'),
503
+        ]);
504
+
505
+        $this->assertEquals($expectedResponse, $response);
506
+    }
507
+
508
+    public function testShowShareWithPrivateName(): void {
509
+        $note = 'personal note';
510
+        $filename = 'file1.txt';
511
+
512
+        $this->shareController->setToken('token');
513
+
514
+        $owner = $this->createMock(IUser::class);
515
+        $owner->method('getDisplayName')->willReturn('ownerDisplay');
516
+        $owner->method('getUID')->willReturn('ownerUID');
517
+        $owner->method('isEnabled')->willReturn(true);
518
+
519
+        $initiator = $this->createMock(IUser::class);
520
+        $initiator->method('getDisplayName')->willReturn('initiatorDisplay');
521
+        $initiator->method('getUID')->willReturn('initiatorUID');
522
+        $initiator->method('isEnabled')->willReturn(true);
523
+
524
+        $file = $this->createMock(File::class);
525
+        $file->method('getName')->willReturn($filename);
526
+        $file->method('getMimetype')->willReturn('text/plain');
527
+        $file->method('getSize')->willReturn(33);
528
+        $file->method('isReadable')->willReturn(true);
529
+        $file->method('isShareable')->willReturn(true);
530
+        $file->method('getId')->willReturn(111);
531
+
532
+        $accountName = $this->createMock(IAccountProperty::class);
533
+        $accountName->method('getScope')
534
+            ->willReturn(IAccountManager::SCOPE_LOCAL);
535
+        $account = $this->createMock(IAccount::class);
536
+        $account->method('getProperty')
537
+            ->with(IAccountManager::PROPERTY_DISPLAYNAME)
538
+            ->willReturn($accountName);
539
+        $this->accountManager->expects($this->once())
540
+            ->method('getAccount')
541
+            ->with($owner)
542
+            ->willReturn($account);
543
+
544
+        /** @var IShare */
545
+        $share = Server::get(Manager::class)->newShare();
546
+        $share->setId(42);
547
+        $share->setPassword('password')
548
+            ->setShareOwner('ownerUID')
549
+            ->setSharedBy('initiatorUID')
550
+            ->setNode($file)
551
+            ->setNote($note)
552
+            ->setToken('token')
553
+            ->setPermissions(Constants::PERMISSION_ALL & ~Constants::PERMISSION_SHARE)
554
+            ->setTarget("/$filename");
555
+
556
+        $this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
557
+        $this->session->method('get')->with('public_link_authenticated')->willReturn('42');
558
+
559
+        $this->urlGenerator->expects(self::atLeast(2))
560
+            ->method('linkToRouteAbsolute')
561
+            ->willReturnMap([
562
+                // every file has the show show share url in the opengraph url prop
563
+                ['files_sharing.sharecontroller.showShare', ['token' => 'token'], 'shareUrl'],
564
+                // this share is not an image to the default preview is used
565
+                ['files_sharing.PublicPreview.getPreview', ['x' => 256, 'y' => 256, 'file' => $share->getTarget(), 'token' => 'token'], 'previewUrl'],
566
+            ]);
567
+
568
+        $this->urlGenerator->expects($this->once())
569
+            ->method('getAbsoluteURL')
570
+            ->willReturnMap([
571
+                ['/public.php/dav/files/token/?accept=zip', 'downloadUrl'],
572
+            ]);
573
+
574
+        $this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true);
575
+
576
+        $this->config->method('getSystemValue')
577
+            ->willReturnMap(
578
+                [
579
+                    ['max_filesize_animated_gifs_public_sharing', 10, 10],
580
+                    ['enable_previews', true, true],
581
+                    ['preview_max_x', 1024, 1024],
582
+                    ['preview_max_y', 1024, 1024],
583
+                ]
584
+            );
585
+        $shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10);
586
+        $shareTmpl['previewEnabled'] = $this->config->getSystemValue('enable_previews', true);
587
+
588
+        $this->shareManager
589
+            ->expects($this->once())
590
+            ->method('getShareByToken')
591
+            ->with('token')
592
+            ->willReturn($share);
593
+
594
+        $this->userManager->method('get')->willReturnCallback(function (string $uid) use ($owner, $initiator) {
595
+            if ($uid === 'ownerUID') {
596
+                return $owner;
597
+            }
598
+            if ($uid === 'initiatorUID') {
599
+                return $initiator;
600
+            }
601
+            return null;
602
+        });
603
+
604
+        $this->eventDispatcher->method('dispatchTyped')->with(
605
+            $this->callback(function ($event) use ($share) {
606
+                if ($event instanceof BeforeTemplateRenderedEvent) {
607
+                    return $event->getShare() === $share;
608
+                } else {
609
+                    return true;
610
+                }
611
+            })
612
+        );
613
+
614
+        $this->l10n->expects($this->any())
615
+            ->method('t')
616
+            ->willReturnCallback(function ($text, $parameters) {
617
+                return vsprintf($text, $parameters);
618
+            });
619
+
620
+        $this->defaults->expects(self::any())
621
+            ->method('getProductName')
622
+            ->willReturn('Nextcloud');
623
+
624
+        $response = $this->shareController->showShare();
625
+
626
+        $csp = new ContentSecurityPolicy();
627
+        $csp->addAllowedFrameDomain('\'self\'');
628
+        $expectedResponse = new PublicTemplateResponse('files', 'index');
629
+        $expectedResponse->setParams(['pageTitle' => $filename]);
630
+        $expectedResponse->setContentSecurityPolicy($csp);
631
+        $expectedResponse->setHeaderTitle($filename);
632
+        $expectedResponse->setHeaderDetails('');
633
+        $expectedResponse->setHeaderActions([
634
+            new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download', 'downloadUrl', 0, '33'),
635
+            new ExternalShareMenuAction($this->l10n->t('Add to your Nextcloud'), 'icon-external', 'owner', 'ownerDisplay', $filename),
636
+            new LinkMenuAction($this->l10n->t('Direct link'), 'icon-public', 'downloadUrl'),
637
+        ]);
638
+
639
+        $this->assertEquals($expectedResponse, $response);
640
+    }
641
+
642
+
643
+    public function testShowShareInvalid(): void {
644
+        $this->expectException(NotFoundException::class);
645
+
646
+        $filename = 'file1.txt';
647
+        $this->shareController->setToken('token');
648
+
649
+        $owner = $this->getMockBuilder(IUser::class)->getMock();
650
+        $owner->method('getDisplayName')->willReturn('ownerDisplay');
651
+        $owner->method('getUID')->willReturn('ownerUID');
652
+
653
+        $file = $this->getMockBuilder('OCP\Files\File')->getMock();
654
+        $file->method('getName')->willReturn($filename);
655
+        $file->method('getMimetype')->willReturn('text/plain');
656
+        $file->method('getSize')->willReturn(33);
657
+        $file->method('isShareable')->willReturn(false);
658
+        $file->method('isReadable')->willReturn(true);
659
+
660
+        $share = Server::get(\OCP\Share\IManager::class)->newShare();
661
+        $share->setId(42);
662
+        $share->setPassword('password')
663
+            ->setShareOwner('ownerUID')
664
+            ->setNode($file)
665
+            ->setTarget("/$filename");
666
+
667
+        $this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
668
+        $this->session->method('get')->with('public_link_authenticated')->willReturn('42');
669
+
670
+        $this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true);
671
+
672
+        $this->config->method('getSystemValue')
673
+            ->willReturnMap(
674
+                [
675
+                    ['max_filesize_animated_gifs_public_sharing', 10, 10],
676
+                    ['enable_previews', true, true],
677
+                ]
678
+            );
679
+        $shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10);
680
+        $shareTmpl['previewEnabled'] = $this->config->getSystemValue('enable_previews', true);
681
+
682
+        $this->shareManager
683
+            ->expects($this->once())
684
+            ->method('getShareByToken')
685
+            ->with('token')
686
+            ->willReturn($share);
687
+
688
+        $this->userManager->method('get')->with('ownerUID')->willReturn($owner);
689
+
690
+        $this->shareController->showShare();
691
+    }
692
+
693
+    public function testDownloadShareWithCreateOnlyShare(): void {
694
+        $share = $this->getMockBuilder(IShare::class)->getMock();
695
+        $share->method('getPassword')->willReturn('password');
696
+        $share
697
+            ->expects($this->once())
698
+            ->method('getPermissions')
699
+            ->willReturn(Constants::PERMISSION_CREATE);
700
+
701
+        $this->shareManager
702
+            ->expects($this->once())
703
+            ->method('getShareByToken')
704
+            ->with('validtoken')
705
+            ->willReturn($share);
706
+
707
+        // Test with a password protected share and no authentication
708
+        $response = $this->shareController->downloadShare('validtoken');
709
+        $expectedResponse = new DataResponse('Share has no read permission');
710
+        $this->assertEquals($expectedResponse, $response);
711
+    }
712
+
713
+    public function testDownloadShareWithoutDownloadPermission(): void {
714
+        $attributes = $this->createMock(IAttributes::class);
715
+        $attributes->expects(self::once())
716
+            ->method('getAttribute')
717
+            ->with('permissions', 'download')
718
+            ->willReturn(false);
719
+
720
+        $share = $this->createMock(IShare::class);
721
+        $share->method('getPassword')->willReturn('password');
722
+        $share->expects(self::once())
723
+            ->method('getPermissions')
724
+            ->willReturn(Constants::PERMISSION_READ);
725
+        $share->expects(self::once())
726
+            ->method('getAttributes')
727
+            ->willReturn($attributes);
728
+
729
+        $this->shareManager
730
+            ->expects(self::once())
731
+            ->method('getShareByToken')
732
+            ->with('validtoken')
733
+            ->willReturn($share);
734
+
735
+        // Test with a password protected share and no authentication
736
+        $response = $this->shareController->downloadShare('validtoken');
737
+        $expectedResponse = new DataResponse('Share has no download permission');
738
+        $this->assertEquals($expectedResponse, $response);
739
+    }
740
+
741
+    public function testDisabledOwner(): void {
742
+        $this->shareController->setToken('token');
743
+
744
+        $owner = $this->getMockBuilder(IUser::class)->getMock();
745
+        $owner->method('isEnabled')->willReturn(false);
746
+
747
+        $initiator = $this->createMock(IUser::class);
748
+        $initiator->method('isEnabled')->willReturn(false);
749
+
750
+        /* @var MockObject|Folder $folder */
751
+        $folder = $this->createMock(Folder::class);
752
+
753
+        $share = Server::get(\OCP\Share\IManager::class)->newShare();
754
+        $share->setId(42);
755
+        $share->setPermissions(Constants::PERMISSION_CREATE)
756
+            ->setShareOwner('ownerUID')
757
+            ->setSharedBy('initiatorUID')
758
+            ->setNode($folder)
759
+            ->setTarget('/share');
760
+
761
+        $this->shareManager
762
+            ->expects($this->once())
763
+            ->method('getShareByToken')
764
+            ->with('token')
765
+            ->willReturn($share);
766
+
767
+        $this->userManager->method('get')->willReturnCallback(function (string $uid) use ($owner, $initiator) {
768
+            if ($uid === 'ownerUID') {
769
+                return $owner;
770
+            }
771
+            if ($uid === 'initiatorUID') {
772
+                return $initiator;
773
+            }
774
+            return null;
775
+        });
776
+
777
+        $this->expectException(NotFoundException::class);
778
+
779
+        $this->shareController->showShare();
780
+    }
781
+
782
+    public function testDisabledInitiator(): void {
783
+        $this->shareController->setToken('token');
784
+
785
+        $owner = $this->getMockBuilder(IUser::class)->getMock();
786
+        $owner->method('isEnabled')->willReturn(false);
787
+
788
+        $initiator = $this->createMock(IUser::class);
789
+        $initiator->method('isEnabled')->willReturn(true);
790
+
791
+        /* @var MockObject|Folder $folder */
792
+        $folder = $this->createMock(Folder::class);
793
+
794
+        $share = Server::get(\OCP\Share\IManager::class)->newShare();
795
+        $share->setId(42);
796
+        $share->setPermissions(Constants::PERMISSION_CREATE)
797
+            ->setShareOwner('ownerUID')
798
+            ->setSharedBy('initiatorUID')
799
+            ->setNode($folder)
800
+            ->setTarget('/share');
801
+
802
+        $this->shareManager
803
+            ->expects($this->once())
804
+            ->method('getShareByToken')
805
+            ->with('token')
806
+            ->willReturn($share);
807
+
808
+        $this->userManager->method('get')->willReturnCallback(function (string $uid) use ($owner, $initiator) {
809
+            if ($uid === 'ownerUID') {
810
+                return $owner;
811
+            }
812
+            if ($uid === 'initiatorUID') {
813
+                return $initiator;
814
+            }
815
+            return null;
816
+        });
817
+
818
+        $this->expectException(NotFoundException::class);
819
+
820
+        $this->shareController->showShare();
821
+    }
822 822
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 			->with('token')
289 289
 			->willReturn($share);
290 290
 
291
-		$this->userManager->method('get')->willReturnCallback(function (string $uid) use ($owner, $initiator) {
291
+		$this->userManager->method('get')->willReturnCallback(function(string $uid) use ($owner, $initiator) {
292 292
 			if ($uid === 'ownerUID') {
293 293
 				return $owner;
294 294
 			}
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 		});
300 300
 
301 301
 		$this->eventDispatcher->method('dispatchTyped')->with(
302
-			$this->callback(function ($event) use ($share) {
302
+			$this->callback(function($event) use ($share) {
303 303
 				if ($event instanceof BeforeTemplateRenderedEvent) {
304 304
 					return $event->getShare() === $share;
305 305
 				} else {
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
 
311 311
 		$this->l10n->expects($this->any())
312 312
 			->method('t')
313
-			->willReturnCallback(function ($text, $parameters) {
313
+			->willReturnCallback(function($text, $parameters) {
314 314
 				return vsprintf($text, $parameters);
315 315
 			});
316 316
 
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 		$initialState = [];
326 326
 		$this->initialState->expects(self::any())
327 327
 			->method('provideInitialState')
328
-			->willReturnCallback(function ($key, $value) use (&$initialState): void {
328
+			->willReturnCallback(function($key, $value) use (&$initialState): void {
329 329
 				$initialState[$key] = $value;
330 330
 			});
331 331
 		$expectedInitialState = [
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
 			->with('token')
441 441
 			->willReturn($share);
442 442
 
443
-		$this->userManager->method('get')->willReturnCallback(function (string $uid) use ($owner, $initiator) {
443
+		$this->userManager->method('get')->willReturnCallback(function(string $uid) use ($owner, $initiator) {
444 444
 			if ($uid === 'ownerUID') {
445 445
 				return $owner;
446 446
 			}
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
 		});
452 452
 
453 453
 		$this->eventDispatcher->method('dispatchTyped')->with(
454
-			$this->callback(function ($event) use ($share) {
454
+			$this->callback(function($event) use ($share) {
455 455
 				if ($event instanceof BeforeTemplateRenderedEvent) {
456 456
 					return $event->getShare() === $share;
457 457
 				} else {
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
 
463 463
 		$this->l10n->expects($this->any())
464 464
 			->method('t')
465
-			->willReturnCallback(function ($text, $parameters) {
465
+			->willReturnCallback(function($text, $parameters) {
466 466
 				return vsprintf($text, $parameters);
467 467
 			});
468 468
 
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
 		$initialState = [];
471 471
 		$this->initialState->expects(self::any())
472 472
 			->method('provideInitialState')
473
-			->willReturnCallback(function ($key, $value) use (&$initialState): void {
473
+			->willReturnCallback(function($key, $value) use (&$initialState): void {
474 474
 				$initialState[$key] = $value;
475 475
 			});
476 476
 		$expectedInitialState = [
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
 			->with('token')
592 592
 			->willReturn($share);
593 593
 
594
-		$this->userManager->method('get')->willReturnCallback(function (string $uid) use ($owner, $initiator) {
594
+		$this->userManager->method('get')->willReturnCallback(function(string $uid) use ($owner, $initiator) {
595 595
 			if ($uid === 'ownerUID') {
596 596
 				return $owner;
597 597
 			}
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
 		});
603 603
 
604 604
 		$this->eventDispatcher->method('dispatchTyped')->with(
605
-			$this->callback(function ($event) use ($share) {
605
+			$this->callback(function($event) use ($share) {
606 606
 				if ($event instanceof BeforeTemplateRenderedEvent) {
607 607
 					return $event->getShare() === $share;
608 608
 				} else {
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
 
614 614
 		$this->l10n->expects($this->any())
615 615
 			->method('t')
616
-			->willReturnCallback(function ($text, $parameters) {
616
+			->willReturnCallback(function($text, $parameters) {
617 617
 				return vsprintf($text, $parameters);
618 618
 			});
619 619
 
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
 			->with('token')
765 765
 			->willReturn($share);
766 766
 
767
-		$this->userManager->method('get')->willReturnCallback(function (string $uid) use ($owner, $initiator) {
767
+		$this->userManager->method('get')->willReturnCallback(function(string $uid) use ($owner, $initiator) {
768 768
 			if ($uid === 'ownerUID') {
769 769
 				return $owner;
770 770
 			}
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
 			->with('token')
806 806
 			->willReturn($share);
807 807
 
808
-		$this->userManager->method('get')->willReturnCallback(function (string $uid) use ($owner, $initiator) {
808
+		$this->userManager->method('get')->willReturnCallback(function(string $uid) use ($owner, $initiator) {
809 809
 			if ($uid === 'ownerUID') {
810 810
 				return $owner;
811 811
 			}
Please login to merge, or discard this patch.
apps/files_sharing/tests/Controller/ShareAPIControllerTest.php 1 patch
Indentation   +5144 added lines, -5144 removed lines patch added patch discarded remove patch
@@ -58,504 +58,504 @@  discard block
 block discarded – undo
58 58
  */
59 59
 class ShareAPIControllerTest extends TestCase {
60 60
 
61
-	private string $appName = 'files_sharing';
62
-	private string $currentUser;
63
-
64
-	private ShareAPIController $ocs;
65
-
66
-	private IManager&MockObject $shareManager;
67
-	private IGroupManager&MockObject $groupManager;
68
-	private IUserManager&MockObject $userManager;
69
-	private IRequest&MockObject $request;
70
-	private IRootFolder&MockObject $rootFolder;
71
-	private IURLGenerator&MockObject $urlGenerator;
72
-	private IL10N&MockObject $l;
73
-	private IConfig&MockObject $config;
74
-	private IAppManager&MockObject $appManager;
75
-	private ContainerInterface&MockObject $serverContainer;
76
-	private IUserStatusManager&MockObject $userStatusManager;
77
-	private IPreview&MockObject $previewManager;
78
-	private IDateTimeZone&MockObject $dateTimeZone;
79
-	private LoggerInterface&MockObject $logger;
80
-	private IProviderFactory&MockObject $factory;
81
-	private IMailer&MockObject $mailer;
82
-	private ITagManager&MockObject $tagManager;
83
-
84
-	protected function setUp(): void {
85
-		$this->shareManager = $this->createMock(IManager::class);
86
-		$this->shareManager
87
-			->expects($this->any())
88
-			->method('shareApiEnabled')
89
-			->willReturn(true);
90
-		$this->shareManager
91
-			->expects($this->any())
92
-			->method('shareProviderExists')->willReturn(true);
93
-		$this->groupManager = $this->createMock(IGroupManager::class);
94
-		$this->userManager = $this->createMock(IUserManager::class);
95
-		$this->request = $this->createMock(IRequest::class);
96
-		$this->rootFolder = $this->createMock(IRootFolder::class);
97
-		$this->urlGenerator = $this->createMock(IURLGenerator::class);
98
-		$this->currentUser = 'currentUser';
99
-
100
-		$this->l = $this->createMock(IL10N::class);
101
-		$this->l->method('t')
102
-			->willReturnCallback(function ($text, $parameters = []) {
103
-				return vsprintf($text, $parameters);
104
-			});
105
-		$this->config = $this->createMock(IConfig::class);
106
-		$this->appManager = $this->createMock(IAppManager::class);
107
-		$this->serverContainer = $this->createMock(ContainerInterface::class);
108
-		$this->userStatusManager = $this->createMock(IUserStatusManager::class);
109
-		$this->previewManager = $this->createMock(IPreview::class);
110
-		$this->previewManager->method('isAvailable')
111
-			->willReturnCallback(function ($fileInfo) {
112
-				return $fileInfo->getMimeType() === 'mimeWithPreview';
113
-			});
114
-		$this->dateTimeZone = $this->createMock(IDateTimeZone::class);
115
-		$this->logger = $this->createMock(LoggerInterface::class);
116
-		$this->factory = $this->createMock(IProviderFactory::class);
117
-		$this->mailer = $this->createMock(IMailer::class);
118
-		$this->tagManager = $this->createMock(ITagManager::class);
119
-
120
-		$this->ocs = new ShareAPIController(
121
-			$this->appName,
122
-			$this->request,
123
-			$this->shareManager,
124
-			$this->groupManager,
125
-			$this->userManager,
126
-			$this->rootFolder,
127
-			$this->urlGenerator,
128
-			$this->l,
129
-			$this->config,
130
-			$this->appManager,
131
-			$this->serverContainer,
132
-			$this->userStatusManager,
133
-			$this->previewManager,
134
-			$this->dateTimeZone,
135
-			$this->logger,
136
-			$this->factory,
137
-			$this->mailer,
138
-			$this->tagManager,
139
-			$this->currentUser,
140
-		);
141
-	}
142
-
143
-	/**
144
-	 * @return ShareAPIController&MockObject
145
-	 */
146
-	private function mockFormatShare() {
147
-		return $this->getMockBuilder(ShareAPIController::class)
148
-			->setConstructorArgs([
149
-				$this->appName,
150
-				$this->request,
151
-				$this->shareManager,
152
-				$this->groupManager,
153
-				$this->userManager,
154
-				$this->rootFolder,
155
-				$this->urlGenerator,
156
-				$this->l,
157
-				$this->config,
158
-				$this->appManager,
159
-				$this->serverContainer,
160
-				$this->userStatusManager,
161
-				$this->previewManager,
162
-				$this->dateTimeZone,
163
-				$this->logger,
164
-				$this->factory,
165
-				$this->mailer,
166
-				$this->tagManager,
167
-				$this->currentUser,
168
-			])->onlyMethods(['formatShare'])
169
-			->getMock();
170
-	}
171
-
172
-	private function newShare() {
173
-		return Server::get(IManager::class)->newShare();
174
-	}
175
-
176
-
177
-	private function mockShareAttributes() {
178
-		$formattedShareAttributes = [
179
-			[
180
-				'scope' => 'permissions',
181
-				'key' => 'download',
182
-				'value' => true
183
-			]
184
-		];
185
-
186
-		$shareAttributes = $this->createMock(IShareAttributes::class);
187
-		$shareAttributes->method('toArray')->willReturn($formattedShareAttributes);
188
-		$shareAttributes->method('getAttribute')->with('permissions', 'download')->willReturn(true);
189
-
190
-		// send both IShare attributes class and expected json string
191
-		return [$shareAttributes, \json_encode($formattedShareAttributes)];
192
-	}
193
-
194
-	public function testDeleteShareShareNotFound(): void {
195
-		$this->expectException(OCSNotFoundException::class);
196
-		$this->expectExceptionMessage('Wrong share ID, share does not exist');
197
-
198
-		$this->shareManager
199
-			->expects($this->exactly(7))
200
-			->method('getShareById')
201
-			->willReturnCallback(function ($id): void {
202
-				if ($id === 'ocinternal:42' || $id === 'ocRoomShare:42' || $id === 'ocFederatedSharing:42' || $id === 'ocCircleShare:42' || $id === 'ocMailShare:42' || $id === 'deck:42' || $id === 'sciencemesh:42') {
203
-					throw new ShareNotFound();
204
-				} else {
205
-					throw new \Exception();
206
-				}
207
-			});
208
-
209
-		$this->shareManager->method('outgoingServer2ServerSharesAllowed')->willReturn(true);
210
-
211
-		$this->ocs->deleteShare(42);
212
-	}
213
-
214
-	public function testDeleteShare(): void {
215
-		$node = $this->getMockBuilder(File::class)->getMock();
216
-
217
-		$share = $this->newShare();
218
-		$share->setSharedBy($this->currentUser)
219
-			->setNode($node);
220
-		$this->shareManager
221
-			->expects($this->once())
222
-			->method('getShareById')
223
-			->with('ocinternal:42')
224
-			->willReturn($share);
225
-		$this->shareManager
226
-			->expects($this->once())
227
-			->method('deleteShare')
228
-			->with($share);
229
-
230
-		$node->expects($this->once())
231
-			->method('lock')
232
-			->with(ILockingProvider::LOCK_SHARED);
233
-
234
-		$expected = new DataResponse();
235
-		$result = $this->ocs->deleteShare(42);
236
-
237
-		$this->assertInstanceOf(get_class($expected), $result);
238
-		$this->assertEquals($expected->getData(), $result->getData());
239
-	}
240
-
241
-
242
-	public function testDeleteShareLocked(): void {
243
-		$this->expectException(OCSNotFoundException::class);
244
-		$this->expectExceptionMessage('Could not delete share');
245
-
246
-		$node = $this->getMockBuilder(File::class)->getMock();
247
-		$node->method('getId')->willReturn(1);
248
-
249
-		$share = $this->newShare();
250
-		$share->setNode($node);
251
-
252
-		$userFolder = $this->getMockBuilder(Folder::class)->getMock();
253
-		$this->rootFolder->method('getUserFolder')
254
-			->with($this->currentUser)
255
-			->willReturn($userFolder);
256
-
257
-		$userFolder->method('getById')
258
-			->with($share->getNodeId())
259
-			->willReturn([$node]);
260
-
261
-		$this->shareManager
262
-			->expects($this->once())
263
-			->method('getShareById')
264
-			->with('ocinternal:42')
265
-			->willReturn($share);
266
-
267
-		$this->shareManager
268
-			->expects($this->never())
269
-			->method('deleteShare')
270
-			->with($share);
271
-
272
-		$node->expects($this->once())
273
-			->method('lock')
274
-			->with(ILockingProvider::LOCK_SHARED)
275
-			->willThrowException(new LockedException('mypath'));
276
-
277
-		$this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share]));
278
-		$this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShare', [$share]));
279
-
280
-		$this->ocs->deleteShare(42);
281
-	}
282
-
283
-	/**
284
-	 * You can always remove a share that was shared with you
285
-	 */
286
-	public function testDeleteShareWithMe(): void {
287
-		$node = $this->getMockBuilder(File::class)->getMock();
288
-
289
-		$share = $this->newShare();
290
-		$share->setSharedWith($this->currentUser)
291
-			->setShareType(IShare::TYPE_USER)
292
-			->setNode($node);
293
-
294
-		$this->shareManager
295
-			->expects($this->once())
296
-			->method('getShareById')
297
-			->with('ocinternal:42')
298
-			->willReturn($share);
299
-
300
-		$this->shareManager
301
-			->expects($this->once())
302
-			->method('deleteShare')
303
-			->with($share);
304
-
305
-		$node->expects($this->once())
306
-			->method('lock')
307
-			->with(ILockingProvider::LOCK_SHARED);
308
-
309
-		$this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share]));
310
-		$this->assertTrue($this->invokePrivate($this->ocs, 'canDeleteShare', [$share]));
311
-
312
-		$this->ocs->deleteShare(42);
313
-	}
314
-
315
-	/**
316
-	 * You can always delete a share you own
317
-	 */
318
-	public function testDeleteShareOwner(): void {
319
-		$node = $this->getMockBuilder(File::class)->getMock();
320
-
321
-		$share = $this->newShare();
322
-		$share->setSharedBy($this->currentUser)
323
-			->setNode($node);
324
-
325
-		$this->shareManager
326
-			->expects($this->once())
327
-			->method('getShareById')
328
-			->with('ocinternal:42')
329
-			->willReturn($share);
330
-
331
-		$this->shareManager
332
-			->expects($this->once())
333
-			->method('deleteShare')
334
-			->with($share);
335
-
336
-		$node->expects($this->once())
337
-			->method('lock')
338
-			->with(ILockingProvider::LOCK_SHARED);
339
-
340
-		$this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share]));
341
-		$this->assertTrue($this->invokePrivate($this->ocs, 'canDeleteShare', [$share]));
342
-
343
-		$this->ocs->deleteShare(42);
344
-	}
345
-
346
-	/**
347
-	 * You can always delete a share when you own
348
-	 * the file path it belong to
349
-	 */
350
-	public function testDeleteShareFileOwner(): void {
351
-		$node = $this->getMockBuilder(File::class)->getMock();
352
-		$node->method('getId')->willReturn(1);
353
-
354
-		$share = $this->newShare();
355
-		$share->setShareOwner($this->currentUser)
356
-			->setNode($node);
357
-
358
-		$this->shareManager
359
-			->expects($this->once())
360
-			->method('getShareById')
361
-			->with('ocinternal:42')
362
-			->willReturn($share);
363
-
364
-		$this->shareManager
365
-			->expects($this->once())
366
-			->method('deleteShare')
367
-			->with($share);
368
-
369
-		$node->expects($this->once())
370
-			->method('lock')
371
-			->with(ILockingProvider::LOCK_SHARED);
372
-
373
-		$this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share]));
374
-		$this->assertTrue($this->invokePrivate($this->ocs, 'canDeleteShare', [$share]));
375
-
376
-		$this->ocs->deleteShare(42);
377
-	}
378
-
379
-	/**
380
-	 * You can remove (the mountpoint, not the share)
381
-	 * a share if you're in the group the share is shared with
382
-	 */
383
-	public function testDeleteSharedWithMyGroup(): void {
384
-		$node = $this->getMockBuilder(File::class)->getMock();
385
-		$node->method('getId')->willReturn(1);
386
-
387
-		$share = $this->newShare();
388
-		$share->setShareType(IShare::TYPE_GROUP)
389
-			->setSharedWith('group')
390
-			->setNode($node);
391
-
392
-		$this->shareManager
393
-			->expects($this->once())
394
-			->method('getShareById')
395
-			->with('ocinternal:42')
396
-			->willReturn($share);
397
-
398
-		// canDeleteShareFromSelf
399
-		$user = $this->createMock(IUser::class);
400
-		$group = $this->getMockBuilder(IGroup::class)->getMock();
401
-		$this->groupManager
402
-			->method('get')
403
-			->with('group')
404
-			->willReturn($group);
405
-		$this->userManager
406
-			->method('get')
407
-			->with($this->currentUser)
408
-			->willReturn($user);
409
-		$group->method('inGroup')
410
-			->with($user)
411
-			->willReturn(true);
412
-
413
-		$node->expects($this->once())
414
-			->method('lock')
415
-			->with(ILockingProvider::LOCK_SHARED);
416
-
417
-		$userFolder = $this->getMockBuilder(Folder::class)->getMock();
418
-		$this->rootFolder->method('getUserFolder')
419
-			->with($this->currentUser)
420
-			->willReturn($userFolder);
421
-
422
-		$userFolder->method('getById')
423
-			->with($share->getNodeId())
424
-			->willReturn([$share->getNode()]);
425
-
426
-		$this->shareManager->expects($this->once())
427
-			->method('deleteFromSelf')
428
-			->with($share, $this->currentUser);
429
-
430
-		$this->shareManager->expects($this->never())
431
-			->method('deleteShare');
432
-
433
-		$this->assertTrue($this->invokePrivate($this->ocs, 'canDeleteShareFromSelf', [$share]));
434
-		$this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShare', [$share]));
435
-
436
-		$this->ocs->deleteShare(42);
437
-	}
438
-
439
-	/**
440
-	 * You cannot remove a share if you're not
441
-	 * in the group the share is shared with
442
-	 */
443
-	public function testDeleteSharedWithGroupIDontBelongTo(): void {
444
-		$this->expectException(OCSNotFoundException::class);
445
-		$this->expectExceptionMessage('Wrong share ID, share does not exist');
446
-
447
-		$node = $this->getMockBuilder(File::class)->getMock();
448
-		$node->method('getId')->willReturn(42);
449
-
450
-		$share = $this->newShare();
451
-		$share->setShareType(IShare::TYPE_GROUP)
452
-			->setSharedWith('group')
453
-			->setNode($node);
454
-
455
-		$this->shareManager
456
-			->expects($this->once())
457
-			->method('getShareById')
458
-			->with('ocinternal:42')
459
-			->willReturn($share);
460
-
461
-		// canDeleteShareFromSelf
462
-		$user = $this->createMock(IUser::class);
463
-		$group = $this->getMockBuilder(IGroup::class)->getMock();
464
-		$this->groupManager
465
-			->method('get')
466
-			->with('group')
467
-			->willReturn($group);
468
-		$this->userManager
469
-			->method('get')
470
-			->with($this->currentUser)
471
-			->willReturn($user);
472
-		$group->method('inGroup')
473
-			->with($user)
474
-			->willReturn(false);
475
-
476
-		$node->expects($this->once())
477
-			->method('lock')
478
-			->with(ILockingProvider::LOCK_SHARED);
479
-
480
-		$userFolder = $this->getMockBuilder(Folder::class)->getMock();
481
-		$this->rootFolder->method('getUserFolder')
482
-			->with($this->currentUser)
483
-			->willReturn($userFolder);
484
-
485
-		$userFolder->method('getById')
486
-			->with($share->getNodeId())
487
-			->willReturn([$share->getNode()]);
488
-
489
-		$this->shareManager->expects($this->never())
490
-			->method('deleteFromSelf');
491
-
492
-		$this->shareManager->expects($this->never())
493
-			->method('deleteShare');
494
-
495
-		$this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShareFromSelf', [$share]));
496
-		$this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShare', [$share]));
497
-
498
-		$this->ocs->deleteShare(42);
499
-	}
500
-
501
-	public function testDeleteShareOwnerless(): void {
502
-		$ocs = $this->mockFormatShare();
503
-
504
-		$mount = $this->createMock(IShareOwnerlessMount::class);
505
-
506
-		$file = $this->createMock(File::class);
507
-		$file
508
-			->expects($this->exactly(2))
509
-			->method('getPermissions')
510
-			->willReturn(Constants::PERMISSION_SHARE);
511
-		$file
512
-			->expects($this->once())
513
-			->method('getMountPoint')
514
-			->willReturn($mount);
515
-
516
-		$userFolder = $this->createMock(Folder::class);
517
-		$userFolder->method('getById')
518
-			->with(2)
519
-			->willReturn([$file]);
520
-		$userFolder->method('getFirstNodeById')
521
-			->with(2)
522
-			->willReturn($file);
523
-
524
-		$this->rootFolder
525
-			->method('getUserFolder')
526
-			->with($this->currentUser)
527
-			->willReturn($userFolder);
528
-
529
-		$share = $this->createMock(IShare::class);
530
-		$share
531
-			->expects($this->once())
532
-			->method('getNode')
533
-			->willReturn($file);
534
-		$share
535
-			->expects($this->exactly(2))
536
-			->method('getNodeId')
537
-			->willReturn(2);
538
-		$share
539
-			->expects($this->exactly(2))
540
-			->method('getPermissions')
541
-			->willReturn(Constants::PERMISSION_SHARE);
542
-
543
-		$this->shareManager
544
-			->expects($this->once())
545
-			->method('getShareById')
546
-			->with('ocinternal:1', $this->currentUser)
547
-			->willReturn($share);
548
-
549
-		$this->shareManager
550
-			->expects($this->once())
551
-			->method('deleteShare')
552
-			->with($share);
553
-
554
-		$result = $ocs->deleteShare(1);
555
-		$this->assertInstanceOf(DataResponse::class, $result);
556
-	}
557
-
558
-	/*
61
+    private string $appName = 'files_sharing';
62
+    private string $currentUser;
63
+
64
+    private ShareAPIController $ocs;
65
+
66
+    private IManager&MockObject $shareManager;
67
+    private IGroupManager&MockObject $groupManager;
68
+    private IUserManager&MockObject $userManager;
69
+    private IRequest&MockObject $request;
70
+    private IRootFolder&MockObject $rootFolder;
71
+    private IURLGenerator&MockObject $urlGenerator;
72
+    private IL10N&MockObject $l;
73
+    private IConfig&MockObject $config;
74
+    private IAppManager&MockObject $appManager;
75
+    private ContainerInterface&MockObject $serverContainer;
76
+    private IUserStatusManager&MockObject $userStatusManager;
77
+    private IPreview&MockObject $previewManager;
78
+    private IDateTimeZone&MockObject $dateTimeZone;
79
+    private LoggerInterface&MockObject $logger;
80
+    private IProviderFactory&MockObject $factory;
81
+    private IMailer&MockObject $mailer;
82
+    private ITagManager&MockObject $tagManager;
83
+
84
+    protected function setUp(): void {
85
+        $this->shareManager = $this->createMock(IManager::class);
86
+        $this->shareManager
87
+            ->expects($this->any())
88
+            ->method('shareApiEnabled')
89
+            ->willReturn(true);
90
+        $this->shareManager
91
+            ->expects($this->any())
92
+            ->method('shareProviderExists')->willReturn(true);
93
+        $this->groupManager = $this->createMock(IGroupManager::class);
94
+        $this->userManager = $this->createMock(IUserManager::class);
95
+        $this->request = $this->createMock(IRequest::class);
96
+        $this->rootFolder = $this->createMock(IRootFolder::class);
97
+        $this->urlGenerator = $this->createMock(IURLGenerator::class);
98
+        $this->currentUser = 'currentUser';
99
+
100
+        $this->l = $this->createMock(IL10N::class);
101
+        $this->l->method('t')
102
+            ->willReturnCallback(function ($text, $parameters = []) {
103
+                return vsprintf($text, $parameters);
104
+            });
105
+        $this->config = $this->createMock(IConfig::class);
106
+        $this->appManager = $this->createMock(IAppManager::class);
107
+        $this->serverContainer = $this->createMock(ContainerInterface::class);
108
+        $this->userStatusManager = $this->createMock(IUserStatusManager::class);
109
+        $this->previewManager = $this->createMock(IPreview::class);
110
+        $this->previewManager->method('isAvailable')
111
+            ->willReturnCallback(function ($fileInfo) {
112
+                return $fileInfo->getMimeType() === 'mimeWithPreview';
113
+            });
114
+        $this->dateTimeZone = $this->createMock(IDateTimeZone::class);
115
+        $this->logger = $this->createMock(LoggerInterface::class);
116
+        $this->factory = $this->createMock(IProviderFactory::class);
117
+        $this->mailer = $this->createMock(IMailer::class);
118
+        $this->tagManager = $this->createMock(ITagManager::class);
119
+
120
+        $this->ocs = new ShareAPIController(
121
+            $this->appName,
122
+            $this->request,
123
+            $this->shareManager,
124
+            $this->groupManager,
125
+            $this->userManager,
126
+            $this->rootFolder,
127
+            $this->urlGenerator,
128
+            $this->l,
129
+            $this->config,
130
+            $this->appManager,
131
+            $this->serverContainer,
132
+            $this->userStatusManager,
133
+            $this->previewManager,
134
+            $this->dateTimeZone,
135
+            $this->logger,
136
+            $this->factory,
137
+            $this->mailer,
138
+            $this->tagManager,
139
+            $this->currentUser,
140
+        );
141
+    }
142
+
143
+    /**
144
+     * @return ShareAPIController&MockObject
145
+     */
146
+    private function mockFormatShare() {
147
+        return $this->getMockBuilder(ShareAPIController::class)
148
+            ->setConstructorArgs([
149
+                $this->appName,
150
+                $this->request,
151
+                $this->shareManager,
152
+                $this->groupManager,
153
+                $this->userManager,
154
+                $this->rootFolder,
155
+                $this->urlGenerator,
156
+                $this->l,
157
+                $this->config,
158
+                $this->appManager,
159
+                $this->serverContainer,
160
+                $this->userStatusManager,
161
+                $this->previewManager,
162
+                $this->dateTimeZone,
163
+                $this->logger,
164
+                $this->factory,
165
+                $this->mailer,
166
+                $this->tagManager,
167
+                $this->currentUser,
168
+            ])->onlyMethods(['formatShare'])
169
+            ->getMock();
170
+    }
171
+
172
+    private function newShare() {
173
+        return Server::get(IManager::class)->newShare();
174
+    }
175
+
176
+
177
+    private function mockShareAttributes() {
178
+        $formattedShareAttributes = [
179
+            [
180
+                'scope' => 'permissions',
181
+                'key' => 'download',
182
+                'value' => true
183
+            ]
184
+        ];
185
+
186
+        $shareAttributes = $this->createMock(IShareAttributes::class);
187
+        $shareAttributes->method('toArray')->willReturn($formattedShareAttributes);
188
+        $shareAttributes->method('getAttribute')->with('permissions', 'download')->willReturn(true);
189
+
190
+        // send both IShare attributes class and expected json string
191
+        return [$shareAttributes, \json_encode($formattedShareAttributes)];
192
+    }
193
+
194
+    public function testDeleteShareShareNotFound(): void {
195
+        $this->expectException(OCSNotFoundException::class);
196
+        $this->expectExceptionMessage('Wrong share ID, share does not exist');
197
+
198
+        $this->shareManager
199
+            ->expects($this->exactly(7))
200
+            ->method('getShareById')
201
+            ->willReturnCallback(function ($id): void {
202
+                if ($id === 'ocinternal:42' || $id === 'ocRoomShare:42' || $id === 'ocFederatedSharing:42' || $id === 'ocCircleShare:42' || $id === 'ocMailShare:42' || $id === 'deck:42' || $id === 'sciencemesh:42') {
203
+                    throw new ShareNotFound();
204
+                } else {
205
+                    throw new \Exception();
206
+                }
207
+            });
208
+
209
+        $this->shareManager->method('outgoingServer2ServerSharesAllowed')->willReturn(true);
210
+
211
+        $this->ocs->deleteShare(42);
212
+    }
213
+
214
+    public function testDeleteShare(): void {
215
+        $node = $this->getMockBuilder(File::class)->getMock();
216
+
217
+        $share = $this->newShare();
218
+        $share->setSharedBy($this->currentUser)
219
+            ->setNode($node);
220
+        $this->shareManager
221
+            ->expects($this->once())
222
+            ->method('getShareById')
223
+            ->with('ocinternal:42')
224
+            ->willReturn($share);
225
+        $this->shareManager
226
+            ->expects($this->once())
227
+            ->method('deleteShare')
228
+            ->with($share);
229
+
230
+        $node->expects($this->once())
231
+            ->method('lock')
232
+            ->with(ILockingProvider::LOCK_SHARED);
233
+
234
+        $expected = new DataResponse();
235
+        $result = $this->ocs->deleteShare(42);
236
+
237
+        $this->assertInstanceOf(get_class($expected), $result);
238
+        $this->assertEquals($expected->getData(), $result->getData());
239
+    }
240
+
241
+
242
+    public function testDeleteShareLocked(): void {
243
+        $this->expectException(OCSNotFoundException::class);
244
+        $this->expectExceptionMessage('Could not delete share');
245
+
246
+        $node = $this->getMockBuilder(File::class)->getMock();
247
+        $node->method('getId')->willReturn(1);
248
+
249
+        $share = $this->newShare();
250
+        $share->setNode($node);
251
+
252
+        $userFolder = $this->getMockBuilder(Folder::class)->getMock();
253
+        $this->rootFolder->method('getUserFolder')
254
+            ->with($this->currentUser)
255
+            ->willReturn($userFolder);
256
+
257
+        $userFolder->method('getById')
258
+            ->with($share->getNodeId())
259
+            ->willReturn([$node]);
260
+
261
+        $this->shareManager
262
+            ->expects($this->once())
263
+            ->method('getShareById')
264
+            ->with('ocinternal:42')
265
+            ->willReturn($share);
266
+
267
+        $this->shareManager
268
+            ->expects($this->never())
269
+            ->method('deleteShare')
270
+            ->with($share);
271
+
272
+        $node->expects($this->once())
273
+            ->method('lock')
274
+            ->with(ILockingProvider::LOCK_SHARED)
275
+            ->willThrowException(new LockedException('mypath'));
276
+
277
+        $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share]));
278
+        $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShare', [$share]));
279
+
280
+        $this->ocs->deleteShare(42);
281
+    }
282
+
283
+    /**
284
+     * You can always remove a share that was shared with you
285
+     */
286
+    public function testDeleteShareWithMe(): void {
287
+        $node = $this->getMockBuilder(File::class)->getMock();
288
+
289
+        $share = $this->newShare();
290
+        $share->setSharedWith($this->currentUser)
291
+            ->setShareType(IShare::TYPE_USER)
292
+            ->setNode($node);
293
+
294
+        $this->shareManager
295
+            ->expects($this->once())
296
+            ->method('getShareById')
297
+            ->with('ocinternal:42')
298
+            ->willReturn($share);
299
+
300
+        $this->shareManager
301
+            ->expects($this->once())
302
+            ->method('deleteShare')
303
+            ->with($share);
304
+
305
+        $node->expects($this->once())
306
+            ->method('lock')
307
+            ->with(ILockingProvider::LOCK_SHARED);
308
+
309
+        $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share]));
310
+        $this->assertTrue($this->invokePrivate($this->ocs, 'canDeleteShare', [$share]));
311
+
312
+        $this->ocs->deleteShare(42);
313
+    }
314
+
315
+    /**
316
+     * You can always delete a share you own
317
+     */
318
+    public function testDeleteShareOwner(): void {
319
+        $node = $this->getMockBuilder(File::class)->getMock();
320
+
321
+        $share = $this->newShare();
322
+        $share->setSharedBy($this->currentUser)
323
+            ->setNode($node);
324
+
325
+        $this->shareManager
326
+            ->expects($this->once())
327
+            ->method('getShareById')
328
+            ->with('ocinternal:42')
329
+            ->willReturn($share);
330
+
331
+        $this->shareManager
332
+            ->expects($this->once())
333
+            ->method('deleteShare')
334
+            ->with($share);
335
+
336
+        $node->expects($this->once())
337
+            ->method('lock')
338
+            ->with(ILockingProvider::LOCK_SHARED);
339
+
340
+        $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share]));
341
+        $this->assertTrue($this->invokePrivate($this->ocs, 'canDeleteShare', [$share]));
342
+
343
+        $this->ocs->deleteShare(42);
344
+    }
345
+
346
+    /**
347
+     * You can always delete a share when you own
348
+     * the file path it belong to
349
+     */
350
+    public function testDeleteShareFileOwner(): void {
351
+        $node = $this->getMockBuilder(File::class)->getMock();
352
+        $node->method('getId')->willReturn(1);
353
+
354
+        $share = $this->newShare();
355
+        $share->setShareOwner($this->currentUser)
356
+            ->setNode($node);
357
+
358
+        $this->shareManager
359
+            ->expects($this->once())
360
+            ->method('getShareById')
361
+            ->with('ocinternal:42')
362
+            ->willReturn($share);
363
+
364
+        $this->shareManager
365
+            ->expects($this->once())
366
+            ->method('deleteShare')
367
+            ->with($share);
368
+
369
+        $node->expects($this->once())
370
+            ->method('lock')
371
+            ->with(ILockingProvider::LOCK_SHARED);
372
+
373
+        $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share]));
374
+        $this->assertTrue($this->invokePrivate($this->ocs, 'canDeleteShare', [$share]));
375
+
376
+        $this->ocs->deleteShare(42);
377
+    }
378
+
379
+    /**
380
+     * You can remove (the mountpoint, not the share)
381
+     * a share if you're in the group the share is shared with
382
+     */
383
+    public function testDeleteSharedWithMyGroup(): void {
384
+        $node = $this->getMockBuilder(File::class)->getMock();
385
+        $node->method('getId')->willReturn(1);
386
+
387
+        $share = $this->newShare();
388
+        $share->setShareType(IShare::TYPE_GROUP)
389
+            ->setSharedWith('group')
390
+            ->setNode($node);
391
+
392
+        $this->shareManager
393
+            ->expects($this->once())
394
+            ->method('getShareById')
395
+            ->with('ocinternal:42')
396
+            ->willReturn($share);
397
+
398
+        // canDeleteShareFromSelf
399
+        $user = $this->createMock(IUser::class);
400
+        $group = $this->getMockBuilder(IGroup::class)->getMock();
401
+        $this->groupManager
402
+            ->method('get')
403
+            ->with('group')
404
+            ->willReturn($group);
405
+        $this->userManager
406
+            ->method('get')
407
+            ->with($this->currentUser)
408
+            ->willReturn($user);
409
+        $group->method('inGroup')
410
+            ->with($user)
411
+            ->willReturn(true);
412
+
413
+        $node->expects($this->once())
414
+            ->method('lock')
415
+            ->with(ILockingProvider::LOCK_SHARED);
416
+
417
+        $userFolder = $this->getMockBuilder(Folder::class)->getMock();
418
+        $this->rootFolder->method('getUserFolder')
419
+            ->with($this->currentUser)
420
+            ->willReturn($userFolder);
421
+
422
+        $userFolder->method('getById')
423
+            ->with($share->getNodeId())
424
+            ->willReturn([$share->getNode()]);
425
+
426
+        $this->shareManager->expects($this->once())
427
+            ->method('deleteFromSelf')
428
+            ->with($share, $this->currentUser);
429
+
430
+        $this->shareManager->expects($this->never())
431
+            ->method('deleteShare');
432
+
433
+        $this->assertTrue($this->invokePrivate($this->ocs, 'canDeleteShareFromSelf', [$share]));
434
+        $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShare', [$share]));
435
+
436
+        $this->ocs->deleteShare(42);
437
+    }
438
+
439
+    /**
440
+     * You cannot remove a share if you're not
441
+     * in the group the share is shared with
442
+     */
443
+    public function testDeleteSharedWithGroupIDontBelongTo(): void {
444
+        $this->expectException(OCSNotFoundException::class);
445
+        $this->expectExceptionMessage('Wrong share ID, share does not exist');
446
+
447
+        $node = $this->getMockBuilder(File::class)->getMock();
448
+        $node->method('getId')->willReturn(42);
449
+
450
+        $share = $this->newShare();
451
+        $share->setShareType(IShare::TYPE_GROUP)
452
+            ->setSharedWith('group')
453
+            ->setNode($node);
454
+
455
+        $this->shareManager
456
+            ->expects($this->once())
457
+            ->method('getShareById')
458
+            ->with('ocinternal:42')
459
+            ->willReturn($share);
460
+
461
+        // canDeleteShareFromSelf
462
+        $user = $this->createMock(IUser::class);
463
+        $group = $this->getMockBuilder(IGroup::class)->getMock();
464
+        $this->groupManager
465
+            ->method('get')
466
+            ->with('group')
467
+            ->willReturn($group);
468
+        $this->userManager
469
+            ->method('get')
470
+            ->with($this->currentUser)
471
+            ->willReturn($user);
472
+        $group->method('inGroup')
473
+            ->with($user)
474
+            ->willReturn(false);
475
+
476
+        $node->expects($this->once())
477
+            ->method('lock')
478
+            ->with(ILockingProvider::LOCK_SHARED);
479
+
480
+        $userFolder = $this->getMockBuilder(Folder::class)->getMock();
481
+        $this->rootFolder->method('getUserFolder')
482
+            ->with($this->currentUser)
483
+            ->willReturn($userFolder);
484
+
485
+        $userFolder->method('getById')
486
+            ->with($share->getNodeId())
487
+            ->willReturn([$share->getNode()]);
488
+
489
+        $this->shareManager->expects($this->never())
490
+            ->method('deleteFromSelf');
491
+
492
+        $this->shareManager->expects($this->never())
493
+            ->method('deleteShare');
494
+
495
+        $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShareFromSelf', [$share]));
496
+        $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShare', [$share]));
497
+
498
+        $this->ocs->deleteShare(42);
499
+    }
500
+
501
+    public function testDeleteShareOwnerless(): void {
502
+        $ocs = $this->mockFormatShare();
503
+
504
+        $mount = $this->createMock(IShareOwnerlessMount::class);
505
+
506
+        $file = $this->createMock(File::class);
507
+        $file
508
+            ->expects($this->exactly(2))
509
+            ->method('getPermissions')
510
+            ->willReturn(Constants::PERMISSION_SHARE);
511
+        $file
512
+            ->expects($this->once())
513
+            ->method('getMountPoint')
514
+            ->willReturn($mount);
515
+
516
+        $userFolder = $this->createMock(Folder::class);
517
+        $userFolder->method('getById')
518
+            ->with(2)
519
+            ->willReturn([$file]);
520
+        $userFolder->method('getFirstNodeById')
521
+            ->with(2)
522
+            ->willReturn($file);
523
+
524
+        $this->rootFolder
525
+            ->method('getUserFolder')
526
+            ->with($this->currentUser)
527
+            ->willReturn($userFolder);
528
+
529
+        $share = $this->createMock(IShare::class);
530
+        $share
531
+            ->expects($this->once())
532
+            ->method('getNode')
533
+            ->willReturn($file);
534
+        $share
535
+            ->expects($this->exactly(2))
536
+            ->method('getNodeId')
537
+            ->willReturn(2);
538
+        $share
539
+            ->expects($this->exactly(2))
540
+            ->method('getPermissions')
541
+            ->willReturn(Constants::PERMISSION_SHARE);
542
+
543
+        $this->shareManager
544
+            ->expects($this->once())
545
+            ->method('getShareById')
546
+            ->with('ocinternal:1', $this->currentUser)
547
+            ->willReturn($share);
548
+
549
+        $this->shareManager
550
+            ->expects($this->once())
551
+            ->method('deleteShare')
552
+            ->with($share);
553
+
554
+        $result = $ocs->deleteShare(1);
555
+        $this->assertInstanceOf(DataResponse::class, $result);
556
+    }
557
+
558
+    /*
559 559
 	 * FIXME: Enable once we have a federated Share Provider
560 560
 
561 561
 	public function testGetGetShareNotExists() {
@@ -570,4650 +570,4650 @@  discard block
 block discarded – undo
570 570
 	}
571 571
 	*/
572 572
 
573
-	public function createShare($id, $shareType, $sharedWith, $sharedBy, $shareOwner, $path, $permissions,
574
-		$shareTime, $expiration, $parent, $target, $mail_send, $note = '', $token = null,
575
-		$password = null, $label = '', $attributes = null) {
576
-		$share = $this->getMockBuilder(IShare::class)->getMock();
577
-		$share->method('getId')->willReturn($id);
578
-		$share->method('getShareType')->willReturn($shareType);
579
-		$share->method('getSharedWith')->willReturn($sharedWith);
580
-		$share->method('getSharedBy')->willReturn($sharedBy);
581
-		$share->method('getShareOwner')->willReturn($shareOwner);
582
-		$share->method('getNode')->willReturn($path);
583
-		$share->method('getPermissions')->willReturn($permissions);
584
-		$share->method('getNote')->willReturn($note);
585
-		$share->method('getLabel')->willReturn($label);
586
-		$share->method('getAttributes')->willReturn($attributes);
587
-		$time = new \DateTime();
588
-		$time->setTimestamp($shareTime);
589
-		$share->method('getShareTime')->willReturn($time);
590
-		$share->method('getExpirationDate')->willReturn($expiration);
591
-		$share->method('getTarget')->willReturn($target);
592
-		$share->method('getMailSend')->willReturn($mail_send);
593
-		$share->method('getToken')->willReturn($token);
594
-		$share->method('getPassword')->willReturn($password);
595
-
596
-		if ($shareType === IShare::TYPE_USER
597
-			|| $shareType === IShare::TYPE_GROUP
598
-			|| $shareType === IShare::TYPE_LINK) {
599
-			$share->method('getFullId')->willReturn('ocinternal:' . $id);
600
-		}
601
-
602
-		return $share;
603
-	}
604
-
605
-	public function dataGetShare() {
606
-		$data = [];
607
-
608
-		$cache = $this->getMockBuilder('OC\Files\Cache\Cache')
609
-			->disableOriginalConstructor()
610
-			->getMock();
611
-		$cache->method('getNumericStorageId')->willReturn(101);
612
-
613
-		$storage = $this->getMockBuilder(IStorage::class)
614
-			->disableOriginalConstructor()
615
-			->getMock();
616
-		$storage->method('getId')->willReturn('STORAGE');
617
-		$storage->method('getCache')->willReturn($cache);
618
-
619
-		$parentFolder = $this->getMockBuilder(Folder::class)->getMock();
620
-		$parentFolder->method('getId')->willReturn(3);
621
-		$mountPoint = $this->createMock(IMountPoint::class);
622
-		$mountPoint->method('getMountType')->willReturn('');
623
-
624
-		$file = $this->getMockBuilder('OCP\Files\File')->getMock();
625
-		$file->method('getId')->willReturn(1);
626
-		$file->method('getPath')->willReturn('file');
627
-		$file->method('getStorage')->willReturn($storage);
628
-		$file->method('getParent')->willReturn($parentFolder);
629
-		$file->method('getSize')->willReturn(123465);
630
-		$file->method('getMTime')->willReturn(1234567890);
631
-		$file->method('getMimeType')->willReturn('myMimeType');
632
-		$file->method('getMountPoint')->willReturn($mountPoint);
633
-
634
-		$folder = $this->getMockBuilder(Folder::class)->getMock();
635
-		$folder->method('getId')->willReturn(2);
636
-		$folder->method('getPath')->willReturn('folder');
637
-		$folder->method('getStorage')->willReturn($storage);
638
-		$folder->method('getParent')->willReturn($parentFolder);
639
-		$folder->method('getSize')->willReturn(123465);
640
-		$folder->method('getMTime')->willReturn(1234567890);
641
-		$folder->method('getMimeType')->willReturn('myFolderMimeType');
642
-		$folder->method('getMountPoint')->willReturn($mountPoint);
643
-
644
-		[$shareAttributes, $shareAttributesReturnJson] = $this->mockShareAttributes();
645
-
646
-		// File shared with user
647
-		$share = $this->createShare(
648
-			100,
649
-			IShare::TYPE_USER,
650
-			'userId',
651
-			'initiatorId',
652
-			'ownerId',
653
-			$file,
654
-			4,
655
-			5,
656
-			null,
657
-			6,
658
-			'target',
659
-			0,
660
-			'personal note',
661
-			$shareAttributes,
662
-		);
663
-		$expected = [
664
-			'id' => 100,
665
-			'share_type' => IShare::TYPE_USER,
666
-			'share_with' => 'userId',
667
-			'share_with_displayname' => 'userDisplay',
668
-			'share_with_displayname_unique' => '[email protected]',
669
-			'uid_owner' => 'initiatorId',
670
-			'displayname_owner' => 'initiatorDisplay',
671
-			'item_type' => 'file',
672
-			'item_source' => 1,
673
-			'file_source' => 1,
674
-			'file_target' => 'target',
675
-			'file_parent' => 3,
676
-			'token' => null,
677
-			'expiration' => null,
678
-			'permissions' => 4,
679
-			'attributes' => $shareAttributesReturnJson,
680
-			'stime' => 5,
681
-			'parent' => null,
682
-			'storage_id' => 'STORAGE',
683
-			'path' => 'file',
684
-			'storage' => 101,
685
-			'mail_send' => 0,
686
-			'uid_file_owner' => 'ownerId',
687
-			'note' => 'personal note',
688
-			'label' => '',
689
-			'displayname_file_owner' => 'ownerDisplay',
690
-			'mimetype' => 'myMimeType',
691
-			'has_preview' => false,
692
-			'hide_download' => 0,
693
-			'can_edit' => false,
694
-			'can_delete' => false,
695
-			'item_size' => 123465,
696
-			'item_mtime' => 1234567890,
697
-			'attributes' => null,
698
-			'item_permissions' => 4,
699
-			'is-mount-root' => false,
700
-			'mount-type' => '',
701
-		];
702
-		$data[] = [$share, $expected];
703
-
704
-		// Folder shared with group
705
-		$share = $this->createShare(
706
-			101,
707
-			IShare::TYPE_GROUP,
708
-			'groupId',
709
-			'initiatorId',
710
-			'ownerId',
711
-			$folder,
712
-			4,
713
-			5,
714
-			null,
715
-			6,
716
-			'target',
717
-			0,
718
-			'personal note',
719
-			$shareAttributes,
720
-		);
721
-		$expected = [
722
-			'id' => 101,
723
-			'share_type' => IShare::TYPE_GROUP,
724
-			'share_with' => 'groupId',
725
-			'share_with_displayname' => 'groupId',
726
-			'uid_owner' => 'initiatorId',
727
-			'displayname_owner' => 'initiatorDisplay',
728
-			'item_type' => 'folder',
729
-			'item_source' => 2,
730
-			'file_source' => 2,
731
-			'file_target' => 'target',
732
-			'file_parent' => 3,
733
-			'token' => null,
734
-			'expiration' => null,
735
-			'permissions' => 4,
736
-			'attributes' => $shareAttributesReturnJson,
737
-			'stime' => 5,
738
-			'parent' => null,
739
-			'storage_id' => 'STORAGE',
740
-			'path' => 'folder',
741
-			'storage' => 101,
742
-			'mail_send' => 0,
743
-			'uid_file_owner' => 'ownerId',
744
-			'note' => 'personal note',
745
-			'label' => '',
746
-			'displayname_file_owner' => 'ownerDisplay',
747
-			'mimetype' => 'myFolderMimeType',
748
-			'has_preview' => false,
749
-			'hide_download' => 0,
750
-			'can_edit' => false,
751
-			'can_delete' => false,
752
-			'item_size' => 123465,
753
-			'item_mtime' => 1234567890,
754
-			'attributes' => null,
755
-			'item_permissions' => 4,
756
-			'is-mount-root' => false,
757
-			'mount-type' => '',
758
-		];
759
-		$data[] = [$share, $expected];
760
-
761
-		// File shared by link with Expire
762
-		$expire = \DateTime::createFromFormat('Y-m-d h:i:s', '2000-01-02 01:02:03');
763
-		$share = $this->createShare(
764
-			101,
765
-			IShare::TYPE_LINK,
766
-			null,
767
-			'initiatorId',
768
-			'ownerId',
769
-			$folder,
770
-			4,
771
-			5,
772
-			$expire,
773
-			6,
774
-			'target',
775
-			0,
776
-			'personal note',
777
-			'token',
778
-			'password',
779
-			'first link share'
780
-		);
781
-		$expected = [
782
-			'id' => 101,
783
-			'share_type' => IShare::TYPE_LINK,
784
-			'password' => 'password',
785
-			'share_with' => 'password',
786
-			'share_with_displayname' => '(Shared link)',
787
-			'send_password_by_talk' => false,
788
-			'uid_owner' => 'initiatorId',
789
-			'displayname_owner' => 'initiatorDisplay',
790
-			'item_type' => 'folder',
791
-			'item_source' => 2,
792
-			'file_source' => 2,
793
-			'file_target' => 'target',
794
-			'file_parent' => 3,
795
-			'token' => 'token',
796
-			'expiration' => '2000-01-02 00:00:00',
797
-			'permissions' => 4,
798
-			'attributes' => null,
799
-			'stime' => 5,
800
-			'parent' => null,
801
-			'storage_id' => 'STORAGE',
802
-			'path' => 'folder',
803
-			'storage' => 101,
804
-			'mail_send' => 0,
805
-			'url' => 'url',
806
-			'uid_file_owner' => 'ownerId',
807
-			'note' => 'personal note',
808
-			'label' => 'first link share',
809
-			'displayname_file_owner' => 'ownerDisplay',
810
-			'mimetype' => 'myFolderMimeType',
811
-			'has_preview' => false,
812
-			'hide_download' => 0,
813
-			'can_edit' => false,
814
-			'can_delete' => false,
815
-			'item_size' => 123465,
816
-			'item_mtime' => 1234567890,
817
-			'attributes' => null,
818
-			'item_permissions' => 4,
819
-			'is-mount-root' => false,
820
-			'mount-type' => '',
821
-		];
822
-		$data[] = [$share, $expected];
823
-
824
-		return $data;
825
-	}
826
-
827
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataGetShare')]
828
-	public function testGetShare(IShare $share, array $result): void {
829
-		/** @var ShareAPIController&MockObject $ocs */
830
-		$ocs = $this->getMockBuilder(ShareAPIController::class)
831
-			->setConstructorArgs([
832
-				$this->appName,
833
-				$this->request,
834
-				$this->shareManager,
835
-				$this->groupManager,
836
-				$this->userManager,
837
-				$this->rootFolder,
838
-				$this->urlGenerator,
839
-				$this->l,
840
-				$this->config,
841
-				$this->appManager,
842
-				$this->serverContainer,
843
-				$this->userStatusManager,
844
-				$this->previewManager,
845
-				$this->dateTimeZone,
846
-				$this->logger,
847
-				$this->factory,
848
-				$this->mailer,
849
-				$this->tagManager,
850
-				$this->currentUser,
851
-			])
852
-			->onlyMethods(['canAccessShare'])
853
-			->getMock();
854
-
855
-		$ocs->expects($this->any())
856
-			->method('canAccessShare')
857
-			->willReturn(true);
858
-
859
-		$this->shareManager
860
-			->expects($this->any())
861
-			->method('getShareById')
862
-			->with($share->getFullId(), 'currentUser')
863
-			->willReturn($share);
864
-
865
-		$userFolder = $this->getMockBuilder(Folder::class)->getMock();
866
-		$userFolder
867
-			->method('getRelativePath')
868
-			->willReturnArgument(0);
869
-
870
-		$userFolder->method('getById')
871
-			->with($share->getNodeId())
872
-			->willReturn([$share->getNode()]);
873
-		$userFolder->method('getFirstNodeById')
874
-			->with($share->getNodeId())
875
-			->willReturn($share->getNode());
876
-
877
-		$this->rootFolder->method('getUserFolder')
878
-			->with($this->currentUser)
879
-			->willReturn($userFolder);
880
-
881
-		$this->urlGenerator
882
-			->method('linkToRouteAbsolute')
883
-			->willReturn('url');
884
-
885
-		$initiator = $this->getMockBuilder(IUser::class)->getMock();
886
-		$initiator->method('getUID')->willReturn('initiatorId');
887
-		$initiator->method('getDisplayName')->willReturn('initiatorDisplay');
888
-
889
-		$owner = $this->getMockBuilder(IUser::class)->getMock();
890
-		$owner->method('getUID')->willReturn('ownerId');
891
-		$owner->method('getDisplayName')->willReturn('ownerDisplay');
892
-
893
-		$user = $this->getMockBuilder(IUser::class)->getMock();
894
-		$user->method('getUID')->willReturn('userId');
895
-		$user->method('getDisplayName')->willReturn('userDisplay');
896
-		$user->method('getSystemEMailAddress')->willReturn('[email protected]');
897
-
898
-		$group = $this->getMockBuilder(IGroup::class)->getMock();
899
-		$group->method('getGID')->willReturn('groupId');
900
-
901
-		$this->userManager->method('get')->willReturnMap([
902
-			['userId', $user],
903
-			['initiatorId', $initiator],
904
-			['ownerId', $owner],
905
-		]);
906
-		$this->groupManager->method('get')->willReturnMap([
907
-			['group', $group],
908
-		]);
909
-		$this->dateTimeZone->method('getTimezone')->willReturn(new \DateTimeZone('UTC'));
910
-
911
-		$data = $ocs->getShare($share->getId())->getData()[0];
912
-		$this->assertEquals($result, $data);
913
-	}
914
-
915
-
916
-	public function testGetShareInvalidNode(): void {
917
-		$this->expectException(OCSNotFoundException::class);
918
-		$this->expectExceptionMessage('Wrong share ID, share does not exist');
919
-
920
-		$share = Server::get(IManager::class)->newShare();
921
-		$share->setSharedBy('initiator')
922
-			->setSharedWith('recipient')
923
-			->setShareOwner('owner');
924
-
925
-		$this->shareManager
926
-			->expects($this->once())
927
-			->method('getShareById')
928
-			->with('ocinternal:42', 'currentUser')
929
-			->willReturn($share);
930
-
931
-		$userFolder = $this->getMockBuilder(Folder::class)->getMock();
932
-		$this->rootFolder->method('getUserFolder')
933
-			->with($this->currentUser)
934
-			->willReturn($userFolder);
935
-
936
-		$this->ocs->getShare(42);
937
-	}
938
-
939
-	public function dataGetShares() {
940
-		$folder = $this->getMockBuilder(Folder::class)->getMock();
941
-		$file1 = $this->getMockBuilder(File::class)->getMock();
942
-		$file1->method('getName')
943
-			->willReturn('file1');
944
-		$file2 = $this->getMockBuilder(File::class)->getMock();
945
-		$file2->method('getName')
946
-			->willReturn('file2');
947
-
948
-		$folder->method('getDirectoryListing')
949
-			->willReturn([$file1, $file2]);
950
-
951
-		$file1UserShareOwner = Server::get(IManager::class)->newShare();
952
-		$file1UserShareOwner->setShareType(IShare::TYPE_USER)
953
-			->setSharedWith('recipient')
954
-			->setSharedBy('initiator')
955
-			->setShareOwner('currentUser')
956
-			->setPermissions(Constants::PERMISSION_READ)
957
-			->setNode($file1)
958
-			->setId(4);
959
-
960
-		$file1UserShareOwnerExpected = [
961
-			'id' => 4,
962
-			'share_type' => IShare::TYPE_USER,
963
-		];
964
-
965
-		$file1UserShareInitiator = Server::get(IManager::class)->newShare();
966
-		$file1UserShareInitiator->setShareType(IShare::TYPE_USER)
967
-			->setSharedWith('recipient')
968
-			->setSharedBy('currentUser')
969
-			->setShareOwner('owner')
970
-			->setPermissions(Constants::PERMISSION_READ)
971
-			->setNode($file1)
972
-			->setId(8);
973
-
974
-		$file1UserShareInitiatorExpected = [
975
-			'id' => 8,
976
-			'share_type' => IShare::TYPE_USER,
977
-		];
978
-
979
-		$file1UserShareRecipient = Server::get(IManager::class)->newShare();
980
-		$file1UserShareRecipient->setShareType(IShare::TYPE_USER)
981
-			->setSharedWith('currentUser')
982
-			->setSharedBy('initiator')
983
-			->setShareOwner('owner')
984
-			->setPermissions(Constants::PERMISSION_READ)
985
-			->setNode($file1)
986
-			->setId(15);
987
-
988
-		$file1UserShareRecipientExpected = [
989
-			'id' => 15,
990
-			'share_type' => IShare::TYPE_USER,
991
-		];
992
-
993
-		$file1UserShareOther = Server::get(IManager::class)->newShare();
994
-		$file1UserShareOther->setShareType(IShare::TYPE_USER)
995
-			->setSharedWith('recipient')
996
-			->setSharedBy('initiator')
997
-			->setShareOwner('owner')
998
-			->setPermissions(Constants::PERMISSION_READ)
999
-			->setNode($file1)
1000
-			->setId(16);
1001
-
1002
-		$file1UserShareOtherExpected = [
1003
-			'id' => 16,
1004
-			'share_type' => IShare::TYPE_USER,
1005
-		];
1006
-
1007
-		$file1GroupShareOwner = Server::get(IManager::class)->newShare();
1008
-		$file1GroupShareOwner->setShareType(IShare::TYPE_GROUP)
1009
-			->setSharedWith('recipient')
1010
-			->setSharedBy('initiator')
1011
-			->setShareOwner('currentUser')
1012
-			->setPermissions(Constants::PERMISSION_READ)
1013
-			->setNode($file1)
1014
-			->setId(23);
1015
-
1016
-		$file1GroupShareOwnerExpected = [
1017
-			'id' => 23,
1018
-			'share_type' => IShare::TYPE_GROUP,
1019
-		];
1020
-
1021
-		$file1GroupShareRecipient = Server::get(IManager::class)->newShare();
1022
-		$file1GroupShareRecipient->setShareType(IShare::TYPE_GROUP)
1023
-			->setSharedWith('currentUserGroup')
1024
-			->setSharedBy('initiator')
1025
-			->setShareOwner('owner')
1026
-			->setPermissions(Constants::PERMISSION_READ)
1027
-			->setNode($file1)
1028
-			->setId(42);
1029
-
1030
-		$file1GroupShareRecipientExpected = [
1031
-			'id' => 42,
1032
-			'share_type' => IShare::TYPE_GROUP,
1033
-		];
1034
-
1035
-		$file1GroupShareOther = Server::get(IManager::class)->newShare();
1036
-		$file1GroupShareOther->setShareType(IShare::TYPE_GROUP)
1037
-			->setSharedWith('recipient')
1038
-			->setSharedBy('initiator')
1039
-			->setShareOwner('owner')
1040
-			->setPermissions(Constants::PERMISSION_READ)
1041
-			->setNode($file1)
1042
-			->setId(108);
1043
-
1044
-		$file1LinkShareOwner = Server::get(IManager::class)->newShare();
1045
-		$file1LinkShareOwner->setShareType(IShare::TYPE_LINK)
1046
-			->setSharedWith('recipient')
1047
-			->setSharedBy('initiator')
1048
-			->setShareOwner('currentUser')
1049
-			->setPermissions(Constants::PERMISSION_READ)
1050
-			->setNode($file1)
1051
-			->setId(415);
1052
-
1053
-		$file1LinkShareOwnerExpected = [
1054
-			'id' => 415,
1055
-			'share_type' => IShare::TYPE_LINK,
1056
-		];
1057
-
1058
-		$file1EmailShareOwner = Server::get(IManager::class)->newShare();
1059
-		$file1EmailShareOwner->setShareType(IShare::TYPE_EMAIL)
1060
-			->setSharedWith('recipient')
1061
-			->setSharedBy('initiator')
1062
-			->setShareOwner('currentUser')
1063
-			->setPermissions(Constants::PERMISSION_READ)
1064
-			->setNode($file1)
1065
-			->setId(416);
1066
-
1067
-		$file1EmailShareOwnerExpected = [
1068
-			'id' => 416,
1069
-			'share_type' => IShare::TYPE_EMAIL,
1070
-		];
1071
-
1072
-		$file1CircleShareOwner = Server::get(IManager::class)->newShare();
1073
-		$file1CircleShareOwner->setShareType(IShare::TYPE_CIRCLE)
1074
-			->setSharedWith('recipient')
1075
-			->setSharedBy('initiator')
1076
-			->setShareOwner('currentUser')
1077
-			->setPermissions(Constants::PERMISSION_READ)
1078
-			->setNode($file1)
1079
-			->setId(423);
1080
-
1081
-		$file1CircleShareOwnerExpected = [
1082
-			'id' => 423,
1083
-			'share_type' => IShare::TYPE_CIRCLE,
1084
-		];
1085
-
1086
-		$file1RoomShareOwner = Server::get(IManager::class)->newShare();
1087
-		$file1RoomShareOwner->setShareType(IShare::TYPE_ROOM)
1088
-			->setSharedWith('recipient')
1089
-			->setSharedBy('initiator')
1090
-			->setShareOwner('currentUser')
1091
-			->setPermissions(Constants::PERMISSION_READ)
1092
-			->setNode($file1)
1093
-			->setId(442);
1094
-
1095
-		$file1RoomShareOwnerExpected = [
1096
-			'id' => 442,
1097
-			'share_type' => IShare::TYPE_ROOM,
1098
-		];
1099
-
1100
-		$file1RemoteShareOwner = Server::get(IManager::class)->newShare();
1101
-		$file1RemoteShareOwner->setShareType(IShare::TYPE_REMOTE)
1102
-			->setSharedWith('recipient')
1103
-			->setSharedBy('initiator')
1104
-			->setShareOwner('currentUser')
1105
-			->setPermissions(Constants::PERMISSION_READ)
1106
-			->setExpirationDate(new \DateTime('2000-01-01T01:02:03'))
1107
-			->setNode($file1)
1108
-			->setId(815);
1109
-
1110
-		$file1RemoteShareOwnerExpected = [
1111
-			'id' => 815,
1112
-			'share_type' => IShare::TYPE_REMOTE,
1113
-		];
1114
-
1115
-		$file1RemoteGroupShareOwner = Server::get(IManager::class)->newShare();
1116
-		$file1RemoteGroupShareOwner->setShareType(IShare::TYPE_REMOTE_GROUP)
1117
-			->setSharedWith('recipient')
1118
-			->setSharedBy('initiator')
1119
-			->setShareOwner('currentUser')
1120
-			->setPermissions(Constants::PERMISSION_READ)
1121
-			->setExpirationDate(new \DateTime('2000-01-02T01:02:03'))
1122
-			->setNode($file1)
1123
-			->setId(816);
1124
-
1125
-		$file1RemoteGroupShareOwnerExpected = [
1126
-			'id' => 816,
1127
-			'share_type' => IShare::TYPE_REMOTE_GROUP,
1128
-		];
1129
-
1130
-		$file2UserShareOwner = Server::get(IManager::class)->newShare();
1131
-		$file2UserShareOwner->setShareType(IShare::TYPE_USER)
1132
-			->setSharedWith('recipient')
1133
-			->setSharedBy('initiator')
1134
-			->setShareOwner('currentUser')
1135
-			->setPermissions(Constants::PERMISSION_READ)
1136
-			->setNode($file2)
1137
-			->setId(823);
1138
-
1139
-		$file2UserShareOwnerExpected = [
1140
-			'id' => 823,
1141
-			'share_type' => IShare::TYPE_USER,
1142
-		];
1143
-
1144
-		$data = [
1145
-			[
1146
-				[
1147
-					'path' => $file1,
1148
-				],
1149
-				[
1150
-					'file1' => [
1151
-						IShare::TYPE_USER => [$file1UserShareOwner, $file1UserShareOwner, $file1UserShareOwner],
1152
-					],
1153
-				],
1154
-				[
1155
-				],
1156
-				[
1157
-					$file1UserShareOwnerExpected
1158
-				]
1159
-			],
1160
-			[
1161
-				[
1162
-					'path' => $file1,
1163
-				],
1164
-				[
1165
-					'file1' => [
1166
-						IShare::TYPE_USER => [$file1UserShareOwner, $file1UserShareRecipient],
1167
-					],
1168
-				],
1169
-				[
1170
-				],
1171
-				[
1172
-					$file1UserShareOwnerExpected,
1173
-				]
1174
-			],
1175
-			[
1176
-				[
1177
-					'path' => $file1,
1178
-				],
1179
-				[
1180
-					'file1' => [
1181
-						IShare::TYPE_USER => [$file1UserShareOwner, $file1UserShareRecipient, $file1UserShareInitiator, $file1UserShareOther],
1182
-					],
1183
-				],
1184
-				[
1185
-				],
1186
-				[
1187
-					$file1UserShareOwnerExpected,
1188
-					$file1UserShareInitiatorExpected,
1189
-					$file1UserShareOtherExpected,
1190
-				]
1191
-			],
1192
-			[
1193
-				[
1194
-					'path' => $file1,
1195
-				],
1196
-				[
1197
-					'file1' => [
1198
-						IShare::TYPE_USER => [$file1UserShareRecipient, $file1UserShareInitiator, $file1UserShareOther],
1199
-					],
1200
-				],
1201
-				[
1202
-				],
1203
-				[
1204
-					$file1UserShareInitiatorExpected,
1205
-				]
1206
-			],
1207
-			[
1208
-				[
1209
-					'path' => $file1,
1210
-				],
1211
-				[
1212
-					'file1' => [
1213
-						IShare::TYPE_USER => [$file1UserShareOwner],
1214
-						IShare::TYPE_GROUP => [$file1GroupShareRecipient],
1215
-					],
1216
-				],
1217
-				[
1218
-				],
1219
-				[
1220
-					$file1UserShareOwnerExpected,
1221
-					$file1GroupShareRecipientExpected,
1222
-				]
1223
-			],
1224
-			[
1225
-				[
1226
-					'path' => $file1,
1227
-				],
1228
-				[
1229
-					'file1' => [
1230
-						IShare::TYPE_USER => [$file1UserShareOwner],
1231
-						IShare::TYPE_GROUP => [$file1GroupShareOwner],
1232
-						IShare::TYPE_LINK => [$file1LinkShareOwner],
1233
-						IShare::TYPE_EMAIL => [$file1EmailShareOwner],
1234
-						IShare::TYPE_CIRCLE => [$file1CircleShareOwner],
1235
-						IShare::TYPE_ROOM => [$file1RoomShareOwner],
1236
-						IShare::TYPE_REMOTE => [$file1RemoteShareOwner],
1237
-						IShare::TYPE_REMOTE_GROUP => [$file1RemoteGroupShareOwner],
1238
-					],
1239
-				],
1240
-				[
1241
-				],
1242
-				[
1243
-					$file1UserShareOwnerExpected,
1244
-					$file1GroupShareOwnerExpected,
1245
-					$file1LinkShareOwnerExpected,
1246
-					$file1EmailShareOwnerExpected,
1247
-					$file1CircleShareOwnerExpected,
1248
-					$file1RoomShareOwnerExpected,
1249
-				]
1250
-			],
1251
-			[
1252
-				[
1253
-					'path' => $file1,
1254
-				],
1255
-				[
1256
-					'file1' => [
1257
-						IShare::TYPE_USER => [$file1UserShareOwner],
1258
-						IShare::TYPE_GROUP => [$file1GroupShareOwner],
1259
-						IShare::TYPE_LINK => [$file1LinkShareOwner],
1260
-						IShare::TYPE_EMAIL => [$file1EmailShareOwner],
1261
-						IShare::TYPE_CIRCLE => [$file1CircleShareOwner],
1262
-						IShare::TYPE_ROOM => [$file1RoomShareOwner],
1263
-						IShare::TYPE_REMOTE => [$file1RemoteShareOwner],
1264
-						IShare::TYPE_REMOTE_GROUP => [$file1RemoteGroupShareOwner],
1265
-					],
1266
-				],
1267
-				[
1268
-					IShare::TYPE_REMOTE => true,
1269
-					IShare::TYPE_REMOTE_GROUP => true,
1270
-				],
1271
-				[
1272
-					$file1UserShareOwnerExpected,
1273
-					$file1GroupShareOwnerExpected,
1274
-					$file1LinkShareOwnerExpected,
1275
-					$file1EmailShareOwnerExpected,
1276
-					$file1CircleShareOwnerExpected,
1277
-					$file1RoomShareOwnerExpected,
1278
-					$file1RemoteShareOwnerExpected,
1279
-					$file1RemoteGroupShareOwnerExpected,
1280
-				]
1281
-			],
1282
-			[
1283
-				[
1284
-					'path' => $folder,
1285
-					'subfiles' => 'true',
1286
-				],
1287
-				[
1288
-					'file1' => [
1289
-						IShare::TYPE_USER => [$file1UserShareOwner],
1290
-					],
1291
-					'file2' => [
1292
-						IShare::TYPE_USER => [$file2UserShareOwner],
1293
-					],
1294
-				],
1295
-				[
1296
-				],
1297
-				[
1298
-					$file1UserShareOwnerExpected,
1299
-					$file2UserShareOwnerExpected,
1300
-				]
1301
-			],
1302
-			[
1303
-				[
1304
-					'path' => $folder,
1305
-					'subfiles' => 'true',
1306
-				],
1307
-				[
1308
-					'file1' => [
1309
-						IShare::TYPE_USER => [$file1UserShareOwner, $file1UserShareOwner, $file1UserShareOwner],
1310
-					],
1311
-				],
1312
-				[
1313
-				],
1314
-				[
1315
-					$file1UserShareOwnerExpected,
1316
-				]
1317
-			],
1318
-			[
1319
-				[
1320
-					'path' => $folder,
1321
-					'subfiles' => 'true',
1322
-				],
1323
-				[
1324
-					'file1' => [
1325
-						IShare::TYPE_USER => [$file1UserShareOwner, $file1UserShareRecipient],
1326
-					],
1327
-				],
1328
-				[
1329
-				],
1330
-				[
1331
-					$file1UserShareOwnerExpected
1332
-				]
1333
-			],
1334
-			[
1335
-				[
1336
-					'path' => $folder,
1337
-					'subfiles' => 'true',
1338
-				],
1339
-				[
1340
-					'file1' => [
1341
-						IShare::TYPE_USER => [$file1UserShareRecipient, $file1UserShareInitiator, $file1UserShareOther],
1342
-					],
1343
-					'file2' => [
1344
-						IShare::TYPE_USER => [$file2UserShareOwner],
1345
-					],
1346
-				],
1347
-				[
1348
-				],
1349
-				[
1350
-					$file1UserShareInitiatorExpected,
1351
-					$file1UserShareOtherExpected,
1352
-					$file2UserShareOwnerExpected,
1353
-				]
1354
-			],
1355
-			// This might not happen in a real environment, as the combination
1356
-			// of shares does not seem to be possible on a folder without
1357
-			// resharing rights; if the folder has resharing rights then the
1358
-			// share with others would be included too in the results.
1359
-			[
1360
-				[
1361
-					'path' => $folder,
1362
-					'subfiles' => 'true',
1363
-				],
1364
-				[
1365
-					'file1' => [
1366
-						IShare::TYPE_USER => [$file1UserShareRecipient, $file1UserShareInitiator, $file1UserShareOther],
1367
-					],
1368
-				],
1369
-				[
1370
-				],
1371
-				[
1372
-					$file1UserShareInitiatorExpected,
1373
-				]
1374
-			],
1375
-			[
1376
-				[
1377
-					'path' => $folder,
1378
-					'subfiles' => 'true',
1379
-				],
1380
-				[
1381
-					'file1' => [
1382
-						IShare::TYPE_USER => [$file1UserShareOwner],
1383
-						IShare::TYPE_GROUP => [$file1GroupShareRecipient],
1384
-					],
1385
-				],
1386
-				[
1387
-				],
1388
-				[
1389
-					$file1UserShareOwnerExpected,
1390
-					$file1GroupShareRecipientExpected,
1391
-				]
1392
-			],
1393
-			[
1394
-				[
1395
-					'path' => $folder,
1396
-					'subfiles' => 'true',
1397
-				],
1398
-				[
1399
-					'file1' => [
1400
-						IShare::TYPE_USER => [$file1UserShareOwner],
1401
-						IShare::TYPE_GROUP => [$file1GroupShareOwner],
1402
-						IShare::TYPE_LINK => [$file1LinkShareOwner],
1403
-						IShare::TYPE_EMAIL => [$file1EmailShareOwner],
1404
-						IShare::TYPE_CIRCLE => [$file1CircleShareOwner],
1405
-						IShare::TYPE_ROOM => [$file1RoomShareOwner],
1406
-						IShare::TYPE_REMOTE => [$file1RemoteShareOwner],
1407
-						IShare::TYPE_REMOTE_GROUP => [$file1RemoteGroupShareOwner],
1408
-					],
1409
-				],
1410
-				[
1411
-				],
1412
-				[
1413
-					$file1UserShareOwnerExpected,
1414
-					$file1GroupShareOwnerExpected,
1415
-					$file1LinkShareOwnerExpected,
1416
-					$file1EmailShareOwnerExpected,
1417
-					$file1CircleShareOwnerExpected,
1418
-					$file1RoomShareOwnerExpected,
1419
-				]
1420
-			],
1421
-			[
1422
-				[
1423
-					'path' => $folder,
1424
-					'subfiles' => 'true',
1425
-				],
1426
-				[
1427
-					'file1' => [
1428
-						IShare::TYPE_USER => [$file1UserShareOwner],
1429
-						IShare::TYPE_GROUP => [$file1GroupShareOwner],
1430
-						IShare::TYPE_LINK => [$file1LinkShareOwner],
1431
-						IShare::TYPE_EMAIL => [$file1EmailShareOwner],
1432
-						IShare::TYPE_CIRCLE => [$file1CircleShareOwner],
1433
-						IShare::TYPE_ROOM => [$file1RoomShareOwner],
1434
-						IShare::TYPE_REMOTE => [$file1RemoteShareOwner],
1435
-						IShare::TYPE_REMOTE_GROUP => [$file1RemoteGroupShareOwner],
1436
-					],
1437
-				],
1438
-				[
1439
-					IShare::TYPE_REMOTE => true,
1440
-					IShare::TYPE_REMOTE_GROUP => true,
1441
-				],
1442
-				[
1443
-					$file1UserShareOwnerExpected,
1444
-					$file1GroupShareOwnerExpected,
1445
-					$file1LinkShareOwnerExpected,
1446
-					$file1EmailShareOwnerExpected,
1447
-					$file1CircleShareOwnerExpected,
1448
-					$file1RoomShareOwnerExpected,
1449
-					$file1RemoteShareOwnerExpected,
1450
-					$file1RemoteGroupShareOwnerExpected,
1451
-				]
1452
-			],
1453
-		];
1454
-
1455
-		return $data;
1456
-	}
1457
-
1458
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataGetShares')]
1459
-	public function testGetShares(array $getSharesParameters, array $shares, array $extraShareTypes, array $expected): void {
1460
-		/** @var ShareAPIController&MockObject $ocs */
1461
-		$ocs = $this->getMockBuilder(ShareAPIController::class)
1462
-			->setConstructorArgs([
1463
-				$this->appName,
1464
-				$this->request,
1465
-				$this->shareManager,
1466
-				$this->groupManager,
1467
-				$this->userManager,
1468
-				$this->rootFolder,
1469
-				$this->urlGenerator,
1470
-				$this->l,
1471
-				$this->config,
1472
-				$this->appManager,
1473
-				$this->serverContainer,
1474
-				$this->userStatusManager,
1475
-				$this->previewManager,
1476
-				$this->dateTimeZone,
1477
-				$this->logger,
1478
-				$this->factory,
1479
-				$this->mailer,
1480
-				$this->tagManager,
1481
-				$this->currentUser,
1482
-			])
1483
-			->onlyMethods(['formatShare'])
1484
-			->getMock();
1485
-
1486
-		$ocs->method('formatShare')
1487
-			->willReturnCallback(
1488
-				function ($share) {
1489
-					return [
1490
-						'id' => $share->getId(),
1491
-						'share_type' => $share->getShareType()
1492
-					];
1493
-				}
1494
-			);
1495
-
1496
-		$userFolder = $this->getMockBuilder(Folder::class)->getMock();
1497
-		$userFolder->method('get')
1498
-			->with('path')
1499
-			->willReturn($getSharesParameters['path']);
1500
-
1501
-		$this->rootFolder->method('getUserFolder')
1502
-			->with($this->currentUser)
1503
-			->willReturn($userFolder);
1504
-
1505
-		$this->shareManager
1506
-			->method('getSharesBy')
1507
-			->willReturnCallback(
1508
-				function ($user, $shareType, $node) use ($shares) {
1509
-					if (!isset($shares[$node->getName()]) || !isset($shares[$node->getName()][$shareType])) {
1510
-						return [];
1511
-					}
1512
-					return $shares[$node->getName()][$shareType];
1513
-				}
1514
-			);
1515
-
1516
-		$this->shareManager
1517
-			->method('outgoingServer2ServerSharesAllowed')
1518
-			->willReturn($extraShareTypes[ISHARE::TYPE_REMOTE] ?? false);
1519
-
1520
-		$this->shareManager
1521
-			->method('outgoingServer2ServerGroupSharesAllowed')
1522
-			->willReturn($extraShareTypes[ISHARE::TYPE_REMOTE_GROUP] ?? false);
1523
-
1524
-		$this->groupManager
1525
-			->method('isInGroup')
1526
-			->willReturnCallback(
1527
-				function ($user, $group) {
1528
-					return $group === 'currentUserGroup';
1529
-				}
1530
-			);
1531
-
1532
-		$result = $ocs->getShares(
1533
-			$getSharesParameters['sharedWithMe'] ?? 'false',
1534
-			$getSharesParameters['reshares'] ?? 'false',
1535
-			$getSharesParameters['subfiles'] ?? 'false',
1536
-			'path'
1537
-		);
1538
-
1539
-		$this->assertEquals($expected, $result->getData());
1540
-	}
1541
-
1542
-	public function testCanAccessShareAsOwner(): void {
1543
-		$share = $this->createMock(IShare::class);
1544
-		$share->method('getShareOwner')->willReturn($this->currentUser);
1545
-		$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
1546
-	}
1547
-
1548
-	public function testCanAccessShareAsSharer(): void {
1549
-		$share = $this->createMock(IShare::class);
1550
-		$share->method('getSharedBy')->willReturn($this->currentUser);
1551
-		$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
1552
-	}
1553
-
1554
-	public function testCanAccessShareAsSharee(): void {
1555
-		$share = $this->createMock(IShare::class);
1556
-		$share->method('getShareType')->willReturn(IShare::TYPE_USER);
1557
-		$share->method('getSharedWith')->willReturn($this->currentUser);
1558
-		$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
1559
-	}
1560
-
1561
-	public function testCannotAccessLinkShare(): void {
1562
-		$share = $this->createMock(IShare::class);
1563
-		$share->method('getShareType')->willReturn(IShare::TYPE_LINK);
1564
-		$share->method('getNodeId')->willReturn(42);
1565
-
1566
-		$userFolder = $this->createMock(Folder::class);
1567
-		$this->rootFolder->method('getUserFolder')
1568
-			->with($this->currentUser)
1569
-			->willReturn($userFolder);
1570
-
1571
-		$this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
1572
-	}
1573
-
1574
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataCanAccessShareWithPermissions')]
1575
-	public function testCanAccessShareWithPermissions(int $permissions, bool $expected): void {
1576
-		$share = $this->createMock(IShare::class);
1577
-		$share->method('getShareType')->willReturn(IShare::TYPE_USER);
1578
-		$share->method('getSharedWith')->willReturn($this->createMock(IUser::class));
1579
-		$share->method('getNodeId')->willReturn(42);
1580
-
1581
-		$file = $this->createMock(File::class);
1582
-
1583
-		$userFolder = $this->getMockBuilder(Folder::class)->getMock();
1584
-		$userFolder->method('getFirstNodeById')
1585
-			->with($share->getNodeId())
1586
-			->willReturn($file);
1587
-		$userFolder->method('getById')
1588
-			->with($share->getNodeId())
1589
-			->willReturn([$file]);
1590
-		$this->rootFolder->method('getUserFolder')
1591
-			->with($this->currentUser)
1592
-			->willReturn($userFolder);
1593
-
1594
-		$file->method('getPermissions')
1595
-			->willReturn($permissions);
1596
-
1597
-		if ($expected) {
1598
-			$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
1599
-		} else {
1600
-			$this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
1601
-		}
1602
-	}
1603
-
1604
-	public static function dataCanAccessShareWithPermissions(): array {
1605
-		return [
1606
-			[Constants::PERMISSION_SHARE, true],
1607
-			[Constants::PERMISSION_READ, false],
1608
-			[Constants::PERMISSION_READ | Constants::PERMISSION_SHARE, true],
1609
-		];
1610
-	}
1611
-
1612
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataCanAccessShareAsGroupMember')]
1613
-	public function testCanAccessShareAsGroupMember(string $group, bool $expected): void {
1614
-		$share = $this->createMock(IShare::class);
1615
-		$share->method('getShareType')->willReturn(IShare::TYPE_GROUP);
1616
-		$share->method('getSharedWith')->willReturn($group);
1617
-		$share->method('getNodeId')->willReturn(42);
1618
-
1619
-		$file = $this->createMock(File::class);
1620
-
1621
-		$userFolder = $this->createMock(Folder::class);
1622
-		$userFolder->method('getFirstNodeById')
1623
-			->with($share->getNodeId())
1624
-			->willReturn($file);
1625
-		$userFolder->method('getById')
1626
-			->with($share->getNodeId())
1627
-			->willReturn([$file]);
1628
-		$this->rootFolder->method('getUserFolder')
1629
-			->with($this->currentUser)
1630
-			->willReturn($userFolder);
1631
-
1632
-		$user = $this->createMock(IUser::class);
1633
-		$this->userManager->method('get')
1634
-			->with($this->currentUser)
1635
-			->willReturn($user);
1636
-
1637
-		$group = $this->createMock(IGroup::class);
1638
-		$group->method('inGroup')->with($user)->willReturn(true);
1639
-		$group2 = $this->createMock(IGroup::class);
1640
-		$group2->method('inGroup')->with($user)->willReturn(false);
1641
-
1642
-		$this->groupManager->method('get')->willReturnMap([
1643
-			['group', $group],
1644
-			['group2', $group2],
1645
-			['group-null', null],
1646
-		]);
1647
-
1648
-		if ($expected) {
1649
-			$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
1650
-		} else {
1651
-			$this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
1652
-		}
1653
-	}
1654
-
1655
-	public static function dataCanAccessShareAsGroupMember(): array {
1656
-		return [
1657
-			['group', true],
1658
-			['group2', false],
1659
-			['group-null', false],
1660
-		];
1661
-	}
1662
-
1663
-	public function dataCanAccessRoomShare() {
1664
-		$result = [];
1665
-
1666
-		$share = $this->createMock(IShare::class);
1667
-		$share->method('getShareType')->willReturn(IShare::TYPE_ROOM);
1668
-		$share->method('getSharedWith')->willReturn('recipientRoom');
1669
-
1670
-		$result[] = [
1671
-			false, $share, false, false
1672
-		];
1673
-
1674
-		$result[] = [
1675
-			false, $share, false, true
1676
-		];
1677
-
1678
-		$result[] = [
1679
-			true, $share, true, true
1680
-		];
1681
-
1682
-		$result[] = [
1683
-			false, $share, true, false
1684
-		];
1685
-
1686
-		return $result;
1687
-	}
1688
-
1689
-	/**
1690
-	 *
1691
-	 * @param bool $expects
1692
-	 * @param IShare $share
1693
-	 * @param bool helperAvailable
1694
-	 * @param bool canAccessShareByHelper
1695
-	 */
1696
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataCanAccessRoomShare')]
1697
-	public function testCanAccessRoomShare(bool $expected, IShare $share, bool $helperAvailable, bool $canAccessShareByHelper): void {
1698
-		$userFolder = $this->getMockBuilder(Folder::class)->getMock();
1699
-		$this->rootFolder->method('getUserFolder')
1700
-			->with($this->currentUser)
1701
-			->willReturn($userFolder);
1702
-
1703
-		$userFolder->method('getById')
1704
-			->with($share->getNodeId())
1705
-			->willReturn([$share->getNode()]);
1706
-
1707
-		if (!$helperAvailable) {
1708
-			$this->appManager->method('isEnabledForUser')
1709
-				->with('spreed')
1710
-				->willReturn(false);
1711
-		} else {
1712
-			$this->appManager->method('isEnabledForUser')
1713
-				->with('spreed')
1714
-				->willReturn(true);
1715
-
1716
-			// This is not possible anymore with PHPUnit 10+
1717
-			// as `setMethods` was removed and now real reflection is used, thus the class needs to exist.
1718
-			// $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
1719
-			$helper = $this->getMockBuilder(\stdClass::class)
1720
-				->addMethods(['canAccessShare'])
1721
-				->getMock();
1722
-			$helper->method('canAccessShare')
1723
-				->with($share, $this->currentUser)
1724
-				->willReturn($canAccessShareByHelper);
1725
-
1726
-			$this->serverContainer->method('get')
1727
-				->with('\OCA\Talk\Share\Helper\ShareAPIController')
1728
-				->willReturn($helper);
1729
-		}
1730
-
1731
-		$this->assertEquals($expected, $this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
1732
-	}
1733
-
1734
-
1735
-	public function testCreateShareNoPath(): void {
1736
-		$this->expectException(OCSNotFoundException::class);
1737
-		$this->expectExceptionMessage('Please specify a file or folder path');
1738
-
1739
-		$this->ocs->createShare();
1740
-	}
1741
-
1742
-
1743
-	public function testCreateShareInvalidPath(): void {
1744
-		$this->expectException(OCSNotFoundException::class);
1745
-		$this->expectExceptionMessage('Wrong path, file/folder does not exist');
1746
-
1747
-		$userFolder = $this->getMockBuilder(Folder::class)->getMock();
1748
-		$this->rootFolder->expects($this->once())
1749
-			->method('getUserFolder')
1750
-			->with('currentUser')
1751
-			->willReturn($userFolder);
1752
-
1753
-		$userFolder->expects($this->once())
1754
-			->method('get')
1755
-			->with('invalid-path')
1756
-			->willThrowException(new NotFoundException());
1757
-
1758
-		$this->ocs->createShare('invalid-path');
1759
-	}
1760
-
1761
-	public function testCreateShareInvalidShareType(): void {
1762
-		$this->expectException(OCSBadRequestException::class);
1763
-		$this->expectExceptionMessage('Unknown share type');
1764
-
1765
-		$share = $this->newShare();
1766
-		$this->shareManager->method('newShare')->willReturn($share);
1767
-
1768
-		[$userFolder, $file] = $this->getNonSharedUserFile();
1769
-		$this->rootFolder->expects($this->atLeastOnce())
1770
-			->method('getUserFolder')
1771
-			->with('currentUser')
1772
-			->willReturn($userFolder);
1773
-
1774
-		$userFolder->expects($this->atLeastOnce())
1775
-			->method('get')
1776
-			->with('valid-path')
1777
-			->willReturn($file);
1778
-		$userFolder->method('getById')
1779
-			->willReturn([]);
1780
-
1781
-		$file->expects($this->once())
1782
-			->method('lock')
1783
-			->with(ILockingProvider::LOCK_SHARED);
1784
-
1785
-		$this->ocs->createShare('valid-path', 31);
1786
-	}
1787
-
1788
-	public function testCreateShareUserNoShareWith(): void {
1789
-		$this->expectException(OCSNotFoundException::class);
1790
-		$this->expectExceptionMessage('Please specify a valid account to share with');
1791
-
1792
-		$share = $this->newShare();
1793
-		$this->shareManager->method('newShare')->willReturn($share);
1794
-
1795
-		[$userFolder, $path] = $this->getNonSharedUserFile();
1796
-		$this->rootFolder->method('getUserFolder')
1797
-			->with('currentUser')
1798
-			->willReturn($userFolder);
1799
-
1800
-		$userFolder->expects($this->once())
1801
-			->method('get')
1802
-			->with('valid-path')
1803
-			->willReturn($path);
1804
-		$userFolder->method('getById')
1805
-			->willReturn([]);
1806
-
1807
-		$path->expects($this->once())
1808
-			->method('lock')
1809
-			->with(ILockingProvider::LOCK_SHARED);
1810
-
1811
-		$this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_USER);
1812
-	}
1813
-
1814
-
1815
-	public function testCreateShareUserNoValidShareWith(): void {
1816
-		$this->expectException(OCSNotFoundException::class);
1817
-		$this->expectExceptionMessage('Please specify a valid account to share with');
1818
-
1819
-		$share = $this->newShare();
1820
-		$this->shareManager->method('newShare')->willReturn($share);
1821
-
1822
-		[$userFolder, $path] = $this->getNonSharedUserFile();
1823
-		$this->rootFolder->method('getUserFolder')
1824
-			->with('currentUser')
1825
-			->willReturn($userFolder);
1826
-
1827
-		$userFolder->expects($this->once())
1828
-			->method('get')
1829
-			->with('valid-path')
1830
-			->willReturn($path);
1831
-		$userFolder->method('getById')
1832
-			->willReturn([]);
1833
-		$path->expects($this->once())
1834
-			->method('lock')
1835
-			->with(ILockingProvider::LOCK_SHARED);
1836
-		$this->userManager->method('userExists')
1837
-			->with('invalidUser')
1838
-			->willReturn(false);
1839
-
1840
-		$this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_USER, 'invalidUser');
1841
-	}
1842
-
1843
-	public function testCreateShareUser(): void {
1844
-		$share = $this->newShare();
1845
-		$this->shareManager->method('newShare')->willReturn($share);
1846
-
1847
-		/** @var ShareAPIController $ocs */
1848
-		$ocs = $this->getMockBuilder(ShareAPIController::class)
1849
-			->setConstructorArgs([
1850
-				$this->appName,
1851
-				$this->request,
1852
-				$this->shareManager,
1853
-				$this->groupManager,
1854
-				$this->userManager,
1855
-				$this->rootFolder,
1856
-				$this->urlGenerator,
1857
-				$this->l,
1858
-				$this->config,
1859
-				$this->appManager,
1860
-				$this->serverContainer,
1861
-				$this->userStatusManager,
1862
-				$this->previewManager,
1863
-				$this->dateTimeZone,
1864
-				$this->logger,
1865
-				$this->factory,
1866
-				$this->mailer,
1867
-				$this->tagManager,
1868
-				$this->currentUser,
1869
-			])->onlyMethods(['formatShare'])
1870
-			->getMock();
1871
-
1872
-		[$userFolder, $path] = $this->getNonSharedUserFile();
1873
-		$this->rootFolder->expects($this->exactly(2))
1874
-			->method('getUserFolder')
1875
-			->with('currentUser')
1876
-			->willReturn($userFolder);
1877
-
1878
-		$userFolder->expects($this->once())
1879
-			->method('get')
1880
-			->with('valid-path')
1881
-			->willReturn($path);
1882
-		$userFolder->method('getById')
1883
-			->willReturn([]);
1884
-
1885
-		$this->userManager->method('userExists')->with('validUser')->willReturn(true);
1886
-
1887
-		$path->expects($this->once())
1888
-			->method('lock')
1889
-			->with(ILockingProvider::LOCK_SHARED);
1890
-
1891
-		$this->shareManager->method('createShare')
1892
-			->with($this->callback(function (IShare $share) use ($path) {
1893
-				return $share->getNode() === $path
1894
-					&& $share->getPermissions() === (
1895
-						Constants::PERMISSION_ALL
1896
-						& ~Constants::PERMISSION_DELETE
1897
-						& ~Constants::PERMISSION_CREATE
1898
-					)
1899
-					&& $share->getShareType() === IShare::TYPE_USER
1900
-					&& $share->getSharedWith() === 'validUser'
1901
-					&& $share->getSharedBy() === 'currentUser';
1902
-			}))
1903
-			->willReturnArgument(0);
1904
-
1905
-		$expected = new DataResponse([]);
1906
-		$result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_USER, 'validUser');
1907
-
1908
-		$this->assertInstanceOf(get_class($expected), $result);
1909
-		$this->assertEquals($expected->getData(), $result->getData());
1910
-	}
1911
-
1912
-
1913
-	public function testCreateShareGroupNoValidShareWith(): void {
1914
-		$this->expectException(OCSNotFoundException::class);
1915
-		$this->expectExceptionMessage('Please specify a valid group');
1916
-
1917
-		$share = $this->newShare();
1918
-		$this->shareManager->method('newShare')->willReturn($share);
1919
-		$this->shareManager->method('createShare')->willReturnArgument(0);
1920
-		$this->shareManager->method('allowGroupSharing')->willReturn(true);
1921
-
1922
-		[$userFolder, $path] = $this->getNonSharedUserFile();
1923
-		$this->rootFolder->method('getUserFolder')
1924
-			->with('currentUser')
1925
-			->willReturn($userFolder);
1926
-
1927
-		$userFolder->expects($this->once())
1928
-			->method('get')
1929
-			->with('valid-path')
1930
-			->willReturn($path);
1931
-		$userFolder->method('getById')
1932
-			->willReturn([]);
1933
-
1934
-		$path->expects($this->once())
1935
-			->method('lock')
1936
-			->with(ILockingProvider::LOCK_SHARED);
1937
-
1938
-		$this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_GROUP, 'invalidGroup');
1939
-	}
1940
-
1941
-	public function testCreateShareGroup(): void {
1942
-		$share = $this->newShare();
1943
-		$this->shareManager->method('newShare')->willReturn($share);
1944
-
1945
-		/** @var ShareAPIController&MockObject $ocs */
1946
-		$ocs = $this->getMockBuilder(ShareAPIController::class)
1947
-			->setConstructorArgs([
1948
-				$this->appName,
1949
-				$this->request,
1950
-				$this->shareManager,
1951
-				$this->groupManager,
1952
-				$this->userManager,
1953
-				$this->rootFolder,
1954
-				$this->urlGenerator,
1955
-				$this->l,
1956
-				$this->config,
1957
-				$this->appManager,
1958
-				$this->serverContainer,
1959
-				$this->userStatusManager,
1960
-				$this->previewManager,
1961
-				$this->dateTimeZone,
1962
-				$this->logger,
1963
-				$this->factory,
1964
-				$this->mailer,
1965
-				$this->tagManager,
1966
-				$this->currentUser,
1967
-			])->onlyMethods(['formatShare'])
1968
-			->getMock();
1969
-
1970
-		$this->request
1971
-			->method('getParam')
1972
-			->willReturnMap([
1973
-				['path', null, 'valid-path'],
1974
-				['permissions', null, Constants::PERMISSION_ALL],
1975
-				['shareType', '-1', IShare::TYPE_GROUP],
1976
-				['shareWith', null, 'validGroup'],
1977
-			]);
1978
-
1979
-		[$userFolder, $path] = $this->getNonSharedUserFolder();
1980
-		$this->rootFolder->expects($this->exactly(2))
1981
-			->method('getUserFolder')
1982
-			->with('currentUser')
1983
-			->willReturn($userFolder);
1984
-
1985
-		$userFolder->expects($this->once())
1986
-			->method('get')
1987
-			->with('valid-path')
1988
-			->willReturn($path);
1989
-		$userFolder->method('getById')
1990
-			->willReturn([]);
1991
-
1992
-		$this->groupManager->method('groupExists')->with('validGroup')->willReturn(true);
1993
-
1994
-		$this->shareManager->expects($this->once())
1995
-			->method('allowGroupSharing')
1996
-			->willReturn(true);
1997
-
1998
-		$path->expects($this->once())
1999
-			->method('lock')
2000
-			->with(ILockingProvider::LOCK_SHARED);
2001
-
2002
-		$this->shareManager->method('createShare')
2003
-			->with($this->callback(function (IShare $share) use ($path) {
2004
-				return $share->getNode() === $path
2005
-				&& $share->getPermissions() === Constants::PERMISSION_ALL
2006
-				&& $share->getShareType() === IShare::TYPE_GROUP
2007
-				&& $share->getSharedWith() === 'validGroup'
2008
-				&& $share->getSharedBy() === 'currentUser';
2009
-			}))
2010
-			->willReturnArgument(0);
2011
-
2012
-		$expected = new DataResponse([]);
2013
-		$result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_GROUP, 'validGroup');
2014
-
2015
-		$this->assertInstanceOf(get_class($expected), $result);
2016
-		$this->assertEquals($expected->getData(), $result->getData());
2017
-	}
2018
-
2019
-
2020
-	public function testCreateShareGroupNotAllowed(): void {
2021
-		$this->expectException(OCSNotFoundException::class);
2022
-		$this->expectExceptionMessage('Group sharing is disabled by the administrator');
2023
-
2024
-		$share = $this->newShare();
2025
-		$this->shareManager->method('newShare')->willReturn($share);
2026
-
2027
-		[$userFolder, $path] = $this->getNonSharedUserFolder();
2028
-		$this->rootFolder->method('getUserFolder')
2029
-			->with('currentUser')
2030
-			->willReturn($userFolder);
2031
-
2032
-		$userFolder->expects($this->once())
2033
-			->method('get')
2034
-			->with('valid-path')
2035
-			->willReturn($path);
2036
-		$userFolder->method('getById')
2037
-			->willReturn([]);
2038
-
2039
-		$this->groupManager->method('groupExists')->with('validGroup')->willReturn(true);
2040
-
2041
-		$this->shareManager->expects($this->once())
2042
-			->method('allowGroupSharing')
2043
-			->willReturn(false);
2044
-
2045
-		$this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_GROUP, 'invalidGroup');
2046
-	}
2047
-
2048
-
2049
-	public function testCreateShareLinkNoLinksAllowed(): void {
2050
-		$this->expectException(OCSNotFoundException::class);
2051
-		$this->expectExceptionMessage('Public link sharing is disabled by the administrator');
2052
-
2053
-		$this->request
2054
-			->method('getParam')
2055
-			->willReturnMap([
2056
-				['path', null, 'valid-path'],
2057
-				['shareType', '-1', IShare::TYPE_LINK],
2058
-			]);
2059
-
2060
-		$path = $this->getMockBuilder(Folder::class)->getMock();
2061
-		$path->method('getId')->willReturn(42);
2062
-		$storage = $this->createMock(IStorage::class);
2063
-		$storage->method('instanceOfStorage')
2064
-			->willReturnMap([
2065
-				['OCA\Files_Sharing\External\Storage', false],
2066
-				['OCA\Files_Sharing\SharedStorage', false],
2067
-			]);
2068
-		$path->method('getStorage')->willReturn($storage);
2069
-		$this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
2070
-		$this->rootFolder->method('get')->with('valid-path')->willReturn($path);
2071
-		$this->rootFolder->method('getById')
2072
-			->willReturn([]);
2073
-
2074
-		$this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
2075
-		$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
2076
-		$this->shareManager->method('shareApiAllowLinks')->willReturn(false);
2077
-
2078
-		$this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK);
2079
-	}
2080
-
2081
-
2082
-	public function testCreateShareLinkNoPublicUpload(): void {
2083
-		$this->expectException(OCSForbiddenException::class);
2084
-		$this->expectExceptionMessage('Public upload disabled by the administrator');
2085
-
2086
-		$path = $this->getMockBuilder(Folder::class)->getMock();
2087
-		$path->method('getId')->willReturn(42);
2088
-		$storage = $this->createMock(IStorage::class);
2089
-		$storage->method('instanceOfStorage')
2090
-			->willReturnMap([
2091
-				['OCA\Files_Sharing\External\Storage', false],
2092
-				['OCA\Files_Sharing\SharedStorage', false],
2093
-			]);
2094
-		$path->method('getStorage')->willReturn($storage);
2095
-		$this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
2096
-		$this->rootFolder->method('get')->with('valid-path')->willReturn($path);
2097
-		$this->rootFolder->method('getById')
2098
-			->willReturn([]);
2099
-
2100
-		$this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
2101
-		$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
2102
-
2103
-		$this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'true');
2104
-	}
2105
-
2106
-
2107
-	public function testCreateShareLinkPublicUploadFile(): void {
2108
-		$this->expectException(OCSBadRequestException::class);
2109
-		$this->expectExceptionMessage('Public upload is only possible for publicly shared folders');
2110
-
2111
-		$storage = $this->createMock(IStorage::class);
2112
-		$storage->method('instanceOfStorage')
2113
-			->willReturnMap([
2114
-				['OCA\Files_Sharing\External\Storage', false],
2115
-				['OCA\Files_Sharing\SharedStorage', false],
2116
-			]);
2117
-
2118
-		$file = $this->createMock(File::class);
2119
-		$file->method('getId')->willReturn(42);
2120
-		$file->method('getStorage')->willReturn($storage);
2121
-
2122
-		$this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
2123
-		$this->rootFolder->method('get')->with('valid-path')->willReturn($file);
2124
-		$this->rootFolder->method('getById')
2125
-			->willReturn([]);
2126
-
2127
-		$this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
2128
-		$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
2129
-		$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
2130
-
2131
-		$this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'true');
2132
-	}
2133
-
2134
-	public function testCreateShareLinkPublicUploadFolder(): void {
2135
-		$ocs = $this->mockFormatShare();
2136
-
2137
-		$path = $this->getMockBuilder(Folder::class)->getMock();
2138
-		$path->method('getId')->willReturn(1);
2139
-		$storage = $this->createMock(IStorage::class);
2140
-		$storage->method('instanceOfStorage')
2141
-			->willReturnMap([
2142
-				['OCA\Files_Sharing\External\Storage', false],
2143
-				['OCA\Files_Sharing\SharedStorage', false],
2144
-			]);
2145
-		$path->method('getStorage')->willReturn($storage);
2146
-		$this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
2147
-		$this->rootFolder->method('get')->with('valid-path')->willReturn($path);
2148
-		$this->rootFolder->method('getById')
2149
-			->willReturn([]);
2150
-
2151
-		$this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
2152
-		$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
2153
-		$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
2154
-
2155
-		$this->shareManager->expects($this->once())->method('createShare')->with(
2156
-			$this->callback(function (IShare $share) use ($path) {
2157
-				return $share->getNode() === $path
2158
-					&& $share->getShareType() === IShare::TYPE_LINK
2159
-					&& $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
2160
-					&& $share->getSharedBy() === 'currentUser'
2161
-					&& $share->getPassword() === null
2162
-					&& $share->getExpirationDate() === null;
2163
-			})
2164
-		)->willReturnArgument(0);
2165
-
2166
-		$expected = new DataResponse([]);
2167
-		$result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'true', '', null, '');
2168
-
2169
-		$this->assertInstanceOf(get_class($expected), $result);
2170
-		$this->assertEquals($expected->getData(), $result->getData());
2171
-	}
2172
-
2173
-	public function testCreateShareLinkPassword(): void {
2174
-		$ocs = $this->mockFormatShare();
2175
-
2176
-		$path = $this->getMockBuilder(Folder::class)->getMock();
2177
-		$path->method('getId')->willReturn(42);
2178
-		$storage = $this->createMock(IStorage::class);
2179
-		$storage->method('instanceOfStorage')
2180
-			->willReturnMap([
2181
-				['OCA\Files_Sharing\External\Storage', false],
2182
-				['OCA\Files_Sharing\SharedStorage', false],
2183
-			]);
2184
-		$path->method('getStorage')->willReturn($storage);
2185
-		$this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
2186
-		$this->rootFolder->method('get')->with('valid-path')->willReturn($path);
2187
-		$this->rootFolder->method('getById')
2188
-			->willReturn([]);
2189
-
2190
-		$this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
2191
-		$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
2192
-		$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
2193
-
2194
-		$this->shareManager->expects($this->once())->method('createShare')->with(
2195
-			$this->callback(function (IShare $share) use ($path) {
2196
-				return $share->getNode() === $path
2197
-				&& $share->getShareType() === IShare::TYPE_LINK
2198
-				&& $share->getPermissions() === Constants::PERMISSION_READ // publicUpload was set to false
2199
-				&& $share->getSharedBy() === 'currentUser'
2200
-				&& $share->getPassword() === 'password'
2201
-				&& $share->getExpirationDate() === null;
2202
-			})
2203
-		)->willReturnArgument(0);
2204
-
2205
-		$expected = new DataResponse([]);
2206
-		$result = $ocs->createShare('valid-path', Constants::PERMISSION_READ, IShare::TYPE_LINK, null, 'false', 'password', null, '');
2207
-
2208
-		$this->assertInstanceOf(get_class($expected), $result);
2209
-		$this->assertEquals($expected->getData(), $result->getData());
2210
-	}
2211
-
2212
-	public function testCreateShareLinkSendPasswordByTalk(): void {
2213
-		$ocs = $this->mockFormatShare();
2214
-
2215
-		$path = $this->getMockBuilder(Folder::class)->getMock();
2216
-		$path->method('getId')->willReturn(42);
2217
-		$storage = $this->createMock(IStorage::class);
2218
-		$storage->method('instanceOfStorage')
2219
-			->willReturnMap([
2220
-				['OCA\Files_Sharing\External\Storage', false],
2221
-				['OCA\Files_Sharing\SharedStorage', false],
2222
-			]);
2223
-		$path->method('getStorage')->willReturn($storage);
2224
-		$this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
2225
-		$this->rootFolder->method('get')->with('valid-path')->willReturn($path);
2226
-		$this->rootFolder->method('getById')
2227
-			->willReturn([]);
2228
-
2229
-		$this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
2230
-		$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
2231
-		$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
2232
-
2233
-		$this->appManager->method('isEnabledForUser')->with('spreed')->willReturn(true);
2234
-
2235
-		$this->shareManager->expects($this->once())->method('createShare')->with(
2236
-			$this->callback(function (IShare $share) use ($path) {
2237
-				return $share->getNode() === $path
2238
-				&& $share->getShareType() === IShare::TYPE_LINK
2239
-				&& $share->getPermissions() === (Constants::PERMISSION_ALL & ~(Constants::PERMISSION_SHARE))
2240
-				&& $share->getSharedBy() === 'currentUser'
2241
-				&& $share->getPassword() === 'password'
2242
-				&& $share->getSendPasswordByTalk() === true
2243
-				&& $share->getExpirationDate() === null;
2244
-			})
2245
-		)->willReturnArgument(0);
2246
-
2247
-		$expected = new DataResponse([]);
2248
-		$result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'true', 'password', 'true', '');
2249
-
2250
-		$this->assertInstanceOf(get_class($expected), $result);
2251
-		$this->assertEquals($expected->getData(), $result->getData());
2252
-	}
2253
-
2254
-
2255
-	public function testCreateShareLinkSendPasswordByTalkWithTalkDisabled(): void {
2256
-		$this->expectException(OCSForbiddenException::class);
2257
-		$this->expectExceptionMessage('Sharing valid-path sending the password by Nextcloud Talk failed because Nextcloud Talk is not enabled');
2258
-
2259
-		$ocs = $this->mockFormatShare();
2260
-
2261
-		$path = $this->getMockBuilder(Folder::class)->getMock();
2262
-		$path->method('getId')->willReturn(42);
2263
-		$storage = $this->createMock(IStorage::class);
2264
-		$storage->method('instanceOfStorage')
2265
-			->willReturnMap([
2266
-				['OCA\Files_Sharing\External\Storage', false],
2267
-				['OCA\Files_Sharing\SharedStorage', false],
2268
-			]);
2269
-		$path->method('getStorage')->willReturn($storage);
2270
-		$path->method('getPath')->willReturn('valid-path');
2271
-		$this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
2272
-		$this->rootFolder->method('get')->with('valid-path')->willReturn($path);
2273
-		$this->rootFolder->method('getById')
2274
-			->willReturn([]);
2275
-
2276
-		$this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
2277
-		$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
2278
-		$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
2279
-
2280
-		$this->appManager->method('isEnabledForUser')->with('spreed')->willReturn(false);
2281
-
2282
-		$this->shareManager->expects($this->never())->method('createShare');
2283
-
2284
-		$ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'false', 'password', 'true', '');
2285
-	}
2286
-
2287
-	public function testCreateShareValidExpireDate(): void {
2288
-		$ocs = $this->mockFormatShare();
2289
-
2290
-		$this->request
2291
-			->method('getParam')
2292
-			->willReturnMap([
2293
-				['path', null, 'valid-path'],
2294
-				['shareType', '-1', IShare::TYPE_LINK],
2295
-				['publicUpload', null, 'false'],
2296
-				['expireDate', '', '2000-01-01'],
2297
-				['password', '', ''],
2298
-			]);
2299
-
2300
-		$path = $this->getMockBuilder(Folder::class)->getMock();
2301
-		$path->method('getId')->willReturn(42);
2302
-		$storage = $this->createMock(IStorage::class);
2303
-		$storage->method('instanceOfStorage')
2304
-			->willReturnMap([
2305
-				['OCA\Files_Sharing\External\Storage', false],
2306
-				['OCA\Files_Sharing\SharedStorage', false],
2307
-			]);
2308
-		$path->method('getStorage')->willReturn($storage);
2309
-		$this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
2310
-		$this->rootFolder->method('get')->with('valid-path')->willReturn($path);
2311
-		$this->rootFolder->method('getById')
2312
-			->willReturn([]);
2313
-
2314
-		$this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
2315
-		$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
2316
-		$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
2317
-
2318
-		$this->shareManager->expects($this->once())->method('createShare')->with(
2319
-			$this->callback(function (IShare $share) use ($path) {
2320
-				$date = new \DateTime('2000-01-01');
2321
-				$date->setTime(0, 0, 0);
2322
-
2323
-				return $share->getNode() === $path
2324
-				&& $share->getShareType() === IShare::TYPE_LINK
2325
-				&& $share->getPermissions() === Constants::PERMISSION_READ | Constants::PERMISSION_SHARE
2326
-				&& $share->getSharedBy() === 'currentUser'
2327
-				&& $share->getPassword() === null
2328
-				&& $share->getExpirationDate() == $date;
2329
-			})
2330
-		)->willReturnArgument(0);
2331
-
2332
-		$expected = new DataResponse([]);
2333
-		$result = $ocs->createShare('valid-path', null, IShare::TYPE_LINK, null, 'false', '', null, '2000-01-01');
2334
-
2335
-		$this->assertInstanceOf(get_class($expected), $result);
2336
-		$this->assertEquals($expected->getData(), $result->getData());
2337
-	}
2338
-
2339
-
2340
-	public function testCreateShareInvalidExpireDate(): void {
2341
-		$this->expectException(OCSNotFoundException::class);
2342
-		$this->expectExceptionMessage('Invalid date. Format must be YYYY-MM-DD');
2343
-
2344
-		$ocs = $this->mockFormatShare();
2345
-
2346
-		$path = $this->getMockBuilder(Folder::class)->getMock();
2347
-		$path->method('getId')->willReturn(42);
2348
-		$storage = $this->createMock(IStorage::class);
2349
-		$storage->method('instanceOfStorage')
2350
-			->willReturnMap([
2351
-				['OCA\Files_Sharing\External\Storage', false],
2352
-				['OCA\Files_Sharing\SharedStorage', false],
2353
-			]);
2354
-		$path->method('getStorage')->willReturn($storage);
2355
-		$this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
2356
-		$this->rootFolder->method('get')->with('valid-path')->willReturn($path);
2357
-		$this->rootFolder->method('getById')
2358
-			->willReturn([]);
2359
-
2360
-		$this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
2361
-		$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
2362
-		$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
2363
-
2364
-		$ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'false', '', null, 'a1b2d3');
2365
-	}
2366
-
2367
-	public function testCreateShareRemote(): void {
2368
-		$share = $this->newShare();
2369
-		$this->shareManager->method('newShare')->willReturn($share);
2370
-
2371
-		/** @var ShareAPIController $ocs */
2372
-		$ocs = $this->getMockBuilder(ShareAPIController::class)
2373
-			->setConstructorArgs([
2374
-				$this->appName,
2375
-				$this->request,
2376
-				$this->shareManager,
2377
-				$this->groupManager,
2378
-				$this->userManager,
2379
-				$this->rootFolder,
2380
-				$this->urlGenerator,
2381
-				$this->l,
2382
-				$this->config,
2383
-				$this->appManager,
2384
-				$this->serverContainer,
2385
-				$this->userStatusManager,
2386
-				$this->previewManager,
2387
-				$this->dateTimeZone,
2388
-				$this->logger,
2389
-				$this->factory,
2390
-				$this->mailer,
2391
-				$this->tagManager,
2392
-				$this->currentUser,
2393
-			])->onlyMethods(['formatShare'])
2394
-			->getMock();
2395
-
2396
-		[$userFolder, $path] = $this->getNonSharedUserFile();
2397
-		$this->rootFolder->expects($this->exactly(2))
2398
-			->method('getUserFolder')
2399
-			->with('currentUser')
2400
-			->willReturn($userFolder);
2401
-
2402
-		$userFolder->expects($this->once())
2403
-			->method('get')
2404
-			->with('valid-path')
2405
-			->willReturn($path);
2406
-		$userFolder->method('getById')
2407
-			->willReturn([]);
2408
-
2409
-		$this->userManager->method('userExists')->with('validUser')->willReturn(true);
2410
-
2411
-		$path->expects($this->once())
2412
-			->method('lock')
2413
-			->with(ILockingProvider::LOCK_SHARED);
2414
-
2415
-		$this->shareManager->method('createShare')
2416
-			->with($this->callback(function (IShare $share) use ($path) {
2417
-				return $share->getNode() === $path
2418
-					&& $share->getPermissions() === (
2419
-						Constants::PERMISSION_ALL
2420
-						& ~Constants::PERMISSION_DELETE
2421
-						& ~Constants::PERMISSION_CREATE
2422
-					)
2423
-					&& $share->getShareType() === IShare::TYPE_REMOTE
2424
-					&& $share->getSharedWith() === '[email protected]'
2425
-					&& $share->getSharedBy() === 'currentUser';
2426
-			}))
2427
-			->willReturnArgument(0);
2428
-
2429
-		$this->shareManager->method('outgoingServer2ServerSharesAllowed')->willReturn(true);
2430
-
2431
-		$expected = new DataResponse([]);
2432
-		$result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_REMOTE, '[email protected]');
2433
-
2434
-		$this->assertInstanceOf(get_class($expected), $result);
2435
-		$this->assertEquals($expected->getData(), $result->getData());
2436
-	}
2437
-
2438
-	public function testCreateShareRemoteGroup(): void {
2439
-		$share = $this->newShare();
2440
-		$this->shareManager->method('newShare')->willReturn($share);
2441
-
2442
-		/** @var ShareAPIController $ocs */
2443
-		$ocs = $this->getMockBuilder(ShareAPIController::class)
2444
-			->setConstructorArgs([
2445
-				$this->appName,
2446
-				$this->request,
2447
-				$this->shareManager,
2448
-				$this->groupManager,
2449
-				$this->userManager,
2450
-				$this->rootFolder,
2451
-				$this->urlGenerator,
2452
-				$this->l,
2453
-				$this->config,
2454
-				$this->appManager,
2455
-				$this->serverContainer,
2456
-				$this->userStatusManager,
2457
-				$this->previewManager,
2458
-				$this->dateTimeZone,
2459
-				$this->logger,
2460
-				$this->factory,
2461
-				$this->mailer,
2462
-				$this->tagManager,
2463
-				$this->currentUser,
2464
-			])->onlyMethods(['formatShare'])
2465
-			->getMock();
2466
-
2467
-		[$userFolder, $path] = $this->getNonSharedUserFile();
2468
-		$this->rootFolder->expects($this->exactly(2))
2469
-			->method('getUserFolder')
2470
-			->with('currentUser')
2471
-			->willReturn($userFolder);
2472
-
2473
-		$userFolder->expects($this->once())
2474
-			->method('get')
2475
-			->with('valid-path')
2476
-			->willReturn($path);
2477
-		$userFolder->method('getById')
2478
-			->willReturn([]);
2479
-
2480
-		$this->userManager->method('userExists')->with('validUser')->willReturn(true);
2481
-
2482
-		$path->expects($this->once())
2483
-			->method('lock')
2484
-			->with(ILockingProvider::LOCK_SHARED);
2485
-
2486
-		$this->shareManager->method('createShare')
2487
-			->with($this->callback(function (IShare $share) use ($path) {
2488
-				return $share->getNode() === $path
2489
-					&& $share->getPermissions() === (
2490
-						Constants::PERMISSION_ALL
2491
-						& ~Constants::PERMISSION_DELETE
2492
-						& ~Constants::PERMISSION_CREATE
2493
-					)
2494
-					&& $share->getShareType() === IShare::TYPE_REMOTE_GROUP
2495
-					&& $share->getSharedWith() === '[email protected]'
2496
-					&& $share->getSharedBy() === 'currentUser';
2497
-			}))
2498
-			->willReturnArgument(0);
2499
-
2500
-		$this->shareManager->method('outgoingServer2ServerGroupSharesAllowed')->willReturn(true);
2501
-
2502
-		$expected = new DataResponse([]);
2503
-		$result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_REMOTE_GROUP, '[email protected]');
2504
-
2505
-		$this->assertInstanceOf(get_class($expected), $result);
2506
-		$this->assertEquals($expected->getData(), $result->getData());
2507
-	}
2508
-
2509
-	public function testCreateShareRoom(): void {
2510
-		$ocs = $this->mockFormatShare();
2511
-
2512
-		$share = $this->newShare();
2513
-		$this->shareManager->method('newShare')->willReturn($share);
2514
-
2515
-		[$userFolder, $path] = $this->getNonSharedUserFile();
2516
-		$this->rootFolder->expects($this->exactly(2))
2517
-			->method('getUserFolder')
2518
-			->with('currentUser')
2519
-			->willReturn($userFolder);
2520
-
2521
-		$userFolder->expects($this->once())
2522
-			->method('get')
2523
-			->with('valid-path')
2524
-			->willReturn($path);
2525
-		$userFolder->method('getById')
2526
-			->willReturn([]);
2527
-
2528
-		$path->expects($this->once())
2529
-			->method('lock')
2530
-			->with(ILockingProvider::LOCK_SHARED);
2531
-
2532
-		$this->appManager->method('isEnabledForUser')
2533
-			->with('spreed')
2534
-			->willReturn(true);
2535
-
2536
-		// This is not possible anymore with PHPUnit 10+
2537
-		// as `setMethods` was removed and now real reflection is used, thus the class needs to exist.
2538
-		// $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
2539
-		$helper = $this->getMockBuilder(\stdClass::class)
2540
-			->addMethods(['createShare'])
2541
-			->getMock();
2542
-		$helper->method('createShare')
2543
-			->with(
2544
-				$share,
2545
-				'recipientRoom',
2546
-				Constants::PERMISSION_ALL
2547
-				& ~Constants::PERMISSION_DELETE
2548
-				& ~Constants::PERMISSION_CREATE,
2549
-				''
2550
-			)->willReturnCallback(
2551
-				function ($share): void {
2552
-					$share->setSharedWith('recipientRoom');
2553
-					$share->setPermissions(Constants::PERMISSION_ALL);
2554
-				}
2555
-			);
2556
-
2557
-		$this->serverContainer->method('get')
2558
-			->with('\OCA\Talk\Share\Helper\ShareAPIController')
2559
-			->willReturn($helper);
2560
-
2561
-		$this->shareManager->method('createShare')
2562
-			->with($this->callback(function (IShare $share) use ($path) {
2563
-				return $share->getNode() === $path
2564
-					&& $share->getPermissions() === Constants::PERMISSION_ALL
2565
-					&& $share->getShareType() === IShare::TYPE_ROOM
2566
-					&& $share->getSharedWith() === 'recipientRoom'
2567
-					&& $share->getSharedBy() === 'currentUser';
2568
-			}))
2569
-			->willReturnArgument(0);
2570
-
2571
-		$expected = new DataResponse([]);
2572
-		$result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_ROOM, 'recipientRoom');
2573
-
2574
-		$this->assertInstanceOf(get_class($expected), $result);
2575
-		$this->assertEquals($expected->getData(), $result->getData());
2576
-	}
2577
-
2578
-
2579
-	public function testCreateShareRoomHelperNotAvailable(): void {
2580
-		$this->expectException(OCSForbiddenException::class);
2581
-		$this->expectExceptionMessage('Sharing valid-path failed because the back end does not support room shares');
2582
-
2583
-		$ocs = $this->mockFormatShare();
2584
-
2585
-		$share = $this->newShare();
2586
-		$this->shareManager->method('newShare')->willReturn($share);
2587
-
2588
-		[$userFolder, $path] = $this->getNonSharedUserFolder();
2589
-		$this->rootFolder->method('getUserFolder')
2590
-			->with('currentUser')
2591
-			->willReturn($userFolder);
2592
-
2593
-		$path->method('getPath')->willReturn('valid-path');
2594
-		$userFolder->expects($this->once())
2595
-			->method('get')
2596
-			->with('valid-path')
2597
-			->willReturn($path);
2598
-		$userFolder->method('getById')
2599
-			->willReturn([]);
2600
-
2601
-		$path->expects($this->once())
2602
-			->method('lock')
2603
-			->with(ILockingProvider::LOCK_SHARED);
2604
-
2605
-		$this->appManager->method('isEnabledForUser')
2606
-			->with('spreed')
2607
-			->willReturn(false);
2608
-
2609
-		$this->shareManager->expects($this->never())->method('createShare');
2610
-
2611
-		$ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_ROOM, 'recipientRoom');
2612
-	}
2613
-
2614
-
2615
-	public function testCreateShareRoomHelperThrowException(): void {
2616
-		$this->expectException(OCSNotFoundException::class);
2617
-		$this->expectExceptionMessage('Exception thrown by the helper');
2618
-
2619
-		$ocs = $this->mockFormatShare();
2620
-
2621
-		$share = $this->newShare();
2622
-		$share->setSharedBy('currentUser');
2623
-		$this->shareManager->method('newShare')->willReturn($share);
2624
-
2625
-		[$userFolder, $path] = $this->getNonSharedUserFile();
2626
-		$this->rootFolder->method('getUserFolder')
2627
-			->with('currentUser')
2628
-			->willReturn($userFolder);
2629
-
2630
-		$userFolder->expects($this->once())
2631
-			->method('get')
2632
-			->with('valid-path')
2633
-			->willReturn($path);
2634
-		$userFolder->method('getById')
2635
-			->willReturn([]);
2636
-
2637
-		$path->expects($this->once())
2638
-			->method('lock')
2639
-			->with(ILockingProvider::LOCK_SHARED);
2640
-
2641
-		$this->appManager->method('isEnabledForUser')
2642
-			->with('spreed')
2643
-			->willReturn(true);
2644
-
2645
-		// This is not possible anymore with PHPUnit 10+
2646
-		// as `setMethods` was removed and now real reflection is used, thus the class needs to exist.
2647
-		// $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
2648
-		$helper = $this->getMockBuilder(\stdClass::class)
2649
-			->addMethods(['createShare'])
2650
-			->getMock();
2651
-		$helper->method('createShare')
2652
-			->with(
2653
-				$share,
2654
-				'recipientRoom',
2655
-				Constants::PERMISSION_ALL & ~(Constants::PERMISSION_CREATE | Constants::PERMISSION_DELETE),
2656
-				''
2657
-			)->willReturnCallback(
2658
-				function ($share): void {
2659
-					throw new OCSNotFoundException('Exception thrown by the helper');
2660
-				}
2661
-			);
2662
-
2663
-		$this->serverContainer->method('get')
2664
-			->with('\OCA\Talk\Share\Helper\ShareAPIController')
2665
-			->willReturn($helper);
2666
-
2667
-		$this->shareManager->expects($this->never())->method('createShare');
2668
-
2669
-		$ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_ROOM, 'recipientRoom');
2670
-	}
2671
-
2672
-	/**
2673
-	 * Test for https://github.com/owncloud/core/issues/22587
2674
-	 * TODO: Remove once proper solution is in place
2675
-	 */
2676
-	public function testCreateReshareOfFederatedMountNoDeletePermissions(): void {
2677
-		$share = Server::get(IManager::class)->newShare();
2678
-		$this->shareManager->method('newShare')->willReturn($share);
2679
-
2680
-		/** @var ShareAPIController&MockObject $ocs */
2681
-		$ocs = $this->getMockBuilder(ShareAPIController::class)
2682
-			->setConstructorArgs([
2683
-				$this->appName,
2684
-				$this->request,
2685
-				$this->shareManager,
2686
-				$this->groupManager,
2687
-				$this->userManager,
2688
-				$this->rootFolder,
2689
-				$this->urlGenerator,
2690
-				$this->l,
2691
-				$this->config,
2692
-				$this->appManager,
2693
-				$this->serverContainer,
2694
-				$this->userStatusManager,
2695
-				$this->previewManager,
2696
-				$this->dateTimeZone,
2697
-				$this->logger,
2698
-				$this->factory,
2699
-				$this->mailer,
2700
-				$this->tagManager,
2701
-				$this->currentUser,
2702
-			])->onlyMethods(['formatShare'])
2703
-			->getMock();
2704
-
2705
-		$userFolder = $this->getMockBuilder(Folder::class)->getMock();
2706
-		$this->rootFolder->expects($this->exactly(2))
2707
-			->method('getUserFolder')
2708
-			->with('currentUser')
2709
-			->willReturn($userFolder);
2710
-
2711
-		$path = $this->getMockBuilder(Folder::class)->getMock();
2712
-		$path->method('getId')->willReturn(42);
2713
-
2714
-		$storage = $this->createMock(IStorage::class);
2715
-		$storage->method('instanceOfStorage')
2716
-			->willReturnMap([
2717
-				['OCA\Files_Sharing\External\Storage', true],
2718
-				['OCA\Files_Sharing\SharedStorage', false],
2719
-			]);
2720
-		$userFolder->method('getStorage')->willReturn($storage);
2721
-		$path->method('getStorage')->willReturn($storage);
2722
-
2723
-		$path->method('getPermissions')->willReturn(Constants::PERMISSION_READ);
2724
-		$userFolder->expects($this->once())
2725
-			->method('get')
2726
-			->with('valid-path')
2727
-			->willReturn($path);
2728
-		$userFolder->method('getById')
2729
-			->willReturn([]);
2730
-
2731
-		$this->userManager->method('userExists')->with('validUser')->willReturn(true);
2732
-
2733
-		$this->shareManager
2734
-			->expects($this->once())
2735
-			->method('createShare')
2736
-			->with($this->callback(function (IShare $share) {
2737
-				return $share->getPermissions() === Constants::PERMISSION_READ;
2738
-			}))
2739
-			->willReturnArgument(0);
2740
-
2741
-		$ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_USER, 'validUser');
2742
-	}
2743
-
2744
-
2745
-	public function testUpdateShareCantAccess(): void {
2746
-		$this->expectException(OCSNotFoundException::class);
2747
-		$this->expectExceptionMessage('Wrong share ID, share does not exist');
2748
-
2749
-		[$userFolder, $node] = $this->getNonSharedUserFolder();
2750
-		$share = $this->newShare();
2751
-		$share->setNode($node);
2752
-
2753
-		$node->expects($this->once())
2754
-			->method('lock')
2755
-			->with(ILockingProvider::LOCK_SHARED);
2756
-
2757
-		$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
2758
-
2759
-		$this->rootFolder->method('getUserFolder')
2760
-			->with($this->currentUser)
2761
-			->willReturn($userFolder);
2762
-
2763
-		$userFolder->method('getById')
2764
-			->with($share->getNodeId())
2765
-			->willReturn([$share->getNode()]);
2766
-
2767
-		$this->ocs->updateShare(42);
2768
-	}
2769
-
2770
-
2771
-	public function testUpdateNoParametersLink(): void {
2772
-		$this->expectException(OCSBadRequestException::class);
2773
-		$this->expectExceptionMessage('Wrong or no update parameter given');
2774
-
2775
-		$node = $this->getMockBuilder(Folder::class)->getMock();
2776
-		$share = $this->newShare();
2777
-		$share->setPermissions(Constants::PERMISSION_ALL)
2778
-			->setSharedBy($this->currentUser)
2779
-			->setShareType(IShare::TYPE_LINK)
2780
-			->setNode($node);
2781
-
2782
-		$node->expects($this->once())
2783
-			->method('lock')
2784
-			->with(ILockingProvider::LOCK_SHARED);
2785
-
2786
-		$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
2787
-
2788
-		$this->ocs->updateShare(42);
2789
-	}
2790
-
2791
-
2792
-	public function testUpdateNoParametersOther(): void {
2793
-		$this->expectException(OCSBadRequestException::class);
2794
-		$this->expectExceptionMessage('Wrong or no update parameter given');
2795
-
2796
-		$node = $this->getMockBuilder(Folder::class)->getMock();
2797
-		$share = $this->newShare();
2798
-		$share->setPermissions(Constants::PERMISSION_ALL)
2799
-			->setSharedBy($this->currentUser)
2800
-			->setShareType(IShare::TYPE_GROUP)
2801
-			->setNode($node);
2802
-
2803
-		$node->expects($this->once())
2804
-			->method('lock')
2805
-			->with(ILockingProvider::LOCK_SHARED);
2806
-
2807
-		$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
2808
-
2809
-		$this->ocs->updateShare(42);
2810
-	}
2811
-
2812
-	public function testUpdateLinkShareClear(): void {
2813
-		$ocs = $this->mockFormatShare();
2814
-
2815
-		[$userFolder, $node] = $this->getNonSharedUserFolder();
2816
-		$node->method('getId')
2817
-			->willReturn(42);
2818
-		$share = $this->newShare();
2819
-		$share->setPermissions(Constants::PERMISSION_ALL)
2820
-			->setSharedBy($this->currentUser)
2821
-			->setShareType(IShare::TYPE_LINK)
2822
-			->setPassword('password')
2823
-			->setExpirationDate(new \DateTime())
2824
-			->setNote('note')
2825
-			->setLabel('label')
2826
-			->setHideDownload(true)
2827
-			->setPermissions(Constants::PERMISSION_ALL)
2828
-			->setNode($node);
2829
-
2830
-		$node->expects($this->once())
2831
-			->method('lock')
2832
-			->with(ILockingProvider::LOCK_SHARED);
2833
-
2834
-		$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
2835
-
2836
-		$this->shareManager->expects($this->once())->method('updateShare')->with(
2837
-			$this->callback(function (IShare $share) {
2838
-				return $share->getPermissions() === Constants::PERMISSION_READ
2839
-				&& $share->getPassword() === null
2840
-				&& $share->getExpirationDate() === null
2841
-				// Once set a note or a label are never back to null, only to an
2842
-				// empty string.
2843
-				&& $share->getNote() === ''
2844
-				&& $share->getLabel() === ''
2845
-				&& $share->getHideDownload() === false;
2846
-			})
2847
-		)->willReturnArgument(0);
2848
-
2849
-		$this->shareManager->method('getSharedWith')
2850
-			->willReturn([]);
2851
-
2852
-		$this->rootFolder->method('getUserFolder')
2853
-			->with($this->currentUser)
2854
-			->willReturn($userFolder);
2855
-
2856
-		$userFolder->method('getById')
2857
-			->with(42)
2858
-			->willReturn([$node]);
2859
-		$userFolder->method('getFirstNodeById')
2860
-			->with(42)
2861
-			->willReturn($node);
2862
-
2863
-		$mountPoint = $this->createMock(IMountPoint::class);
2864
-		$node->method('getMountPoint')
2865
-			->willReturn($mountPoint);
2866
-		$mountPoint->method('getStorageRootId')
2867
-			->willReturn(42);
2868
-
2869
-		$expected = new DataResponse([]);
2870
-		$result = $ocs->updateShare(42, null, '', null, 'false', '', '', '', 'false');
2871
-
2872
-		$this->assertInstanceOf(get_class($expected), $result);
2873
-		$this->assertEquals($expected->getData(), $result->getData());
2874
-	}
2875
-
2876
-	public function testUpdateLinkShareSet(): void {
2877
-		$ocs = $this->mockFormatShare();
2878
-
2879
-		[$userFolder, $folder] = $this->getNonSharedUserFolder();
2880
-		$folder->method('getId')
2881
-			->willReturn(42);
2882
-
2883
-		$share = Server::get(IManager::class)->newShare();
2884
-		$share->setPermissions(Constants::PERMISSION_ALL)
2885
-			->setSharedBy($this->currentUser)
2886
-			->setShareType(IShare::TYPE_LINK)
2887
-			->setNode($folder);
2888
-
2889
-		$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
2890
-		$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
2891
-
2892
-		$this->shareManager->expects($this->once())->method('updateShare')->with(
2893
-			$this->callback(function (IShare $share) {
2894
-				$date = new \DateTime('2000-01-01');
2895
-				$date->setTime(0, 0, 0);
2896
-
2897
-				return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
2898
-				&& $share->getPassword() === 'password'
2899
-				&& $share->getExpirationDate() == $date
2900
-				&& $share->getNote() === 'note'
2901
-				&& $share->getLabel() === 'label'
2902
-				&& $share->getHideDownload() === true;
2903
-			})
2904
-		)->willReturnArgument(0);
2905
-
2906
-		$this->shareManager->method('getSharedWith')
2907
-			->willReturn([]);
2908
-
2909
-		$this->rootFolder->method('getUserFolder')
2910
-			->with($this->currentUser)
2911
-			->willReturn($userFolder);
2912
-
2913
-		$userFolder->method('getById')
2914
-			->with(42)
2915
-			->willReturn([$folder]);
2916
-
2917
-		$mountPoint = $this->createMock(IMountPoint::class);
2918
-		$folder->method('getMountPoint')
2919
-			->willReturn($mountPoint);
2920
-		$mountPoint->method('getStorageRootId')
2921
-			->willReturn(42);
2922
-
2923
-		$expected = new DataResponse([]);
2924
-		$result = $ocs->updateShare(42, null, 'password', null, 'true', '2000-01-01', 'note', 'label', 'true');
2925
-
2926
-		$this->assertInstanceOf(get_class($expected), $result);
2927
-		$this->assertEquals($expected->getData(), $result->getData());
2928
-	}
2929
-
2930
-	#[\PHPUnit\Framework\Attributes\DataProvider('publicUploadParamsProvider')]
2931
-	public function testUpdateLinkShareEnablePublicUpload($permissions, $publicUpload, $expireDate, $password): void {
2932
-		$ocs = $this->mockFormatShare();
2933
-
2934
-		[$userFolder, $folder] = $this->getNonSharedUserFolder();
2935
-		$folder->method('getId')
2936
-			->willReturn(42);
2937
-
2938
-		$share = Server::get(IManager::class)->newShare();
2939
-		$share->setPermissions(Constants::PERMISSION_ALL)
2940
-			->setSharedBy($this->currentUser)
2941
-			->setShareType(IShare::TYPE_LINK)
2942
-			->setPassword('password')
2943
-			->setNode($folder);
2944
-
2945
-		$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
2946
-		$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
2947
-		$this->shareManager->method('getSharedWith')->willReturn([]);
2948
-
2949
-		$this->shareManager->expects($this->once())->method('updateShare')->with(
2950
-			$this->callback(function (IShare $share) {
2951
-				return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
2952
-				&& $share->getPassword() === 'password'
2953
-				&& $share->getExpirationDate() === null;
2954
-			})
2955
-		)->willReturnArgument(0);
2956
-
2957
-		$this->rootFolder->method('getUserFolder')
2958
-			->with($this->currentUser)
2959
-			->willReturn($userFolder);
2960
-
2961
-		$userFolder->method('getById')
2962
-			->with(42)
2963
-			->willReturn([$folder]);
2964
-
2965
-		$mountPoint = $this->createMock(IMountPoint::class);
2966
-		$folder->method('getMountPoint')
2967
-			->willReturn($mountPoint);
2968
-		$mountPoint->method('getStorageRootId')
2969
-			->willReturn(42);
2970
-
2971
-		$expected = new DataResponse([]);
2972
-		$result = $ocs->updateShare(42, $permissions, $password, null, $publicUpload, $expireDate);
2973
-
2974
-		$this->assertInstanceOf(get_class($expected), $result);
2975
-		$this->assertEquals($expected->getData(), $result->getData());
2976
-	}
2977
-
2978
-
2979
-	public static function publicLinkValidPermissionsProvider() {
2980
-		return [
2981
-			[Constants::PERMISSION_CREATE],
2982
-			[Constants::PERMISSION_READ],
2983
-			[Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE],
2984
-			[Constants::PERMISSION_READ | Constants::PERMISSION_DELETE],
2985
-			[Constants::PERMISSION_READ | Constants::PERMISSION_CREATE],
2986
-		];
2987
-	}
2988
-
2989
-	#[\PHPUnit\Framework\Attributes\DataProvider('publicLinkValidPermissionsProvider')]
2990
-	public function testUpdateLinkShareSetCRUDPermissions($permissions): void {
2991
-		$ocs = $this->mockFormatShare();
2992
-
2993
-		[$userFolder, $folder] = $this->getNonSharedUserFolder();
2994
-		$folder->method('getId')
2995
-			->willReturn(42);
2996
-
2997
-		$share = Server::get(IManager::class)->newShare();
2998
-		$share->setPermissions(Constants::PERMISSION_ALL)
2999
-			->setSharedBy($this->currentUser)
3000
-			->setShareType(IShare::TYPE_LINK)
3001
-			->setPassword('password')
3002
-			->setNode($folder);
3003
-
3004
-		$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3005
-		$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
3006
-		$this->shareManager->method('getSharedWith')->willReturn([]);
3007
-
3008
-		$this->shareManager
3009
-			->expects($this->any())
3010
-			->method('updateShare')
3011
-			->willReturnArgument(0);
3012
-
3013
-		$this->rootFolder->method('getUserFolder')
3014
-			->with($this->currentUser)
3015
-			->willReturn($userFolder);
3016
-
3017
-		$userFolder->method('getById')
3018
-			->with(42)
3019
-			->willReturn([$folder]);
3020
-
3021
-		$mountPoint = $this->createMock(IMountPoint::class);
3022
-		$folder->method('getMountPoint')
3023
-			->willReturn($mountPoint);
3024
-		$mountPoint->method('getStorageRootId')
3025
-			->willReturn(42);
3026
-
3027
-		$expected = new DataResponse([]);
3028
-		$result = $ocs->updateShare(42, $permissions, 'password', null, null, null);
3029
-
3030
-		$this->assertInstanceOf(get_class($expected), $result);
3031
-		$this->assertEquals($expected->getData(), $result->getData());
3032
-	}
3033
-
3034
-	public static function publicLinkInvalidPermissionsProvider1() {
3035
-		return [
3036
-			[Constants::PERMISSION_DELETE],
3037
-			[Constants::PERMISSION_UPDATE],
3038
-			[Constants::PERMISSION_SHARE],
3039
-		];
3040
-	}
3041
-
3042
-	#[\PHPUnit\Framework\Attributes\DataProvider('publicLinkInvalidPermissionsProvider1')]
3043
-	public function testUpdateLinkShareSetInvalidCRUDPermissions1($permissions): void {
3044
-		$this->expectException(OCSBadRequestException::class);
3045
-		$this->expectExceptionMessage('Share must at least have READ or CREATE permissions');
3046
-
3047
-		$this->testUpdateLinkShareSetCRUDPermissions($permissions, null);
3048
-	}
3049
-
3050
-	public static function publicLinkInvalidPermissionsProvider2() {
3051
-		return [
3052
-			[Constants::PERMISSION_CREATE | Constants::PERMISSION_DELETE],
3053
-			[Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE],
3054
-		];
3055
-	}
3056
-
3057
-	#[\PHPUnit\Framework\Attributes\DataProvider('publicLinkInvalidPermissionsProvider2')]
3058
-	public function testUpdateLinkShareSetInvalidCRUDPermissions2($permissions): void {
3059
-		$this->expectException(OCSBadRequestException::class);
3060
-		$this->expectExceptionMessage('Share must have READ permission if UPDATE or DELETE permission is set');
3061
-
3062
-		$this->testUpdateLinkShareSetCRUDPermissions($permissions);
3063
-	}
3064
-
3065
-	public function testUpdateLinkShareInvalidDate(): void {
3066
-		$this->expectException(OCSBadRequestException::class);
3067
-		$this->expectExceptionMessage('Invalid date. Format must be YYYY-MM-DD');
3068
-
3069
-		$ocs = $this->mockFormatShare();
3070
-		[$userFolder, $folder] = $this->getNonSharedUserFolder();
3071
-		$userFolder->method('getById')
3072
-			->with(42)
3073
-			->willReturn([$folder]);
3074
-		$this->rootFolder->method('getUserFolder')
3075
-			->with($this->currentUser)
3076
-			->willReturn($userFolder);
3077
-
3078
-		$folder->method('getId')
3079
-			->willReturn(42);
3080
-
3081
-		$share = Server::get(IManager::class)->newShare();
3082
-		$share->setPermissions(Constants::PERMISSION_ALL)
3083
-			->setSharedBy($this->currentUser)
3084
-			->setShareType(IShare::TYPE_LINK)
3085
-			->setNode($folder);
3086
-
3087
-		$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3088
-		$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
3089
-
3090
-		$ocs->updateShare(42, null, 'password', null, 'true', '2000-01-a');
3091
-	}
3092
-
3093
-	public static function publicUploadParamsProvider() {
3094
-		return [
3095
-			[null, 'true', null, 'password'],
3096
-			// legacy had no delete
3097
-			[
3098
-				Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE,
3099
-				'true', null, 'password'
3100
-			],
3101
-			// correct
3102
-			[
3103
-				Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE,
3104
-				null, null, 'password'
3105
-			],
3106
-		];
3107
-	}
3108
-
3109
-	#[\PHPUnit\Framework\Attributes\DataProvider('publicUploadParamsProvider')]
3110
-	public function testUpdateLinkSharePublicUploadNotAllowed($permissions, $publicUpload, $expireDate, $password): void {
3111
-		$this->expectException(OCSForbiddenException::class);
3112
-		$this->expectExceptionMessage('Public upload disabled by the administrator');
3113
-
3114
-		$ocs = $this->mockFormatShare();
3115
-		[$userFolder, $folder] = $this->getNonSharedUserFolder();
3116
-		$userFolder->method('getById')
3117
-			->with(42)
3118
-			->willReturn([$folder]);
3119
-		$this->rootFolder->method('getUserFolder')
3120
-			->with($this->currentUser)
3121
-			->willReturn($userFolder);
3122
-
3123
-		$folder->method('getId')->willReturn(42);
3124
-
3125
-		$share = Server::get(IManager::class)->newShare();
3126
-		$share->setPermissions(Constants::PERMISSION_ALL)
3127
-			->setSharedBy($this->currentUser)
3128
-			->setShareType(IShare::TYPE_LINK)
3129
-			->setNode($folder);
3130
-
3131
-		$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3132
-		$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(false);
3133
-
3134
-		$ocs->updateShare(42, $permissions, $password, null, $publicUpload, $expireDate);
3135
-	}
3136
-
3137
-
3138
-	public function testUpdateLinkSharePublicUploadOnFile(): void {
3139
-		$this->expectException(OCSBadRequestException::class);
3140
-		$this->expectExceptionMessage('Public upload is only possible for publicly shared folders');
3141
-
3142
-		$ocs = $this->mockFormatShare();
3143
-
3144
-		$file = $this->getMockBuilder(File::class)->getMock();
3145
-		$file->method('getId')
3146
-			->willReturn(42);
3147
-		[$userFolder, $folder] = $this->getNonSharedUserFolder();
3148
-		$userFolder->method('getById')
3149
-			->with(42)
3150
-			->willReturn([$folder]);
3151
-		$this->rootFolder->method('getUserFolder')
3152
-			->with($this->currentUser)
3153
-			->willReturn($userFolder);
3154
-
3155
-		$share = Server::get(IManager::class)->newShare();
3156
-		$share->setPermissions(Constants::PERMISSION_ALL)
3157
-			->setSharedBy($this->currentUser)
3158
-			->setShareType(IShare::TYPE_LINK)
3159
-			->setNode($file);
3160
-
3161
-		$this->shareManager
3162
-			->method('getShareById')
3163
-			->with('ocinternal:42')
3164
-			->willReturn($share);
3165
-		$this->shareManager
3166
-			->method('shareApiLinkAllowPublicUpload')
3167
-			->willReturn(true);
3168
-		$this->shareManager
3169
-			->method('updateShare')
3170
-			->with($share)
3171
-			->willThrowException(new \InvalidArgumentException('File shares cannot have create or delete permissions'));
3172
-
3173
-		$ocs->updateShare(42, null, 'password', null, 'true', '');
3174
-	}
3175
-
3176
-	public function testUpdateLinkSharePasswordDoesNotChangeOther(): void {
3177
-		$ocs = $this->mockFormatShare();
3178
-
3179
-		$date = new \DateTime('2000-01-01');
3180
-		$date->setTime(0, 0, 0);
3181
-
3182
-		[$userFolder, $node] = $this->getNonSharedUserFolder();
3183
-		$node->method('getId')->willReturn(42);
3184
-		$userFolder->method('getById')
3185
-			->with(42)
3186
-			->willReturn([$node]);
3187
-		$this->rootFolder->method('getUserFolder')
3188
-			->with($this->currentUser)
3189
-			->willReturn($userFolder);
3190
-		$share = $this->newShare();
3191
-		$share->setPermissions(Constants::PERMISSION_ALL)
3192
-			->setSharedBy($this->currentUser)
3193
-			->setShareType(IShare::TYPE_LINK)
3194
-			->setPassword('password')
3195
-			->setSendPasswordByTalk(true)
3196
-			->setExpirationDate($date)
3197
-			->setNote('note')
3198
-			->setLabel('label')
3199
-			->setHideDownload(true)
3200
-			->setPermissions(Constants::PERMISSION_ALL)
3201
-			->setNode($node);
3202
-
3203
-		$node->expects($this->once())
3204
-			->method('lock')
3205
-			->with(ILockingProvider::LOCK_SHARED);
3206
-
3207
-		$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3208
-
3209
-		$this->shareManager->expects($this->once())->method('updateShare')->with(
3210
-			$this->callback(function (IShare $share) use ($date) {
3211
-				return $share->getPermissions() === Constants::PERMISSION_ALL
3212
-				&& $share->getPassword() === 'newpassword'
3213
-				&& $share->getSendPasswordByTalk() === true
3214
-				&& $share->getExpirationDate() === $date
3215
-				&& $share->getNote() === 'note'
3216
-				&& $share->getLabel() === 'label'
3217
-				&& $share->getHideDownload() === true;
3218
-			})
3219
-		)->willReturnArgument(0);
3220
-
3221
-		$expected = new DataResponse([]);
3222
-		$result = $ocs->updateShare(42, null, 'newpassword', null, null, null, null, null, null);
3223
-
3224
-		$this->assertInstanceOf(get_class($expected), $result);
3225
-		$this->assertEquals($expected->getData(), $result->getData());
3226
-	}
3227
-
3228
-	public function testUpdateLinkShareSendPasswordByTalkDoesNotChangeOther(): void {
3229
-		$ocs = $this->mockFormatShare();
3230
-
3231
-		$date = new \DateTime('2000-01-01');
3232
-		$date->setTime(0, 0, 0);
3233
-
3234
-		[$userFolder, $node] = $this->getNonSharedUserFolder();
3235
-		$userFolder->method('getById')
3236
-			->with(42)
3237
-			->willReturn([$node]);
3238
-		$this->rootFolder->method('getUserFolder')
3239
-			->with($this->currentUser)
3240
-			->willReturn($userFolder);
3241
-		$node->method('getId')->willReturn(42);
3242
-		$share = $this->newShare();
3243
-		$share->setPermissions(Constants::PERMISSION_ALL)
3244
-			->setSharedBy($this->currentUser)
3245
-			->setShareType(IShare::TYPE_LINK)
3246
-			->setPassword('password')
3247
-			->setSendPasswordByTalk(false)
3248
-			->setExpirationDate($date)
3249
-			->setNote('note')
3250
-			->setLabel('label')
3251
-			->setHideDownload(true)
3252
-			->setPermissions(Constants::PERMISSION_ALL)
3253
-			->setNode($node);
3254
-
3255
-		$node->expects($this->once())
3256
-			->method('lock')
3257
-			->with(ILockingProvider::LOCK_SHARED);
3258
-
3259
-		$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3260
-
3261
-		$this->appManager->method('isEnabledForUser')->with('spreed')->willReturn(true);
3262
-
3263
-		$this->shareManager->expects($this->once())->method('updateShare')->with(
3264
-			$this->callback(function (IShare $share) use ($date) {
3265
-				return $share->getPermissions() === Constants::PERMISSION_ALL
3266
-				&& $share->getPassword() === 'password'
3267
-				&& $share->getSendPasswordByTalk() === true
3268
-				&& $share->getExpirationDate() === $date
3269
-				&& $share->getNote() === 'note'
3270
-				&& $share->getLabel() === 'label'
3271
-				&& $share->getHideDownload() === true;
3272
-			})
3273
-		)->willReturnArgument(0);
3274
-
3275
-		$expected = new DataResponse([]);
3276
-		$result = $ocs->updateShare(42, null, null, 'true', null, null, null, null, null);
3277
-
3278
-		$this->assertInstanceOf(get_class($expected), $result);
3279
-		$this->assertEquals($expected->getData(), $result->getData());
3280
-	}
3281
-
3282
-
3283
-	public function testUpdateLinkShareSendPasswordByTalkWithTalkDisabledDoesNotChangeOther(): void {
3284
-		$this->expectException(OCSForbiddenException::class);
3285
-		$this->expectExceptionMessage('"Sending the password by Nextcloud Talk" for sharing a file or folder failed because Nextcloud Talk is not enabled.');
3286
-
3287
-		$ocs = $this->mockFormatShare();
3288
-
3289
-		$date = new \DateTime('2000-01-01');
3290
-		$date->setTime(0, 0, 0);
3291
-
3292
-		[$userFolder, $node] = $this->getNonSharedUserFolder();
3293
-		$userFolder->method('getById')
3294
-			->with(42)
3295
-			->willReturn([$node]);
3296
-		$this->rootFolder->method('getUserFolder')
3297
-			->with($this->currentUser)
3298
-			->willReturn($userFolder);
3299
-		$node->method('getId')->willReturn(42);
3300
-		$share = $this->newShare();
3301
-		$share->setPermissions(Constants::PERMISSION_ALL)
3302
-			->setSharedBy($this->currentUser)
3303
-			->setShareType(IShare::TYPE_LINK)
3304
-			->setPassword('password')
3305
-			->setSendPasswordByTalk(false)
3306
-			->setExpirationDate($date)
3307
-			->setNote('note')
3308
-			->setLabel('label')
3309
-			->setHideDownload(true)
3310
-			->setPermissions(Constants::PERMISSION_ALL)
3311
-			->setNode($node);
3312
-
3313
-		$node->expects($this->once())
3314
-			->method('lock')
3315
-			->with(ILockingProvider::LOCK_SHARED);
3316
-
3317
-		$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3318
-
3319
-		$this->appManager->method('isEnabledForUser')->with('spreed')->willReturn(false);
3320
-
3321
-		$this->shareManager->expects($this->never())->method('updateShare');
3322
-
3323
-		$ocs->updateShare(42, null, null, 'true', null, null, null, null, null);
3324
-	}
3325
-
3326
-	public function testUpdateLinkShareDoNotSendPasswordByTalkDoesNotChangeOther(): void {
3327
-		$ocs = $this->mockFormatShare();
3328
-
3329
-		$date = new \DateTime('2000-01-01');
3330
-		$date->setTime(0, 0, 0);
3331
-
3332
-		[$userFolder, $node] = $this->getNonSharedUserFolder();
3333
-		$userFolder->method('getById')
3334
-			->with(42)
3335
-			->willReturn([$node]);
3336
-		$this->rootFolder->method('getUserFolder')
3337
-			->with($this->currentUser)
3338
-			->willReturn($userFolder);
3339
-		$node->method('getId')->willReturn(42);
3340
-		$share = $this->newShare();
3341
-		$share->setPermissions(Constants::PERMISSION_ALL)
3342
-			->setSharedBy($this->currentUser)
3343
-			->setShareType(IShare::TYPE_LINK)
3344
-			->setPassword('password')
3345
-			->setSendPasswordByTalk(true)
3346
-			->setExpirationDate($date)
3347
-			->setNote('note')
3348
-			->setLabel('label')
3349
-			->setHideDownload(true)
3350
-			->setPermissions(Constants::PERMISSION_ALL)
3351
-			->setNode($node);
3352
-
3353
-		$node->expects($this->once())
3354
-			->method('lock')
3355
-			->with(ILockingProvider::LOCK_SHARED);
3356
-
3357
-		$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3358
-
3359
-		$this->appManager->method('isEnabledForUser')->with('spreed')->willReturn(true);
3360
-
3361
-		$this->shareManager->expects($this->once())->method('updateShare')->with(
3362
-			$this->callback(function (IShare $share) use ($date) {
3363
-				return $share->getPermissions() === Constants::PERMISSION_ALL
3364
-				&& $share->getPassword() === 'password'
3365
-				&& $share->getSendPasswordByTalk() === false
3366
-				&& $share->getExpirationDate() === $date
3367
-				&& $share->getNote() === 'note'
3368
-				&& $share->getLabel() === 'label'
3369
-				&& $share->getHideDownload() === true;
3370
-			})
3371
-		)->willReturnArgument(0);
3372
-
3373
-		$expected = new DataResponse([]);
3374
-		$result = $ocs->updateShare(42, null, null, 'false', null, null, null, null, null);
3375
-
3376
-		$this->assertInstanceOf(get_class($expected), $result);
3377
-		$this->assertEquals($expected->getData(), $result->getData());
3378
-	}
3379
-
3380
-	public function testUpdateLinkShareDoNotSendPasswordByTalkWithTalkDisabledDoesNotChangeOther(): void {
3381
-		$ocs = $this->mockFormatShare();
3382
-
3383
-		$date = new \DateTime('2000-01-01');
3384
-		$date->setTime(0, 0, 0);
3385
-
3386
-		[$userFolder, $node] = $this->getNonSharedUserFolder();
3387
-		$node->method('getId')
3388
-			->willReturn(42);
3389
-
3390
-		$share = $this->newShare();
3391
-		$share->setPermissions(Constants::PERMISSION_ALL)
3392
-			->setSharedBy($this->currentUser)
3393
-			->setShareType(IShare::TYPE_LINK)
3394
-			->setPassword('password')
3395
-			->setSendPasswordByTalk(true)
3396
-			->setExpirationDate($date)
3397
-			->setNote('note')
3398
-			->setLabel('label')
3399
-			->setHideDownload(true)
3400
-			->setPermissions(Constants::PERMISSION_ALL)
3401
-			->setNode($node);
3402
-
3403
-		$node->expects($this->once())
3404
-			->method('lock')
3405
-			->with(ILockingProvider::LOCK_SHARED);
3406
-
3407
-		$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3408
-
3409
-		$this->appManager->method('isEnabledForUser')->with('spreed')->willReturn(false);
3410
-
3411
-		$this->shareManager->expects($this->once())->method('updateShare')->with(
3412
-			$this->callback(function (IShare $share) use ($date) {
3413
-				return $share->getPermissions() === Constants::PERMISSION_ALL
3414
-				&& $share->getPassword() === 'password'
3415
-				&& $share->getSendPasswordByTalk() === false
3416
-				&& $share->getExpirationDate() === $date
3417
-				&& $share->getNote() === 'note'
3418
-				&& $share->getLabel() === 'label'
3419
-				&& $share->getHideDownload() === true;
3420
-			})
3421
-		)->willReturnArgument(0);
3422
-
3423
-		$this->rootFolder->method('getUserFolder')
3424
-			->with($this->currentUser)
3425
-			->willReturn($userFolder);
3426
-
3427
-		$userFolder->method('getById')
3428
-			->with(42)
3429
-			->willReturn([$node]);
3430
-
3431
-		$mountPoint = $this->createMock(IMountPoint::class);
3432
-		$node->method('getMountPoint')
3433
-			->willReturn($mountPoint);
3434
-		$mountPoint->method('getStorageRootId')
3435
-			->willReturn(42);
3436
-
3437
-		$mountPoint = $this->createMock(IMountPoint::class);
3438
-		$node->method('getMountPoint')
3439
-			->willReturn($mountPoint);
3440
-		$mountPoint->method('getStorageRootId')
3441
-			->willReturn(42);
3442
-
3443
-		$expected = new DataResponse([]);
3444
-		$result = $ocs->updateShare(42, null, null, 'false', null, null, null, null, null);
3445
-
3446
-		$this->assertInstanceOf(get_class($expected), $result);
3447
-		$this->assertEquals($expected->getData(), $result->getData());
3448
-	}
3449
-
3450
-	public function testUpdateLinkShareExpireDateDoesNotChangeOther(): void {
3451
-		$ocs = $this->mockFormatShare();
3452
-
3453
-		[$userFolder, $node] = $this->getNonSharedUserFolder();
3454
-		$node->method('getId')
3455
-			->willReturn(42);
3456
-
3457
-		$share = $this->newShare();
3458
-		$share->setPermissions(Constants::PERMISSION_ALL)
3459
-			->setSharedBy($this->currentUser)
3460
-			->setShareType(IShare::TYPE_LINK)
3461
-			->setPassword('password')
3462
-			->setSendPasswordByTalk(true)
3463
-			->setExpirationDate(new \DateTime())
3464
-			->setNote('note')
3465
-			->setLabel('label')
3466
-			->setHideDownload(true)
3467
-			->setPermissions(Constants::PERMISSION_ALL)
3468
-			->setNode($node);
3469
-
3470
-		$node->expects($this->once())
3471
-			->method('lock')
3472
-			->with(ILockingProvider::LOCK_SHARED);
3473
-
3474
-		$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3475
-
3476
-		$this->shareManager->expects($this->once())->method('updateShare')->with(
3477
-			$this->callback(function (IShare $share) {
3478
-				$date = new \DateTime('2010-12-23');
3479
-				$date->setTime(0, 0, 0);
3480
-
3481
-				return $share->getPermissions() === Constants::PERMISSION_ALL
3482
-				&& $share->getPassword() === 'password'
3483
-				&& $share->getSendPasswordByTalk() === true
3484
-				&& $share->getExpirationDate() == $date
3485
-				&& $share->getNote() === 'note'
3486
-				&& $share->getLabel() === 'label'
3487
-				&& $share->getHideDownload() === true;
3488
-			})
3489
-		)->willReturnArgument(0);
3490
-
3491
-		$this->rootFolder->method('getUserFolder')
3492
-			->with($this->currentUser)
3493
-			->willReturn($userFolder);
3494
-
3495
-		$userFolder->method('getById')
3496
-			->with(42)
3497
-			->willReturn([$node]);
3498
-
3499
-		$mountPoint = $this->createMock(IMountPoint::class);
3500
-		$node->method('getMountPoint')
3501
-			->willReturn($mountPoint);
3502
-		$mountPoint->method('getStorageRootId')
3503
-			->willReturn(42);
3504
-
3505
-		$expected = new DataResponse([]);
3506
-		$result = $ocs->updateShare(42, null, null, null, null, '2010-12-23', null, null, null);
3507
-
3508
-		$this->assertInstanceOf(get_class($expected), $result);
3509
-		$this->assertEquals($expected->getData(), $result->getData());
3510
-	}
3511
-
3512
-	public function testUpdateLinkSharePublicUploadDoesNotChangeOther(): void {
3513
-		$ocs = $this->mockFormatShare();
3514
-
3515
-		$date = new \DateTime('2000-01-01');
3516
-
3517
-		[$userFolder, $folder] = $this->getNonSharedUserFolder();
3518
-		$folder->method('getId')
3519
-			->willReturn(42);
3520
-
3521
-		$share = Server::get(IManager::class)->newShare();
3522
-		$share->setPermissions(Constants::PERMISSION_ALL)
3523
-			->setSharedBy($this->currentUser)
3524
-			->setShareType(IShare::TYPE_LINK)
3525
-			->setPassword('password')
3526
-			->setSendPasswordByTalk(true)
3527
-			->setExpirationDate($date)
3528
-			->setNote('note')
3529
-			->setLabel('label')
3530
-			->setHideDownload(true)
3531
-			->setPermissions(Constants::PERMISSION_ALL)
3532
-			->setNode($folder);
3533
-
3534
-		$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3535
-		$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
3536
-
3537
-		$this->shareManager->expects($this->once())->method('updateShare')->with(
3538
-			$this->callback(function (IShare $share) use ($date) {
3539
-				return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
3540
-				&& $share->getPassword() === 'password'
3541
-				&& $share->getSendPasswordByTalk() === true
3542
-				&& $share->getExpirationDate() === $date
3543
-				&& $share->getNote() === 'note'
3544
-				&& $share->getLabel() === 'label'
3545
-				&& $share->getHideDownload() === true;
3546
-			})
3547
-		)->willReturnArgument(0);
3548
-
3549
-		$this->shareManager->method('getSharedWith')
3550
-			->willReturn([]);
3551
-
3552
-		$this->rootFolder->method('getUserFolder')
3553
-			->with($this->currentUser)
3554
-			->willReturn($userFolder);
3555
-
3556
-		$userFolder->method('getById')
3557
-			->with(42)
3558
-			->willReturn([$folder]);
3559
-
3560
-		$mountPoint = $this->createMock(IMountPoint::class);
3561
-		$folder->method('getMountPoint')
3562
-			->willReturn($mountPoint);
3563
-		$mountPoint->method('getStorageRootId')
3564
-			->willReturn(42);
3565
-
3566
-		$expected = new DataResponse([]);
3567
-		$result = $ocs->updateShare(42, null, null, null, 'true', null, null, null, null);
3568
-
3569
-		$this->assertInstanceOf(get_class($expected), $result);
3570
-		$this->assertEquals($expected->getData(), $result->getData());
3571
-	}
3572
-
3573
-	public function testUpdateLinkSharePermissions(): void {
3574
-		$ocs = $this->mockFormatShare();
3575
-
3576
-		$date = new \DateTime('2000-01-01');
3577
-
3578
-		[$userFolder, $folder] = $this->getNonSharedUserFolder();
3579
-		$folder->method('getId')
3580
-			->willReturn(42);
3581
-
3582
-		$share = Server::get(IManager::class)->newShare();
3583
-		$share->setPermissions(Constants::PERMISSION_ALL)
3584
-			->setSharedBy($this->currentUser)
3585
-			->setShareType(IShare::TYPE_LINK)
3586
-			->setPassword('password')
3587
-			->setSendPasswordByTalk(true)
3588
-			->setExpirationDate($date)
3589
-			->setNote('note')
3590
-			->setLabel('label')
3591
-			->setHideDownload(true)
3592
-			->setPermissions(Constants::PERMISSION_ALL)
3593
-			->setNode($folder);
3594
-
3595
-		$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3596
-		$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
3597
-
3598
-		$this->shareManager->expects($this->once())->method('updateShare')->with(
3599
-			$this->callback(function (IShare $share) use ($date): bool {
3600
-				return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
3601
-				&& $share->getPassword() === 'password'
3602
-				&& $share->getSendPasswordByTalk() === true
3603
-				&& $share->getExpirationDate() === $date
3604
-				&& $share->getNote() === 'note'
3605
-				&& $share->getLabel() === 'label'
3606
-				&& $share->getHideDownload() === true;
3607
-			})
3608
-		)->willReturnArgument(0);
3609
-
3610
-		$this->shareManager->method('getSharedWith')->willReturn([]);
3611
-
3612
-		$this->rootFolder->method('getUserFolder')
3613
-			->with($this->currentUser)
3614
-			->willReturn($userFolder);
3615
-
3616
-		$userFolder->method('getById')
3617
-			->with(42)
3618
-			->willReturn([$folder]);
3619
-
3620
-		$mountPoint = $this->createMock(IMountPoint::class);
3621
-		$folder->method('getMountPoint')
3622
-			->willReturn($mountPoint);
3623
-		$mountPoint->method('getStorageRootId')
3624
-			->willReturn(42);
3625
-
3626
-		$expected = new DataResponse([]);
3627
-		$result = $ocs->updateShare(42, 7, null, null, 'true', null, null, null, null);
3628
-
3629
-		$this->assertInstanceOf(get_class($expected), $result);
3630
-		$this->assertEquals($expected->getData(), $result->getData());
3631
-	}
3632
-
3633
-	public function testUpdateLinkSharePermissionsShare(): void {
3634
-		$ocs = $this->mockFormatShare();
3635
-
3636
-		$date = new \DateTime('2000-01-01');
3637
-
3638
-		[$userFolder, $folder] = $this->getNonSharedUserFolder();
3639
-		$folder->method('getId')
3640
-			->willReturn(42);
3641
-
3642
-		$share = Server::get(IManager::class)->newShare();
3643
-		$share->setPermissions(Constants::PERMISSION_ALL)
3644
-			->setSharedBy($this->currentUser)
3645
-			->setShareType(IShare::TYPE_LINK)
3646
-			->setPassword('password')
3647
-			->setSendPasswordByTalk(true)
3648
-			->setExpirationDate($date)
3649
-			->setNote('note')
3650
-			->setLabel('label')
3651
-			->setHideDownload(true)
3652
-			->setPermissions(Constants::PERMISSION_READ)
3653
-			->setNode($folder);
3654
-
3655
-		$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3656
-		$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
3657
-
3658
-		$this->shareManager->expects($this->once())
3659
-			->method('updateShare')
3660
-			->with(
3661
-				$this->callback(function (IShare $share) use ($date) {
3662
-					return $share->getPermissions() === Constants::PERMISSION_ALL
3663
-						&& $share->getPassword() === 'password'
3664
-						&& $share->getSendPasswordByTalk() === true
3665
-						&& $share->getExpirationDate() === $date
3666
-						&& $share->getNote() === 'note'
3667
-						&& $share->getLabel() === 'label'
3668
-						&& $share->getHideDownload() === true;
3669
-				})
3670
-			)->willReturnArgument(0);
3671
-
3672
-		$this->rootFolder->method('getUserFolder')
3673
-			->with($this->currentUser)
3674
-			->willReturn($userFolder);
3675
-
3676
-		$userFolder->method('getById')
3677
-			->with(42)
3678
-			->willReturn([$folder]);
3679
-
3680
-		$mountPoint = $this->createMock(IMountPoint::class);
3681
-		$folder->method('getMountPoint')
3682
-			->willReturn($mountPoint);
3683
-		$mountPoint->method('getStorageRootId')
3684
-			->willReturn(42);
3685
-
3686
-		$this->shareManager->method('getSharedWith')->willReturn([]);
3687
-
3688
-		$expected = new DataResponse([]);
3689
-		$result = $ocs->updateShare(42, Constants::PERMISSION_ALL, null, null, null, null, null, null, null);
3690
-
3691
-		$this->assertInstanceOf(get_class($expected), $result);
3692
-		$this->assertEquals($expected->getData(), $result->getData());
3693
-	}
3694
-
3695
-	public function testUpdateOtherPermissions(): void {
3696
-		$ocs = $this->mockFormatShare();
3697
-
3698
-		[$userFolder, $file] = $this->getNonSharedUserFolder();
3699
-		$file->method('getId')
3700
-			->willReturn(42);
3701
-
3702
-		$share = Server::get(IManager::class)->newShare();
3703
-		$share->setPermissions(Constants::PERMISSION_ALL)
3704
-			->setSharedBy($this->currentUser)
3705
-			->setShareType(IShare::TYPE_USER)
3706
-			->setNode($file);
3707
-
3708
-		$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3709
-		$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
3710
-
3711
-		$this->shareManager->expects($this->once())->method('updateShare')->with(
3712
-			$this->callback(function (IShare $share) {
3713
-				return $share->getPermissions() === Constants::PERMISSION_ALL;
3714
-			})
3715
-		)->willReturnArgument(0);
3716
-
3717
-		$this->shareManager->method('getSharedWith')->willReturn([]);
3718
-
3719
-		[$userFolder, $folder] = $this->getNonSharedUserFolder();
3720
-		$this->rootFolder->method('getUserFolder')
3721
-			->with($this->currentUser)
3722
-			->willReturn($userFolder);
3723
-
3724
-		$userFolder->method('getById')
3725
-			->with(42)
3726
-			->willReturn([$file]);
3727
-
3728
-		$mountPoint = $this->createMock(IMountPoint::class);
3729
-		$file->method('getMountPoint')
3730
-			->willReturn($mountPoint);
3731
-		$mountPoint->method('getStorageRootId')
3732
-			->willReturn(42);
3733
-
3734
-		$expected = new DataResponse([]);
3735
-		$result = $ocs->updateShare(42, 31, null, null, null, null);
3736
-
3737
-		$this->assertInstanceOf(get_class($expected), $result);
3738
-		$this->assertEquals($expected->getData(), $result->getData());
3739
-	}
3740
-
3741
-	public function testUpdateShareCannotIncreasePermissions(): void {
3742
-		$ocs = $this->mockFormatShare();
3743
-
3744
-		[$userFolder, $folder] = $this->getNonSharedUserFolder();
3745
-		$folder->method('getId')
3746
-			->willReturn(42);
3747
-
3748
-		$share = Server::get(IManager::class)->newShare();
3749
-		$share
3750
-			->setId(42)
3751
-			->setSharedBy($this->currentUser)
3752
-			->setShareOwner('anotheruser')
3753
-			->setShareType(IShare::TYPE_GROUP)
3754
-			->setSharedWith('group1')
3755
-			->setPermissions(Constants::PERMISSION_READ)
3756
-			->setNode($folder);
3757
-
3758
-		// note: updateShare will modify the received instance but getSharedWith will reread from the database,
3759
-		// so their values will be different
3760
-		$incomingShare = Server::get(IManager::class)->newShare();
3761
-		$incomingShare
3762
-			->setId(42)
3763
-			->setSharedBy($this->currentUser)
3764
-			->setShareOwner('anotheruser')
3765
-			->setShareType(IShare::TYPE_GROUP)
3766
-			->setSharedWith('group1')
3767
-			->setPermissions(Constants::PERMISSION_READ)
3768
-			->setNode($folder);
3769
-
3770
-		$this->request
3771
-			->method('getParam')
3772
-			->willReturnMap([
3773
-				['permissions', null, '31'],
3774
-			]);
3775
-
3776
-		$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3777
-
3778
-		$this->shareManager->expects($this->any())
3779
-			->method('getSharedWith')
3780
-			->willReturnMap([
3781
-				['currentUser', IShare::TYPE_USER, $share->getNode(), -1, 0, []],
3782
-				['currentUser', IShare::TYPE_GROUP, $share->getNode(), -1, 0, [$incomingShare]],
3783
-				['currentUser', IShare::TYPE_ROOM, $share->getNode(), -1, 0, []]
3784
-			]);
3785
-
3786
-		$this->rootFolder->method('getUserFolder')
3787
-			->with($this->currentUser)
3788
-			->willReturn($userFolder);
3789
-
3790
-		$userFolder->method('getById')
3791
-			->with(42)
3792
-			->willReturn([$folder]);
3793
-		$userFolder->method('getFirstNodeById')
3794
-			->with(42)
3795
-			->willReturn($folder);
3796
-
3797
-		$mountPoint = $this->createMock(IMountPoint::class);
3798
-		$folder->method('getMountPoint')
3799
-			->willReturn($mountPoint);
3800
-		$mountPoint->method('getStorageRootId')
3801
-			->willReturn(42);
3802
-
3803
-		$this->shareManager->expects($this->once())
3804
-			->method('updateShare')
3805
-			->with($share)
3806
-			->willThrowException(new GenericShareException('Cannot increase permissions of path/file', 'Cannot increase permissions of path/file', 404));
3807
-
3808
-		try {
3809
-			$ocs->updateShare(42, 31);
3810
-			$this->fail();
3811
-		} catch (OCSException $e) {
3812
-			$this->assertEquals('Cannot increase permissions of path/file', $e->getMessage());
3813
-		}
3814
-	}
3815
-
3816
-	public function testUpdateShareCanIncreasePermissionsIfOwner(): void {
3817
-		$ocs = $this->mockFormatShare();
3818
-
3819
-		[$userFolder, $folder] = $this->getNonSharedUserFolder();
3820
-		$folder->method('getId')
3821
-			->willReturn(42);
3822
-
3823
-		$share = Server::get(IManager::class)->newShare();
3824
-		$share
3825
-			->setId(42)
3826
-			->setSharedBy($this->currentUser)
3827
-			->setShareOwner($this->currentUser)
3828
-			->setShareType(IShare::TYPE_GROUP)
3829
-			->setSharedWith('group1')
3830
-			->setPermissions(Constants::PERMISSION_READ)
3831
-			->setNode($folder);
3832
-
3833
-		// note: updateShare will modify the received instance but getSharedWith will reread from the database,
3834
-		// so their values will be different
3835
-		$incomingShare = Server::get(IManager::class)->newShare();
3836
-		$incomingShare
3837
-			->setId(42)
3838
-			->setSharedBy($this->currentUser)
3839
-			->setShareOwner($this->currentUser)
3840
-			->setShareType(IShare::TYPE_GROUP)
3841
-			->setSharedWith('group1')
3842
-			->setPermissions(Constants::PERMISSION_READ)
3843
-			->setNode($folder);
3844
-
3845
-		$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3846
-
3847
-		$this->shareManager->expects($this->any())
3848
-			->method('getSharedWith')
3849
-			->willReturnMap([
3850
-				['currentUser', IShare::TYPE_USER, $share->getNode(), -1, 0, []],
3851
-				['currentUser', IShare::TYPE_GROUP, $share->getNode(), -1, 0, [$incomingShare]]
3852
-			]);
3853
-
3854
-		$this->shareManager->expects($this->once())
3855
-			->method('updateShare')
3856
-			->with($share)
3857
-			->willReturn($share);
3858
-
3859
-		$this->rootFolder->method('getUserFolder')
3860
-			->with($this->currentUser)
3861
-			->willReturn($userFolder);
3862
-
3863
-		$userFolder->method('getById')
3864
-			->with(42)
3865
-			->willReturn([$folder]);
3866
-
3867
-		$mountPoint = $this->createMock(IMountPoint::class);
3868
-		$folder->method('getMountPoint')
3869
-			->willReturn($mountPoint);
3870
-		$mountPoint->method('getStorageRootId')
3871
-			->willReturn(42);
3872
-
3873
-		$result = $ocs->updateShare(42, 31);
3874
-		$this->assertInstanceOf(DataResponse::class, $result);
3875
-	}
3876
-
3877
-	public function testUpdateShareOwnerless(): void {
3878
-		$ocs = $this->mockFormatShare();
3879
-
3880
-		$mount = $this->createMock(IShareOwnerlessMount::class);
3881
-
3882
-		$file = $this->createMock(File::class);
3883
-		$file
3884
-			->expects($this->exactly(2))
3885
-			->method('getPermissions')
3886
-			->willReturn(Constants::PERMISSION_SHARE);
3887
-		$file
3888
-			->expects($this->once())
3889
-			->method('getMountPoint')
3890
-			->willReturn($mount);
3891
-
3892
-		$userFolder = $this->createMock(Folder::class);
3893
-		$userFolder->method('getById')
3894
-			->with(2)
3895
-			->willReturn([$file]);
3896
-		$userFolder->method('getFirstNodeById')
3897
-			->with(2)
3898
-			->willReturn($file);
3899
-
3900
-		$this->rootFolder
3901
-			->method('getUserFolder')
3902
-			->with($this->currentUser)
3903
-			->willReturn($userFolder);
3904
-
3905
-		$share = $this->createMock(IShare::class);
3906
-		$share
3907
-			->expects($this->once())
3908
-			->method('getNode')
3909
-			->willReturn($file);
3910
-		$share
3911
-			->expects($this->exactly(2))
3912
-			->method('getNodeId')
3913
-			->willReturn(2);
3914
-		$share
3915
-			->expects($this->exactly(2))
3916
-			->method('getPermissions')
3917
-			->willReturn(Constants::PERMISSION_SHARE);
3918
-
3919
-		$this->shareManager
3920
-			->expects($this->once())
3921
-			->method('getShareById')
3922
-			->with('ocinternal:1', $this->currentUser)
3923
-			->willReturn($share);
3924
-
3925
-		$this->shareManager
3926
-			->expects($this->once())
3927
-			->method('updateShare')
3928
-			->with($share)
3929
-			->willReturn($share);
3930
-
3931
-		$result = $ocs->updateShare(1, Constants::PERMISSION_ALL);
3932
-		$this->assertInstanceOf(DataResponse::class, $result);
3933
-	}
3934
-
3935
-	public function dataFormatShare() {
3936
-		$file = $this->getMockBuilder(File::class)->getMock();
3937
-		$folder = $this->getMockBuilder(Folder::class)->getMock();
3938
-		$parent = $this->getMockBuilder(Folder::class)->getMock();
3939
-		$fileWithPreview = $this->getMockBuilder(File::class)->getMock();
3940
-
3941
-		$file->method('getMimeType')->willReturn('myMimeType');
3942
-		$folder->method('getMimeType')->willReturn('myFolderMimeType');
3943
-		$fileWithPreview->method('getMimeType')->willReturn('mimeWithPreview');
3944
-
3945
-		$mountPoint = $this->createMock(IMountPoint::class);
3946
-		$mountPoint->method('getMountType')->willReturn('');
3947
-		$file->method('getMountPoint')->willReturn($mountPoint);
3948
-		$folder->method('getMountPoint')->willReturn($mountPoint);
3949
-		$fileWithPreview->method('getMountPoint')->willReturn($mountPoint);
3950
-
3951
-		$file->method('getPath')->willReturn('file');
3952
-		$folder->method('getPath')->willReturn('folder');
3953
-		$fileWithPreview->method('getPath')->willReturn('fileWithPreview');
3954
-
3955
-		$parent->method('getId')->willReturn(1);
3956
-		$folder->method('getId')->willReturn(2);
3957
-		$file->method('getId')->willReturn(3);
3958
-		$fileWithPreview->method('getId')->willReturn(4);
3959
-
3960
-		$file->method('getParent')->willReturn($parent);
3961
-		$folder->method('getParent')->willReturn($parent);
3962
-		$fileWithPreview->method('getParent')->willReturn($parent);
3963
-
3964
-		$file->method('getSize')->willReturn(123456);
3965
-		$folder->method('getSize')->willReturn(123456);
3966
-		$fileWithPreview->method('getSize')->willReturn(123456);
3967
-		$file->method('getMTime')->willReturn(1234567890);
3968
-		$folder->method('getMTime')->willReturn(1234567890);
3969
-		$fileWithPreview->method('getMTime')->willReturn(1234567890);
3970
-
3971
-		$cache = $this->getMockBuilder('OCP\Files\Cache\ICache')->getMock();
3972
-		$cache->method('getNumericStorageId')->willReturn(100);
3973
-		$storage = $this->createMock(IStorage::class);
3974
-		$storage->method('getId')->willReturn('storageId');
3975
-		$storage->method('getCache')->willReturn($cache);
3976
-
3977
-		$file->method('getStorage')->willReturn($storage);
3978
-		$folder->method('getStorage')->willReturn($storage);
3979
-		$fileWithPreview->method('getStorage')->willReturn($storage);
3980
-
3981
-
3982
-		$mountPoint = $this->getMockBuilder(IMountPoint::class)->getMock();
3983
-		$mountPoint->method('getMountType')->willReturn('');
3984
-		$file->method('getMountPoint')->willReturn($mountPoint);
3985
-		$folder->method('getMountPoint')->willReturn($mountPoint);
3986
-
3987
-		$owner = $this->getMockBuilder(IUser::class)->getMock();
3988
-		$owner->method('getDisplayName')->willReturn('ownerDN');
3989
-		$initiator = $this->getMockBuilder(IUser::class)->getMock();
3990
-		$initiator->method('getDisplayName')->willReturn('initiatorDN');
3991
-		$recipient = $this->getMockBuilder(IUser::class)->getMock();
3992
-		$recipient->method('getDisplayName')->willReturn('recipientDN');
3993
-		$recipient->method('getSystemEMailAddress')->willReturn('recipient');
3994
-		[$shareAttributes, $shareAttributesReturnJson] = $this->mockShareAttributes();
3995
-
3996
-		$result = [];
3997
-
3998
-		$share = Server::get(IManager::class)->newShare();
3999
-		$share->setShareType(IShare::TYPE_USER)
4000
-			->setSharedWith('recipient')
4001
-			->setSharedBy('initiator')
4002
-			->setShareOwner('owner')
4003
-			->setPermissions(Constants::PERMISSION_READ)
4004
-			->setAttributes($shareAttributes)
4005
-			->setNode($file)
4006
-			->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4007
-			->setTarget('myTarget')
4008
-			->setNote('personal note')
4009
-			->setId(42);
4010
-
4011
-		// User backend down
4012
-		$result[] = [
4013
-			[
4014
-				'id' => '42',
4015
-				'share_type' => IShare::TYPE_USER,
4016
-				'uid_owner' => 'initiator',
4017
-				'displayname_owner' => 'initiator',
4018
-				'permissions' => 1,
4019
-				'attributes' => $shareAttributesReturnJson,
4020
-				'stime' => 946684862,
4021
-				'parent' => null,
4022
-				'expiration' => null,
4023
-				'token' => null,
4024
-				'uid_file_owner' => 'owner',
4025
-				'displayname_file_owner' => 'owner',
4026
-				'path' => 'file',
4027
-				'item_type' => 'file',
4028
-				'storage_id' => 'storageId',
4029
-				'storage' => 100,
4030
-				'item_source' => 3,
4031
-				'file_source' => 3,
4032
-				'file_parent' => 1,
4033
-				'file_target' => 'myTarget',
4034
-				'share_with' => 'recipient',
4035
-				'share_with_displayname' => 'recipient',
4036
-				'share_with_displayname_unique' => 'recipient',
4037
-				'note' => 'personal note',
4038
-				'label' => '',
4039
-				'mail_send' => 0,
4040
-				'mimetype' => 'myMimeType',
4041
-				'has_preview' => false,
4042
-				'hide_download' => 0,
4043
-				'can_edit' => false,
4044
-				'can_delete' => false,
4045
-				'item_size' => 123456,
4046
-				'item_mtime' => 1234567890,
4047
-				'is-mount-root' => false,
4048
-				'mount-type' => '',
4049
-				'attributes' => '[{"scope":"permissions","key":"download","value":true}]',
4050
-				'item_permissions' => 1,
4051
-			], $share, [], false
4052
-		];
4053
-		// User backend up
4054
-		$result[] = [
4055
-			[
4056
-				'id' => '42',
4057
-				'share_type' => IShare::TYPE_USER,
4058
-				'uid_owner' => 'initiator',
4059
-				'displayname_owner' => 'initiatorDN',
4060
-				'permissions' => 1,
4061
-				'attributes' => $shareAttributesReturnJson,
4062
-				'stime' => 946684862,
4063
-				'parent' => null,
4064
-				'expiration' => null,
4065
-				'token' => null,
4066
-				'uid_file_owner' => 'owner',
4067
-				'displayname_file_owner' => 'ownerDN',
4068
-				'note' => 'personal note',
4069
-				'label' => '',
4070
-				'path' => 'file',
4071
-				'item_type' => 'file',
4072
-				'storage_id' => 'storageId',
4073
-				'storage' => 100,
4074
-				'item_source' => 3,
4075
-				'file_source' => 3,
4076
-				'file_parent' => 1,
4077
-				'file_target' => 'myTarget',
4078
-				'share_with' => 'recipient',
4079
-				'share_with_displayname' => 'recipientDN',
4080
-				'share_with_displayname_unique' => 'recipient',
4081
-				'mail_send' => 0,
4082
-				'mimetype' => 'myMimeType',
4083
-				'has_preview' => false,
4084
-				'hide_download' => 0,
4085
-				'can_edit' => false,
4086
-				'can_delete' => false,
4087
-				'item_size' => 123456,
4088
-				'item_mtime' => 1234567890,
4089
-				'is-mount-root' => false,
4090
-				'mount-type' => '',
4091
-				'attributes' => '[{"scope":"permissions","key":"download","value":true}]',
4092
-				'item_permissions' => 1,
4093
-			], $share, [
4094
-				['owner', $owner],
4095
-				['initiator', $initiator],
4096
-				['recipient', $recipient],
4097
-			], false
4098
-		];
4099
-
4100
-		$share = Server::get(IManager::class)->newShare();
4101
-		$share->setShareType(IShare::TYPE_USER)
4102
-			->setSharedWith('recipient')
4103
-			->setSharedBy('initiator')
4104
-			->setShareOwner('owner')
4105
-			->setPermissions(Constants::PERMISSION_READ)
4106
-			->setNode($file)
4107
-			->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4108
-			->setTarget('myTarget')
4109
-			->setNote('personal note')
4110
-			->setId(42);
4111
-		// User backend down
4112
-		$result[] = [
4113
-			[
4114
-				'id' => '42',
4115
-				'share_type' => IShare::TYPE_USER,
4116
-				'uid_owner' => 'initiator',
4117
-				'displayname_owner' => 'initiator',
4118
-				'permissions' => 1,
4119
-				'attributes' => null,
4120
-				'stime' => 946684862,
4121
-				'parent' => null,
4122
-				'expiration' => null,
4123
-				'token' => null,
4124
-				'uid_file_owner' => 'owner',
4125
-				'displayname_file_owner' => 'owner',
4126
-				'note' => 'personal note',
4127
-				'label' => '',
4128
-				'path' => 'file',
4129
-				'item_type' => 'file',
4130
-				'storage_id' => 'storageId',
4131
-				'storage' => 100,
4132
-				'item_source' => 3,
4133
-				'file_source' => 3,
4134
-				'file_parent' => 1,
4135
-				'file_target' => 'myTarget',
4136
-				'share_with' => 'recipient',
4137
-				'share_with_displayname' => 'recipient',
4138
-				'share_with_displayname_unique' => 'recipient',
4139
-				'mail_send' => 0,
4140
-				'mimetype' => 'myMimeType',
4141
-				'has_preview' => false,
4142
-				'hide_download' => 0,
4143
-				'can_edit' => false,
4144
-				'can_delete' => false,
4145
-				'item_size' => 123456,
4146
-				'item_mtime' => 1234567890,
4147
-				'is-mount-root' => false,
4148
-				'mount-type' => '',
4149
-				'attributes' => null,
4150
-				'item_permissions' => 1,
4151
-			], $share, [], false
4152
-		];
4153
-
4154
-		$share = Server::get(IManager::class)->newShare();
4155
-		$share->setShareType(IShare::TYPE_USER)
4156
-			->setSharedWith('recipient')
4157
-			->setSharedBy('initiator')
4158
-			->setShareOwner('currentUser')
4159
-			->setPermissions(Constants::PERMISSION_READ)
4160
-			->setNode($file)
4161
-			->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4162
-			->setTarget('myTarget')
4163
-			->setNote('personal note')
4164
-			->setId(42);
4165
-		// User backend down
4166
-		$result[] = [
4167
-			[
4168
-				'id' => '42',
4169
-				'share_type' => IShare::TYPE_USER,
4170
-				'uid_owner' => 'initiator',
4171
-				'displayname_owner' => 'initiator',
4172
-				'permissions' => 1,
4173
-				'attributes' => null,
4174
-				'stime' => 946684862,
4175
-				'parent' => null,
4176
-				'expiration' => null,
4177
-				'token' => null,
4178
-				'uid_file_owner' => 'currentUser',
4179
-				'displayname_file_owner' => 'currentUser',
4180
-				'note' => 'personal note',
4181
-				'label' => '',
4182
-				'path' => 'file',
4183
-				'item_type' => 'file',
4184
-				'storage_id' => 'storageId',
4185
-				'storage' => 100,
4186
-				'item_source' => 3,
4187
-				'file_source' => 3,
4188
-				'file_parent' => 1,
4189
-				'file_target' => 'myTarget',
4190
-				'share_with' => 'recipient',
4191
-				'share_with_displayname' => 'recipient',
4192
-				'share_with_displayname_unique' => 'recipient',
4193
-				'mail_send' => 0,
4194
-				'mimetype' => 'myMimeType',
4195
-				'has_preview' => false,
4196
-				'hide_download' => 0,
4197
-				'can_edit' => true,
4198
-				'can_delete' => true,
4199
-				'item_size' => 123456,
4200
-				'item_mtime' => 1234567890,
4201
-				'is-mount-root' => false,
4202
-				'mount-type' => '',
4203
-				'attributes' => null,
4204
-				'item_permissions' => 11,
4205
-			], $share, [], false
4206
-		];
4207
-
4208
-		// with existing group
4209
-
4210
-		$share = Server::get(IManager::class)->newShare();
4211
-		$share->setShareType(IShare::TYPE_GROUP)
4212
-			->setSharedWith('recipientGroup')
4213
-			->setSharedBy('initiator')
4214
-			->setShareOwner('owner')
4215
-			->setPermissions(Constants::PERMISSION_READ)
4216
-			->setNode($file)
4217
-			->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4218
-			->setTarget('myTarget')
4219
-			->setNote('personal note')
4220
-			->setId(42);
4221
-
4222
-		$result[] = [
4223
-			[
4224
-				'id' => '42',
4225
-				'share_type' => IShare::TYPE_GROUP,
4226
-				'uid_owner' => 'initiator',
4227
-				'displayname_owner' => 'initiator',
4228
-				'permissions' => 1,
4229
-				'attributes' => null,
4230
-				'stime' => 946684862,
4231
-				'parent' => null,
4232
-				'expiration' => null,
4233
-				'token' => null,
4234
-				'uid_file_owner' => 'owner',
4235
-				'displayname_file_owner' => 'owner',
4236
-				'note' => 'personal note',
4237
-				'label' => '',
4238
-				'path' => 'file',
4239
-				'item_type' => 'file',
4240
-				'storage_id' => 'storageId',
4241
-				'storage' => 100,
4242
-				'item_source' => 3,
4243
-				'file_source' => 3,
4244
-				'file_parent' => 1,
4245
-				'file_target' => 'myTarget',
4246
-				'share_with' => 'recipientGroup',
4247
-				'share_with_displayname' => 'recipientGroupDisplayName',
4248
-				'mail_send' => 0,
4249
-				'mimetype' => 'myMimeType',
4250
-				'has_preview' => false,
4251
-				'hide_download' => 0,
4252
-				'can_edit' => false,
4253
-				'can_delete' => false,
4254
-				'item_size' => 123456,
4255
-				'item_mtime' => 1234567890,
4256
-				'is-mount-root' => false,
4257
-				'mount-type' => '',
4258
-				'attributes' => null,
4259
-				'item_permissions' => 1,
4260
-			], $share, [], false
4261
-		];
4262
-
4263
-		// with unknown group / no group backend
4264
-		$share = Server::get(IManager::class)->newShare();
4265
-		$share->setShareType(IShare::TYPE_GROUP)
4266
-			->setSharedWith('recipientGroup2')
4267
-			->setSharedBy('initiator')
4268
-			->setShareOwner('owner')
4269
-			->setPermissions(Constants::PERMISSION_READ)
4270
-			->setNode($file)
4271
-			->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4272
-			->setTarget('myTarget')
4273
-			->setNote('personal note')
4274
-			->setId(42);
4275
-		$result[] = [
4276
-			[
4277
-				'id' => '42',
4278
-				'share_type' => IShare::TYPE_GROUP,
4279
-				'uid_owner' => 'initiator',
4280
-				'displayname_owner' => 'initiator',
4281
-				'permissions' => 1,
4282
-				'stime' => 946684862,
4283
-				'parent' => null,
4284
-				'expiration' => null,
4285
-				'token' => null,
4286
-				'uid_file_owner' => 'owner',
4287
-				'displayname_file_owner' => 'owner',
4288
-				'note' => 'personal note',
4289
-				'label' => '',
4290
-				'path' => 'file',
4291
-				'item_type' => 'file',
4292
-				'storage_id' => 'storageId',
4293
-				'storage' => 100,
4294
-				'item_source' => 3,
4295
-				'file_source' => 3,
4296
-				'file_parent' => 1,
4297
-				'file_target' => 'myTarget',
4298
-				'share_with' => 'recipientGroup2',
4299
-				'share_with_displayname' => 'recipientGroup2',
4300
-				'mail_send' => 0,
4301
-				'mimetype' => 'myMimeType',
4302
-				'has_preview' => false,
4303
-				'hide_download' => 0,
4304
-				'can_edit' => false,
4305
-				'can_delete' => false,
4306
-				'item_size' => 123456,
4307
-				'item_mtime' => 1234567890,
4308
-				'is-mount-root' => false,
4309
-				'mount-type' => '',
4310
-				'attributes' => null,
4311
-				'item_permissions' => 1,
4312
-			], $share, [], false
4313
-		];
4314
-
4315
-		$share = Server::get(IManager::class)->newShare();
4316
-		$share->setShareType(IShare::TYPE_LINK)
4317
-			->setSharedBy('initiator')
4318
-			->setShareOwner('owner')
4319
-			->setPermissions(Constants::PERMISSION_READ)
4320
-			->setNode($file)
4321
-			->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4322
-			->setTarget('myTarget')
4323
-			->setPassword('mypassword')
4324
-			->setExpirationDate(new \DateTime('2001-01-02T00:00:00'))
4325
-			->setToken('myToken')
4326
-			->setNote('personal note')
4327
-			->setLabel('new link share')
4328
-			->setId(42);
4329
-
4330
-		$result[] = [
4331
-			[
4332
-				'id' => '42',
4333
-				'share_type' => IShare::TYPE_LINK,
4334
-				'uid_owner' => 'initiator',
4335
-				'displayname_owner' => 'initiator',
4336
-				'permissions' => 1,
4337
-				'attributes' => null,
4338
-				'stime' => 946684862,
4339
-				'parent' => null,
4340
-				'expiration' => '2001-01-02 00:00:00',
4341
-				'token' => 'myToken',
4342
-				'uid_file_owner' => 'owner',
4343
-				'displayname_file_owner' => 'owner',
4344
-				'note' => 'personal note',
4345
-				'label' => 'new link share',
4346
-				'path' => 'file',
4347
-				'item_type' => 'file',
4348
-				'storage_id' => 'storageId',
4349
-				'storage' => 100,
4350
-				'item_source' => 3,
4351
-				'file_source' => 3,
4352
-				'file_parent' => 1,
4353
-				'file_target' => 'myTarget',
4354
-				'password' => 'mypassword',
4355
-				'share_with' => 'mypassword',
4356
-				'share_with_displayname' => '(Shared link)',
4357
-				'send_password_by_talk' => false,
4358
-				'mail_send' => 0,
4359
-				'url' => 'myLink',
4360
-				'mimetype' => 'myMimeType',
4361
-				'has_preview' => false,
4362
-				'hide_download' => 0,
4363
-				'can_edit' => false,
4364
-				'can_delete' => false,
4365
-				'item_size' => 123456,
4366
-				'item_mtime' => 1234567890,
4367
-				'is-mount-root' => false,
4368
-				'mount-type' => '',
4369
-				'attributes' => null,
4370
-				'item_permissions' => 1,
4371
-			], $share, [], false
4372
-		];
4373
-
4374
-		$share = Server::get(IManager::class)->newShare();
4375
-		$share->setShareType(IShare::TYPE_LINK)
4376
-			->setSharedBy('initiator')
4377
-			->setShareOwner('owner')
4378
-			->setPermissions(Constants::PERMISSION_READ)
4379
-			->setNode($file)
4380
-			->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4381
-			->setTarget('myTarget')
4382
-			->setPassword('mypassword')
4383
-			->setSendPasswordByTalk(true)
4384
-			->setExpirationDate(new \DateTime('2001-01-02T00:00:00'))
4385
-			->setToken('myToken')
4386
-			->setNote('personal note')
4387
-			->setLabel('new link share')
4388
-			->setId(42);
4389
-
4390
-		$result[] = [
4391
-			[
4392
-				'id' => '42',
4393
-				'share_type' => IShare::TYPE_LINK,
4394
-				'uid_owner' => 'initiator',
4395
-				'displayname_owner' => 'initiator',
4396
-				'permissions' => 1,
4397
-				'stime' => 946684862,
4398
-				'parent' => null,
4399
-				'expiration' => '2001-01-02 00:00:00',
4400
-				'token' => 'myToken',
4401
-				'uid_file_owner' => 'owner',
4402
-				'displayname_file_owner' => 'owner',
4403
-				'note' => 'personal note',
4404
-				'label' => 'new link share',
4405
-				'path' => 'file',
4406
-				'item_type' => 'file',
4407
-				'storage_id' => 'storageId',
4408
-				'storage' => 100,
4409
-				'item_source' => 3,
4410
-				'file_source' => 3,
4411
-				'file_parent' => 1,
4412
-				'file_target' => 'myTarget',
4413
-				'password' => 'mypassword',
4414
-				'share_with' => 'mypassword',
4415
-				'share_with_displayname' => '(Shared link)',
4416
-				'send_password_by_talk' => true,
4417
-				'mail_send' => 0,
4418
-				'url' => 'myLink',
4419
-				'mimetype' => 'myMimeType',
4420
-				'has_preview' => false,
4421
-				'hide_download' => 0,
4422
-				'can_edit' => false,
4423
-				'can_delete' => false,
4424
-				'item_size' => 123456,
4425
-				'item_mtime' => 1234567890,
4426
-				'is-mount-root' => false,
4427
-				'mount-type' => '',
4428
-				'attributes' => null,
4429
-				'item_permissions' => 1,
4430
-			], $share, [], false
4431
-		];
4432
-
4433
-		$share = Server::get(IManager::class)->newShare();
4434
-		$share->setShareType(IShare::TYPE_REMOTE)
4435
-			->setSharedBy('initiator')
4436
-			->setSharedWith('[email protected]')
4437
-			->setShareOwner('owner')
4438
-			->setPermissions(Constants::PERMISSION_READ)
4439
-			->setNode($folder)
4440
-			->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4441
-			->setExpirationDate(new \DateTime('2001-02-03T04:05:06'))
4442
-			->setTarget('myTarget')
4443
-			->setNote('personal note')
4444
-			->setId(42);
4445
-
4446
-		$result[] = [
4447
-			[
4448
-				'id' => '42',
4449
-				'share_type' => IShare::TYPE_REMOTE,
4450
-				'uid_owner' => 'initiator',
4451
-				'displayname_owner' => 'initiator',
4452
-				'permissions' => 1,
4453
-				'stime' => 946684862,
4454
-				'parent' => null,
4455
-				'expiration' => '2001-02-03 00:00:00',
4456
-				'token' => null,
4457
-				'uid_file_owner' => 'owner',
4458
-				'displayname_file_owner' => 'owner',
4459
-				'note' => 'personal note',
4460
-				'label' => '',
4461
-				'path' => 'folder',
4462
-				'item_type' => 'folder',
4463
-				'storage_id' => 'storageId',
4464
-				'storage' => 100,
4465
-				'item_source' => 2,
4466
-				'file_source' => 2,
4467
-				'file_parent' => 1,
4468
-				'file_target' => 'myTarget',
4469
-				'share_with' => '[email protected]',
4470
-				'share_with_displayname' => 'foobar',
4471
-				'mail_send' => 0,
4472
-				'mimetype' => 'myFolderMimeType',
4473
-				'has_preview' => false,
4474
-				'hide_download' => 0,
4475
-				'can_edit' => false,
4476
-				'can_delete' => false,
4477
-				'item_size' => 123456,
4478
-				'item_mtime' => 1234567890,
4479
-				'is-mount-root' => false,
4480
-				'mount-type' => '',
4481
-				'attributes' => null,
4482
-				'item_permissions' => 1,
4483
-			], $share, [], false
4484
-		];
4485
-
4486
-		$share = Server::get(IManager::class)->newShare();
4487
-		$share->setShareType(IShare::TYPE_REMOTE_GROUP)
4488
-			->setSharedBy('initiator')
4489
-			->setSharedWith('[email protected]')
4490
-			->setShareOwner('owner')
4491
-			->setPermissions(Constants::PERMISSION_READ)
4492
-			->setNode($folder)
4493
-			->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4494
-			->setExpirationDate(new \DateTime('2001-02-03T04:05:06'))
4495
-			->setTarget('myTarget')
4496
-			->setNote('personal note')
4497
-			->setId(42);
4498
-
4499
-		$result[] = [
4500
-			[
4501
-				'id' => '42',
4502
-				'share_type' => IShare::TYPE_REMOTE_GROUP,
4503
-				'uid_owner' => 'initiator',
4504
-				'displayname_owner' => 'initiator',
4505
-				'permissions' => 1,
4506
-				'stime' => 946684862,
4507
-				'parent' => null,
4508
-				'expiration' => '2001-02-03 00:00:00',
4509
-				'token' => null,
4510
-				'uid_file_owner' => 'owner',
4511
-				'displayname_file_owner' => 'owner',
4512
-				'note' => 'personal note',
4513
-				'label' => '',
4514
-				'path' => 'folder',
4515
-				'item_type' => 'folder',
4516
-				'storage_id' => 'storageId',
4517
-				'storage' => 100,
4518
-				'item_source' => 2,
4519
-				'file_source' => 2,
4520
-				'file_parent' => 1,
4521
-				'file_target' => 'myTarget',
4522
-				'share_with' => '[email protected]',
4523
-				'share_with_displayname' => 'foobar',
4524
-				'mail_send' => 0,
4525
-				'mimetype' => 'myFolderMimeType',
4526
-				'has_preview' => false,
4527
-				'hide_download' => 0,
4528
-				'can_edit' => false,
4529
-				'can_delete' => false,
4530
-				'item_size' => 123456,
4531
-				'item_mtime' => 1234567890,
4532
-				'is-mount-root' => false,
4533
-				'mount-type' => '',
4534
-				'attributes' => null,
4535
-				'item_permissions' => 1,
4536
-			], $share, [], false
4537
-		];
4538
-
4539
-		// Circle with id, display name and avatar set by the Circles app
4540
-		$share = Server::get(IManager::class)->newShare();
4541
-		$share->setShareType(IShare::TYPE_CIRCLE)
4542
-			->setSharedBy('initiator')
4543
-			->setSharedWith('Circle (Public circle, circleOwner) [4815162342]')
4544
-			->setSharedWithDisplayName('The display name')
4545
-			->setSharedWithAvatar('path/to/the/avatar')
4546
-			->setShareOwner('owner')
4547
-			->setPermissions(Constants::PERMISSION_READ)
4548
-			->setNode($folder)
4549
-			->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4550
-			->setTarget('myTarget')
4551
-			->setId(42);
4552
-
4553
-		$result[] = [
4554
-			[
4555
-				'id' => '42',
4556
-				'share_type' => IShare::TYPE_CIRCLE,
4557
-				'uid_owner' => 'initiator',
4558
-				'displayname_owner' => 'initiator',
4559
-				'permissions' => 1,
4560
-				'attributes' => null,
4561
-				'stime' => 946684862,
4562
-				'parent' => null,
4563
-				'expiration' => null,
4564
-				'token' => null,
4565
-				'uid_file_owner' => 'owner',
4566
-				'displayname_file_owner' => 'owner',
4567
-				'note' => '',
4568
-				'label' => '',
4569
-				'path' => 'folder',
4570
-				'item_type' => 'folder',
4571
-				'storage_id' => 'storageId',
4572
-				'storage' => 100,
4573
-				'item_source' => 2,
4574
-				'file_source' => 2,
4575
-				'file_parent' => 1,
4576
-				'file_target' => 'myTarget',
4577
-				'share_with' => '4815162342',
4578
-				'share_with_displayname' => 'The display name',
4579
-				'share_with_avatar' => 'path/to/the/avatar',
4580
-				'mail_send' => 0,
4581
-				'mimetype' => 'myFolderMimeType',
4582
-				'has_preview' => false,
4583
-				'hide_download' => 0,
4584
-				'can_edit' => false,
4585
-				'can_delete' => false,
4586
-				'item_size' => 123456,
4587
-				'item_mtime' => 1234567890,
4588
-				'is-mount-root' => false,
4589
-				'mount-type' => '',
4590
-				'attributes' => null,
4591
-				'item_permissions' => 1,
4592
-			], $share, [], false
4593
-		];
4594
-
4595
-		// Circle with id set by the Circles app
4596
-		$share = Server::get(IManager::class)->newShare();
4597
-		$share->setShareType(IShare::TYPE_CIRCLE)
4598
-			->setSharedBy('initiator')
4599
-			->setSharedWith('Circle (Public circle, circleOwner) [4815162342]')
4600
-			->setShareOwner('owner')
4601
-			->setPermissions(Constants::PERMISSION_READ)
4602
-			->setNode($folder)
4603
-			->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4604
-			->setTarget('myTarget')
4605
-			->setId(42);
4606
-
4607
-		$result[] = [
4608
-			[
4609
-				'id' => '42',
4610
-				'share_type' => IShare::TYPE_CIRCLE,
4611
-				'uid_owner' => 'initiator',
4612
-				'displayname_owner' => 'initiator',
4613
-				'permissions' => 1,
4614
-				'stime' => 946684862,
4615
-				'parent' => null,
4616
-				'expiration' => null,
4617
-				'token' => null,
4618
-				'uid_file_owner' => 'owner',
4619
-				'displayname_file_owner' => 'owner',
4620
-				'note' => '',
4621
-				'label' => '',
4622
-				'path' => 'folder',
4623
-				'item_type' => 'folder',
4624
-				'storage_id' => 'storageId',
4625
-				'storage' => 100,
4626
-				'item_source' => 2,
4627
-				'file_source' => 2,
4628
-				'file_parent' => 1,
4629
-				'file_target' => 'myTarget',
4630
-				'share_with' => '4815162342',
4631
-				'share_with_displayname' => 'Circle (Public circle, circleOwner)',
4632
-				'share_with_avatar' => '',
4633
-				'mail_send' => 0,
4634
-				'mimetype' => 'myFolderMimeType',
4635
-				'has_preview' => false,
4636
-				'hide_download' => 0,
4637
-				'can_edit' => false,
4638
-				'can_delete' => false,
4639
-				'item_size' => 123456,
4640
-				'item_mtime' => 1234567890,
4641
-				'is-mount-root' => false,
4642
-				'mount-type' => '',
4643
-				'attributes' => null,
4644
-				'item_permissions' => 1,
4645
-			], $share, [], false
4646
-		];
4647
-
4648
-		// Circle with id not set by the Circles app
4649
-		$share = Server::get(IManager::class)->newShare();
4650
-		$share->setShareType(IShare::TYPE_CIRCLE)
4651
-			->setSharedBy('initiator')
4652
-			->setSharedWith('Circle (Public circle, circleOwner)')
4653
-			->setShareOwner('owner')
4654
-			->setPermissions(Constants::PERMISSION_READ)
4655
-			->setNode($folder)
4656
-			->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4657
-			->setTarget('myTarget')
4658
-			->setId(42);
4659
-
4660
-		$result[] = [
4661
-			[
4662
-				'id' => '42',
4663
-				'share_type' => IShare::TYPE_CIRCLE,
4664
-				'uid_owner' => 'initiator',
4665
-				'displayname_owner' => 'initiator',
4666
-				'permissions' => 1,
4667
-				'stime' => 946684862,
4668
-				'parent' => null,
4669
-				'expiration' => null,
4670
-				'token' => null,
4671
-				'uid_file_owner' => 'owner',
4672
-				'displayname_file_owner' => 'owner',
4673
-				'note' => '',
4674
-				'label' => '',
4675
-				'path' => 'folder',
4676
-				'item_type' => 'folder',
4677
-				'storage_id' => 'storageId',
4678
-				'storage' => 100,
4679
-				'item_source' => 2,
4680
-				'file_source' => 2,
4681
-				'file_parent' => 1,
4682
-				'file_target' => 'myTarget',
4683
-				'share_with' => 'Circle',
4684
-				'share_with_displayname' => 'Circle (Public circle, circleOwner)',
4685
-				'share_with_avatar' => '',
4686
-				'mail_send' => 0,
4687
-				'mimetype' => 'myFolderMimeType',
4688
-				'has_preview' => false,
4689
-				'hide_download' => 0,
4690
-				'can_edit' => false,
4691
-				'can_delete' => false,
4692
-				'item_size' => 123456,
4693
-				'item_mtime' => 1234567890,
4694
-				'is-mount-root' => false,
4695
-				'mount-type' => '',
4696
-				'attributes' => null,
4697
-				'item_permissions' => 1,
4698
-			], $share, [], false
4699
-		];
4700
-
4701
-		$share = Server::get(IManager::class)->newShare();
4702
-		$share->setShareType(IShare::TYPE_USER)
4703
-			->setSharedBy('initiator')
4704
-			->setSharedWith('recipient')
4705
-			->setShareOwner('owner')
4706
-			->setPermissions(Constants::PERMISSION_READ)
4707
-			->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4708
-			->setTarget('myTarget')
4709
-			->setNote('personal note')
4710
-			->setId(42);
4711
-
4712
-		$result[] = [
4713
-			[], $share, [], true
4714
-		];
4715
-
4716
-		$share = Server::get(IManager::class)->newShare();
4717
-		$share->setShareType(IShare::TYPE_EMAIL)
4718
-			->setSharedBy('initiator')
4719
-			->setSharedWith('[email protected]')
4720
-			->setShareOwner('owner')
4721
-			->setPermissions(Constants::PERMISSION_READ)
4722
-			->setNode($folder)
4723
-			->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4724
-			->setTarget('myTarget')
4725
-			->setId(42)
4726
-			->setPassword('password');
4727
-
4728
-		$result[] = [
4729
-			[
4730
-				'id' => '42',
4731
-				'share_type' => IShare::TYPE_EMAIL,
4732
-				'uid_owner' => 'initiator',
4733
-				'displayname_owner' => 'initiator',
4734
-				'permissions' => 1,
4735
-				'stime' => 946684862,
4736
-				'parent' => null,
4737
-				'expiration' => null,
4738
-				'token' => null,
4739
-				'uid_file_owner' => 'owner',
4740
-				'displayname_file_owner' => 'owner',
4741
-				'note' => '',
4742
-				'label' => '',
4743
-				'path' => 'folder',
4744
-				'item_type' => 'folder',
4745
-				'storage_id' => 'storageId',
4746
-				'storage' => 100,
4747
-				'item_source' => 2,
4748
-				'file_source' => 2,
4749
-				'file_parent' => 1,
4750
-				'file_target' => 'myTarget',
4751
-				'share_with' => '[email protected]',
4752
-				'share_with_displayname' => 'mail display name',
4753
-				'mail_send' => 0,
4754
-				'mimetype' => 'myFolderMimeType',
4755
-				'has_preview' => false,
4756
-				'password' => 'password',
4757
-				'send_password_by_talk' => false,
4758
-				'hide_download' => 0,
4759
-				'can_edit' => false,
4760
-				'can_delete' => false,
4761
-				'password_expiration_time' => null,
4762
-				'item_size' => 123456,
4763
-				'item_mtime' => 1234567890,
4764
-				'is-mount-root' => false,
4765
-				'mount-type' => '',
4766
-				'attributes' => null,
4767
-				'item_permissions' => 1,
4768
-			], $share, [], false
4769
-		];
4770
-
4771
-		$share = Server::get(IManager::class)->newShare();
4772
-		$share->setShareType(IShare::TYPE_EMAIL)
4773
-			->setSharedBy('initiator')
4774
-			->setSharedWith('[email protected]')
4775
-			->setShareOwner('owner')
4776
-			->setPermissions(Constants::PERMISSION_READ)
4777
-			->setNode($folder)
4778
-			->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4779
-			->setTarget('myTarget')
4780
-			->setId(42)
4781
-			->setPassword('password')
4782
-			->setSendPasswordByTalk(true);
4783
-
4784
-		$result[] = [
4785
-			[
4786
-				'id' => '42',
4787
-				'share_type' => IShare::TYPE_EMAIL,
4788
-				'uid_owner' => 'initiator',
4789
-				'displayname_owner' => 'initiator',
4790
-				'permissions' => 1,
4791
-				'stime' => 946684862,
4792
-				'parent' => null,
4793
-				'expiration' => null,
4794
-				'token' => null,
4795
-				'uid_file_owner' => 'owner',
4796
-				'displayname_file_owner' => 'owner',
4797
-				'note' => '',
4798
-				'label' => '',
4799
-				'path' => 'folder',
4800
-				'item_type' => 'folder',
4801
-				'storage_id' => 'storageId',
4802
-				'storage' => 100,
4803
-				'item_source' => 2,
4804
-				'file_source' => 2,
4805
-				'file_parent' => 1,
4806
-				'file_target' => 'myTarget',
4807
-				'share_with' => '[email protected]',
4808
-				'share_with_displayname' => 'mail display name',
4809
-				'mail_send' => 0,
4810
-				'mimetype' => 'myFolderMimeType',
4811
-				'has_preview' => false,
4812
-				'password' => 'password',
4813
-				'send_password_by_talk' => true,
4814
-				'hide_download' => 0,
4815
-				'can_edit' => false,
4816
-				'can_delete' => false,
4817
-				'password_expiration_time' => null,
4818
-				'item_size' => 123456,
4819
-				'item_mtime' => 1234567890,
4820
-				'is-mount-root' => false,
4821
-				'mount-type' => '',
4822
-				'attributes' => null,
4823
-				'item_permissions' => 1,
4824
-			], $share, [], false
4825
-		];
4826
-
4827
-		// Preview is available
4828
-		$share = Server::get(IManager::class)->newShare();
4829
-		$share->setShareType(IShare::TYPE_USER)
4830
-			->setSharedWith('recipient')
4831
-			->setSharedBy('initiator')
4832
-			->setShareOwner('currentUser')
4833
-			->setPermissions(Constants::PERMISSION_READ)
4834
-			->setNode($fileWithPreview)
4835
-			->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4836
-			->setTarget('myTarget')
4837
-			->setNote('personal note')
4838
-			->setId(42);
4839
-
4840
-		$result[] = [
4841
-			[
4842
-				'id' => '42',
4843
-				'share_type' => IShare::TYPE_USER,
4844
-				'uid_owner' => 'initiator',
4845
-				'displayname_owner' => 'initiator',
4846
-				'permissions' => 1,
4847
-				'stime' => 946684862,
4848
-				'parent' => null,
4849
-				'expiration' => null,
4850
-				'token' => null,
4851
-				'uid_file_owner' => 'currentUser',
4852
-				'displayname_file_owner' => 'currentUser',
4853
-				'note' => 'personal note',
4854
-				'label' => '',
4855
-				'path' => 'fileWithPreview',
4856
-				'item_type' => 'file',
4857
-				'storage_id' => 'storageId',
4858
-				'storage' => 100,
4859
-				'item_source' => 4,
4860
-				'file_source' => 4,
4861
-				'file_parent' => 1,
4862
-				'file_target' => 'myTarget',
4863
-				'share_with' => 'recipient',
4864
-				'share_with_displayname' => 'recipient',
4865
-				'share_with_displayname_unique' => 'recipient',
4866
-				'mail_send' => 0,
4867
-				'mimetype' => 'mimeWithPreview',
4868
-				'has_preview' => true,
4869
-				'hide_download' => 0,
4870
-				'can_edit' => true,
4871
-				'can_delete' => true,
4872
-				'item_size' => 123456,
4873
-				'item_mtime' => 1234567890,
4874
-				'is-mount-root' => false,
4875
-				'mount-type' => '',
4876
-				'attributes' => null,
4877
-				'item_permissions' => 11,
4878
-			], $share, [], false
4879
-		];
4880
-
4881
-		return $result;
4882
-	}
4883
-
4884
-	/**
4885
-	 *
4886
-	 * @param array $expects
4887
-	 * @param IShare $share
4888
-	 * @param array $users
4889
-	 * @param $exception
4890
-	 */
4891
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataFormatShare')]
4892
-	public function testFormatShare(array $expects, IShare $share, array $users, $exception): void {
4893
-		$this->userManager->method('get')->willReturnMap($users);
4894
-
4895
-		$recipientGroup = $this->createMock(IGroup::class);
4896
-		$recipientGroup->method('getDisplayName')->willReturn('recipientGroupDisplayName');
4897
-		$this->groupManager->method('get')->willReturnMap([
4898
-			['recipientGroup', $recipientGroup],
4899
-		]);
4900
-
4901
-		$this->urlGenerator->method('linkToRouteAbsolute')
4902
-			->with('files_sharing.sharecontroller.showShare', ['token' => 'myToken'])
4903
-			->willReturn('myLink');
4904
-
4905
-		$this->rootFolder->method('getUserFolder')
4906
-			->with($this->currentUser)
4907
-			->willReturnSelf();
4908
-		$this->dateTimeZone->method('getTimezone')->willReturn(new \DateTimeZone('UTC'));
4909
-
4910
-		if (!$exception) {
4911
-			$this->rootFolder->method('getFirstNodeById')
4912
-				->with($share->getNodeId())
4913
-				->willReturn($share->getNode());
4914
-
4915
-			$this->rootFolder->method('getRelativePath')
4916
-				->with($share->getNode()->getPath())
4917
-				->willReturnArgument(0);
4918
-		}
4919
-
4920
-		$cm = $this->createMock(\OCP\Contacts\IManager::class);
4921
-		$this->overwriteService(\OCP\Contacts\IManager::class, $cm);
4922
-
4923
-		$cm->method('search')
4924
-			->willReturnMap([
4925
-				['[email protected]', ['CLOUD'], [
4926
-					'limit' => 1,
4927
-					'enumeration' => false,
4928
-					'strict_search' => true,
4929
-				],
4930
-					[
4931
-						[
4932
-							'CLOUD' => [
4933
-								'[email protected]',
4934
-							],
4935
-							'FN' => 'foobar',
4936
-						],
4937
-					],
4938
-				],
4939
-				['[email protected]', ['EMAIL'], [
4940
-					'limit' => 1,
4941
-					'enumeration' => false,
4942
-					'strict_search' => true,
4943
-				],
4944
-					[
4945
-						[
4946
-							'EMAIL' => [
4947
-								'[email protected]',
4948
-							],
4949
-							'FN' => 'mail display name',
4950
-						],
4951
-					],
4952
-				],
4953
-			]);
4954
-
4955
-		try {
4956
-			$result = $this->invokePrivate($this->ocs, 'formatShare', [$share]);
4957
-			$this->assertFalse($exception);
4958
-			$this->assertEquals($expects, $result);
4959
-		} catch (NotFoundException $e) {
4960
-			$this->assertTrue($exception);
4961
-		}
4962
-	}
4963
-
4964
-	public function dataFormatRoomShare() {
4965
-		$file = $this->getMockBuilder(File::class)->getMock();
4966
-		$parent = $this->getMockBuilder(Folder::class)->getMock();
4967
-
4968
-		$file->method('getMimeType')->willReturn('myMimeType');
4969
-
4970
-		$file->method('getPath')->willReturn('file');
4971
-
4972
-		$parent->method('getId')->willReturn(1);
4973
-		$file->method('getId')->willReturn(3);
4974
-
4975
-		$file->method('getParent')->willReturn($parent);
4976
-
4977
-		$file->method('getSize')->willReturn(123456);
4978
-		$file->method('getMTime')->willReturn(1234567890);
4979
-
4980
-		$mountPoint = $this->getMockBuilder(IMountPoint::class)->getMock();
4981
-		$mountPoint->method('getMountType')->willReturn('');
4982
-		$file->method('getMountPoint')->willReturn($mountPoint);
4983
-
4984
-		$cache = $this->getMockBuilder('OCP\Files\Cache\ICache')->getMock();
4985
-		$cache->method('getNumericStorageId')->willReturn(100);
4986
-		$storage = $this->createMock(IStorage::class);
4987
-		$storage->method('getId')->willReturn('storageId');
4988
-		$storage->method('getCache')->willReturn($cache);
4989
-
4990
-		$file->method('getStorage')->willReturn($storage);
4991
-
4992
-		$result = [];
4993
-
4994
-		$share = Server::get(IManager::class)->newShare();
4995
-		$share->setShareType(IShare::TYPE_ROOM)
4996
-			->setSharedWith('recipientRoom')
4997
-			->setSharedBy('initiator')
4998
-			->setShareOwner('owner')
4999
-			->setPermissions(Constants::PERMISSION_READ)
5000
-			->setNode($file)
5001
-			->setShareTime(new \DateTime('2000-01-01T00:01:02'))
5002
-			->setTarget('myTarget')
5003
-			->setNote('personal note')
5004
-			->setId(42);
5005
-
5006
-		$result[] = [
5007
-			[
5008
-				'id' => '42',
5009
-				'share_type' => IShare::TYPE_ROOM,
5010
-				'uid_owner' => 'initiator',
5011
-				'displayname_owner' => 'initiator',
5012
-				'permissions' => 1,
5013
-				'stime' => 946684862,
5014
-				'parent' => null,
5015
-				'expiration' => null,
5016
-				'token' => null,
5017
-				'uid_file_owner' => 'owner',
5018
-				'displayname_file_owner' => 'owner',
5019
-				'note' => 'personal note',
5020
-				'path' => 'file',
5021
-				'item_type' => 'file',
5022
-				'storage_id' => 'storageId',
5023
-				'storage' => 100,
5024
-				'item_source' => 3,
5025
-				'file_source' => 3,
5026
-				'file_parent' => 1,
5027
-				'file_target' => 'myTarget',
5028
-				'share_with' => 'recipientRoom',
5029
-				'share_with_displayname' => '',
5030
-				'mail_send' => 0,
5031
-				'mimetype' => 'myMimeType',
5032
-				'has_preview' => false,
5033
-				'hide_download' => 0,
5034
-				'label' => '',
5035
-				'can_edit' => false,
5036
-				'can_delete' => false,
5037
-				'item_size' => 123456,
5038
-				'item_mtime' => 1234567890,
5039
-				'is-mount-root' => false,
5040
-				'mount-type' => '',
5041
-				'attributes' => null,
5042
-				'item_permissions' => 1,
5043
-			], $share, false, []
5044
-		];
5045
-
5046
-		$share = Server::get(IManager::class)->newShare();
5047
-		$share->setShareType(IShare::TYPE_ROOM)
5048
-			->setSharedWith('recipientRoom')
5049
-			->setSharedBy('initiator')
5050
-			->setShareOwner('owner')
5051
-			->setPermissions(Constants::PERMISSION_READ)
5052
-			->setNode($file)
5053
-			->setShareTime(new \DateTime('2000-01-01T00:01:02'))
5054
-			->setTarget('myTarget')
5055
-			->setNote('personal note')
5056
-			->setId(42);
5057
-
5058
-		$result[] = [
5059
-			[
5060
-				'id' => '42',
5061
-				'share_type' => IShare::TYPE_ROOM,
5062
-				'uid_owner' => 'initiator',
5063
-				'displayname_owner' => 'initiator',
5064
-				'permissions' => 1,
5065
-				'stime' => 946684862,
5066
-				'parent' => null,
5067
-				'expiration' => null,
5068
-				'token' => null,
5069
-				'uid_file_owner' => 'owner',
5070
-				'displayname_file_owner' => 'owner',
5071
-				'note' => 'personal note',
5072
-				'path' => 'file',
5073
-				'item_type' => 'file',
5074
-				'storage_id' => 'storageId',
5075
-				'storage' => 100,
5076
-				'item_source' => 3,
5077
-				'file_source' => 3,
5078
-				'file_parent' => 1,
5079
-				'file_target' => 'myTarget',
5080
-				'share_with' => 'recipientRoom',
5081
-				'share_with_displayname' => 'recipientRoomName',
5082
-				'mail_send' => 0,
5083
-				'mimetype' => 'myMimeType',
5084
-				'has_preview' => false,
5085
-				'hide_download' => 0,
5086
-				'label' => '',
5087
-				'can_edit' => false,
5088
-				'can_delete' => false,
5089
-				'item_size' => 123456,
5090
-				'item_mtime' => 1234567890,
5091
-				'is-mount-root' => false,
5092
-				'mount-type' => '',
5093
-				'attributes' => null,
5094
-				'item_permissions' => 9,
5095
-			], $share, true, [
5096
-				'share_with_displayname' => 'recipientRoomName'
5097
-			]
5098
-		];
5099
-
5100
-		return $result;
5101
-	}
5102
-
5103
-	/**
5104
-	 *
5105
-	 * @param array $expects
5106
-	 * @param IShare $share
5107
-	 * @param bool $helperAvailable
5108
-	 * @param array $formatShareByHelper
5109
-	 */
5110
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataFormatRoomShare')]
5111
-	public function testFormatRoomShare(array $expects, IShare $share, bool $helperAvailable, array $formatShareByHelper): void {
5112
-		$this->rootFolder->method('getUserFolder')
5113
-			->with($this->currentUser)
5114
-			->willReturnSelf();
5115
-
5116
-		$this->rootFolder->method('getFirstNodeById')
5117
-			->with($share->getNodeId())
5118
-			->willReturn($share->getNode());
5119
-
5120
-		$this->rootFolder->method('getRelativePath')
5121
-			->with($share->getNode()->getPath())
5122
-			->willReturnArgument(0);
5123
-
5124
-		if (!$helperAvailable) {
5125
-			$this->appManager->method('isEnabledForUser')
5126
-				->with('spreed')
5127
-				->willReturn(false);
5128
-		} else {
5129
-			$this->appManager->method('isEnabledForUser')
5130
-				->with('spreed')
5131
-				->willReturn(true);
5132
-
5133
-			// This is not possible anymore with PHPUnit 10+
5134
-			// as `setMethods` was removed and now real reflection is used, thus the class needs to exist.
5135
-			// $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
5136
-			$helper = $this->getMockBuilder(\stdClass::class)
5137
-				->addMethods(['formatShare', 'canAccessShare'])
5138
-				->getMock();
5139
-			$helper->method('formatShare')
5140
-				->with($share)
5141
-				->willReturn($formatShareByHelper);
5142
-			$helper->method('canAccessShare')
5143
-				->with($share)
5144
-				->willReturn(true);
5145
-
5146
-			$this->serverContainer->method('get')
5147
-				->with('\OCA\Talk\Share\Helper\ShareAPIController')
5148
-				->willReturn($helper);
5149
-		}
5150
-
5151
-		$result = $this->invokePrivate($this->ocs, 'formatShare', [$share]);
5152
-		$this->assertEquals($expects, $result);
5153
-	}
5154
-
5155
-	/**
5156
-	 * @return list{Folder, Folder}
5157
-	 */
5158
-	private function getNonSharedUserFolder(): array {
5159
-		$node = $this->getMockBuilder(Folder::class)->getMock();
5160
-		$userFolder = $this->getMockBuilder(Folder::class)->getMock();
5161
-		$storage = $this->createMock(IStorage::class);
5162
-		$storage->method('instanceOfStorage')
5163
-			->willReturnMap([
5164
-				['OCA\Files_Sharing\External\Storage', false],
5165
-				['OCA\Files_Sharing\SharedStorage', false],
5166
-			]);
5167
-		$userFolder->method('getStorage')->willReturn($storage);
5168
-		$node->method('getStorage')->willReturn($storage);
5169
-		$node->method('getId')->willReturn(42);
5170
-		$user = $this->createMock(IUser::class);
5171
-		$user->method('getUID')->willReturn($this->currentUser);
5172
-		$node->method('getOwner')->willReturn($user);
5173
-		return [$userFolder, $node];
5174
-	}
5175
-
5176
-	/**
5177
-	 * @return list{Folder, File}
5178
-	 */
5179
-	private function getNonSharedUserFile(): array {
5180
-		$node = $this->getMockBuilder(File::class)->getMock();
5181
-		$userFolder = $this->getMockBuilder(Folder::class)->getMock();
5182
-		$storage = $this->createMock(IStorage::class);
5183
-		$storage->method('instanceOfStorage')
5184
-			->willReturnMap([
5185
-				['OCA\Files_Sharing\External\Storage', false],
5186
-				['OCA\Files_Sharing\SharedStorage', false],
5187
-			]);
5188
-		$userFolder->method('getStorage')->willReturn($storage);
5189
-		$node->method('getStorage')->willReturn($storage);
5190
-		$node->method('getId')->willReturn(42);
5191
-		return [$userFolder, $node];
5192
-	}
5193
-
5194
-	public function testPopulateTags(): void {
5195
-		$tagger = $this->createMock(ITags::class);
5196
-		$this->tagManager->method('load')
5197
-			->with('files')
5198
-			->willReturn($tagger);
5199
-		$data = [
5200
-			['file_source' => 10],
5201
-			['file_source' => 22, 'foo' => 'bar'],
5202
-			['file_source' => 42, 'x' => 'y'],
5203
-		];
5204
-		$tags = [
5205
-			10 => ['tag3'],
5206
-			42 => ['tag1', 'tag2'],
5207
-		];
5208
-		$tagger->method('getTagsForObjects')
5209
-			->with([10, 22, 42])
5210
-			->willReturn($tags);
5211
-
5212
-		$result = self::invokePrivate($this->ocs, 'populateTags', [$data]);
5213
-		$this->assertSame([
5214
-			['file_source' => 10, 'tags' => ['tag3']],
5215
-			['file_source' => 22, 'foo' => 'bar', 'tags' => []],
5216
-			['file_source' => 42, 'x' => 'y', 'tags' => ['tag1', 'tag2']],
5217
-		], $result);
5218
-	}
573
+    public function createShare($id, $shareType, $sharedWith, $sharedBy, $shareOwner, $path, $permissions,
574
+        $shareTime, $expiration, $parent, $target, $mail_send, $note = '', $token = null,
575
+        $password = null, $label = '', $attributes = null) {
576
+        $share = $this->getMockBuilder(IShare::class)->getMock();
577
+        $share->method('getId')->willReturn($id);
578
+        $share->method('getShareType')->willReturn($shareType);
579
+        $share->method('getSharedWith')->willReturn($sharedWith);
580
+        $share->method('getSharedBy')->willReturn($sharedBy);
581
+        $share->method('getShareOwner')->willReturn($shareOwner);
582
+        $share->method('getNode')->willReturn($path);
583
+        $share->method('getPermissions')->willReturn($permissions);
584
+        $share->method('getNote')->willReturn($note);
585
+        $share->method('getLabel')->willReturn($label);
586
+        $share->method('getAttributes')->willReturn($attributes);
587
+        $time = new \DateTime();
588
+        $time->setTimestamp($shareTime);
589
+        $share->method('getShareTime')->willReturn($time);
590
+        $share->method('getExpirationDate')->willReturn($expiration);
591
+        $share->method('getTarget')->willReturn($target);
592
+        $share->method('getMailSend')->willReturn($mail_send);
593
+        $share->method('getToken')->willReturn($token);
594
+        $share->method('getPassword')->willReturn($password);
595
+
596
+        if ($shareType === IShare::TYPE_USER
597
+            || $shareType === IShare::TYPE_GROUP
598
+            || $shareType === IShare::TYPE_LINK) {
599
+            $share->method('getFullId')->willReturn('ocinternal:' . $id);
600
+        }
601
+
602
+        return $share;
603
+    }
604
+
605
+    public function dataGetShare() {
606
+        $data = [];
607
+
608
+        $cache = $this->getMockBuilder('OC\Files\Cache\Cache')
609
+            ->disableOriginalConstructor()
610
+            ->getMock();
611
+        $cache->method('getNumericStorageId')->willReturn(101);
612
+
613
+        $storage = $this->getMockBuilder(IStorage::class)
614
+            ->disableOriginalConstructor()
615
+            ->getMock();
616
+        $storage->method('getId')->willReturn('STORAGE');
617
+        $storage->method('getCache')->willReturn($cache);
618
+
619
+        $parentFolder = $this->getMockBuilder(Folder::class)->getMock();
620
+        $parentFolder->method('getId')->willReturn(3);
621
+        $mountPoint = $this->createMock(IMountPoint::class);
622
+        $mountPoint->method('getMountType')->willReturn('');
623
+
624
+        $file = $this->getMockBuilder('OCP\Files\File')->getMock();
625
+        $file->method('getId')->willReturn(1);
626
+        $file->method('getPath')->willReturn('file');
627
+        $file->method('getStorage')->willReturn($storage);
628
+        $file->method('getParent')->willReturn($parentFolder);
629
+        $file->method('getSize')->willReturn(123465);
630
+        $file->method('getMTime')->willReturn(1234567890);
631
+        $file->method('getMimeType')->willReturn('myMimeType');
632
+        $file->method('getMountPoint')->willReturn($mountPoint);
633
+
634
+        $folder = $this->getMockBuilder(Folder::class)->getMock();
635
+        $folder->method('getId')->willReturn(2);
636
+        $folder->method('getPath')->willReturn('folder');
637
+        $folder->method('getStorage')->willReturn($storage);
638
+        $folder->method('getParent')->willReturn($parentFolder);
639
+        $folder->method('getSize')->willReturn(123465);
640
+        $folder->method('getMTime')->willReturn(1234567890);
641
+        $folder->method('getMimeType')->willReturn('myFolderMimeType');
642
+        $folder->method('getMountPoint')->willReturn($mountPoint);
643
+
644
+        [$shareAttributes, $shareAttributesReturnJson] = $this->mockShareAttributes();
645
+
646
+        // File shared with user
647
+        $share = $this->createShare(
648
+            100,
649
+            IShare::TYPE_USER,
650
+            'userId',
651
+            'initiatorId',
652
+            'ownerId',
653
+            $file,
654
+            4,
655
+            5,
656
+            null,
657
+            6,
658
+            'target',
659
+            0,
660
+            'personal note',
661
+            $shareAttributes,
662
+        );
663
+        $expected = [
664
+            'id' => 100,
665
+            'share_type' => IShare::TYPE_USER,
666
+            'share_with' => 'userId',
667
+            'share_with_displayname' => 'userDisplay',
668
+            'share_with_displayname_unique' => '[email protected]',
669
+            'uid_owner' => 'initiatorId',
670
+            'displayname_owner' => 'initiatorDisplay',
671
+            'item_type' => 'file',
672
+            'item_source' => 1,
673
+            'file_source' => 1,
674
+            'file_target' => 'target',
675
+            'file_parent' => 3,
676
+            'token' => null,
677
+            'expiration' => null,
678
+            'permissions' => 4,
679
+            'attributes' => $shareAttributesReturnJson,
680
+            'stime' => 5,
681
+            'parent' => null,
682
+            'storage_id' => 'STORAGE',
683
+            'path' => 'file',
684
+            'storage' => 101,
685
+            'mail_send' => 0,
686
+            'uid_file_owner' => 'ownerId',
687
+            'note' => 'personal note',
688
+            'label' => '',
689
+            'displayname_file_owner' => 'ownerDisplay',
690
+            'mimetype' => 'myMimeType',
691
+            'has_preview' => false,
692
+            'hide_download' => 0,
693
+            'can_edit' => false,
694
+            'can_delete' => false,
695
+            'item_size' => 123465,
696
+            'item_mtime' => 1234567890,
697
+            'attributes' => null,
698
+            'item_permissions' => 4,
699
+            'is-mount-root' => false,
700
+            'mount-type' => '',
701
+        ];
702
+        $data[] = [$share, $expected];
703
+
704
+        // Folder shared with group
705
+        $share = $this->createShare(
706
+            101,
707
+            IShare::TYPE_GROUP,
708
+            'groupId',
709
+            'initiatorId',
710
+            'ownerId',
711
+            $folder,
712
+            4,
713
+            5,
714
+            null,
715
+            6,
716
+            'target',
717
+            0,
718
+            'personal note',
719
+            $shareAttributes,
720
+        );
721
+        $expected = [
722
+            'id' => 101,
723
+            'share_type' => IShare::TYPE_GROUP,
724
+            'share_with' => 'groupId',
725
+            'share_with_displayname' => 'groupId',
726
+            'uid_owner' => 'initiatorId',
727
+            'displayname_owner' => 'initiatorDisplay',
728
+            'item_type' => 'folder',
729
+            'item_source' => 2,
730
+            'file_source' => 2,
731
+            'file_target' => 'target',
732
+            'file_parent' => 3,
733
+            'token' => null,
734
+            'expiration' => null,
735
+            'permissions' => 4,
736
+            'attributes' => $shareAttributesReturnJson,
737
+            'stime' => 5,
738
+            'parent' => null,
739
+            'storage_id' => 'STORAGE',
740
+            'path' => 'folder',
741
+            'storage' => 101,
742
+            'mail_send' => 0,
743
+            'uid_file_owner' => 'ownerId',
744
+            'note' => 'personal note',
745
+            'label' => '',
746
+            'displayname_file_owner' => 'ownerDisplay',
747
+            'mimetype' => 'myFolderMimeType',
748
+            'has_preview' => false,
749
+            'hide_download' => 0,
750
+            'can_edit' => false,
751
+            'can_delete' => false,
752
+            'item_size' => 123465,
753
+            'item_mtime' => 1234567890,
754
+            'attributes' => null,
755
+            'item_permissions' => 4,
756
+            'is-mount-root' => false,
757
+            'mount-type' => '',
758
+        ];
759
+        $data[] = [$share, $expected];
760
+
761
+        // File shared by link with Expire
762
+        $expire = \DateTime::createFromFormat('Y-m-d h:i:s', '2000-01-02 01:02:03');
763
+        $share = $this->createShare(
764
+            101,
765
+            IShare::TYPE_LINK,
766
+            null,
767
+            'initiatorId',
768
+            'ownerId',
769
+            $folder,
770
+            4,
771
+            5,
772
+            $expire,
773
+            6,
774
+            'target',
775
+            0,
776
+            'personal note',
777
+            'token',
778
+            'password',
779
+            'first link share'
780
+        );
781
+        $expected = [
782
+            'id' => 101,
783
+            'share_type' => IShare::TYPE_LINK,
784
+            'password' => 'password',
785
+            'share_with' => 'password',
786
+            'share_with_displayname' => '(Shared link)',
787
+            'send_password_by_talk' => false,
788
+            'uid_owner' => 'initiatorId',
789
+            'displayname_owner' => 'initiatorDisplay',
790
+            'item_type' => 'folder',
791
+            'item_source' => 2,
792
+            'file_source' => 2,
793
+            'file_target' => 'target',
794
+            'file_parent' => 3,
795
+            'token' => 'token',
796
+            'expiration' => '2000-01-02 00:00:00',
797
+            'permissions' => 4,
798
+            'attributes' => null,
799
+            'stime' => 5,
800
+            'parent' => null,
801
+            'storage_id' => 'STORAGE',
802
+            'path' => 'folder',
803
+            'storage' => 101,
804
+            'mail_send' => 0,
805
+            'url' => 'url',
806
+            'uid_file_owner' => 'ownerId',
807
+            'note' => 'personal note',
808
+            'label' => 'first link share',
809
+            'displayname_file_owner' => 'ownerDisplay',
810
+            'mimetype' => 'myFolderMimeType',
811
+            'has_preview' => false,
812
+            'hide_download' => 0,
813
+            'can_edit' => false,
814
+            'can_delete' => false,
815
+            'item_size' => 123465,
816
+            'item_mtime' => 1234567890,
817
+            'attributes' => null,
818
+            'item_permissions' => 4,
819
+            'is-mount-root' => false,
820
+            'mount-type' => '',
821
+        ];
822
+        $data[] = [$share, $expected];
823
+
824
+        return $data;
825
+    }
826
+
827
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataGetShare')]
828
+    public function testGetShare(IShare $share, array $result): void {
829
+        /** @var ShareAPIController&MockObject $ocs */
830
+        $ocs = $this->getMockBuilder(ShareAPIController::class)
831
+            ->setConstructorArgs([
832
+                $this->appName,
833
+                $this->request,
834
+                $this->shareManager,
835
+                $this->groupManager,
836
+                $this->userManager,
837
+                $this->rootFolder,
838
+                $this->urlGenerator,
839
+                $this->l,
840
+                $this->config,
841
+                $this->appManager,
842
+                $this->serverContainer,
843
+                $this->userStatusManager,
844
+                $this->previewManager,
845
+                $this->dateTimeZone,
846
+                $this->logger,
847
+                $this->factory,
848
+                $this->mailer,
849
+                $this->tagManager,
850
+                $this->currentUser,
851
+            ])
852
+            ->onlyMethods(['canAccessShare'])
853
+            ->getMock();
854
+
855
+        $ocs->expects($this->any())
856
+            ->method('canAccessShare')
857
+            ->willReturn(true);
858
+
859
+        $this->shareManager
860
+            ->expects($this->any())
861
+            ->method('getShareById')
862
+            ->with($share->getFullId(), 'currentUser')
863
+            ->willReturn($share);
864
+
865
+        $userFolder = $this->getMockBuilder(Folder::class)->getMock();
866
+        $userFolder
867
+            ->method('getRelativePath')
868
+            ->willReturnArgument(0);
869
+
870
+        $userFolder->method('getById')
871
+            ->with($share->getNodeId())
872
+            ->willReturn([$share->getNode()]);
873
+        $userFolder->method('getFirstNodeById')
874
+            ->with($share->getNodeId())
875
+            ->willReturn($share->getNode());
876
+
877
+        $this->rootFolder->method('getUserFolder')
878
+            ->with($this->currentUser)
879
+            ->willReturn($userFolder);
880
+
881
+        $this->urlGenerator
882
+            ->method('linkToRouteAbsolute')
883
+            ->willReturn('url');
884
+
885
+        $initiator = $this->getMockBuilder(IUser::class)->getMock();
886
+        $initiator->method('getUID')->willReturn('initiatorId');
887
+        $initiator->method('getDisplayName')->willReturn('initiatorDisplay');
888
+
889
+        $owner = $this->getMockBuilder(IUser::class)->getMock();
890
+        $owner->method('getUID')->willReturn('ownerId');
891
+        $owner->method('getDisplayName')->willReturn('ownerDisplay');
892
+
893
+        $user = $this->getMockBuilder(IUser::class)->getMock();
894
+        $user->method('getUID')->willReturn('userId');
895
+        $user->method('getDisplayName')->willReturn('userDisplay');
896
+        $user->method('getSystemEMailAddress')->willReturn('[email protected]');
897
+
898
+        $group = $this->getMockBuilder(IGroup::class)->getMock();
899
+        $group->method('getGID')->willReturn('groupId');
900
+
901
+        $this->userManager->method('get')->willReturnMap([
902
+            ['userId', $user],
903
+            ['initiatorId', $initiator],
904
+            ['ownerId', $owner],
905
+        ]);
906
+        $this->groupManager->method('get')->willReturnMap([
907
+            ['group', $group],
908
+        ]);
909
+        $this->dateTimeZone->method('getTimezone')->willReturn(new \DateTimeZone('UTC'));
910
+
911
+        $data = $ocs->getShare($share->getId())->getData()[0];
912
+        $this->assertEquals($result, $data);
913
+    }
914
+
915
+
916
+    public function testGetShareInvalidNode(): void {
917
+        $this->expectException(OCSNotFoundException::class);
918
+        $this->expectExceptionMessage('Wrong share ID, share does not exist');
919
+
920
+        $share = Server::get(IManager::class)->newShare();
921
+        $share->setSharedBy('initiator')
922
+            ->setSharedWith('recipient')
923
+            ->setShareOwner('owner');
924
+
925
+        $this->shareManager
926
+            ->expects($this->once())
927
+            ->method('getShareById')
928
+            ->with('ocinternal:42', 'currentUser')
929
+            ->willReturn($share);
930
+
931
+        $userFolder = $this->getMockBuilder(Folder::class)->getMock();
932
+        $this->rootFolder->method('getUserFolder')
933
+            ->with($this->currentUser)
934
+            ->willReturn($userFolder);
935
+
936
+        $this->ocs->getShare(42);
937
+    }
938
+
939
+    public function dataGetShares() {
940
+        $folder = $this->getMockBuilder(Folder::class)->getMock();
941
+        $file1 = $this->getMockBuilder(File::class)->getMock();
942
+        $file1->method('getName')
943
+            ->willReturn('file1');
944
+        $file2 = $this->getMockBuilder(File::class)->getMock();
945
+        $file2->method('getName')
946
+            ->willReturn('file2');
947
+
948
+        $folder->method('getDirectoryListing')
949
+            ->willReturn([$file1, $file2]);
950
+
951
+        $file1UserShareOwner = Server::get(IManager::class)->newShare();
952
+        $file1UserShareOwner->setShareType(IShare::TYPE_USER)
953
+            ->setSharedWith('recipient')
954
+            ->setSharedBy('initiator')
955
+            ->setShareOwner('currentUser')
956
+            ->setPermissions(Constants::PERMISSION_READ)
957
+            ->setNode($file1)
958
+            ->setId(4);
959
+
960
+        $file1UserShareOwnerExpected = [
961
+            'id' => 4,
962
+            'share_type' => IShare::TYPE_USER,
963
+        ];
964
+
965
+        $file1UserShareInitiator = Server::get(IManager::class)->newShare();
966
+        $file1UserShareInitiator->setShareType(IShare::TYPE_USER)
967
+            ->setSharedWith('recipient')
968
+            ->setSharedBy('currentUser')
969
+            ->setShareOwner('owner')
970
+            ->setPermissions(Constants::PERMISSION_READ)
971
+            ->setNode($file1)
972
+            ->setId(8);
973
+
974
+        $file1UserShareInitiatorExpected = [
975
+            'id' => 8,
976
+            'share_type' => IShare::TYPE_USER,
977
+        ];
978
+
979
+        $file1UserShareRecipient = Server::get(IManager::class)->newShare();
980
+        $file1UserShareRecipient->setShareType(IShare::TYPE_USER)
981
+            ->setSharedWith('currentUser')
982
+            ->setSharedBy('initiator')
983
+            ->setShareOwner('owner')
984
+            ->setPermissions(Constants::PERMISSION_READ)
985
+            ->setNode($file1)
986
+            ->setId(15);
987
+
988
+        $file1UserShareRecipientExpected = [
989
+            'id' => 15,
990
+            'share_type' => IShare::TYPE_USER,
991
+        ];
992
+
993
+        $file1UserShareOther = Server::get(IManager::class)->newShare();
994
+        $file1UserShareOther->setShareType(IShare::TYPE_USER)
995
+            ->setSharedWith('recipient')
996
+            ->setSharedBy('initiator')
997
+            ->setShareOwner('owner')
998
+            ->setPermissions(Constants::PERMISSION_READ)
999
+            ->setNode($file1)
1000
+            ->setId(16);
1001
+
1002
+        $file1UserShareOtherExpected = [
1003
+            'id' => 16,
1004
+            'share_type' => IShare::TYPE_USER,
1005
+        ];
1006
+
1007
+        $file1GroupShareOwner = Server::get(IManager::class)->newShare();
1008
+        $file1GroupShareOwner->setShareType(IShare::TYPE_GROUP)
1009
+            ->setSharedWith('recipient')
1010
+            ->setSharedBy('initiator')
1011
+            ->setShareOwner('currentUser')
1012
+            ->setPermissions(Constants::PERMISSION_READ)
1013
+            ->setNode($file1)
1014
+            ->setId(23);
1015
+
1016
+        $file1GroupShareOwnerExpected = [
1017
+            'id' => 23,
1018
+            'share_type' => IShare::TYPE_GROUP,
1019
+        ];
1020
+
1021
+        $file1GroupShareRecipient = Server::get(IManager::class)->newShare();
1022
+        $file1GroupShareRecipient->setShareType(IShare::TYPE_GROUP)
1023
+            ->setSharedWith('currentUserGroup')
1024
+            ->setSharedBy('initiator')
1025
+            ->setShareOwner('owner')
1026
+            ->setPermissions(Constants::PERMISSION_READ)
1027
+            ->setNode($file1)
1028
+            ->setId(42);
1029
+
1030
+        $file1GroupShareRecipientExpected = [
1031
+            'id' => 42,
1032
+            'share_type' => IShare::TYPE_GROUP,
1033
+        ];
1034
+
1035
+        $file1GroupShareOther = Server::get(IManager::class)->newShare();
1036
+        $file1GroupShareOther->setShareType(IShare::TYPE_GROUP)
1037
+            ->setSharedWith('recipient')
1038
+            ->setSharedBy('initiator')
1039
+            ->setShareOwner('owner')
1040
+            ->setPermissions(Constants::PERMISSION_READ)
1041
+            ->setNode($file1)
1042
+            ->setId(108);
1043
+
1044
+        $file1LinkShareOwner = Server::get(IManager::class)->newShare();
1045
+        $file1LinkShareOwner->setShareType(IShare::TYPE_LINK)
1046
+            ->setSharedWith('recipient')
1047
+            ->setSharedBy('initiator')
1048
+            ->setShareOwner('currentUser')
1049
+            ->setPermissions(Constants::PERMISSION_READ)
1050
+            ->setNode($file1)
1051
+            ->setId(415);
1052
+
1053
+        $file1LinkShareOwnerExpected = [
1054
+            'id' => 415,
1055
+            'share_type' => IShare::TYPE_LINK,
1056
+        ];
1057
+
1058
+        $file1EmailShareOwner = Server::get(IManager::class)->newShare();
1059
+        $file1EmailShareOwner->setShareType(IShare::TYPE_EMAIL)
1060
+            ->setSharedWith('recipient')
1061
+            ->setSharedBy('initiator')
1062
+            ->setShareOwner('currentUser')
1063
+            ->setPermissions(Constants::PERMISSION_READ)
1064
+            ->setNode($file1)
1065
+            ->setId(416);
1066
+
1067
+        $file1EmailShareOwnerExpected = [
1068
+            'id' => 416,
1069
+            'share_type' => IShare::TYPE_EMAIL,
1070
+        ];
1071
+
1072
+        $file1CircleShareOwner = Server::get(IManager::class)->newShare();
1073
+        $file1CircleShareOwner->setShareType(IShare::TYPE_CIRCLE)
1074
+            ->setSharedWith('recipient')
1075
+            ->setSharedBy('initiator')
1076
+            ->setShareOwner('currentUser')
1077
+            ->setPermissions(Constants::PERMISSION_READ)
1078
+            ->setNode($file1)
1079
+            ->setId(423);
1080
+
1081
+        $file1CircleShareOwnerExpected = [
1082
+            'id' => 423,
1083
+            'share_type' => IShare::TYPE_CIRCLE,
1084
+        ];
1085
+
1086
+        $file1RoomShareOwner = Server::get(IManager::class)->newShare();
1087
+        $file1RoomShareOwner->setShareType(IShare::TYPE_ROOM)
1088
+            ->setSharedWith('recipient')
1089
+            ->setSharedBy('initiator')
1090
+            ->setShareOwner('currentUser')
1091
+            ->setPermissions(Constants::PERMISSION_READ)
1092
+            ->setNode($file1)
1093
+            ->setId(442);
1094
+
1095
+        $file1RoomShareOwnerExpected = [
1096
+            'id' => 442,
1097
+            'share_type' => IShare::TYPE_ROOM,
1098
+        ];
1099
+
1100
+        $file1RemoteShareOwner = Server::get(IManager::class)->newShare();
1101
+        $file1RemoteShareOwner->setShareType(IShare::TYPE_REMOTE)
1102
+            ->setSharedWith('recipient')
1103
+            ->setSharedBy('initiator')
1104
+            ->setShareOwner('currentUser')
1105
+            ->setPermissions(Constants::PERMISSION_READ)
1106
+            ->setExpirationDate(new \DateTime('2000-01-01T01:02:03'))
1107
+            ->setNode($file1)
1108
+            ->setId(815);
1109
+
1110
+        $file1RemoteShareOwnerExpected = [
1111
+            'id' => 815,
1112
+            'share_type' => IShare::TYPE_REMOTE,
1113
+        ];
1114
+
1115
+        $file1RemoteGroupShareOwner = Server::get(IManager::class)->newShare();
1116
+        $file1RemoteGroupShareOwner->setShareType(IShare::TYPE_REMOTE_GROUP)
1117
+            ->setSharedWith('recipient')
1118
+            ->setSharedBy('initiator')
1119
+            ->setShareOwner('currentUser')
1120
+            ->setPermissions(Constants::PERMISSION_READ)
1121
+            ->setExpirationDate(new \DateTime('2000-01-02T01:02:03'))
1122
+            ->setNode($file1)
1123
+            ->setId(816);
1124
+
1125
+        $file1RemoteGroupShareOwnerExpected = [
1126
+            'id' => 816,
1127
+            'share_type' => IShare::TYPE_REMOTE_GROUP,
1128
+        ];
1129
+
1130
+        $file2UserShareOwner = Server::get(IManager::class)->newShare();
1131
+        $file2UserShareOwner->setShareType(IShare::TYPE_USER)
1132
+            ->setSharedWith('recipient')
1133
+            ->setSharedBy('initiator')
1134
+            ->setShareOwner('currentUser')
1135
+            ->setPermissions(Constants::PERMISSION_READ)
1136
+            ->setNode($file2)
1137
+            ->setId(823);
1138
+
1139
+        $file2UserShareOwnerExpected = [
1140
+            'id' => 823,
1141
+            'share_type' => IShare::TYPE_USER,
1142
+        ];
1143
+
1144
+        $data = [
1145
+            [
1146
+                [
1147
+                    'path' => $file1,
1148
+                ],
1149
+                [
1150
+                    'file1' => [
1151
+                        IShare::TYPE_USER => [$file1UserShareOwner, $file1UserShareOwner, $file1UserShareOwner],
1152
+                    ],
1153
+                ],
1154
+                [
1155
+                ],
1156
+                [
1157
+                    $file1UserShareOwnerExpected
1158
+                ]
1159
+            ],
1160
+            [
1161
+                [
1162
+                    'path' => $file1,
1163
+                ],
1164
+                [
1165
+                    'file1' => [
1166
+                        IShare::TYPE_USER => [$file1UserShareOwner, $file1UserShareRecipient],
1167
+                    ],
1168
+                ],
1169
+                [
1170
+                ],
1171
+                [
1172
+                    $file1UserShareOwnerExpected,
1173
+                ]
1174
+            ],
1175
+            [
1176
+                [
1177
+                    'path' => $file1,
1178
+                ],
1179
+                [
1180
+                    'file1' => [
1181
+                        IShare::TYPE_USER => [$file1UserShareOwner, $file1UserShareRecipient, $file1UserShareInitiator, $file1UserShareOther],
1182
+                    ],
1183
+                ],
1184
+                [
1185
+                ],
1186
+                [
1187
+                    $file1UserShareOwnerExpected,
1188
+                    $file1UserShareInitiatorExpected,
1189
+                    $file1UserShareOtherExpected,
1190
+                ]
1191
+            ],
1192
+            [
1193
+                [
1194
+                    'path' => $file1,
1195
+                ],
1196
+                [
1197
+                    'file1' => [
1198
+                        IShare::TYPE_USER => [$file1UserShareRecipient, $file1UserShareInitiator, $file1UserShareOther],
1199
+                    ],
1200
+                ],
1201
+                [
1202
+                ],
1203
+                [
1204
+                    $file1UserShareInitiatorExpected,
1205
+                ]
1206
+            ],
1207
+            [
1208
+                [
1209
+                    'path' => $file1,
1210
+                ],
1211
+                [
1212
+                    'file1' => [
1213
+                        IShare::TYPE_USER => [$file1UserShareOwner],
1214
+                        IShare::TYPE_GROUP => [$file1GroupShareRecipient],
1215
+                    ],
1216
+                ],
1217
+                [
1218
+                ],
1219
+                [
1220
+                    $file1UserShareOwnerExpected,
1221
+                    $file1GroupShareRecipientExpected,
1222
+                ]
1223
+            ],
1224
+            [
1225
+                [
1226
+                    'path' => $file1,
1227
+                ],
1228
+                [
1229
+                    'file1' => [
1230
+                        IShare::TYPE_USER => [$file1UserShareOwner],
1231
+                        IShare::TYPE_GROUP => [$file1GroupShareOwner],
1232
+                        IShare::TYPE_LINK => [$file1LinkShareOwner],
1233
+                        IShare::TYPE_EMAIL => [$file1EmailShareOwner],
1234
+                        IShare::TYPE_CIRCLE => [$file1CircleShareOwner],
1235
+                        IShare::TYPE_ROOM => [$file1RoomShareOwner],
1236
+                        IShare::TYPE_REMOTE => [$file1RemoteShareOwner],
1237
+                        IShare::TYPE_REMOTE_GROUP => [$file1RemoteGroupShareOwner],
1238
+                    ],
1239
+                ],
1240
+                [
1241
+                ],
1242
+                [
1243
+                    $file1UserShareOwnerExpected,
1244
+                    $file1GroupShareOwnerExpected,
1245
+                    $file1LinkShareOwnerExpected,
1246
+                    $file1EmailShareOwnerExpected,
1247
+                    $file1CircleShareOwnerExpected,
1248
+                    $file1RoomShareOwnerExpected,
1249
+                ]
1250
+            ],
1251
+            [
1252
+                [
1253
+                    'path' => $file1,
1254
+                ],
1255
+                [
1256
+                    'file1' => [
1257
+                        IShare::TYPE_USER => [$file1UserShareOwner],
1258
+                        IShare::TYPE_GROUP => [$file1GroupShareOwner],
1259
+                        IShare::TYPE_LINK => [$file1LinkShareOwner],
1260
+                        IShare::TYPE_EMAIL => [$file1EmailShareOwner],
1261
+                        IShare::TYPE_CIRCLE => [$file1CircleShareOwner],
1262
+                        IShare::TYPE_ROOM => [$file1RoomShareOwner],
1263
+                        IShare::TYPE_REMOTE => [$file1RemoteShareOwner],
1264
+                        IShare::TYPE_REMOTE_GROUP => [$file1RemoteGroupShareOwner],
1265
+                    ],
1266
+                ],
1267
+                [
1268
+                    IShare::TYPE_REMOTE => true,
1269
+                    IShare::TYPE_REMOTE_GROUP => true,
1270
+                ],
1271
+                [
1272
+                    $file1UserShareOwnerExpected,
1273
+                    $file1GroupShareOwnerExpected,
1274
+                    $file1LinkShareOwnerExpected,
1275
+                    $file1EmailShareOwnerExpected,
1276
+                    $file1CircleShareOwnerExpected,
1277
+                    $file1RoomShareOwnerExpected,
1278
+                    $file1RemoteShareOwnerExpected,
1279
+                    $file1RemoteGroupShareOwnerExpected,
1280
+                ]
1281
+            ],
1282
+            [
1283
+                [
1284
+                    'path' => $folder,
1285
+                    'subfiles' => 'true',
1286
+                ],
1287
+                [
1288
+                    'file1' => [
1289
+                        IShare::TYPE_USER => [$file1UserShareOwner],
1290
+                    ],
1291
+                    'file2' => [
1292
+                        IShare::TYPE_USER => [$file2UserShareOwner],
1293
+                    ],
1294
+                ],
1295
+                [
1296
+                ],
1297
+                [
1298
+                    $file1UserShareOwnerExpected,
1299
+                    $file2UserShareOwnerExpected,
1300
+                ]
1301
+            ],
1302
+            [
1303
+                [
1304
+                    'path' => $folder,
1305
+                    'subfiles' => 'true',
1306
+                ],
1307
+                [
1308
+                    'file1' => [
1309
+                        IShare::TYPE_USER => [$file1UserShareOwner, $file1UserShareOwner, $file1UserShareOwner],
1310
+                    ],
1311
+                ],
1312
+                [
1313
+                ],
1314
+                [
1315
+                    $file1UserShareOwnerExpected,
1316
+                ]
1317
+            ],
1318
+            [
1319
+                [
1320
+                    'path' => $folder,
1321
+                    'subfiles' => 'true',
1322
+                ],
1323
+                [
1324
+                    'file1' => [
1325
+                        IShare::TYPE_USER => [$file1UserShareOwner, $file1UserShareRecipient],
1326
+                    ],
1327
+                ],
1328
+                [
1329
+                ],
1330
+                [
1331
+                    $file1UserShareOwnerExpected
1332
+                ]
1333
+            ],
1334
+            [
1335
+                [
1336
+                    'path' => $folder,
1337
+                    'subfiles' => 'true',
1338
+                ],
1339
+                [
1340
+                    'file1' => [
1341
+                        IShare::TYPE_USER => [$file1UserShareRecipient, $file1UserShareInitiator, $file1UserShareOther],
1342
+                    ],
1343
+                    'file2' => [
1344
+                        IShare::TYPE_USER => [$file2UserShareOwner],
1345
+                    ],
1346
+                ],
1347
+                [
1348
+                ],
1349
+                [
1350
+                    $file1UserShareInitiatorExpected,
1351
+                    $file1UserShareOtherExpected,
1352
+                    $file2UserShareOwnerExpected,
1353
+                ]
1354
+            ],
1355
+            // This might not happen in a real environment, as the combination
1356
+            // of shares does not seem to be possible on a folder without
1357
+            // resharing rights; if the folder has resharing rights then the
1358
+            // share with others would be included too in the results.
1359
+            [
1360
+                [
1361
+                    'path' => $folder,
1362
+                    'subfiles' => 'true',
1363
+                ],
1364
+                [
1365
+                    'file1' => [
1366
+                        IShare::TYPE_USER => [$file1UserShareRecipient, $file1UserShareInitiator, $file1UserShareOther],
1367
+                    ],
1368
+                ],
1369
+                [
1370
+                ],
1371
+                [
1372
+                    $file1UserShareInitiatorExpected,
1373
+                ]
1374
+            ],
1375
+            [
1376
+                [
1377
+                    'path' => $folder,
1378
+                    'subfiles' => 'true',
1379
+                ],
1380
+                [
1381
+                    'file1' => [
1382
+                        IShare::TYPE_USER => [$file1UserShareOwner],
1383
+                        IShare::TYPE_GROUP => [$file1GroupShareRecipient],
1384
+                    ],
1385
+                ],
1386
+                [
1387
+                ],
1388
+                [
1389
+                    $file1UserShareOwnerExpected,
1390
+                    $file1GroupShareRecipientExpected,
1391
+                ]
1392
+            ],
1393
+            [
1394
+                [
1395
+                    'path' => $folder,
1396
+                    'subfiles' => 'true',
1397
+                ],
1398
+                [
1399
+                    'file1' => [
1400
+                        IShare::TYPE_USER => [$file1UserShareOwner],
1401
+                        IShare::TYPE_GROUP => [$file1GroupShareOwner],
1402
+                        IShare::TYPE_LINK => [$file1LinkShareOwner],
1403
+                        IShare::TYPE_EMAIL => [$file1EmailShareOwner],
1404
+                        IShare::TYPE_CIRCLE => [$file1CircleShareOwner],
1405
+                        IShare::TYPE_ROOM => [$file1RoomShareOwner],
1406
+                        IShare::TYPE_REMOTE => [$file1RemoteShareOwner],
1407
+                        IShare::TYPE_REMOTE_GROUP => [$file1RemoteGroupShareOwner],
1408
+                    ],
1409
+                ],
1410
+                [
1411
+                ],
1412
+                [
1413
+                    $file1UserShareOwnerExpected,
1414
+                    $file1GroupShareOwnerExpected,
1415
+                    $file1LinkShareOwnerExpected,
1416
+                    $file1EmailShareOwnerExpected,
1417
+                    $file1CircleShareOwnerExpected,
1418
+                    $file1RoomShareOwnerExpected,
1419
+                ]
1420
+            ],
1421
+            [
1422
+                [
1423
+                    'path' => $folder,
1424
+                    'subfiles' => 'true',
1425
+                ],
1426
+                [
1427
+                    'file1' => [
1428
+                        IShare::TYPE_USER => [$file1UserShareOwner],
1429
+                        IShare::TYPE_GROUP => [$file1GroupShareOwner],
1430
+                        IShare::TYPE_LINK => [$file1LinkShareOwner],
1431
+                        IShare::TYPE_EMAIL => [$file1EmailShareOwner],
1432
+                        IShare::TYPE_CIRCLE => [$file1CircleShareOwner],
1433
+                        IShare::TYPE_ROOM => [$file1RoomShareOwner],
1434
+                        IShare::TYPE_REMOTE => [$file1RemoteShareOwner],
1435
+                        IShare::TYPE_REMOTE_GROUP => [$file1RemoteGroupShareOwner],
1436
+                    ],
1437
+                ],
1438
+                [
1439
+                    IShare::TYPE_REMOTE => true,
1440
+                    IShare::TYPE_REMOTE_GROUP => true,
1441
+                ],
1442
+                [
1443
+                    $file1UserShareOwnerExpected,
1444
+                    $file1GroupShareOwnerExpected,
1445
+                    $file1LinkShareOwnerExpected,
1446
+                    $file1EmailShareOwnerExpected,
1447
+                    $file1CircleShareOwnerExpected,
1448
+                    $file1RoomShareOwnerExpected,
1449
+                    $file1RemoteShareOwnerExpected,
1450
+                    $file1RemoteGroupShareOwnerExpected,
1451
+                ]
1452
+            ],
1453
+        ];
1454
+
1455
+        return $data;
1456
+    }
1457
+
1458
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataGetShares')]
1459
+    public function testGetShares(array $getSharesParameters, array $shares, array $extraShareTypes, array $expected): void {
1460
+        /** @var ShareAPIController&MockObject $ocs */
1461
+        $ocs = $this->getMockBuilder(ShareAPIController::class)
1462
+            ->setConstructorArgs([
1463
+                $this->appName,
1464
+                $this->request,
1465
+                $this->shareManager,
1466
+                $this->groupManager,
1467
+                $this->userManager,
1468
+                $this->rootFolder,
1469
+                $this->urlGenerator,
1470
+                $this->l,
1471
+                $this->config,
1472
+                $this->appManager,
1473
+                $this->serverContainer,
1474
+                $this->userStatusManager,
1475
+                $this->previewManager,
1476
+                $this->dateTimeZone,
1477
+                $this->logger,
1478
+                $this->factory,
1479
+                $this->mailer,
1480
+                $this->tagManager,
1481
+                $this->currentUser,
1482
+            ])
1483
+            ->onlyMethods(['formatShare'])
1484
+            ->getMock();
1485
+
1486
+        $ocs->method('formatShare')
1487
+            ->willReturnCallback(
1488
+                function ($share) {
1489
+                    return [
1490
+                        'id' => $share->getId(),
1491
+                        'share_type' => $share->getShareType()
1492
+                    ];
1493
+                }
1494
+            );
1495
+
1496
+        $userFolder = $this->getMockBuilder(Folder::class)->getMock();
1497
+        $userFolder->method('get')
1498
+            ->with('path')
1499
+            ->willReturn($getSharesParameters['path']);
1500
+
1501
+        $this->rootFolder->method('getUserFolder')
1502
+            ->with($this->currentUser)
1503
+            ->willReturn($userFolder);
1504
+
1505
+        $this->shareManager
1506
+            ->method('getSharesBy')
1507
+            ->willReturnCallback(
1508
+                function ($user, $shareType, $node) use ($shares) {
1509
+                    if (!isset($shares[$node->getName()]) || !isset($shares[$node->getName()][$shareType])) {
1510
+                        return [];
1511
+                    }
1512
+                    return $shares[$node->getName()][$shareType];
1513
+                }
1514
+            );
1515
+
1516
+        $this->shareManager
1517
+            ->method('outgoingServer2ServerSharesAllowed')
1518
+            ->willReturn($extraShareTypes[ISHARE::TYPE_REMOTE] ?? false);
1519
+
1520
+        $this->shareManager
1521
+            ->method('outgoingServer2ServerGroupSharesAllowed')
1522
+            ->willReturn($extraShareTypes[ISHARE::TYPE_REMOTE_GROUP] ?? false);
1523
+
1524
+        $this->groupManager
1525
+            ->method('isInGroup')
1526
+            ->willReturnCallback(
1527
+                function ($user, $group) {
1528
+                    return $group === 'currentUserGroup';
1529
+                }
1530
+            );
1531
+
1532
+        $result = $ocs->getShares(
1533
+            $getSharesParameters['sharedWithMe'] ?? 'false',
1534
+            $getSharesParameters['reshares'] ?? 'false',
1535
+            $getSharesParameters['subfiles'] ?? 'false',
1536
+            'path'
1537
+        );
1538
+
1539
+        $this->assertEquals($expected, $result->getData());
1540
+    }
1541
+
1542
+    public function testCanAccessShareAsOwner(): void {
1543
+        $share = $this->createMock(IShare::class);
1544
+        $share->method('getShareOwner')->willReturn($this->currentUser);
1545
+        $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
1546
+    }
1547
+
1548
+    public function testCanAccessShareAsSharer(): void {
1549
+        $share = $this->createMock(IShare::class);
1550
+        $share->method('getSharedBy')->willReturn($this->currentUser);
1551
+        $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
1552
+    }
1553
+
1554
+    public function testCanAccessShareAsSharee(): void {
1555
+        $share = $this->createMock(IShare::class);
1556
+        $share->method('getShareType')->willReturn(IShare::TYPE_USER);
1557
+        $share->method('getSharedWith')->willReturn($this->currentUser);
1558
+        $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
1559
+    }
1560
+
1561
+    public function testCannotAccessLinkShare(): void {
1562
+        $share = $this->createMock(IShare::class);
1563
+        $share->method('getShareType')->willReturn(IShare::TYPE_LINK);
1564
+        $share->method('getNodeId')->willReturn(42);
1565
+
1566
+        $userFolder = $this->createMock(Folder::class);
1567
+        $this->rootFolder->method('getUserFolder')
1568
+            ->with($this->currentUser)
1569
+            ->willReturn($userFolder);
1570
+
1571
+        $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
1572
+    }
1573
+
1574
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataCanAccessShareWithPermissions')]
1575
+    public function testCanAccessShareWithPermissions(int $permissions, bool $expected): void {
1576
+        $share = $this->createMock(IShare::class);
1577
+        $share->method('getShareType')->willReturn(IShare::TYPE_USER);
1578
+        $share->method('getSharedWith')->willReturn($this->createMock(IUser::class));
1579
+        $share->method('getNodeId')->willReturn(42);
1580
+
1581
+        $file = $this->createMock(File::class);
1582
+
1583
+        $userFolder = $this->getMockBuilder(Folder::class)->getMock();
1584
+        $userFolder->method('getFirstNodeById')
1585
+            ->with($share->getNodeId())
1586
+            ->willReturn($file);
1587
+        $userFolder->method('getById')
1588
+            ->with($share->getNodeId())
1589
+            ->willReturn([$file]);
1590
+        $this->rootFolder->method('getUserFolder')
1591
+            ->with($this->currentUser)
1592
+            ->willReturn($userFolder);
1593
+
1594
+        $file->method('getPermissions')
1595
+            ->willReturn($permissions);
1596
+
1597
+        if ($expected) {
1598
+            $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
1599
+        } else {
1600
+            $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
1601
+        }
1602
+    }
1603
+
1604
+    public static function dataCanAccessShareWithPermissions(): array {
1605
+        return [
1606
+            [Constants::PERMISSION_SHARE, true],
1607
+            [Constants::PERMISSION_READ, false],
1608
+            [Constants::PERMISSION_READ | Constants::PERMISSION_SHARE, true],
1609
+        ];
1610
+    }
1611
+
1612
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataCanAccessShareAsGroupMember')]
1613
+    public function testCanAccessShareAsGroupMember(string $group, bool $expected): void {
1614
+        $share = $this->createMock(IShare::class);
1615
+        $share->method('getShareType')->willReturn(IShare::TYPE_GROUP);
1616
+        $share->method('getSharedWith')->willReturn($group);
1617
+        $share->method('getNodeId')->willReturn(42);
1618
+
1619
+        $file = $this->createMock(File::class);
1620
+
1621
+        $userFolder = $this->createMock(Folder::class);
1622
+        $userFolder->method('getFirstNodeById')
1623
+            ->with($share->getNodeId())
1624
+            ->willReturn($file);
1625
+        $userFolder->method('getById')
1626
+            ->with($share->getNodeId())
1627
+            ->willReturn([$file]);
1628
+        $this->rootFolder->method('getUserFolder')
1629
+            ->with($this->currentUser)
1630
+            ->willReturn($userFolder);
1631
+
1632
+        $user = $this->createMock(IUser::class);
1633
+        $this->userManager->method('get')
1634
+            ->with($this->currentUser)
1635
+            ->willReturn($user);
1636
+
1637
+        $group = $this->createMock(IGroup::class);
1638
+        $group->method('inGroup')->with($user)->willReturn(true);
1639
+        $group2 = $this->createMock(IGroup::class);
1640
+        $group2->method('inGroup')->with($user)->willReturn(false);
1641
+
1642
+        $this->groupManager->method('get')->willReturnMap([
1643
+            ['group', $group],
1644
+            ['group2', $group2],
1645
+            ['group-null', null],
1646
+        ]);
1647
+
1648
+        if ($expected) {
1649
+            $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
1650
+        } else {
1651
+            $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
1652
+        }
1653
+    }
1654
+
1655
+    public static function dataCanAccessShareAsGroupMember(): array {
1656
+        return [
1657
+            ['group', true],
1658
+            ['group2', false],
1659
+            ['group-null', false],
1660
+        ];
1661
+    }
1662
+
1663
+    public function dataCanAccessRoomShare() {
1664
+        $result = [];
1665
+
1666
+        $share = $this->createMock(IShare::class);
1667
+        $share->method('getShareType')->willReturn(IShare::TYPE_ROOM);
1668
+        $share->method('getSharedWith')->willReturn('recipientRoom');
1669
+
1670
+        $result[] = [
1671
+            false, $share, false, false
1672
+        ];
1673
+
1674
+        $result[] = [
1675
+            false, $share, false, true
1676
+        ];
1677
+
1678
+        $result[] = [
1679
+            true, $share, true, true
1680
+        ];
1681
+
1682
+        $result[] = [
1683
+            false, $share, true, false
1684
+        ];
1685
+
1686
+        return $result;
1687
+    }
1688
+
1689
+    /**
1690
+     *
1691
+     * @param bool $expects
1692
+     * @param IShare $share
1693
+     * @param bool helperAvailable
1694
+     * @param bool canAccessShareByHelper
1695
+     */
1696
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataCanAccessRoomShare')]
1697
+    public function testCanAccessRoomShare(bool $expected, IShare $share, bool $helperAvailable, bool $canAccessShareByHelper): void {
1698
+        $userFolder = $this->getMockBuilder(Folder::class)->getMock();
1699
+        $this->rootFolder->method('getUserFolder')
1700
+            ->with($this->currentUser)
1701
+            ->willReturn($userFolder);
1702
+
1703
+        $userFolder->method('getById')
1704
+            ->with($share->getNodeId())
1705
+            ->willReturn([$share->getNode()]);
1706
+
1707
+        if (!$helperAvailable) {
1708
+            $this->appManager->method('isEnabledForUser')
1709
+                ->with('spreed')
1710
+                ->willReturn(false);
1711
+        } else {
1712
+            $this->appManager->method('isEnabledForUser')
1713
+                ->with('spreed')
1714
+                ->willReturn(true);
1715
+
1716
+            // This is not possible anymore with PHPUnit 10+
1717
+            // as `setMethods` was removed and now real reflection is used, thus the class needs to exist.
1718
+            // $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
1719
+            $helper = $this->getMockBuilder(\stdClass::class)
1720
+                ->addMethods(['canAccessShare'])
1721
+                ->getMock();
1722
+            $helper->method('canAccessShare')
1723
+                ->with($share, $this->currentUser)
1724
+                ->willReturn($canAccessShareByHelper);
1725
+
1726
+            $this->serverContainer->method('get')
1727
+                ->with('\OCA\Talk\Share\Helper\ShareAPIController')
1728
+                ->willReturn($helper);
1729
+        }
1730
+
1731
+        $this->assertEquals($expected, $this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
1732
+    }
1733
+
1734
+
1735
+    public function testCreateShareNoPath(): void {
1736
+        $this->expectException(OCSNotFoundException::class);
1737
+        $this->expectExceptionMessage('Please specify a file or folder path');
1738
+
1739
+        $this->ocs->createShare();
1740
+    }
1741
+
1742
+
1743
+    public function testCreateShareInvalidPath(): void {
1744
+        $this->expectException(OCSNotFoundException::class);
1745
+        $this->expectExceptionMessage('Wrong path, file/folder does not exist');
1746
+
1747
+        $userFolder = $this->getMockBuilder(Folder::class)->getMock();
1748
+        $this->rootFolder->expects($this->once())
1749
+            ->method('getUserFolder')
1750
+            ->with('currentUser')
1751
+            ->willReturn($userFolder);
1752
+
1753
+        $userFolder->expects($this->once())
1754
+            ->method('get')
1755
+            ->with('invalid-path')
1756
+            ->willThrowException(new NotFoundException());
1757
+
1758
+        $this->ocs->createShare('invalid-path');
1759
+    }
1760
+
1761
+    public function testCreateShareInvalidShareType(): void {
1762
+        $this->expectException(OCSBadRequestException::class);
1763
+        $this->expectExceptionMessage('Unknown share type');
1764
+
1765
+        $share = $this->newShare();
1766
+        $this->shareManager->method('newShare')->willReturn($share);
1767
+
1768
+        [$userFolder, $file] = $this->getNonSharedUserFile();
1769
+        $this->rootFolder->expects($this->atLeastOnce())
1770
+            ->method('getUserFolder')
1771
+            ->with('currentUser')
1772
+            ->willReturn($userFolder);
1773
+
1774
+        $userFolder->expects($this->atLeastOnce())
1775
+            ->method('get')
1776
+            ->with('valid-path')
1777
+            ->willReturn($file);
1778
+        $userFolder->method('getById')
1779
+            ->willReturn([]);
1780
+
1781
+        $file->expects($this->once())
1782
+            ->method('lock')
1783
+            ->with(ILockingProvider::LOCK_SHARED);
1784
+
1785
+        $this->ocs->createShare('valid-path', 31);
1786
+    }
1787
+
1788
+    public function testCreateShareUserNoShareWith(): void {
1789
+        $this->expectException(OCSNotFoundException::class);
1790
+        $this->expectExceptionMessage('Please specify a valid account to share with');
1791
+
1792
+        $share = $this->newShare();
1793
+        $this->shareManager->method('newShare')->willReturn($share);
1794
+
1795
+        [$userFolder, $path] = $this->getNonSharedUserFile();
1796
+        $this->rootFolder->method('getUserFolder')
1797
+            ->with('currentUser')
1798
+            ->willReturn($userFolder);
1799
+
1800
+        $userFolder->expects($this->once())
1801
+            ->method('get')
1802
+            ->with('valid-path')
1803
+            ->willReturn($path);
1804
+        $userFolder->method('getById')
1805
+            ->willReturn([]);
1806
+
1807
+        $path->expects($this->once())
1808
+            ->method('lock')
1809
+            ->with(ILockingProvider::LOCK_SHARED);
1810
+
1811
+        $this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_USER);
1812
+    }
1813
+
1814
+
1815
+    public function testCreateShareUserNoValidShareWith(): void {
1816
+        $this->expectException(OCSNotFoundException::class);
1817
+        $this->expectExceptionMessage('Please specify a valid account to share with');
1818
+
1819
+        $share = $this->newShare();
1820
+        $this->shareManager->method('newShare')->willReturn($share);
1821
+
1822
+        [$userFolder, $path] = $this->getNonSharedUserFile();
1823
+        $this->rootFolder->method('getUserFolder')
1824
+            ->with('currentUser')
1825
+            ->willReturn($userFolder);
1826
+
1827
+        $userFolder->expects($this->once())
1828
+            ->method('get')
1829
+            ->with('valid-path')
1830
+            ->willReturn($path);
1831
+        $userFolder->method('getById')
1832
+            ->willReturn([]);
1833
+        $path->expects($this->once())
1834
+            ->method('lock')
1835
+            ->with(ILockingProvider::LOCK_SHARED);
1836
+        $this->userManager->method('userExists')
1837
+            ->with('invalidUser')
1838
+            ->willReturn(false);
1839
+
1840
+        $this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_USER, 'invalidUser');
1841
+    }
1842
+
1843
+    public function testCreateShareUser(): void {
1844
+        $share = $this->newShare();
1845
+        $this->shareManager->method('newShare')->willReturn($share);
1846
+
1847
+        /** @var ShareAPIController $ocs */
1848
+        $ocs = $this->getMockBuilder(ShareAPIController::class)
1849
+            ->setConstructorArgs([
1850
+                $this->appName,
1851
+                $this->request,
1852
+                $this->shareManager,
1853
+                $this->groupManager,
1854
+                $this->userManager,
1855
+                $this->rootFolder,
1856
+                $this->urlGenerator,
1857
+                $this->l,
1858
+                $this->config,
1859
+                $this->appManager,
1860
+                $this->serverContainer,
1861
+                $this->userStatusManager,
1862
+                $this->previewManager,
1863
+                $this->dateTimeZone,
1864
+                $this->logger,
1865
+                $this->factory,
1866
+                $this->mailer,
1867
+                $this->tagManager,
1868
+                $this->currentUser,
1869
+            ])->onlyMethods(['formatShare'])
1870
+            ->getMock();
1871
+
1872
+        [$userFolder, $path] = $this->getNonSharedUserFile();
1873
+        $this->rootFolder->expects($this->exactly(2))
1874
+            ->method('getUserFolder')
1875
+            ->with('currentUser')
1876
+            ->willReturn($userFolder);
1877
+
1878
+        $userFolder->expects($this->once())
1879
+            ->method('get')
1880
+            ->with('valid-path')
1881
+            ->willReturn($path);
1882
+        $userFolder->method('getById')
1883
+            ->willReturn([]);
1884
+
1885
+        $this->userManager->method('userExists')->with('validUser')->willReturn(true);
1886
+
1887
+        $path->expects($this->once())
1888
+            ->method('lock')
1889
+            ->with(ILockingProvider::LOCK_SHARED);
1890
+
1891
+        $this->shareManager->method('createShare')
1892
+            ->with($this->callback(function (IShare $share) use ($path) {
1893
+                return $share->getNode() === $path
1894
+                    && $share->getPermissions() === (
1895
+                        Constants::PERMISSION_ALL
1896
+                        & ~Constants::PERMISSION_DELETE
1897
+                        & ~Constants::PERMISSION_CREATE
1898
+                    )
1899
+                    && $share->getShareType() === IShare::TYPE_USER
1900
+                    && $share->getSharedWith() === 'validUser'
1901
+                    && $share->getSharedBy() === 'currentUser';
1902
+            }))
1903
+            ->willReturnArgument(0);
1904
+
1905
+        $expected = new DataResponse([]);
1906
+        $result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_USER, 'validUser');
1907
+
1908
+        $this->assertInstanceOf(get_class($expected), $result);
1909
+        $this->assertEquals($expected->getData(), $result->getData());
1910
+    }
1911
+
1912
+
1913
+    public function testCreateShareGroupNoValidShareWith(): void {
1914
+        $this->expectException(OCSNotFoundException::class);
1915
+        $this->expectExceptionMessage('Please specify a valid group');
1916
+
1917
+        $share = $this->newShare();
1918
+        $this->shareManager->method('newShare')->willReturn($share);
1919
+        $this->shareManager->method('createShare')->willReturnArgument(0);
1920
+        $this->shareManager->method('allowGroupSharing')->willReturn(true);
1921
+
1922
+        [$userFolder, $path] = $this->getNonSharedUserFile();
1923
+        $this->rootFolder->method('getUserFolder')
1924
+            ->with('currentUser')
1925
+            ->willReturn($userFolder);
1926
+
1927
+        $userFolder->expects($this->once())
1928
+            ->method('get')
1929
+            ->with('valid-path')
1930
+            ->willReturn($path);
1931
+        $userFolder->method('getById')
1932
+            ->willReturn([]);
1933
+
1934
+        $path->expects($this->once())
1935
+            ->method('lock')
1936
+            ->with(ILockingProvider::LOCK_SHARED);
1937
+
1938
+        $this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_GROUP, 'invalidGroup');
1939
+    }
1940
+
1941
+    public function testCreateShareGroup(): void {
1942
+        $share = $this->newShare();
1943
+        $this->shareManager->method('newShare')->willReturn($share);
1944
+
1945
+        /** @var ShareAPIController&MockObject $ocs */
1946
+        $ocs = $this->getMockBuilder(ShareAPIController::class)
1947
+            ->setConstructorArgs([
1948
+                $this->appName,
1949
+                $this->request,
1950
+                $this->shareManager,
1951
+                $this->groupManager,
1952
+                $this->userManager,
1953
+                $this->rootFolder,
1954
+                $this->urlGenerator,
1955
+                $this->l,
1956
+                $this->config,
1957
+                $this->appManager,
1958
+                $this->serverContainer,
1959
+                $this->userStatusManager,
1960
+                $this->previewManager,
1961
+                $this->dateTimeZone,
1962
+                $this->logger,
1963
+                $this->factory,
1964
+                $this->mailer,
1965
+                $this->tagManager,
1966
+                $this->currentUser,
1967
+            ])->onlyMethods(['formatShare'])
1968
+            ->getMock();
1969
+
1970
+        $this->request
1971
+            ->method('getParam')
1972
+            ->willReturnMap([
1973
+                ['path', null, 'valid-path'],
1974
+                ['permissions', null, Constants::PERMISSION_ALL],
1975
+                ['shareType', '-1', IShare::TYPE_GROUP],
1976
+                ['shareWith', null, 'validGroup'],
1977
+            ]);
1978
+
1979
+        [$userFolder, $path] = $this->getNonSharedUserFolder();
1980
+        $this->rootFolder->expects($this->exactly(2))
1981
+            ->method('getUserFolder')
1982
+            ->with('currentUser')
1983
+            ->willReturn($userFolder);
1984
+
1985
+        $userFolder->expects($this->once())
1986
+            ->method('get')
1987
+            ->with('valid-path')
1988
+            ->willReturn($path);
1989
+        $userFolder->method('getById')
1990
+            ->willReturn([]);
1991
+
1992
+        $this->groupManager->method('groupExists')->with('validGroup')->willReturn(true);
1993
+
1994
+        $this->shareManager->expects($this->once())
1995
+            ->method('allowGroupSharing')
1996
+            ->willReturn(true);
1997
+
1998
+        $path->expects($this->once())
1999
+            ->method('lock')
2000
+            ->with(ILockingProvider::LOCK_SHARED);
2001
+
2002
+        $this->shareManager->method('createShare')
2003
+            ->with($this->callback(function (IShare $share) use ($path) {
2004
+                return $share->getNode() === $path
2005
+                && $share->getPermissions() === Constants::PERMISSION_ALL
2006
+                && $share->getShareType() === IShare::TYPE_GROUP
2007
+                && $share->getSharedWith() === 'validGroup'
2008
+                && $share->getSharedBy() === 'currentUser';
2009
+            }))
2010
+            ->willReturnArgument(0);
2011
+
2012
+        $expected = new DataResponse([]);
2013
+        $result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_GROUP, 'validGroup');
2014
+
2015
+        $this->assertInstanceOf(get_class($expected), $result);
2016
+        $this->assertEquals($expected->getData(), $result->getData());
2017
+    }
2018
+
2019
+
2020
+    public function testCreateShareGroupNotAllowed(): void {
2021
+        $this->expectException(OCSNotFoundException::class);
2022
+        $this->expectExceptionMessage('Group sharing is disabled by the administrator');
2023
+
2024
+        $share = $this->newShare();
2025
+        $this->shareManager->method('newShare')->willReturn($share);
2026
+
2027
+        [$userFolder, $path] = $this->getNonSharedUserFolder();
2028
+        $this->rootFolder->method('getUserFolder')
2029
+            ->with('currentUser')
2030
+            ->willReturn($userFolder);
2031
+
2032
+        $userFolder->expects($this->once())
2033
+            ->method('get')
2034
+            ->with('valid-path')
2035
+            ->willReturn($path);
2036
+        $userFolder->method('getById')
2037
+            ->willReturn([]);
2038
+
2039
+        $this->groupManager->method('groupExists')->with('validGroup')->willReturn(true);
2040
+
2041
+        $this->shareManager->expects($this->once())
2042
+            ->method('allowGroupSharing')
2043
+            ->willReturn(false);
2044
+
2045
+        $this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_GROUP, 'invalidGroup');
2046
+    }
2047
+
2048
+
2049
+    public function testCreateShareLinkNoLinksAllowed(): void {
2050
+        $this->expectException(OCSNotFoundException::class);
2051
+        $this->expectExceptionMessage('Public link sharing is disabled by the administrator');
2052
+
2053
+        $this->request
2054
+            ->method('getParam')
2055
+            ->willReturnMap([
2056
+                ['path', null, 'valid-path'],
2057
+                ['shareType', '-1', IShare::TYPE_LINK],
2058
+            ]);
2059
+
2060
+        $path = $this->getMockBuilder(Folder::class)->getMock();
2061
+        $path->method('getId')->willReturn(42);
2062
+        $storage = $this->createMock(IStorage::class);
2063
+        $storage->method('instanceOfStorage')
2064
+            ->willReturnMap([
2065
+                ['OCA\Files_Sharing\External\Storage', false],
2066
+                ['OCA\Files_Sharing\SharedStorage', false],
2067
+            ]);
2068
+        $path->method('getStorage')->willReturn($storage);
2069
+        $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
2070
+        $this->rootFolder->method('get')->with('valid-path')->willReturn($path);
2071
+        $this->rootFolder->method('getById')
2072
+            ->willReturn([]);
2073
+
2074
+        $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
2075
+        $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
2076
+        $this->shareManager->method('shareApiAllowLinks')->willReturn(false);
2077
+
2078
+        $this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK);
2079
+    }
2080
+
2081
+
2082
+    public function testCreateShareLinkNoPublicUpload(): void {
2083
+        $this->expectException(OCSForbiddenException::class);
2084
+        $this->expectExceptionMessage('Public upload disabled by the administrator');
2085
+
2086
+        $path = $this->getMockBuilder(Folder::class)->getMock();
2087
+        $path->method('getId')->willReturn(42);
2088
+        $storage = $this->createMock(IStorage::class);
2089
+        $storage->method('instanceOfStorage')
2090
+            ->willReturnMap([
2091
+                ['OCA\Files_Sharing\External\Storage', false],
2092
+                ['OCA\Files_Sharing\SharedStorage', false],
2093
+            ]);
2094
+        $path->method('getStorage')->willReturn($storage);
2095
+        $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
2096
+        $this->rootFolder->method('get')->with('valid-path')->willReturn($path);
2097
+        $this->rootFolder->method('getById')
2098
+            ->willReturn([]);
2099
+
2100
+        $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
2101
+        $this->shareManager->method('shareApiAllowLinks')->willReturn(true);
2102
+
2103
+        $this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'true');
2104
+    }
2105
+
2106
+
2107
+    public function testCreateShareLinkPublicUploadFile(): void {
2108
+        $this->expectException(OCSBadRequestException::class);
2109
+        $this->expectExceptionMessage('Public upload is only possible for publicly shared folders');
2110
+
2111
+        $storage = $this->createMock(IStorage::class);
2112
+        $storage->method('instanceOfStorage')
2113
+            ->willReturnMap([
2114
+                ['OCA\Files_Sharing\External\Storage', false],
2115
+                ['OCA\Files_Sharing\SharedStorage', false],
2116
+            ]);
2117
+
2118
+        $file = $this->createMock(File::class);
2119
+        $file->method('getId')->willReturn(42);
2120
+        $file->method('getStorage')->willReturn($storage);
2121
+
2122
+        $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
2123
+        $this->rootFolder->method('get')->with('valid-path')->willReturn($file);
2124
+        $this->rootFolder->method('getById')
2125
+            ->willReturn([]);
2126
+
2127
+        $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
2128
+        $this->shareManager->method('shareApiAllowLinks')->willReturn(true);
2129
+        $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
2130
+
2131
+        $this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'true');
2132
+    }
2133
+
2134
+    public function testCreateShareLinkPublicUploadFolder(): void {
2135
+        $ocs = $this->mockFormatShare();
2136
+
2137
+        $path = $this->getMockBuilder(Folder::class)->getMock();
2138
+        $path->method('getId')->willReturn(1);
2139
+        $storage = $this->createMock(IStorage::class);
2140
+        $storage->method('instanceOfStorage')
2141
+            ->willReturnMap([
2142
+                ['OCA\Files_Sharing\External\Storage', false],
2143
+                ['OCA\Files_Sharing\SharedStorage', false],
2144
+            ]);
2145
+        $path->method('getStorage')->willReturn($storage);
2146
+        $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
2147
+        $this->rootFolder->method('get')->with('valid-path')->willReturn($path);
2148
+        $this->rootFolder->method('getById')
2149
+            ->willReturn([]);
2150
+
2151
+        $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
2152
+        $this->shareManager->method('shareApiAllowLinks')->willReturn(true);
2153
+        $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
2154
+
2155
+        $this->shareManager->expects($this->once())->method('createShare')->with(
2156
+            $this->callback(function (IShare $share) use ($path) {
2157
+                return $share->getNode() === $path
2158
+                    && $share->getShareType() === IShare::TYPE_LINK
2159
+                    && $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
2160
+                    && $share->getSharedBy() === 'currentUser'
2161
+                    && $share->getPassword() === null
2162
+                    && $share->getExpirationDate() === null;
2163
+            })
2164
+        )->willReturnArgument(0);
2165
+
2166
+        $expected = new DataResponse([]);
2167
+        $result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'true', '', null, '');
2168
+
2169
+        $this->assertInstanceOf(get_class($expected), $result);
2170
+        $this->assertEquals($expected->getData(), $result->getData());
2171
+    }
2172
+
2173
+    public function testCreateShareLinkPassword(): void {
2174
+        $ocs = $this->mockFormatShare();
2175
+
2176
+        $path = $this->getMockBuilder(Folder::class)->getMock();
2177
+        $path->method('getId')->willReturn(42);
2178
+        $storage = $this->createMock(IStorage::class);
2179
+        $storage->method('instanceOfStorage')
2180
+            ->willReturnMap([
2181
+                ['OCA\Files_Sharing\External\Storage', false],
2182
+                ['OCA\Files_Sharing\SharedStorage', false],
2183
+            ]);
2184
+        $path->method('getStorage')->willReturn($storage);
2185
+        $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
2186
+        $this->rootFolder->method('get')->with('valid-path')->willReturn($path);
2187
+        $this->rootFolder->method('getById')
2188
+            ->willReturn([]);
2189
+
2190
+        $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
2191
+        $this->shareManager->method('shareApiAllowLinks')->willReturn(true);
2192
+        $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
2193
+
2194
+        $this->shareManager->expects($this->once())->method('createShare')->with(
2195
+            $this->callback(function (IShare $share) use ($path) {
2196
+                return $share->getNode() === $path
2197
+                && $share->getShareType() === IShare::TYPE_LINK
2198
+                && $share->getPermissions() === Constants::PERMISSION_READ // publicUpload was set to false
2199
+                && $share->getSharedBy() === 'currentUser'
2200
+                && $share->getPassword() === 'password'
2201
+                && $share->getExpirationDate() === null;
2202
+            })
2203
+        )->willReturnArgument(0);
2204
+
2205
+        $expected = new DataResponse([]);
2206
+        $result = $ocs->createShare('valid-path', Constants::PERMISSION_READ, IShare::TYPE_LINK, null, 'false', 'password', null, '');
2207
+
2208
+        $this->assertInstanceOf(get_class($expected), $result);
2209
+        $this->assertEquals($expected->getData(), $result->getData());
2210
+    }
2211
+
2212
+    public function testCreateShareLinkSendPasswordByTalk(): void {
2213
+        $ocs = $this->mockFormatShare();
2214
+
2215
+        $path = $this->getMockBuilder(Folder::class)->getMock();
2216
+        $path->method('getId')->willReturn(42);
2217
+        $storage = $this->createMock(IStorage::class);
2218
+        $storage->method('instanceOfStorage')
2219
+            ->willReturnMap([
2220
+                ['OCA\Files_Sharing\External\Storage', false],
2221
+                ['OCA\Files_Sharing\SharedStorage', false],
2222
+            ]);
2223
+        $path->method('getStorage')->willReturn($storage);
2224
+        $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
2225
+        $this->rootFolder->method('get')->with('valid-path')->willReturn($path);
2226
+        $this->rootFolder->method('getById')
2227
+            ->willReturn([]);
2228
+
2229
+        $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
2230
+        $this->shareManager->method('shareApiAllowLinks')->willReturn(true);
2231
+        $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
2232
+
2233
+        $this->appManager->method('isEnabledForUser')->with('spreed')->willReturn(true);
2234
+
2235
+        $this->shareManager->expects($this->once())->method('createShare')->with(
2236
+            $this->callback(function (IShare $share) use ($path) {
2237
+                return $share->getNode() === $path
2238
+                && $share->getShareType() === IShare::TYPE_LINK
2239
+                && $share->getPermissions() === (Constants::PERMISSION_ALL & ~(Constants::PERMISSION_SHARE))
2240
+                && $share->getSharedBy() === 'currentUser'
2241
+                && $share->getPassword() === 'password'
2242
+                && $share->getSendPasswordByTalk() === true
2243
+                && $share->getExpirationDate() === null;
2244
+            })
2245
+        )->willReturnArgument(0);
2246
+
2247
+        $expected = new DataResponse([]);
2248
+        $result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'true', 'password', 'true', '');
2249
+
2250
+        $this->assertInstanceOf(get_class($expected), $result);
2251
+        $this->assertEquals($expected->getData(), $result->getData());
2252
+    }
2253
+
2254
+
2255
+    public function testCreateShareLinkSendPasswordByTalkWithTalkDisabled(): void {
2256
+        $this->expectException(OCSForbiddenException::class);
2257
+        $this->expectExceptionMessage('Sharing valid-path sending the password by Nextcloud Talk failed because Nextcloud Talk is not enabled');
2258
+
2259
+        $ocs = $this->mockFormatShare();
2260
+
2261
+        $path = $this->getMockBuilder(Folder::class)->getMock();
2262
+        $path->method('getId')->willReturn(42);
2263
+        $storage = $this->createMock(IStorage::class);
2264
+        $storage->method('instanceOfStorage')
2265
+            ->willReturnMap([
2266
+                ['OCA\Files_Sharing\External\Storage', false],
2267
+                ['OCA\Files_Sharing\SharedStorage', false],
2268
+            ]);
2269
+        $path->method('getStorage')->willReturn($storage);
2270
+        $path->method('getPath')->willReturn('valid-path');
2271
+        $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
2272
+        $this->rootFolder->method('get')->with('valid-path')->willReturn($path);
2273
+        $this->rootFolder->method('getById')
2274
+            ->willReturn([]);
2275
+
2276
+        $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
2277
+        $this->shareManager->method('shareApiAllowLinks')->willReturn(true);
2278
+        $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
2279
+
2280
+        $this->appManager->method('isEnabledForUser')->with('spreed')->willReturn(false);
2281
+
2282
+        $this->shareManager->expects($this->never())->method('createShare');
2283
+
2284
+        $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'false', 'password', 'true', '');
2285
+    }
2286
+
2287
+    public function testCreateShareValidExpireDate(): void {
2288
+        $ocs = $this->mockFormatShare();
2289
+
2290
+        $this->request
2291
+            ->method('getParam')
2292
+            ->willReturnMap([
2293
+                ['path', null, 'valid-path'],
2294
+                ['shareType', '-1', IShare::TYPE_LINK],
2295
+                ['publicUpload', null, 'false'],
2296
+                ['expireDate', '', '2000-01-01'],
2297
+                ['password', '', ''],
2298
+            ]);
2299
+
2300
+        $path = $this->getMockBuilder(Folder::class)->getMock();
2301
+        $path->method('getId')->willReturn(42);
2302
+        $storage = $this->createMock(IStorage::class);
2303
+        $storage->method('instanceOfStorage')
2304
+            ->willReturnMap([
2305
+                ['OCA\Files_Sharing\External\Storage', false],
2306
+                ['OCA\Files_Sharing\SharedStorage', false],
2307
+            ]);
2308
+        $path->method('getStorage')->willReturn($storage);
2309
+        $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
2310
+        $this->rootFolder->method('get')->with('valid-path')->willReturn($path);
2311
+        $this->rootFolder->method('getById')
2312
+            ->willReturn([]);
2313
+
2314
+        $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
2315
+        $this->shareManager->method('shareApiAllowLinks')->willReturn(true);
2316
+        $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
2317
+
2318
+        $this->shareManager->expects($this->once())->method('createShare')->with(
2319
+            $this->callback(function (IShare $share) use ($path) {
2320
+                $date = new \DateTime('2000-01-01');
2321
+                $date->setTime(0, 0, 0);
2322
+
2323
+                return $share->getNode() === $path
2324
+                && $share->getShareType() === IShare::TYPE_LINK
2325
+                && $share->getPermissions() === Constants::PERMISSION_READ | Constants::PERMISSION_SHARE
2326
+                && $share->getSharedBy() === 'currentUser'
2327
+                && $share->getPassword() === null
2328
+                && $share->getExpirationDate() == $date;
2329
+            })
2330
+        )->willReturnArgument(0);
2331
+
2332
+        $expected = new DataResponse([]);
2333
+        $result = $ocs->createShare('valid-path', null, IShare::TYPE_LINK, null, 'false', '', null, '2000-01-01');
2334
+
2335
+        $this->assertInstanceOf(get_class($expected), $result);
2336
+        $this->assertEquals($expected->getData(), $result->getData());
2337
+    }
2338
+
2339
+
2340
+    public function testCreateShareInvalidExpireDate(): void {
2341
+        $this->expectException(OCSNotFoundException::class);
2342
+        $this->expectExceptionMessage('Invalid date. Format must be YYYY-MM-DD');
2343
+
2344
+        $ocs = $this->mockFormatShare();
2345
+
2346
+        $path = $this->getMockBuilder(Folder::class)->getMock();
2347
+        $path->method('getId')->willReturn(42);
2348
+        $storage = $this->createMock(IStorage::class);
2349
+        $storage->method('instanceOfStorage')
2350
+            ->willReturnMap([
2351
+                ['OCA\Files_Sharing\External\Storage', false],
2352
+                ['OCA\Files_Sharing\SharedStorage', false],
2353
+            ]);
2354
+        $path->method('getStorage')->willReturn($storage);
2355
+        $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
2356
+        $this->rootFolder->method('get')->with('valid-path')->willReturn($path);
2357
+        $this->rootFolder->method('getById')
2358
+            ->willReturn([]);
2359
+
2360
+        $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare());
2361
+        $this->shareManager->method('shareApiAllowLinks')->willReturn(true);
2362
+        $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
2363
+
2364
+        $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'false', '', null, 'a1b2d3');
2365
+    }
2366
+
2367
+    public function testCreateShareRemote(): void {
2368
+        $share = $this->newShare();
2369
+        $this->shareManager->method('newShare')->willReturn($share);
2370
+
2371
+        /** @var ShareAPIController $ocs */
2372
+        $ocs = $this->getMockBuilder(ShareAPIController::class)
2373
+            ->setConstructorArgs([
2374
+                $this->appName,
2375
+                $this->request,
2376
+                $this->shareManager,
2377
+                $this->groupManager,
2378
+                $this->userManager,
2379
+                $this->rootFolder,
2380
+                $this->urlGenerator,
2381
+                $this->l,
2382
+                $this->config,
2383
+                $this->appManager,
2384
+                $this->serverContainer,
2385
+                $this->userStatusManager,
2386
+                $this->previewManager,
2387
+                $this->dateTimeZone,
2388
+                $this->logger,
2389
+                $this->factory,
2390
+                $this->mailer,
2391
+                $this->tagManager,
2392
+                $this->currentUser,
2393
+            ])->onlyMethods(['formatShare'])
2394
+            ->getMock();
2395
+
2396
+        [$userFolder, $path] = $this->getNonSharedUserFile();
2397
+        $this->rootFolder->expects($this->exactly(2))
2398
+            ->method('getUserFolder')
2399
+            ->with('currentUser')
2400
+            ->willReturn($userFolder);
2401
+
2402
+        $userFolder->expects($this->once())
2403
+            ->method('get')
2404
+            ->with('valid-path')
2405
+            ->willReturn($path);
2406
+        $userFolder->method('getById')
2407
+            ->willReturn([]);
2408
+
2409
+        $this->userManager->method('userExists')->with('validUser')->willReturn(true);
2410
+
2411
+        $path->expects($this->once())
2412
+            ->method('lock')
2413
+            ->with(ILockingProvider::LOCK_SHARED);
2414
+
2415
+        $this->shareManager->method('createShare')
2416
+            ->with($this->callback(function (IShare $share) use ($path) {
2417
+                return $share->getNode() === $path
2418
+                    && $share->getPermissions() === (
2419
+                        Constants::PERMISSION_ALL
2420
+                        & ~Constants::PERMISSION_DELETE
2421
+                        & ~Constants::PERMISSION_CREATE
2422
+                    )
2423
+                    && $share->getShareType() === IShare::TYPE_REMOTE
2424
+                    && $share->getSharedWith() === '[email protected]'
2425
+                    && $share->getSharedBy() === 'currentUser';
2426
+            }))
2427
+            ->willReturnArgument(0);
2428
+
2429
+        $this->shareManager->method('outgoingServer2ServerSharesAllowed')->willReturn(true);
2430
+
2431
+        $expected = new DataResponse([]);
2432
+        $result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_REMOTE, '[email protected]');
2433
+
2434
+        $this->assertInstanceOf(get_class($expected), $result);
2435
+        $this->assertEquals($expected->getData(), $result->getData());
2436
+    }
2437
+
2438
+    public function testCreateShareRemoteGroup(): void {
2439
+        $share = $this->newShare();
2440
+        $this->shareManager->method('newShare')->willReturn($share);
2441
+
2442
+        /** @var ShareAPIController $ocs */
2443
+        $ocs = $this->getMockBuilder(ShareAPIController::class)
2444
+            ->setConstructorArgs([
2445
+                $this->appName,
2446
+                $this->request,
2447
+                $this->shareManager,
2448
+                $this->groupManager,
2449
+                $this->userManager,
2450
+                $this->rootFolder,
2451
+                $this->urlGenerator,
2452
+                $this->l,
2453
+                $this->config,
2454
+                $this->appManager,
2455
+                $this->serverContainer,
2456
+                $this->userStatusManager,
2457
+                $this->previewManager,
2458
+                $this->dateTimeZone,
2459
+                $this->logger,
2460
+                $this->factory,
2461
+                $this->mailer,
2462
+                $this->tagManager,
2463
+                $this->currentUser,
2464
+            ])->onlyMethods(['formatShare'])
2465
+            ->getMock();
2466
+
2467
+        [$userFolder, $path] = $this->getNonSharedUserFile();
2468
+        $this->rootFolder->expects($this->exactly(2))
2469
+            ->method('getUserFolder')
2470
+            ->with('currentUser')
2471
+            ->willReturn($userFolder);
2472
+
2473
+        $userFolder->expects($this->once())
2474
+            ->method('get')
2475
+            ->with('valid-path')
2476
+            ->willReturn($path);
2477
+        $userFolder->method('getById')
2478
+            ->willReturn([]);
2479
+
2480
+        $this->userManager->method('userExists')->with('validUser')->willReturn(true);
2481
+
2482
+        $path->expects($this->once())
2483
+            ->method('lock')
2484
+            ->with(ILockingProvider::LOCK_SHARED);
2485
+
2486
+        $this->shareManager->method('createShare')
2487
+            ->with($this->callback(function (IShare $share) use ($path) {
2488
+                return $share->getNode() === $path
2489
+                    && $share->getPermissions() === (
2490
+                        Constants::PERMISSION_ALL
2491
+                        & ~Constants::PERMISSION_DELETE
2492
+                        & ~Constants::PERMISSION_CREATE
2493
+                    )
2494
+                    && $share->getShareType() === IShare::TYPE_REMOTE_GROUP
2495
+                    && $share->getSharedWith() === '[email protected]'
2496
+                    && $share->getSharedBy() === 'currentUser';
2497
+            }))
2498
+            ->willReturnArgument(0);
2499
+
2500
+        $this->shareManager->method('outgoingServer2ServerGroupSharesAllowed')->willReturn(true);
2501
+
2502
+        $expected = new DataResponse([]);
2503
+        $result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_REMOTE_GROUP, '[email protected]');
2504
+
2505
+        $this->assertInstanceOf(get_class($expected), $result);
2506
+        $this->assertEquals($expected->getData(), $result->getData());
2507
+    }
2508
+
2509
+    public function testCreateShareRoom(): void {
2510
+        $ocs = $this->mockFormatShare();
2511
+
2512
+        $share = $this->newShare();
2513
+        $this->shareManager->method('newShare')->willReturn($share);
2514
+
2515
+        [$userFolder, $path] = $this->getNonSharedUserFile();
2516
+        $this->rootFolder->expects($this->exactly(2))
2517
+            ->method('getUserFolder')
2518
+            ->with('currentUser')
2519
+            ->willReturn($userFolder);
2520
+
2521
+        $userFolder->expects($this->once())
2522
+            ->method('get')
2523
+            ->with('valid-path')
2524
+            ->willReturn($path);
2525
+        $userFolder->method('getById')
2526
+            ->willReturn([]);
2527
+
2528
+        $path->expects($this->once())
2529
+            ->method('lock')
2530
+            ->with(ILockingProvider::LOCK_SHARED);
2531
+
2532
+        $this->appManager->method('isEnabledForUser')
2533
+            ->with('spreed')
2534
+            ->willReturn(true);
2535
+
2536
+        // This is not possible anymore with PHPUnit 10+
2537
+        // as `setMethods` was removed and now real reflection is used, thus the class needs to exist.
2538
+        // $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
2539
+        $helper = $this->getMockBuilder(\stdClass::class)
2540
+            ->addMethods(['createShare'])
2541
+            ->getMock();
2542
+        $helper->method('createShare')
2543
+            ->with(
2544
+                $share,
2545
+                'recipientRoom',
2546
+                Constants::PERMISSION_ALL
2547
+                & ~Constants::PERMISSION_DELETE
2548
+                & ~Constants::PERMISSION_CREATE,
2549
+                ''
2550
+            )->willReturnCallback(
2551
+                function ($share): void {
2552
+                    $share->setSharedWith('recipientRoom');
2553
+                    $share->setPermissions(Constants::PERMISSION_ALL);
2554
+                }
2555
+            );
2556
+
2557
+        $this->serverContainer->method('get')
2558
+            ->with('\OCA\Talk\Share\Helper\ShareAPIController')
2559
+            ->willReturn($helper);
2560
+
2561
+        $this->shareManager->method('createShare')
2562
+            ->with($this->callback(function (IShare $share) use ($path) {
2563
+                return $share->getNode() === $path
2564
+                    && $share->getPermissions() === Constants::PERMISSION_ALL
2565
+                    && $share->getShareType() === IShare::TYPE_ROOM
2566
+                    && $share->getSharedWith() === 'recipientRoom'
2567
+                    && $share->getSharedBy() === 'currentUser';
2568
+            }))
2569
+            ->willReturnArgument(0);
2570
+
2571
+        $expected = new DataResponse([]);
2572
+        $result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_ROOM, 'recipientRoom');
2573
+
2574
+        $this->assertInstanceOf(get_class($expected), $result);
2575
+        $this->assertEquals($expected->getData(), $result->getData());
2576
+    }
2577
+
2578
+
2579
+    public function testCreateShareRoomHelperNotAvailable(): void {
2580
+        $this->expectException(OCSForbiddenException::class);
2581
+        $this->expectExceptionMessage('Sharing valid-path failed because the back end does not support room shares');
2582
+
2583
+        $ocs = $this->mockFormatShare();
2584
+
2585
+        $share = $this->newShare();
2586
+        $this->shareManager->method('newShare')->willReturn($share);
2587
+
2588
+        [$userFolder, $path] = $this->getNonSharedUserFolder();
2589
+        $this->rootFolder->method('getUserFolder')
2590
+            ->with('currentUser')
2591
+            ->willReturn($userFolder);
2592
+
2593
+        $path->method('getPath')->willReturn('valid-path');
2594
+        $userFolder->expects($this->once())
2595
+            ->method('get')
2596
+            ->with('valid-path')
2597
+            ->willReturn($path);
2598
+        $userFolder->method('getById')
2599
+            ->willReturn([]);
2600
+
2601
+        $path->expects($this->once())
2602
+            ->method('lock')
2603
+            ->with(ILockingProvider::LOCK_SHARED);
2604
+
2605
+        $this->appManager->method('isEnabledForUser')
2606
+            ->with('spreed')
2607
+            ->willReturn(false);
2608
+
2609
+        $this->shareManager->expects($this->never())->method('createShare');
2610
+
2611
+        $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_ROOM, 'recipientRoom');
2612
+    }
2613
+
2614
+
2615
+    public function testCreateShareRoomHelperThrowException(): void {
2616
+        $this->expectException(OCSNotFoundException::class);
2617
+        $this->expectExceptionMessage('Exception thrown by the helper');
2618
+
2619
+        $ocs = $this->mockFormatShare();
2620
+
2621
+        $share = $this->newShare();
2622
+        $share->setSharedBy('currentUser');
2623
+        $this->shareManager->method('newShare')->willReturn($share);
2624
+
2625
+        [$userFolder, $path] = $this->getNonSharedUserFile();
2626
+        $this->rootFolder->method('getUserFolder')
2627
+            ->with('currentUser')
2628
+            ->willReturn($userFolder);
2629
+
2630
+        $userFolder->expects($this->once())
2631
+            ->method('get')
2632
+            ->with('valid-path')
2633
+            ->willReturn($path);
2634
+        $userFolder->method('getById')
2635
+            ->willReturn([]);
2636
+
2637
+        $path->expects($this->once())
2638
+            ->method('lock')
2639
+            ->with(ILockingProvider::LOCK_SHARED);
2640
+
2641
+        $this->appManager->method('isEnabledForUser')
2642
+            ->with('spreed')
2643
+            ->willReturn(true);
2644
+
2645
+        // This is not possible anymore with PHPUnit 10+
2646
+        // as `setMethods` was removed and now real reflection is used, thus the class needs to exist.
2647
+        // $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
2648
+        $helper = $this->getMockBuilder(\stdClass::class)
2649
+            ->addMethods(['createShare'])
2650
+            ->getMock();
2651
+        $helper->method('createShare')
2652
+            ->with(
2653
+                $share,
2654
+                'recipientRoom',
2655
+                Constants::PERMISSION_ALL & ~(Constants::PERMISSION_CREATE | Constants::PERMISSION_DELETE),
2656
+                ''
2657
+            )->willReturnCallback(
2658
+                function ($share): void {
2659
+                    throw new OCSNotFoundException('Exception thrown by the helper');
2660
+                }
2661
+            );
2662
+
2663
+        $this->serverContainer->method('get')
2664
+            ->with('\OCA\Talk\Share\Helper\ShareAPIController')
2665
+            ->willReturn($helper);
2666
+
2667
+        $this->shareManager->expects($this->never())->method('createShare');
2668
+
2669
+        $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_ROOM, 'recipientRoom');
2670
+    }
2671
+
2672
+    /**
2673
+     * Test for https://github.com/owncloud/core/issues/22587
2674
+     * TODO: Remove once proper solution is in place
2675
+     */
2676
+    public function testCreateReshareOfFederatedMountNoDeletePermissions(): void {
2677
+        $share = Server::get(IManager::class)->newShare();
2678
+        $this->shareManager->method('newShare')->willReturn($share);
2679
+
2680
+        /** @var ShareAPIController&MockObject $ocs */
2681
+        $ocs = $this->getMockBuilder(ShareAPIController::class)
2682
+            ->setConstructorArgs([
2683
+                $this->appName,
2684
+                $this->request,
2685
+                $this->shareManager,
2686
+                $this->groupManager,
2687
+                $this->userManager,
2688
+                $this->rootFolder,
2689
+                $this->urlGenerator,
2690
+                $this->l,
2691
+                $this->config,
2692
+                $this->appManager,
2693
+                $this->serverContainer,
2694
+                $this->userStatusManager,
2695
+                $this->previewManager,
2696
+                $this->dateTimeZone,
2697
+                $this->logger,
2698
+                $this->factory,
2699
+                $this->mailer,
2700
+                $this->tagManager,
2701
+                $this->currentUser,
2702
+            ])->onlyMethods(['formatShare'])
2703
+            ->getMock();
2704
+
2705
+        $userFolder = $this->getMockBuilder(Folder::class)->getMock();
2706
+        $this->rootFolder->expects($this->exactly(2))
2707
+            ->method('getUserFolder')
2708
+            ->with('currentUser')
2709
+            ->willReturn($userFolder);
2710
+
2711
+        $path = $this->getMockBuilder(Folder::class)->getMock();
2712
+        $path->method('getId')->willReturn(42);
2713
+
2714
+        $storage = $this->createMock(IStorage::class);
2715
+        $storage->method('instanceOfStorage')
2716
+            ->willReturnMap([
2717
+                ['OCA\Files_Sharing\External\Storage', true],
2718
+                ['OCA\Files_Sharing\SharedStorage', false],
2719
+            ]);
2720
+        $userFolder->method('getStorage')->willReturn($storage);
2721
+        $path->method('getStorage')->willReturn($storage);
2722
+
2723
+        $path->method('getPermissions')->willReturn(Constants::PERMISSION_READ);
2724
+        $userFolder->expects($this->once())
2725
+            ->method('get')
2726
+            ->with('valid-path')
2727
+            ->willReturn($path);
2728
+        $userFolder->method('getById')
2729
+            ->willReturn([]);
2730
+
2731
+        $this->userManager->method('userExists')->with('validUser')->willReturn(true);
2732
+
2733
+        $this->shareManager
2734
+            ->expects($this->once())
2735
+            ->method('createShare')
2736
+            ->with($this->callback(function (IShare $share) {
2737
+                return $share->getPermissions() === Constants::PERMISSION_READ;
2738
+            }))
2739
+            ->willReturnArgument(0);
2740
+
2741
+        $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_USER, 'validUser');
2742
+    }
2743
+
2744
+
2745
+    public function testUpdateShareCantAccess(): void {
2746
+        $this->expectException(OCSNotFoundException::class);
2747
+        $this->expectExceptionMessage('Wrong share ID, share does not exist');
2748
+
2749
+        [$userFolder, $node] = $this->getNonSharedUserFolder();
2750
+        $share = $this->newShare();
2751
+        $share->setNode($node);
2752
+
2753
+        $node->expects($this->once())
2754
+            ->method('lock')
2755
+            ->with(ILockingProvider::LOCK_SHARED);
2756
+
2757
+        $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
2758
+
2759
+        $this->rootFolder->method('getUserFolder')
2760
+            ->with($this->currentUser)
2761
+            ->willReturn($userFolder);
2762
+
2763
+        $userFolder->method('getById')
2764
+            ->with($share->getNodeId())
2765
+            ->willReturn([$share->getNode()]);
2766
+
2767
+        $this->ocs->updateShare(42);
2768
+    }
2769
+
2770
+
2771
+    public function testUpdateNoParametersLink(): void {
2772
+        $this->expectException(OCSBadRequestException::class);
2773
+        $this->expectExceptionMessage('Wrong or no update parameter given');
2774
+
2775
+        $node = $this->getMockBuilder(Folder::class)->getMock();
2776
+        $share = $this->newShare();
2777
+        $share->setPermissions(Constants::PERMISSION_ALL)
2778
+            ->setSharedBy($this->currentUser)
2779
+            ->setShareType(IShare::TYPE_LINK)
2780
+            ->setNode($node);
2781
+
2782
+        $node->expects($this->once())
2783
+            ->method('lock')
2784
+            ->with(ILockingProvider::LOCK_SHARED);
2785
+
2786
+        $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
2787
+
2788
+        $this->ocs->updateShare(42);
2789
+    }
2790
+
2791
+
2792
+    public function testUpdateNoParametersOther(): void {
2793
+        $this->expectException(OCSBadRequestException::class);
2794
+        $this->expectExceptionMessage('Wrong or no update parameter given');
2795
+
2796
+        $node = $this->getMockBuilder(Folder::class)->getMock();
2797
+        $share = $this->newShare();
2798
+        $share->setPermissions(Constants::PERMISSION_ALL)
2799
+            ->setSharedBy($this->currentUser)
2800
+            ->setShareType(IShare::TYPE_GROUP)
2801
+            ->setNode($node);
2802
+
2803
+        $node->expects($this->once())
2804
+            ->method('lock')
2805
+            ->with(ILockingProvider::LOCK_SHARED);
2806
+
2807
+        $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
2808
+
2809
+        $this->ocs->updateShare(42);
2810
+    }
2811
+
2812
+    public function testUpdateLinkShareClear(): void {
2813
+        $ocs = $this->mockFormatShare();
2814
+
2815
+        [$userFolder, $node] = $this->getNonSharedUserFolder();
2816
+        $node->method('getId')
2817
+            ->willReturn(42);
2818
+        $share = $this->newShare();
2819
+        $share->setPermissions(Constants::PERMISSION_ALL)
2820
+            ->setSharedBy($this->currentUser)
2821
+            ->setShareType(IShare::TYPE_LINK)
2822
+            ->setPassword('password')
2823
+            ->setExpirationDate(new \DateTime())
2824
+            ->setNote('note')
2825
+            ->setLabel('label')
2826
+            ->setHideDownload(true)
2827
+            ->setPermissions(Constants::PERMISSION_ALL)
2828
+            ->setNode($node);
2829
+
2830
+        $node->expects($this->once())
2831
+            ->method('lock')
2832
+            ->with(ILockingProvider::LOCK_SHARED);
2833
+
2834
+        $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
2835
+
2836
+        $this->shareManager->expects($this->once())->method('updateShare')->with(
2837
+            $this->callback(function (IShare $share) {
2838
+                return $share->getPermissions() === Constants::PERMISSION_READ
2839
+                && $share->getPassword() === null
2840
+                && $share->getExpirationDate() === null
2841
+                // Once set a note or a label are never back to null, only to an
2842
+                // empty string.
2843
+                && $share->getNote() === ''
2844
+                && $share->getLabel() === ''
2845
+                && $share->getHideDownload() === false;
2846
+            })
2847
+        )->willReturnArgument(0);
2848
+
2849
+        $this->shareManager->method('getSharedWith')
2850
+            ->willReturn([]);
2851
+
2852
+        $this->rootFolder->method('getUserFolder')
2853
+            ->with($this->currentUser)
2854
+            ->willReturn($userFolder);
2855
+
2856
+        $userFolder->method('getById')
2857
+            ->with(42)
2858
+            ->willReturn([$node]);
2859
+        $userFolder->method('getFirstNodeById')
2860
+            ->with(42)
2861
+            ->willReturn($node);
2862
+
2863
+        $mountPoint = $this->createMock(IMountPoint::class);
2864
+        $node->method('getMountPoint')
2865
+            ->willReturn($mountPoint);
2866
+        $mountPoint->method('getStorageRootId')
2867
+            ->willReturn(42);
2868
+
2869
+        $expected = new DataResponse([]);
2870
+        $result = $ocs->updateShare(42, null, '', null, 'false', '', '', '', 'false');
2871
+
2872
+        $this->assertInstanceOf(get_class($expected), $result);
2873
+        $this->assertEquals($expected->getData(), $result->getData());
2874
+    }
2875
+
2876
+    public function testUpdateLinkShareSet(): void {
2877
+        $ocs = $this->mockFormatShare();
2878
+
2879
+        [$userFolder, $folder] = $this->getNonSharedUserFolder();
2880
+        $folder->method('getId')
2881
+            ->willReturn(42);
2882
+
2883
+        $share = Server::get(IManager::class)->newShare();
2884
+        $share->setPermissions(Constants::PERMISSION_ALL)
2885
+            ->setSharedBy($this->currentUser)
2886
+            ->setShareType(IShare::TYPE_LINK)
2887
+            ->setNode($folder);
2888
+
2889
+        $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
2890
+        $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
2891
+
2892
+        $this->shareManager->expects($this->once())->method('updateShare')->with(
2893
+            $this->callback(function (IShare $share) {
2894
+                $date = new \DateTime('2000-01-01');
2895
+                $date->setTime(0, 0, 0);
2896
+
2897
+                return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
2898
+                && $share->getPassword() === 'password'
2899
+                && $share->getExpirationDate() == $date
2900
+                && $share->getNote() === 'note'
2901
+                && $share->getLabel() === 'label'
2902
+                && $share->getHideDownload() === true;
2903
+            })
2904
+        )->willReturnArgument(0);
2905
+
2906
+        $this->shareManager->method('getSharedWith')
2907
+            ->willReturn([]);
2908
+
2909
+        $this->rootFolder->method('getUserFolder')
2910
+            ->with($this->currentUser)
2911
+            ->willReturn($userFolder);
2912
+
2913
+        $userFolder->method('getById')
2914
+            ->with(42)
2915
+            ->willReturn([$folder]);
2916
+
2917
+        $mountPoint = $this->createMock(IMountPoint::class);
2918
+        $folder->method('getMountPoint')
2919
+            ->willReturn($mountPoint);
2920
+        $mountPoint->method('getStorageRootId')
2921
+            ->willReturn(42);
2922
+
2923
+        $expected = new DataResponse([]);
2924
+        $result = $ocs->updateShare(42, null, 'password', null, 'true', '2000-01-01', 'note', 'label', 'true');
2925
+
2926
+        $this->assertInstanceOf(get_class($expected), $result);
2927
+        $this->assertEquals($expected->getData(), $result->getData());
2928
+    }
2929
+
2930
+    #[\PHPUnit\Framework\Attributes\DataProvider('publicUploadParamsProvider')]
2931
+    public function testUpdateLinkShareEnablePublicUpload($permissions, $publicUpload, $expireDate, $password): void {
2932
+        $ocs = $this->mockFormatShare();
2933
+
2934
+        [$userFolder, $folder] = $this->getNonSharedUserFolder();
2935
+        $folder->method('getId')
2936
+            ->willReturn(42);
2937
+
2938
+        $share = Server::get(IManager::class)->newShare();
2939
+        $share->setPermissions(Constants::PERMISSION_ALL)
2940
+            ->setSharedBy($this->currentUser)
2941
+            ->setShareType(IShare::TYPE_LINK)
2942
+            ->setPassword('password')
2943
+            ->setNode($folder);
2944
+
2945
+        $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
2946
+        $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
2947
+        $this->shareManager->method('getSharedWith')->willReturn([]);
2948
+
2949
+        $this->shareManager->expects($this->once())->method('updateShare')->with(
2950
+            $this->callback(function (IShare $share) {
2951
+                return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
2952
+                && $share->getPassword() === 'password'
2953
+                && $share->getExpirationDate() === null;
2954
+            })
2955
+        )->willReturnArgument(0);
2956
+
2957
+        $this->rootFolder->method('getUserFolder')
2958
+            ->with($this->currentUser)
2959
+            ->willReturn($userFolder);
2960
+
2961
+        $userFolder->method('getById')
2962
+            ->with(42)
2963
+            ->willReturn([$folder]);
2964
+
2965
+        $mountPoint = $this->createMock(IMountPoint::class);
2966
+        $folder->method('getMountPoint')
2967
+            ->willReturn($mountPoint);
2968
+        $mountPoint->method('getStorageRootId')
2969
+            ->willReturn(42);
2970
+
2971
+        $expected = new DataResponse([]);
2972
+        $result = $ocs->updateShare(42, $permissions, $password, null, $publicUpload, $expireDate);
2973
+
2974
+        $this->assertInstanceOf(get_class($expected), $result);
2975
+        $this->assertEquals($expected->getData(), $result->getData());
2976
+    }
2977
+
2978
+
2979
+    public static function publicLinkValidPermissionsProvider() {
2980
+        return [
2981
+            [Constants::PERMISSION_CREATE],
2982
+            [Constants::PERMISSION_READ],
2983
+            [Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE],
2984
+            [Constants::PERMISSION_READ | Constants::PERMISSION_DELETE],
2985
+            [Constants::PERMISSION_READ | Constants::PERMISSION_CREATE],
2986
+        ];
2987
+    }
2988
+
2989
+    #[\PHPUnit\Framework\Attributes\DataProvider('publicLinkValidPermissionsProvider')]
2990
+    public function testUpdateLinkShareSetCRUDPermissions($permissions): void {
2991
+        $ocs = $this->mockFormatShare();
2992
+
2993
+        [$userFolder, $folder] = $this->getNonSharedUserFolder();
2994
+        $folder->method('getId')
2995
+            ->willReturn(42);
2996
+
2997
+        $share = Server::get(IManager::class)->newShare();
2998
+        $share->setPermissions(Constants::PERMISSION_ALL)
2999
+            ->setSharedBy($this->currentUser)
3000
+            ->setShareType(IShare::TYPE_LINK)
3001
+            ->setPassword('password')
3002
+            ->setNode($folder);
3003
+
3004
+        $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3005
+        $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
3006
+        $this->shareManager->method('getSharedWith')->willReturn([]);
3007
+
3008
+        $this->shareManager
3009
+            ->expects($this->any())
3010
+            ->method('updateShare')
3011
+            ->willReturnArgument(0);
3012
+
3013
+        $this->rootFolder->method('getUserFolder')
3014
+            ->with($this->currentUser)
3015
+            ->willReturn($userFolder);
3016
+
3017
+        $userFolder->method('getById')
3018
+            ->with(42)
3019
+            ->willReturn([$folder]);
3020
+
3021
+        $mountPoint = $this->createMock(IMountPoint::class);
3022
+        $folder->method('getMountPoint')
3023
+            ->willReturn($mountPoint);
3024
+        $mountPoint->method('getStorageRootId')
3025
+            ->willReturn(42);
3026
+
3027
+        $expected = new DataResponse([]);
3028
+        $result = $ocs->updateShare(42, $permissions, 'password', null, null, null);
3029
+
3030
+        $this->assertInstanceOf(get_class($expected), $result);
3031
+        $this->assertEquals($expected->getData(), $result->getData());
3032
+    }
3033
+
3034
+    public static function publicLinkInvalidPermissionsProvider1() {
3035
+        return [
3036
+            [Constants::PERMISSION_DELETE],
3037
+            [Constants::PERMISSION_UPDATE],
3038
+            [Constants::PERMISSION_SHARE],
3039
+        ];
3040
+    }
3041
+
3042
+    #[\PHPUnit\Framework\Attributes\DataProvider('publicLinkInvalidPermissionsProvider1')]
3043
+    public function testUpdateLinkShareSetInvalidCRUDPermissions1($permissions): void {
3044
+        $this->expectException(OCSBadRequestException::class);
3045
+        $this->expectExceptionMessage('Share must at least have READ or CREATE permissions');
3046
+
3047
+        $this->testUpdateLinkShareSetCRUDPermissions($permissions, null);
3048
+    }
3049
+
3050
+    public static function publicLinkInvalidPermissionsProvider2() {
3051
+        return [
3052
+            [Constants::PERMISSION_CREATE | Constants::PERMISSION_DELETE],
3053
+            [Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE],
3054
+        ];
3055
+    }
3056
+
3057
+    #[\PHPUnit\Framework\Attributes\DataProvider('publicLinkInvalidPermissionsProvider2')]
3058
+    public function testUpdateLinkShareSetInvalidCRUDPermissions2($permissions): void {
3059
+        $this->expectException(OCSBadRequestException::class);
3060
+        $this->expectExceptionMessage('Share must have READ permission if UPDATE or DELETE permission is set');
3061
+
3062
+        $this->testUpdateLinkShareSetCRUDPermissions($permissions);
3063
+    }
3064
+
3065
+    public function testUpdateLinkShareInvalidDate(): void {
3066
+        $this->expectException(OCSBadRequestException::class);
3067
+        $this->expectExceptionMessage('Invalid date. Format must be YYYY-MM-DD');
3068
+
3069
+        $ocs = $this->mockFormatShare();
3070
+        [$userFolder, $folder] = $this->getNonSharedUserFolder();
3071
+        $userFolder->method('getById')
3072
+            ->with(42)
3073
+            ->willReturn([$folder]);
3074
+        $this->rootFolder->method('getUserFolder')
3075
+            ->with($this->currentUser)
3076
+            ->willReturn($userFolder);
3077
+
3078
+        $folder->method('getId')
3079
+            ->willReturn(42);
3080
+
3081
+        $share = Server::get(IManager::class)->newShare();
3082
+        $share->setPermissions(Constants::PERMISSION_ALL)
3083
+            ->setSharedBy($this->currentUser)
3084
+            ->setShareType(IShare::TYPE_LINK)
3085
+            ->setNode($folder);
3086
+
3087
+        $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3088
+        $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
3089
+
3090
+        $ocs->updateShare(42, null, 'password', null, 'true', '2000-01-a');
3091
+    }
3092
+
3093
+    public static function publicUploadParamsProvider() {
3094
+        return [
3095
+            [null, 'true', null, 'password'],
3096
+            // legacy had no delete
3097
+            [
3098
+                Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE,
3099
+                'true', null, 'password'
3100
+            ],
3101
+            // correct
3102
+            [
3103
+                Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE,
3104
+                null, null, 'password'
3105
+            ],
3106
+        ];
3107
+    }
3108
+
3109
+    #[\PHPUnit\Framework\Attributes\DataProvider('publicUploadParamsProvider')]
3110
+    public function testUpdateLinkSharePublicUploadNotAllowed($permissions, $publicUpload, $expireDate, $password): void {
3111
+        $this->expectException(OCSForbiddenException::class);
3112
+        $this->expectExceptionMessage('Public upload disabled by the administrator');
3113
+
3114
+        $ocs = $this->mockFormatShare();
3115
+        [$userFolder, $folder] = $this->getNonSharedUserFolder();
3116
+        $userFolder->method('getById')
3117
+            ->with(42)
3118
+            ->willReturn([$folder]);
3119
+        $this->rootFolder->method('getUserFolder')
3120
+            ->with($this->currentUser)
3121
+            ->willReturn($userFolder);
3122
+
3123
+        $folder->method('getId')->willReturn(42);
3124
+
3125
+        $share = Server::get(IManager::class)->newShare();
3126
+        $share->setPermissions(Constants::PERMISSION_ALL)
3127
+            ->setSharedBy($this->currentUser)
3128
+            ->setShareType(IShare::TYPE_LINK)
3129
+            ->setNode($folder);
3130
+
3131
+        $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3132
+        $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(false);
3133
+
3134
+        $ocs->updateShare(42, $permissions, $password, null, $publicUpload, $expireDate);
3135
+    }
3136
+
3137
+
3138
+    public function testUpdateLinkSharePublicUploadOnFile(): void {
3139
+        $this->expectException(OCSBadRequestException::class);
3140
+        $this->expectExceptionMessage('Public upload is only possible for publicly shared folders');
3141
+
3142
+        $ocs = $this->mockFormatShare();
3143
+
3144
+        $file = $this->getMockBuilder(File::class)->getMock();
3145
+        $file->method('getId')
3146
+            ->willReturn(42);
3147
+        [$userFolder, $folder] = $this->getNonSharedUserFolder();
3148
+        $userFolder->method('getById')
3149
+            ->with(42)
3150
+            ->willReturn([$folder]);
3151
+        $this->rootFolder->method('getUserFolder')
3152
+            ->with($this->currentUser)
3153
+            ->willReturn($userFolder);
3154
+
3155
+        $share = Server::get(IManager::class)->newShare();
3156
+        $share->setPermissions(Constants::PERMISSION_ALL)
3157
+            ->setSharedBy($this->currentUser)
3158
+            ->setShareType(IShare::TYPE_LINK)
3159
+            ->setNode($file);
3160
+
3161
+        $this->shareManager
3162
+            ->method('getShareById')
3163
+            ->with('ocinternal:42')
3164
+            ->willReturn($share);
3165
+        $this->shareManager
3166
+            ->method('shareApiLinkAllowPublicUpload')
3167
+            ->willReturn(true);
3168
+        $this->shareManager
3169
+            ->method('updateShare')
3170
+            ->with($share)
3171
+            ->willThrowException(new \InvalidArgumentException('File shares cannot have create or delete permissions'));
3172
+
3173
+        $ocs->updateShare(42, null, 'password', null, 'true', '');
3174
+    }
3175
+
3176
+    public function testUpdateLinkSharePasswordDoesNotChangeOther(): void {
3177
+        $ocs = $this->mockFormatShare();
3178
+
3179
+        $date = new \DateTime('2000-01-01');
3180
+        $date->setTime(0, 0, 0);
3181
+
3182
+        [$userFolder, $node] = $this->getNonSharedUserFolder();
3183
+        $node->method('getId')->willReturn(42);
3184
+        $userFolder->method('getById')
3185
+            ->with(42)
3186
+            ->willReturn([$node]);
3187
+        $this->rootFolder->method('getUserFolder')
3188
+            ->with($this->currentUser)
3189
+            ->willReturn($userFolder);
3190
+        $share = $this->newShare();
3191
+        $share->setPermissions(Constants::PERMISSION_ALL)
3192
+            ->setSharedBy($this->currentUser)
3193
+            ->setShareType(IShare::TYPE_LINK)
3194
+            ->setPassword('password')
3195
+            ->setSendPasswordByTalk(true)
3196
+            ->setExpirationDate($date)
3197
+            ->setNote('note')
3198
+            ->setLabel('label')
3199
+            ->setHideDownload(true)
3200
+            ->setPermissions(Constants::PERMISSION_ALL)
3201
+            ->setNode($node);
3202
+
3203
+        $node->expects($this->once())
3204
+            ->method('lock')
3205
+            ->with(ILockingProvider::LOCK_SHARED);
3206
+
3207
+        $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3208
+
3209
+        $this->shareManager->expects($this->once())->method('updateShare')->with(
3210
+            $this->callback(function (IShare $share) use ($date) {
3211
+                return $share->getPermissions() === Constants::PERMISSION_ALL
3212
+                && $share->getPassword() === 'newpassword'
3213
+                && $share->getSendPasswordByTalk() === true
3214
+                && $share->getExpirationDate() === $date
3215
+                && $share->getNote() === 'note'
3216
+                && $share->getLabel() === 'label'
3217
+                && $share->getHideDownload() === true;
3218
+            })
3219
+        )->willReturnArgument(0);
3220
+
3221
+        $expected = new DataResponse([]);
3222
+        $result = $ocs->updateShare(42, null, 'newpassword', null, null, null, null, null, null);
3223
+
3224
+        $this->assertInstanceOf(get_class($expected), $result);
3225
+        $this->assertEquals($expected->getData(), $result->getData());
3226
+    }
3227
+
3228
+    public function testUpdateLinkShareSendPasswordByTalkDoesNotChangeOther(): void {
3229
+        $ocs = $this->mockFormatShare();
3230
+
3231
+        $date = new \DateTime('2000-01-01');
3232
+        $date->setTime(0, 0, 0);
3233
+
3234
+        [$userFolder, $node] = $this->getNonSharedUserFolder();
3235
+        $userFolder->method('getById')
3236
+            ->with(42)
3237
+            ->willReturn([$node]);
3238
+        $this->rootFolder->method('getUserFolder')
3239
+            ->with($this->currentUser)
3240
+            ->willReturn($userFolder);
3241
+        $node->method('getId')->willReturn(42);
3242
+        $share = $this->newShare();
3243
+        $share->setPermissions(Constants::PERMISSION_ALL)
3244
+            ->setSharedBy($this->currentUser)
3245
+            ->setShareType(IShare::TYPE_LINK)
3246
+            ->setPassword('password')
3247
+            ->setSendPasswordByTalk(false)
3248
+            ->setExpirationDate($date)
3249
+            ->setNote('note')
3250
+            ->setLabel('label')
3251
+            ->setHideDownload(true)
3252
+            ->setPermissions(Constants::PERMISSION_ALL)
3253
+            ->setNode($node);
3254
+
3255
+        $node->expects($this->once())
3256
+            ->method('lock')
3257
+            ->with(ILockingProvider::LOCK_SHARED);
3258
+
3259
+        $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3260
+
3261
+        $this->appManager->method('isEnabledForUser')->with('spreed')->willReturn(true);
3262
+
3263
+        $this->shareManager->expects($this->once())->method('updateShare')->with(
3264
+            $this->callback(function (IShare $share) use ($date) {
3265
+                return $share->getPermissions() === Constants::PERMISSION_ALL
3266
+                && $share->getPassword() === 'password'
3267
+                && $share->getSendPasswordByTalk() === true
3268
+                && $share->getExpirationDate() === $date
3269
+                && $share->getNote() === 'note'
3270
+                && $share->getLabel() === 'label'
3271
+                && $share->getHideDownload() === true;
3272
+            })
3273
+        )->willReturnArgument(0);
3274
+
3275
+        $expected = new DataResponse([]);
3276
+        $result = $ocs->updateShare(42, null, null, 'true', null, null, null, null, null);
3277
+
3278
+        $this->assertInstanceOf(get_class($expected), $result);
3279
+        $this->assertEquals($expected->getData(), $result->getData());
3280
+    }
3281
+
3282
+
3283
+    public function testUpdateLinkShareSendPasswordByTalkWithTalkDisabledDoesNotChangeOther(): void {
3284
+        $this->expectException(OCSForbiddenException::class);
3285
+        $this->expectExceptionMessage('"Sending the password by Nextcloud Talk" for sharing a file or folder failed because Nextcloud Talk is not enabled.');
3286
+
3287
+        $ocs = $this->mockFormatShare();
3288
+
3289
+        $date = new \DateTime('2000-01-01');
3290
+        $date->setTime(0, 0, 0);
3291
+
3292
+        [$userFolder, $node] = $this->getNonSharedUserFolder();
3293
+        $userFolder->method('getById')
3294
+            ->with(42)
3295
+            ->willReturn([$node]);
3296
+        $this->rootFolder->method('getUserFolder')
3297
+            ->with($this->currentUser)
3298
+            ->willReturn($userFolder);
3299
+        $node->method('getId')->willReturn(42);
3300
+        $share = $this->newShare();
3301
+        $share->setPermissions(Constants::PERMISSION_ALL)
3302
+            ->setSharedBy($this->currentUser)
3303
+            ->setShareType(IShare::TYPE_LINK)
3304
+            ->setPassword('password')
3305
+            ->setSendPasswordByTalk(false)
3306
+            ->setExpirationDate($date)
3307
+            ->setNote('note')
3308
+            ->setLabel('label')
3309
+            ->setHideDownload(true)
3310
+            ->setPermissions(Constants::PERMISSION_ALL)
3311
+            ->setNode($node);
3312
+
3313
+        $node->expects($this->once())
3314
+            ->method('lock')
3315
+            ->with(ILockingProvider::LOCK_SHARED);
3316
+
3317
+        $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3318
+
3319
+        $this->appManager->method('isEnabledForUser')->with('spreed')->willReturn(false);
3320
+
3321
+        $this->shareManager->expects($this->never())->method('updateShare');
3322
+
3323
+        $ocs->updateShare(42, null, null, 'true', null, null, null, null, null);
3324
+    }
3325
+
3326
+    public function testUpdateLinkShareDoNotSendPasswordByTalkDoesNotChangeOther(): void {
3327
+        $ocs = $this->mockFormatShare();
3328
+
3329
+        $date = new \DateTime('2000-01-01');
3330
+        $date->setTime(0, 0, 0);
3331
+
3332
+        [$userFolder, $node] = $this->getNonSharedUserFolder();
3333
+        $userFolder->method('getById')
3334
+            ->with(42)
3335
+            ->willReturn([$node]);
3336
+        $this->rootFolder->method('getUserFolder')
3337
+            ->with($this->currentUser)
3338
+            ->willReturn($userFolder);
3339
+        $node->method('getId')->willReturn(42);
3340
+        $share = $this->newShare();
3341
+        $share->setPermissions(Constants::PERMISSION_ALL)
3342
+            ->setSharedBy($this->currentUser)
3343
+            ->setShareType(IShare::TYPE_LINK)
3344
+            ->setPassword('password')
3345
+            ->setSendPasswordByTalk(true)
3346
+            ->setExpirationDate($date)
3347
+            ->setNote('note')
3348
+            ->setLabel('label')
3349
+            ->setHideDownload(true)
3350
+            ->setPermissions(Constants::PERMISSION_ALL)
3351
+            ->setNode($node);
3352
+
3353
+        $node->expects($this->once())
3354
+            ->method('lock')
3355
+            ->with(ILockingProvider::LOCK_SHARED);
3356
+
3357
+        $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3358
+
3359
+        $this->appManager->method('isEnabledForUser')->with('spreed')->willReturn(true);
3360
+
3361
+        $this->shareManager->expects($this->once())->method('updateShare')->with(
3362
+            $this->callback(function (IShare $share) use ($date) {
3363
+                return $share->getPermissions() === Constants::PERMISSION_ALL
3364
+                && $share->getPassword() === 'password'
3365
+                && $share->getSendPasswordByTalk() === false
3366
+                && $share->getExpirationDate() === $date
3367
+                && $share->getNote() === 'note'
3368
+                && $share->getLabel() === 'label'
3369
+                && $share->getHideDownload() === true;
3370
+            })
3371
+        )->willReturnArgument(0);
3372
+
3373
+        $expected = new DataResponse([]);
3374
+        $result = $ocs->updateShare(42, null, null, 'false', null, null, null, null, null);
3375
+
3376
+        $this->assertInstanceOf(get_class($expected), $result);
3377
+        $this->assertEquals($expected->getData(), $result->getData());
3378
+    }
3379
+
3380
+    public function testUpdateLinkShareDoNotSendPasswordByTalkWithTalkDisabledDoesNotChangeOther(): void {
3381
+        $ocs = $this->mockFormatShare();
3382
+
3383
+        $date = new \DateTime('2000-01-01');
3384
+        $date->setTime(0, 0, 0);
3385
+
3386
+        [$userFolder, $node] = $this->getNonSharedUserFolder();
3387
+        $node->method('getId')
3388
+            ->willReturn(42);
3389
+
3390
+        $share = $this->newShare();
3391
+        $share->setPermissions(Constants::PERMISSION_ALL)
3392
+            ->setSharedBy($this->currentUser)
3393
+            ->setShareType(IShare::TYPE_LINK)
3394
+            ->setPassword('password')
3395
+            ->setSendPasswordByTalk(true)
3396
+            ->setExpirationDate($date)
3397
+            ->setNote('note')
3398
+            ->setLabel('label')
3399
+            ->setHideDownload(true)
3400
+            ->setPermissions(Constants::PERMISSION_ALL)
3401
+            ->setNode($node);
3402
+
3403
+        $node->expects($this->once())
3404
+            ->method('lock')
3405
+            ->with(ILockingProvider::LOCK_SHARED);
3406
+
3407
+        $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3408
+
3409
+        $this->appManager->method('isEnabledForUser')->with('spreed')->willReturn(false);
3410
+
3411
+        $this->shareManager->expects($this->once())->method('updateShare')->with(
3412
+            $this->callback(function (IShare $share) use ($date) {
3413
+                return $share->getPermissions() === Constants::PERMISSION_ALL
3414
+                && $share->getPassword() === 'password'
3415
+                && $share->getSendPasswordByTalk() === false
3416
+                && $share->getExpirationDate() === $date
3417
+                && $share->getNote() === 'note'
3418
+                && $share->getLabel() === 'label'
3419
+                && $share->getHideDownload() === true;
3420
+            })
3421
+        )->willReturnArgument(0);
3422
+
3423
+        $this->rootFolder->method('getUserFolder')
3424
+            ->with($this->currentUser)
3425
+            ->willReturn($userFolder);
3426
+
3427
+        $userFolder->method('getById')
3428
+            ->with(42)
3429
+            ->willReturn([$node]);
3430
+
3431
+        $mountPoint = $this->createMock(IMountPoint::class);
3432
+        $node->method('getMountPoint')
3433
+            ->willReturn($mountPoint);
3434
+        $mountPoint->method('getStorageRootId')
3435
+            ->willReturn(42);
3436
+
3437
+        $mountPoint = $this->createMock(IMountPoint::class);
3438
+        $node->method('getMountPoint')
3439
+            ->willReturn($mountPoint);
3440
+        $mountPoint->method('getStorageRootId')
3441
+            ->willReturn(42);
3442
+
3443
+        $expected = new DataResponse([]);
3444
+        $result = $ocs->updateShare(42, null, null, 'false', null, null, null, null, null);
3445
+
3446
+        $this->assertInstanceOf(get_class($expected), $result);
3447
+        $this->assertEquals($expected->getData(), $result->getData());
3448
+    }
3449
+
3450
+    public function testUpdateLinkShareExpireDateDoesNotChangeOther(): void {
3451
+        $ocs = $this->mockFormatShare();
3452
+
3453
+        [$userFolder, $node] = $this->getNonSharedUserFolder();
3454
+        $node->method('getId')
3455
+            ->willReturn(42);
3456
+
3457
+        $share = $this->newShare();
3458
+        $share->setPermissions(Constants::PERMISSION_ALL)
3459
+            ->setSharedBy($this->currentUser)
3460
+            ->setShareType(IShare::TYPE_LINK)
3461
+            ->setPassword('password')
3462
+            ->setSendPasswordByTalk(true)
3463
+            ->setExpirationDate(new \DateTime())
3464
+            ->setNote('note')
3465
+            ->setLabel('label')
3466
+            ->setHideDownload(true)
3467
+            ->setPermissions(Constants::PERMISSION_ALL)
3468
+            ->setNode($node);
3469
+
3470
+        $node->expects($this->once())
3471
+            ->method('lock')
3472
+            ->with(ILockingProvider::LOCK_SHARED);
3473
+
3474
+        $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3475
+
3476
+        $this->shareManager->expects($this->once())->method('updateShare')->with(
3477
+            $this->callback(function (IShare $share) {
3478
+                $date = new \DateTime('2010-12-23');
3479
+                $date->setTime(0, 0, 0);
3480
+
3481
+                return $share->getPermissions() === Constants::PERMISSION_ALL
3482
+                && $share->getPassword() === 'password'
3483
+                && $share->getSendPasswordByTalk() === true
3484
+                && $share->getExpirationDate() == $date
3485
+                && $share->getNote() === 'note'
3486
+                && $share->getLabel() === 'label'
3487
+                && $share->getHideDownload() === true;
3488
+            })
3489
+        )->willReturnArgument(0);
3490
+
3491
+        $this->rootFolder->method('getUserFolder')
3492
+            ->with($this->currentUser)
3493
+            ->willReturn($userFolder);
3494
+
3495
+        $userFolder->method('getById')
3496
+            ->with(42)
3497
+            ->willReturn([$node]);
3498
+
3499
+        $mountPoint = $this->createMock(IMountPoint::class);
3500
+        $node->method('getMountPoint')
3501
+            ->willReturn($mountPoint);
3502
+        $mountPoint->method('getStorageRootId')
3503
+            ->willReturn(42);
3504
+
3505
+        $expected = new DataResponse([]);
3506
+        $result = $ocs->updateShare(42, null, null, null, null, '2010-12-23', null, null, null);
3507
+
3508
+        $this->assertInstanceOf(get_class($expected), $result);
3509
+        $this->assertEquals($expected->getData(), $result->getData());
3510
+    }
3511
+
3512
+    public function testUpdateLinkSharePublicUploadDoesNotChangeOther(): void {
3513
+        $ocs = $this->mockFormatShare();
3514
+
3515
+        $date = new \DateTime('2000-01-01');
3516
+
3517
+        [$userFolder, $folder] = $this->getNonSharedUserFolder();
3518
+        $folder->method('getId')
3519
+            ->willReturn(42);
3520
+
3521
+        $share = Server::get(IManager::class)->newShare();
3522
+        $share->setPermissions(Constants::PERMISSION_ALL)
3523
+            ->setSharedBy($this->currentUser)
3524
+            ->setShareType(IShare::TYPE_LINK)
3525
+            ->setPassword('password')
3526
+            ->setSendPasswordByTalk(true)
3527
+            ->setExpirationDate($date)
3528
+            ->setNote('note')
3529
+            ->setLabel('label')
3530
+            ->setHideDownload(true)
3531
+            ->setPermissions(Constants::PERMISSION_ALL)
3532
+            ->setNode($folder);
3533
+
3534
+        $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3535
+        $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
3536
+
3537
+        $this->shareManager->expects($this->once())->method('updateShare')->with(
3538
+            $this->callback(function (IShare $share) use ($date) {
3539
+                return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
3540
+                && $share->getPassword() === 'password'
3541
+                && $share->getSendPasswordByTalk() === true
3542
+                && $share->getExpirationDate() === $date
3543
+                && $share->getNote() === 'note'
3544
+                && $share->getLabel() === 'label'
3545
+                && $share->getHideDownload() === true;
3546
+            })
3547
+        )->willReturnArgument(0);
3548
+
3549
+        $this->shareManager->method('getSharedWith')
3550
+            ->willReturn([]);
3551
+
3552
+        $this->rootFolder->method('getUserFolder')
3553
+            ->with($this->currentUser)
3554
+            ->willReturn($userFolder);
3555
+
3556
+        $userFolder->method('getById')
3557
+            ->with(42)
3558
+            ->willReturn([$folder]);
3559
+
3560
+        $mountPoint = $this->createMock(IMountPoint::class);
3561
+        $folder->method('getMountPoint')
3562
+            ->willReturn($mountPoint);
3563
+        $mountPoint->method('getStorageRootId')
3564
+            ->willReturn(42);
3565
+
3566
+        $expected = new DataResponse([]);
3567
+        $result = $ocs->updateShare(42, null, null, null, 'true', null, null, null, null);
3568
+
3569
+        $this->assertInstanceOf(get_class($expected), $result);
3570
+        $this->assertEquals($expected->getData(), $result->getData());
3571
+    }
3572
+
3573
+    public function testUpdateLinkSharePermissions(): void {
3574
+        $ocs = $this->mockFormatShare();
3575
+
3576
+        $date = new \DateTime('2000-01-01');
3577
+
3578
+        [$userFolder, $folder] = $this->getNonSharedUserFolder();
3579
+        $folder->method('getId')
3580
+            ->willReturn(42);
3581
+
3582
+        $share = Server::get(IManager::class)->newShare();
3583
+        $share->setPermissions(Constants::PERMISSION_ALL)
3584
+            ->setSharedBy($this->currentUser)
3585
+            ->setShareType(IShare::TYPE_LINK)
3586
+            ->setPassword('password')
3587
+            ->setSendPasswordByTalk(true)
3588
+            ->setExpirationDate($date)
3589
+            ->setNote('note')
3590
+            ->setLabel('label')
3591
+            ->setHideDownload(true)
3592
+            ->setPermissions(Constants::PERMISSION_ALL)
3593
+            ->setNode($folder);
3594
+
3595
+        $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3596
+        $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
3597
+
3598
+        $this->shareManager->expects($this->once())->method('updateShare')->with(
3599
+            $this->callback(function (IShare $share) use ($date): bool {
3600
+                return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE)
3601
+                && $share->getPassword() === 'password'
3602
+                && $share->getSendPasswordByTalk() === true
3603
+                && $share->getExpirationDate() === $date
3604
+                && $share->getNote() === 'note'
3605
+                && $share->getLabel() === 'label'
3606
+                && $share->getHideDownload() === true;
3607
+            })
3608
+        )->willReturnArgument(0);
3609
+
3610
+        $this->shareManager->method('getSharedWith')->willReturn([]);
3611
+
3612
+        $this->rootFolder->method('getUserFolder')
3613
+            ->with($this->currentUser)
3614
+            ->willReturn($userFolder);
3615
+
3616
+        $userFolder->method('getById')
3617
+            ->with(42)
3618
+            ->willReturn([$folder]);
3619
+
3620
+        $mountPoint = $this->createMock(IMountPoint::class);
3621
+        $folder->method('getMountPoint')
3622
+            ->willReturn($mountPoint);
3623
+        $mountPoint->method('getStorageRootId')
3624
+            ->willReturn(42);
3625
+
3626
+        $expected = new DataResponse([]);
3627
+        $result = $ocs->updateShare(42, 7, null, null, 'true', null, null, null, null);
3628
+
3629
+        $this->assertInstanceOf(get_class($expected), $result);
3630
+        $this->assertEquals($expected->getData(), $result->getData());
3631
+    }
3632
+
3633
+    public function testUpdateLinkSharePermissionsShare(): void {
3634
+        $ocs = $this->mockFormatShare();
3635
+
3636
+        $date = new \DateTime('2000-01-01');
3637
+
3638
+        [$userFolder, $folder] = $this->getNonSharedUserFolder();
3639
+        $folder->method('getId')
3640
+            ->willReturn(42);
3641
+
3642
+        $share = Server::get(IManager::class)->newShare();
3643
+        $share->setPermissions(Constants::PERMISSION_ALL)
3644
+            ->setSharedBy($this->currentUser)
3645
+            ->setShareType(IShare::TYPE_LINK)
3646
+            ->setPassword('password')
3647
+            ->setSendPasswordByTalk(true)
3648
+            ->setExpirationDate($date)
3649
+            ->setNote('note')
3650
+            ->setLabel('label')
3651
+            ->setHideDownload(true)
3652
+            ->setPermissions(Constants::PERMISSION_READ)
3653
+            ->setNode($folder);
3654
+
3655
+        $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3656
+        $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
3657
+
3658
+        $this->shareManager->expects($this->once())
3659
+            ->method('updateShare')
3660
+            ->with(
3661
+                $this->callback(function (IShare $share) use ($date) {
3662
+                    return $share->getPermissions() === Constants::PERMISSION_ALL
3663
+                        && $share->getPassword() === 'password'
3664
+                        && $share->getSendPasswordByTalk() === true
3665
+                        && $share->getExpirationDate() === $date
3666
+                        && $share->getNote() === 'note'
3667
+                        && $share->getLabel() === 'label'
3668
+                        && $share->getHideDownload() === true;
3669
+                })
3670
+            )->willReturnArgument(0);
3671
+
3672
+        $this->rootFolder->method('getUserFolder')
3673
+            ->with($this->currentUser)
3674
+            ->willReturn($userFolder);
3675
+
3676
+        $userFolder->method('getById')
3677
+            ->with(42)
3678
+            ->willReturn([$folder]);
3679
+
3680
+        $mountPoint = $this->createMock(IMountPoint::class);
3681
+        $folder->method('getMountPoint')
3682
+            ->willReturn($mountPoint);
3683
+        $mountPoint->method('getStorageRootId')
3684
+            ->willReturn(42);
3685
+
3686
+        $this->shareManager->method('getSharedWith')->willReturn([]);
3687
+
3688
+        $expected = new DataResponse([]);
3689
+        $result = $ocs->updateShare(42, Constants::PERMISSION_ALL, null, null, null, null, null, null, null);
3690
+
3691
+        $this->assertInstanceOf(get_class($expected), $result);
3692
+        $this->assertEquals($expected->getData(), $result->getData());
3693
+    }
3694
+
3695
+    public function testUpdateOtherPermissions(): void {
3696
+        $ocs = $this->mockFormatShare();
3697
+
3698
+        [$userFolder, $file] = $this->getNonSharedUserFolder();
3699
+        $file->method('getId')
3700
+            ->willReturn(42);
3701
+
3702
+        $share = Server::get(IManager::class)->newShare();
3703
+        $share->setPermissions(Constants::PERMISSION_ALL)
3704
+            ->setSharedBy($this->currentUser)
3705
+            ->setShareType(IShare::TYPE_USER)
3706
+            ->setNode($file);
3707
+
3708
+        $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3709
+        $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
3710
+
3711
+        $this->shareManager->expects($this->once())->method('updateShare')->with(
3712
+            $this->callback(function (IShare $share) {
3713
+                return $share->getPermissions() === Constants::PERMISSION_ALL;
3714
+            })
3715
+        )->willReturnArgument(0);
3716
+
3717
+        $this->shareManager->method('getSharedWith')->willReturn([]);
3718
+
3719
+        [$userFolder, $folder] = $this->getNonSharedUserFolder();
3720
+        $this->rootFolder->method('getUserFolder')
3721
+            ->with($this->currentUser)
3722
+            ->willReturn($userFolder);
3723
+
3724
+        $userFolder->method('getById')
3725
+            ->with(42)
3726
+            ->willReturn([$file]);
3727
+
3728
+        $mountPoint = $this->createMock(IMountPoint::class);
3729
+        $file->method('getMountPoint')
3730
+            ->willReturn($mountPoint);
3731
+        $mountPoint->method('getStorageRootId')
3732
+            ->willReturn(42);
3733
+
3734
+        $expected = new DataResponse([]);
3735
+        $result = $ocs->updateShare(42, 31, null, null, null, null);
3736
+
3737
+        $this->assertInstanceOf(get_class($expected), $result);
3738
+        $this->assertEquals($expected->getData(), $result->getData());
3739
+    }
3740
+
3741
+    public function testUpdateShareCannotIncreasePermissions(): void {
3742
+        $ocs = $this->mockFormatShare();
3743
+
3744
+        [$userFolder, $folder] = $this->getNonSharedUserFolder();
3745
+        $folder->method('getId')
3746
+            ->willReturn(42);
3747
+
3748
+        $share = Server::get(IManager::class)->newShare();
3749
+        $share
3750
+            ->setId(42)
3751
+            ->setSharedBy($this->currentUser)
3752
+            ->setShareOwner('anotheruser')
3753
+            ->setShareType(IShare::TYPE_GROUP)
3754
+            ->setSharedWith('group1')
3755
+            ->setPermissions(Constants::PERMISSION_READ)
3756
+            ->setNode($folder);
3757
+
3758
+        // note: updateShare will modify the received instance but getSharedWith will reread from the database,
3759
+        // so their values will be different
3760
+        $incomingShare = Server::get(IManager::class)->newShare();
3761
+        $incomingShare
3762
+            ->setId(42)
3763
+            ->setSharedBy($this->currentUser)
3764
+            ->setShareOwner('anotheruser')
3765
+            ->setShareType(IShare::TYPE_GROUP)
3766
+            ->setSharedWith('group1')
3767
+            ->setPermissions(Constants::PERMISSION_READ)
3768
+            ->setNode($folder);
3769
+
3770
+        $this->request
3771
+            ->method('getParam')
3772
+            ->willReturnMap([
3773
+                ['permissions', null, '31'],
3774
+            ]);
3775
+
3776
+        $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3777
+
3778
+        $this->shareManager->expects($this->any())
3779
+            ->method('getSharedWith')
3780
+            ->willReturnMap([
3781
+                ['currentUser', IShare::TYPE_USER, $share->getNode(), -1, 0, []],
3782
+                ['currentUser', IShare::TYPE_GROUP, $share->getNode(), -1, 0, [$incomingShare]],
3783
+                ['currentUser', IShare::TYPE_ROOM, $share->getNode(), -1, 0, []]
3784
+            ]);
3785
+
3786
+        $this->rootFolder->method('getUserFolder')
3787
+            ->with($this->currentUser)
3788
+            ->willReturn($userFolder);
3789
+
3790
+        $userFolder->method('getById')
3791
+            ->with(42)
3792
+            ->willReturn([$folder]);
3793
+        $userFolder->method('getFirstNodeById')
3794
+            ->with(42)
3795
+            ->willReturn($folder);
3796
+
3797
+        $mountPoint = $this->createMock(IMountPoint::class);
3798
+        $folder->method('getMountPoint')
3799
+            ->willReturn($mountPoint);
3800
+        $mountPoint->method('getStorageRootId')
3801
+            ->willReturn(42);
3802
+
3803
+        $this->shareManager->expects($this->once())
3804
+            ->method('updateShare')
3805
+            ->with($share)
3806
+            ->willThrowException(new GenericShareException('Cannot increase permissions of path/file', 'Cannot increase permissions of path/file', 404));
3807
+
3808
+        try {
3809
+            $ocs->updateShare(42, 31);
3810
+            $this->fail();
3811
+        } catch (OCSException $e) {
3812
+            $this->assertEquals('Cannot increase permissions of path/file', $e->getMessage());
3813
+        }
3814
+    }
3815
+
3816
+    public function testUpdateShareCanIncreasePermissionsIfOwner(): void {
3817
+        $ocs = $this->mockFormatShare();
3818
+
3819
+        [$userFolder, $folder] = $this->getNonSharedUserFolder();
3820
+        $folder->method('getId')
3821
+            ->willReturn(42);
3822
+
3823
+        $share = Server::get(IManager::class)->newShare();
3824
+        $share
3825
+            ->setId(42)
3826
+            ->setSharedBy($this->currentUser)
3827
+            ->setShareOwner($this->currentUser)
3828
+            ->setShareType(IShare::TYPE_GROUP)
3829
+            ->setSharedWith('group1')
3830
+            ->setPermissions(Constants::PERMISSION_READ)
3831
+            ->setNode($folder);
3832
+
3833
+        // note: updateShare will modify the received instance but getSharedWith will reread from the database,
3834
+        // so their values will be different
3835
+        $incomingShare = Server::get(IManager::class)->newShare();
3836
+        $incomingShare
3837
+            ->setId(42)
3838
+            ->setSharedBy($this->currentUser)
3839
+            ->setShareOwner($this->currentUser)
3840
+            ->setShareType(IShare::TYPE_GROUP)
3841
+            ->setSharedWith('group1')
3842
+            ->setPermissions(Constants::PERMISSION_READ)
3843
+            ->setNode($folder);
3844
+
3845
+        $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
3846
+
3847
+        $this->shareManager->expects($this->any())
3848
+            ->method('getSharedWith')
3849
+            ->willReturnMap([
3850
+                ['currentUser', IShare::TYPE_USER, $share->getNode(), -1, 0, []],
3851
+                ['currentUser', IShare::TYPE_GROUP, $share->getNode(), -1, 0, [$incomingShare]]
3852
+            ]);
3853
+
3854
+        $this->shareManager->expects($this->once())
3855
+            ->method('updateShare')
3856
+            ->with($share)
3857
+            ->willReturn($share);
3858
+
3859
+        $this->rootFolder->method('getUserFolder')
3860
+            ->with($this->currentUser)
3861
+            ->willReturn($userFolder);
3862
+
3863
+        $userFolder->method('getById')
3864
+            ->with(42)
3865
+            ->willReturn([$folder]);
3866
+
3867
+        $mountPoint = $this->createMock(IMountPoint::class);
3868
+        $folder->method('getMountPoint')
3869
+            ->willReturn($mountPoint);
3870
+        $mountPoint->method('getStorageRootId')
3871
+            ->willReturn(42);
3872
+
3873
+        $result = $ocs->updateShare(42, 31);
3874
+        $this->assertInstanceOf(DataResponse::class, $result);
3875
+    }
3876
+
3877
+    public function testUpdateShareOwnerless(): void {
3878
+        $ocs = $this->mockFormatShare();
3879
+
3880
+        $mount = $this->createMock(IShareOwnerlessMount::class);
3881
+
3882
+        $file = $this->createMock(File::class);
3883
+        $file
3884
+            ->expects($this->exactly(2))
3885
+            ->method('getPermissions')
3886
+            ->willReturn(Constants::PERMISSION_SHARE);
3887
+        $file
3888
+            ->expects($this->once())
3889
+            ->method('getMountPoint')
3890
+            ->willReturn($mount);
3891
+
3892
+        $userFolder = $this->createMock(Folder::class);
3893
+        $userFolder->method('getById')
3894
+            ->with(2)
3895
+            ->willReturn([$file]);
3896
+        $userFolder->method('getFirstNodeById')
3897
+            ->with(2)
3898
+            ->willReturn($file);
3899
+
3900
+        $this->rootFolder
3901
+            ->method('getUserFolder')
3902
+            ->with($this->currentUser)
3903
+            ->willReturn($userFolder);
3904
+
3905
+        $share = $this->createMock(IShare::class);
3906
+        $share
3907
+            ->expects($this->once())
3908
+            ->method('getNode')
3909
+            ->willReturn($file);
3910
+        $share
3911
+            ->expects($this->exactly(2))
3912
+            ->method('getNodeId')
3913
+            ->willReturn(2);
3914
+        $share
3915
+            ->expects($this->exactly(2))
3916
+            ->method('getPermissions')
3917
+            ->willReturn(Constants::PERMISSION_SHARE);
3918
+
3919
+        $this->shareManager
3920
+            ->expects($this->once())
3921
+            ->method('getShareById')
3922
+            ->with('ocinternal:1', $this->currentUser)
3923
+            ->willReturn($share);
3924
+
3925
+        $this->shareManager
3926
+            ->expects($this->once())
3927
+            ->method('updateShare')
3928
+            ->with($share)
3929
+            ->willReturn($share);
3930
+
3931
+        $result = $ocs->updateShare(1, Constants::PERMISSION_ALL);
3932
+        $this->assertInstanceOf(DataResponse::class, $result);
3933
+    }
3934
+
3935
+    public function dataFormatShare() {
3936
+        $file = $this->getMockBuilder(File::class)->getMock();
3937
+        $folder = $this->getMockBuilder(Folder::class)->getMock();
3938
+        $parent = $this->getMockBuilder(Folder::class)->getMock();
3939
+        $fileWithPreview = $this->getMockBuilder(File::class)->getMock();
3940
+
3941
+        $file->method('getMimeType')->willReturn('myMimeType');
3942
+        $folder->method('getMimeType')->willReturn('myFolderMimeType');
3943
+        $fileWithPreview->method('getMimeType')->willReturn('mimeWithPreview');
3944
+
3945
+        $mountPoint = $this->createMock(IMountPoint::class);
3946
+        $mountPoint->method('getMountType')->willReturn('');
3947
+        $file->method('getMountPoint')->willReturn($mountPoint);
3948
+        $folder->method('getMountPoint')->willReturn($mountPoint);
3949
+        $fileWithPreview->method('getMountPoint')->willReturn($mountPoint);
3950
+
3951
+        $file->method('getPath')->willReturn('file');
3952
+        $folder->method('getPath')->willReturn('folder');
3953
+        $fileWithPreview->method('getPath')->willReturn('fileWithPreview');
3954
+
3955
+        $parent->method('getId')->willReturn(1);
3956
+        $folder->method('getId')->willReturn(2);
3957
+        $file->method('getId')->willReturn(3);
3958
+        $fileWithPreview->method('getId')->willReturn(4);
3959
+
3960
+        $file->method('getParent')->willReturn($parent);
3961
+        $folder->method('getParent')->willReturn($parent);
3962
+        $fileWithPreview->method('getParent')->willReturn($parent);
3963
+
3964
+        $file->method('getSize')->willReturn(123456);
3965
+        $folder->method('getSize')->willReturn(123456);
3966
+        $fileWithPreview->method('getSize')->willReturn(123456);
3967
+        $file->method('getMTime')->willReturn(1234567890);
3968
+        $folder->method('getMTime')->willReturn(1234567890);
3969
+        $fileWithPreview->method('getMTime')->willReturn(1234567890);
3970
+
3971
+        $cache = $this->getMockBuilder('OCP\Files\Cache\ICache')->getMock();
3972
+        $cache->method('getNumericStorageId')->willReturn(100);
3973
+        $storage = $this->createMock(IStorage::class);
3974
+        $storage->method('getId')->willReturn('storageId');
3975
+        $storage->method('getCache')->willReturn($cache);
3976
+
3977
+        $file->method('getStorage')->willReturn($storage);
3978
+        $folder->method('getStorage')->willReturn($storage);
3979
+        $fileWithPreview->method('getStorage')->willReturn($storage);
3980
+
3981
+
3982
+        $mountPoint = $this->getMockBuilder(IMountPoint::class)->getMock();
3983
+        $mountPoint->method('getMountType')->willReturn('');
3984
+        $file->method('getMountPoint')->willReturn($mountPoint);
3985
+        $folder->method('getMountPoint')->willReturn($mountPoint);
3986
+
3987
+        $owner = $this->getMockBuilder(IUser::class)->getMock();
3988
+        $owner->method('getDisplayName')->willReturn('ownerDN');
3989
+        $initiator = $this->getMockBuilder(IUser::class)->getMock();
3990
+        $initiator->method('getDisplayName')->willReturn('initiatorDN');
3991
+        $recipient = $this->getMockBuilder(IUser::class)->getMock();
3992
+        $recipient->method('getDisplayName')->willReturn('recipientDN');
3993
+        $recipient->method('getSystemEMailAddress')->willReturn('recipient');
3994
+        [$shareAttributes, $shareAttributesReturnJson] = $this->mockShareAttributes();
3995
+
3996
+        $result = [];
3997
+
3998
+        $share = Server::get(IManager::class)->newShare();
3999
+        $share->setShareType(IShare::TYPE_USER)
4000
+            ->setSharedWith('recipient')
4001
+            ->setSharedBy('initiator')
4002
+            ->setShareOwner('owner')
4003
+            ->setPermissions(Constants::PERMISSION_READ)
4004
+            ->setAttributes($shareAttributes)
4005
+            ->setNode($file)
4006
+            ->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4007
+            ->setTarget('myTarget')
4008
+            ->setNote('personal note')
4009
+            ->setId(42);
4010
+
4011
+        // User backend down
4012
+        $result[] = [
4013
+            [
4014
+                'id' => '42',
4015
+                'share_type' => IShare::TYPE_USER,
4016
+                'uid_owner' => 'initiator',
4017
+                'displayname_owner' => 'initiator',
4018
+                'permissions' => 1,
4019
+                'attributes' => $shareAttributesReturnJson,
4020
+                'stime' => 946684862,
4021
+                'parent' => null,
4022
+                'expiration' => null,
4023
+                'token' => null,
4024
+                'uid_file_owner' => 'owner',
4025
+                'displayname_file_owner' => 'owner',
4026
+                'path' => 'file',
4027
+                'item_type' => 'file',
4028
+                'storage_id' => 'storageId',
4029
+                'storage' => 100,
4030
+                'item_source' => 3,
4031
+                'file_source' => 3,
4032
+                'file_parent' => 1,
4033
+                'file_target' => 'myTarget',
4034
+                'share_with' => 'recipient',
4035
+                'share_with_displayname' => 'recipient',
4036
+                'share_with_displayname_unique' => 'recipient',
4037
+                'note' => 'personal note',
4038
+                'label' => '',
4039
+                'mail_send' => 0,
4040
+                'mimetype' => 'myMimeType',
4041
+                'has_preview' => false,
4042
+                'hide_download' => 0,
4043
+                'can_edit' => false,
4044
+                'can_delete' => false,
4045
+                'item_size' => 123456,
4046
+                'item_mtime' => 1234567890,
4047
+                'is-mount-root' => false,
4048
+                'mount-type' => '',
4049
+                'attributes' => '[{"scope":"permissions","key":"download","value":true}]',
4050
+                'item_permissions' => 1,
4051
+            ], $share, [], false
4052
+        ];
4053
+        // User backend up
4054
+        $result[] = [
4055
+            [
4056
+                'id' => '42',
4057
+                'share_type' => IShare::TYPE_USER,
4058
+                'uid_owner' => 'initiator',
4059
+                'displayname_owner' => 'initiatorDN',
4060
+                'permissions' => 1,
4061
+                'attributes' => $shareAttributesReturnJson,
4062
+                'stime' => 946684862,
4063
+                'parent' => null,
4064
+                'expiration' => null,
4065
+                'token' => null,
4066
+                'uid_file_owner' => 'owner',
4067
+                'displayname_file_owner' => 'ownerDN',
4068
+                'note' => 'personal note',
4069
+                'label' => '',
4070
+                'path' => 'file',
4071
+                'item_type' => 'file',
4072
+                'storage_id' => 'storageId',
4073
+                'storage' => 100,
4074
+                'item_source' => 3,
4075
+                'file_source' => 3,
4076
+                'file_parent' => 1,
4077
+                'file_target' => 'myTarget',
4078
+                'share_with' => 'recipient',
4079
+                'share_with_displayname' => 'recipientDN',
4080
+                'share_with_displayname_unique' => 'recipient',
4081
+                'mail_send' => 0,
4082
+                'mimetype' => 'myMimeType',
4083
+                'has_preview' => false,
4084
+                'hide_download' => 0,
4085
+                'can_edit' => false,
4086
+                'can_delete' => false,
4087
+                'item_size' => 123456,
4088
+                'item_mtime' => 1234567890,
4089
+                'is-mount-root' => false,
4090
+                'mount-type' => '',
4091
+                'attributes' => '[{"scope":"permissions","key":"download","value":true}]',
4092
+                'item_permissions' => 1,
4093
+            ], $share, [
4094
+                ['owner', $owner],
4095
+                ['initiator', $initiator],
4096
+                ['recipient', $recipient],
4097
+            ], false
4098
+        ];
4099
+
4100
+        $share = Server::get(IManager::class)->newShare();
4101
+        $share->setShareType(IShare::TYPE_USER)
4102
+            ->setSharedWith('recipient')
4103
+            ->setSharedBy('initiator')
4104
+            ->setShareOwner('owner')
4105
+            ->setPermissions(Constants::PERMISSION_READ)
4106
+            ->setNode($file)
4107
+            ->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4108
+            ->setTarget('myTarget')
4109
+            ->setNote('personal note')
4110
+            ->setId(42);
4111
+        // User backend down
4112
+        $result[] = [
4113
+            [
4114
+                'id' => '42',
4115
+                'share_type' => IShare::TYPE_USER,
4116
+                'uid_owner' => 'initiator',
4117
+                'displayname_owner' => 'initiator',
4118
+                'permissions' => 1,
4119
+                'attributes' => null,
4120
+                'stime' => 946684862,
4121
+                'parent' => null,
4122
+                'expiration' => null,
4123
+                'token' => null,
4124
+                'uid_file_owner' => 'owner',
4125
+                'displayname_file_owner' => 'owner',
4126
+                'note' => 'personal note',
4127
+                'label' => '',
4128
+                'path' => 'file',
4129
+                'item_type' => 'file',
4130
+                'storage_id' => 'storageId',
4131
+                'storage' => 100,
4132
+                'item_source' => 3,
4133
+                'file_source' => 3,
4134
+                'file_parent' => 1,
4135
+                'file_target' => 'myTarget',
4136
+                'share_with' => 'recipient',
4137
+                'share_with_displayname' => 'recipient',
4138
+                'share_with_displayname_unique' => 'recipient',
4139
+                'mail_send' => 0,
4140
+                'mimetype' => 'myMimeType',
4141
+                'has_preview' => false,
4142
+                'hide_download' => 0,
4143
+                'can_edit' => false,
4144
+                'can_delete' => false,
4145
+                'item_size' => 123456,
4146
+                'item_mtime' => 1234567890,
4147
+                'is-mount-root' => false,
4148
+                'mount-type' => '',
4149
+                'attributes' => null,
4150
+                'item_permissions' => 1,
4151
+            ], $share, [], false
4152
+        ];
4153
+
4154
+        $share = Server::get(IManager::class)->newShare();
4155
+        $share->setShareType(IShare::TYPE_USER)
4156
+            ->setSharedWith('recipient')
4157
+            ->setSharedBy('initiator')
4158
+            ->setShareOwner('currentUser')
4159
+            ->setPermissions(Constants::PERMISSION_READ)
4160
+            ->setNode($file)
4161
+            ->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4162
+            ->setTarget('myTarget')
4163
+            ->setNote('personal note')
4164
+            ->setId(42);
4165
+        // User backend down
4166
+        $result[] = [
4167
+            [
4168
+                'id' => '42',
4169
+                'share_type' => IShare::TYPE_USER,
4170
+                'uid_owner' => 'initiator',
4171
+                'displayname_owner' => 'initiator',
4172
+                'permissions' => 1,
4173
+                'attributes' => null,
4174
+                'stime' => 946684862,
4175
+                'parent' => null,
4176
+                'expiration' => null,
4177
+                'token' => null,
4178
+                'uid_file_owner' => 'currentUser',
4179
+                'displayname_file_owner' => 'currentUser',
4180
+                'note' => 'personal note',
4181
+                'label' => '',
4182
+                'path' => 'file',
4183
+                'item_type' => 'file',
4184
+                'storage_id' => 'storageId',
4185
+                'storage' => 100,
4186
+                'item_source' => 3,
4187
+                'file_source' => 3,
4188
+                'file_parent' => 1,
4189
+                'file_target' => 'myTarget',
4190
+                'share_with' => 'recipient',
4191
+                'share_with_displayname' => 'recipient',
4192
+                'share_with_displayname_unique' => 'recipient',
4193
+                'mail_send' => 0,
4194
+                'mimetype' => 'myMimeType',
4195
+                'has_preview' => false,
4196
+                'hide_download' => 0,
4197
+                'can_edit' => true,
4198
+                'can_delete' => true,
4199
+                'item_size' => 123456,
4200
+                'item_mtime' => 1234567890,
4201
+                'is-mount-root' => false,
4202
+                'mount-type' => '',
4203
+                'attributes' => null,
4204
+                'item_permissions' => 11,
4205
+            ], $share, [], false
4206
+        ];
4207
+
4208
+        // with existing group
4209
+
4210
+        $share = Server::get(IManager::class)->newShare();
4211
+        $share->setShareType(IShare::TYPE_GROUP)
4212
+            ->setSharedWith('recipientGroup')
4213
+            ->setSharedBy('initiator')
4214
+            ->setShareOwner('owner')
4215
+            ->setPermissions(Constants::PERMISSION_READ)
4216
+            ->setNode($file)
4217
+            ->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4218
+            ->setTarget('myTarget')
4219
+            ->setNote('personal note')
4220
+            ->setId(42);
4221
+
4222
+        $result[] = [
4223
+            [
4224
+                'id' => '42',
4225
+                'share_type' => IShare::TYPE_GROUP,
4226
+                'uid_owner' => 'initiator',
4227
+                'displayname_owner' => 'initiator',
4228
+                'permissions' => 1,
4229
+                'attributes' => null,
4230
+                'stime' => 946684862,
4231
+                'parent' => null,
4232
+                'expiration' => null,
4233
+                'token' => null,
4234
+                'uid_file_owner' => 'owner',
4235
+                'displayname_file_owner' => 'owner',
4236
+                'note' => 'personal note',
4237
+                'label' => '',
4238
+                'path' => 'file',
4239
+                'item_type' => 'file',
4240
+                'storage_id' => 'storageId',
4241
+                'storage' => 100,
4242
+                'item_source' => 3,
4243
+                'file_source' => 3,
4244
+                'file_parent' => 1,
4245
+                'file_target' => 'myTarget',
4246
+                'share_with' => 'recipientGroup',
4247
+                'share_with_displayname' => 'recipientGroupDisplayName',
4248
+                'mail_send' => 0,
4249
+                'mimetype' => 'myMimeType',
4250
+                'has_preview' => false,
4251
+                'hide_download' => 0,
4252
+                'can_edit' => false,
4253
+                'can_delete' => false,
4254
+                'item_size' => 123456,
4255
+                'item_mtime' => 1234567890,
4256
+                'is-mount-root' => false,
4257
+                'mount-type' => '',
4258
+                'attributes' => null,
4259
+                'item_permissions' => 1,
4260
+            ], $share, [], false
4261
+        ];
4262
+
4263
+        // with unknown group / no group backend
4264
+        $share = Server::get(IManager::class)->newShare();
4265
+        $share->setShareType(IShare::TYPE_GROUP)
4266
+            ->setSharedWith('recipientGroup2')
4267
+            ->setSharedBy('initiator')
4268
+            ->setShareOwner('owner')
4269
+            ->setPermissions(Constants::PERMISSION_READ)
4270
+            ->setNode($file)
4271
+            ->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4272
+            ->setTarget('myTarget')
4273
+            ->setNote('personal note')
4274
+            ->setId(42);
4275
+        $result[] = [
4276
+            [
4277
+                'id' => '42',
4278
+                'share_type' => IShare::TYPE_GROUP,
4279
+                'uid_owner' => 'initiator',
4280
+                'displayname_owner' => 'initiator',
4281
+                'permissions' => 1,
4282
+                'stime' => 946684862,
4283
+                'parent' => null,
4284
+                'expiration' => null,
4285
+                'token' => null,
4286
+                'uid_file_owner' => 'owner',
4287
+                'displayname_file_owner' => 'owner',
4288
+                'note' => 'personal note',
4289
+                'label' => '',
4290
+                'path' => 'file',
4291
+                'item_type' => 'file',
4292
+                'storage_id' => 'storageId',
4293
+                'storage' => 100,
4294
+                'item_source' => 3,
4295
+                'file_source' => 3,
4296
+                'file_parent' => 1,
4297
+                'file_target' => 'myTarget',
4298
+                'share_with' => 'recipientGroup2',
4299
+                'share_with_displayname' => 'recipientGroup2',
4300
+                'mail_send' => 0,
4301
+                'mimetype' => 'myMimeType',
4302
+                'has_preview' => false,
4303
+                'hide_download' => 0,
4304
+                'can_edit' => false,
4305
+                'can_delete' => false,
4306
+                'item_size' => 123456,
4307
+                'item_mtime' => 1234567890,
4308
+                'is-mount-root' => false,
4309
+                'mount-type' => '',
4310
+                'attributes' => null,
4311
+                'item_permissions' => 1,
4312
+            ], $share, [], false
4313
+        ];
4314
+
4315
+        $share = Server::get(IManager::class)->newShare();
4316
+        $share->setShareType(IShare::TYPE_LINK)
4317
+            ->setSharedBy('initiator')
4318
+            ->setShareOwner('owner')
4319
+            ->setPermissions(Constants::PERMISSION_READ)
4320
+            ->setNode($file)
4321
+            ->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4322
+            ->setTarget('myTarget')
4323
+            ->setPassword('mypassword')
4324
+            ->setExpirationDate(new \DateTime('2001-01-02T00:00:00'))
4325
+            ->setToken('myToken')
4326
+            ->setNote('personal note')
4327
+            ->setLabel('new link share')
4328
+            ->setId(42);
4329
+
4330
+        $result[] = [
4331
+            [
4332
+                'id' => '42',
4333
+                'share_type' => IShare::TYPE_LINK,
4334
+                'uid_owner' => 'initiator',
4335
+                'displayname_owner' => 'initiator',
4336
+                'permissions' => 1,
4337
+                'attributes' => null,
4338
+                'stime' => 946684862,
4339
+                'parent' => null,
4340
+                'expiration' => '2001-01-02 00:00:00',
4341
+                'token' => 'myToken',
4342
+                'uid_file_owner' => 'owner',
4343
+                'displayname_file_owner' => 'owner',
4344
+                'note' => 'personal note',
4345
+                'label' => 'new link share',
4346
+                'path' => 'file',
4347
+                'item_type' => 'file',
4348
+                'storage_id' => 'storageId',
4349
+                'storage' => 100,
4350
+                'item_source' => 3,
4351
+                'file_source' => 3,
4352
+                'file_parent' => 1,
4353
+                'file_target' => 'myTarget',
4354
+                'password' => 'mypassword',
4355
+                'share_with' => 'mypassword',
4356
+                'share_with_displayname' => '(Shared link)',
4357
+                'send_password_by_talk' => false,
4358
+                'mail_send' => 0,
4359
+                'url' => 'myLink',
4360
+                'mimetype' => 'myMimeType',
4361
+                'has_preview' => false,
4362
+                'hide_download' => 0,
4363
+                'can_edit' => false,
4364
+                'can_delete' => false,
4365
+                'item_size' => 123456,
4366
+                'item_mtime' => 1234567890,
4367
+                'is-mount-root' => false,
4368
+                'mount-type' => '',
4369
+                'attributes' => null,
4370
+                'item_permissions' => 1,
4371
+            ], $share, [], false
4372
+        ];
4373
+
4374
+        $share = Server::get(IManager::class)->newShare();
4375
+        $share->setShareType(IShare::TYPE_LINK)
4376
+            ->setSharedBy('initiator')
4377
+            ->setShareOwner('owner')
4378
+            ->setPermissions(Constants::PERMISSION_READ)
4379
+            ->setNode($file)
4380
+            ->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4381
+            ->setTarget('myTarget')
4382
+            ->setPassword('mypassword')
4383
+            ->setSendPasswordByTalk(true)
4384
+            ->setExpirationDate(new \DateTime('2001-01-02T00:00:00'))
4385
+            ->setToken('myToken')
4386
+            ->setNote('personal note')
4387
+            ->setLabel('new link share')
4388
+            ->setId(42);
4389
+
4390
+        $result[] = [
4391
+            [
4392
+                'id' => '42',
4393
+                'share_type' => IShare::TYPE_LINK,
4394
+                'uid_owner' => 'initiator',
4395
+                'displayname_owner' => 'initiator',
4396
+                'permissions' => 1,
4397
+                'stime' => 946684862,
4398
+                'parent' => null,
4399
+                'expiration' => '2001-01-02 00:00:00',
4400
+                'token' => 'myToken',
4401
+                'uid_file_owner' => 'owner',
4402
+                'displayname_file_owner' => 'owner',
4403
+                'note' => 'personal note',
4404
+                'label' => 'new link share',
4405
+                'path' => 'file',
4406
+                'item_type' => 'file',
4407
+                'storage_id' => 'storageId',
4408
+                'storage' => 100,
4409
+                'item_source' => 3,
4410
+                'file_source' => 3,
4411
+                'file_parent' => 1,
4412
+                'file_target' => 'myTarget',
4413
+                'password' => 'mypassword',
4414
+                'share_with' => 'mypassword',
4415
+                'share_with_displayname' => '(Shared link)',
4416
+                'send_password_by_talk' => true,
4417
+                'mail_send' => 0,
4418
+                'url' => 'myLink',
4419
+                'mimetype' => 'myMimeType',
4420
+                'has_preview' => false,
4421
+                'hide_download' => 0,
4422
+                'can_edit' => false,
4423
+                'can_delete' => false,
4424
+                'item_size' => 123456,
4425
+                'item_mtime' => 1234567890,
4426
+                'is-mount-root' => false,
4427
+                'mount-type' => '',
4428
+                'attributes' => null,
4429
+                'item_permissions' => 1,
4430
+            ], $share, [], false
4431
+        ];
4432
+
4433
+        $share = Server::get(IManager::class)->newShare();
4434
+        $share->setShareType(IShare::TYPE_REMOTE)
4435
+            ->setSharedBy('initiator')
4436
+            ->setSharedWith('[email protected]')
4437
+            ->setShareOwner('owner')
4438
+            ->setPermissions(Constants::PERMISSION_READ)
4439
+            ->setNode($folder)
4440
+            ->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4441
+            ->setExpirationDate(new \DateTime('2001-02-03T04:05:06'))
4442
+            ->setTarget('myTarget')
4443
+            ->setNote('personal note')
4444
+            ->setId(42);
4445
+
4446
+        $result[] = [
4447
+            [
4448
+                'id' => '42',
4449
+                'share_type' => IShare::TYPE_REMOTE,
4450
+                'uid_owner' => 'initiator',
4451
+                'displayname_owner' => 'initiator',
4452
+                'permissions' => 1,
4453
+                'stime' => 946684862,
4454
+                'parent' => null,
4455
+                'expiration' => '2001-02-03 00:00:00',
4456
+                'token' => null,
4457
+                'uid_file_owner' => 'owner',
4458
+                'displayname_file_owner' => 'owner',
4459
+                'note' => 'personal note',
4460
+                'label' => '',
4461
+                'path' => 'folder',
4462
+                'item_type' => 'folder',
4463
+                'storage_id' => 'storageId',
4464
+                'storage' => 100,
4465
+                'item_source' => 2,
4466
+                'file_source' => 2,
4467
+                'file_parent' => 1,
4468
+                'file_target' => 'myTarget',
4469
+                'share_with' => '[email protected]',
4470
+                'share_with_displayname' => 'foobar',
4471
+                'mail_send' => 0,
4472
+                'mimetype' => 'myFolderMimeType',
4473
+                'has_preview' => false,
4474
+                'hide_download' => 0,
4475
+                'can_edit' => false,
4476
+                'can_delete' => false,
4477
+                'item_size' => 123456,
4478
+                'item_mtime' => 1234567890,
4479
+                'is-mount-root' => false,
4480
+                'mount-type' => '',
4481
+                'attributes' => null,
4482
+                'item_permissions' => 1,
4483
+            ], $share, [], false
4484
+        ];
4485
+
4486
+        $share = Server::get(IManager::class)->newShare();
4487
+        $share->setShareType(IShare::TYPE_REMOTE_GROUP)
4488
+            ->setSharedBy('initiator')
4489
+            ->setSharedWith('[email protected]')
4490
+            ->setShareOwner('owner')
4491
+            ->setPermissions(Constants::PERMISSION_READ)
4492
+            ->setNode($folder)
4493
+            ->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4494
+            ->setExpirationDate(new \DateTime('2001-02-03T04:05:06'))
4495
+            ->setTarget('myTarget')
4496
+            ->setNote('personal note')
4497
+            ->setId(42);
4498
+
4499
+        $result[] = [
4500
+            [
4501
+                'id' => '42',
4502
+                'share_type' => IShare::TYPE_REMOTE_GROUP,
4503
+                'uid_owner' => 'initiator',
4504
+                'displayname_owner' => 'initiator',
4505
+                'permissions' => 1,
4506
+                'stime' => 946684862,
4507
+                'parent' => null,
4508
+                'expiration' => '2001-02-03 00:00:00',
4509
+                'token' => null,
4510
+                'uid_file_owner' => 'owner',
4511
+                'displayname_file_owner' => 'owner',
4512
+                'note' => 'personal note',
4513
+                'label' => '',
4514
+                'path' => 'folder',
4515
+                'item_type' => 'folder',
4516
+                'storage_id' => 'storageId',
4517
+                'storage' => 100,
4518
+                'item_source' => 2,
4519
+                'file_source' => 2,
4520
+                'file_parent' => 1,
4521
+                'file_target' => 'myTarget',
4522
+                'share_with' => '[email protected]',
4523
+                'share_with_displayname' => 'foobar',
4524
+                'mail_send' => 0,
4525
+                'mimetype' => 'myFolderMimeType',
4526
+                'has_preview' => false,
4527
+                'hide_download' => 0,
4528
+                'can_edit' => false,
4529
+                'can_delete' => false,
4530
+                'item_size' => 123456,
4531
+                'item_mtime' => 1234567890,
4532
+                'is-mount-root' => false,
4533
+                'mount-type' => '',
4534
+                'attributes' => null,
4535
+                'item_permissions' => 1,
4536
+            ], $share, [], false
4537
+        ];
4538
+
4539
+        // Circle with id, display name and avatar set by the Circles app
4540
+        $share = Server::get(IManager::class)->newShare();
4541
+        $share->setShareType(IShare::TYPE_CIRCLE)
4542
+            ->setSharedBy('initiator')
4543
+            ->setSharedWith('Circle (Public circle, circleOwner) [4815162342]')
4544
+            ->setSharedWithDisplayName('The display name')
4545
+            ->setSharedWithAvatar('path/to/the/avatar')
4546
+            ->setShareOwner('owner')
4547
+            ->setPermissions(Constants::PERMISSION_READ)
4548
+            ->setNode($folder)
4549
+            ->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4550
+            ->setTarget('myTarget')
4551
+            ->setId(42);
4552
+
4553
+        $result[] = [
4554
+            [
4555
+                'id' => '42',
4556
+                'share_type' => IShare::TYPE_CIRCLE,
4557
+                'uid_owner' => 'initiator',
4558
+                'displayname_owner' => 'initiator',
4559
+                'permissions' => 1,
4560
+                'attributes' => null,
4561
+                'stime' => 946684862,
4562
+                'parent' => null,
4563
+                'expiration' => null,
4564
+                'token' => null,
4565
+                'uid_file_owner' => 'owner',
4566
+                'displayname_file_owner' => 'owner',
4567
+                'note' => '',
4568
+                'label' => '',
4569
+                'path' => 'folder',
4570
+                'item_type' => 'folder',
4571
+                'storage_id' => 'storageId',
4572
+                'storage' => 100,
4573
+                'item_source' => 2,
4574
+                'file_source' => 2,
4575
+                'file_parent' => 1,
4576
+                'file_target' => 'myTarget',
4577
+                'share_with' => '4815162342',
4578
+                'share_with_displayname' => 'The display name',
4579
+                'share_with_avatar' => 'path/to/the/avatar',
4580
+                'mail_send' => 0,
4581
+                'mimetype' => 'myFolderMimeType',
4582
+                'has_preview' => false,
4583
+                'hide_download' => 0,
4584
+                'can_edit' => false,
4585
+                'can_delete' => false,
4586
+                'item_size' => 123456,
4587
+                'item_mtime' => 1234567890,
4588
+                'is-mount-root' => false,
4589
+                'mount-type' => '',
4590
+                'attributes' => null,
4591
+                'item_permissions' => 1,
4592
+            ], $share, [], false
4593
+        ];
4594
+
4595
+        // Circle with id set by the Circles app
4596
+        $share = Server::get(IManager::class)->newShare();
4597
+        $share->setShareType(IShare::TYPE_CIRCLE)
4598
+            ->setSharedBy('initiator')
4599
+            ->setSharedWith('Circle (Public circle, circleOwner) [4815162342]')
4600
+            ->setShareOwner('owner')
4601
+            ->setPermissions(Constants::PERMISSION_READ)
4602
+            ->setNode($folder)
4603
+            ->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4604
+            ->setTarget('myTarget')
4605
+            ->setId(42);
4606
+
4607
+        $result[] = [
4608
+            [
4609
+                'id' => '42',
4610
+                'share_type' => IShare::TYPE_CIRCLE,
4611
+                'uid_owner' => 'initiator',
4612
+                'displayname_owner' => 'initiator',
4613
+                'permissions' => 1,
4614
+                'stime' => 946684862,
4615
+                'parent' => null,
4616
+                'expiration' => null,
4617
+                'token' => null,
4618
+                'uid_file_owner' => 'owner',
4619
+                'displayname_file_owner' => 'owner',
4620
+                'note' => '',
4621
+                'label' => '',
4622
+                'path' => 'folder',
4623
+                'item_type' => 'folder',
4624
+                'storage_id' => 'storageId',
4625
+                'storage' => 100,
4626
+                'item_source' => 2,
4627
+                'file_source' => 2,
4628
+                'file_parent' => 1,
4629
+                'file_target' => 'myTarget',
4630
+                'share_with' => '4815162342',
4631
+                'share_with_displayname' => 'Circle (Public circle, circleOwner)',
4632
+                'share_with_avatar' => '',
4633
+                'mail_send' => 0,
4634
+                'mimetype' => 'myFolderMimeType',
4635
+                'has_preview' => false,
4636
+                'hide_download' => 0,
4637
+                'can_edit' => false,
4638
+                'can_delete' => false,
4639
+                'item_size' => 123456,
4640
+                'item_mtime' => 1234567890,
4641
+                'is-mount-root' => false,
4642
+                'mount-type' => '',
4643
+                'attributes' => null,
4644
+                'item_permissions' => 1,
4645
+            ], $share, [], false
4646
+        ];
4647
+
4648
+        // Circle with id not set by the Circles app
4649
+        $share = Server::get(IManager::class)->newShare();
4650
+        $share->setShareType(IShare::TYPE_CIRCLE)
4651
+            ->setSharedBy('initiator')
4652
+            ->setSharedWith('Circle (Public circle, circleOwner)')
4653
+            ->setShareOwner('owner')
4654
+            ->setPermissions(Constants::PERMISSION_READ)
4655
+            ->setNode($folder)
4656
+            ->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4657
+            ->setTarget('myTarget')
4658
+            ->setId(42);
4659
+
4660
+        $result[] = [
4661
+            [
4662
+                'id' => '42',
4663
+                'share_type' => IShare::TYPE_CIRCLE,
4664
+                'uid_owner' => 'initiator',
4665
+                'displayname_owner' => 'initiator',
4666
+                'permissions' => 1,
4667
+                'stime' => 946684862,
4668
+                'parent' => null,
4669
+                'expiration' => null,
4670
+                'token' => null,
4671
+                'uid_file_owner' => 'owner',
4672
+                'displayname_file_owner' => 'owner',
4673
+                'note' => '',
4674
+                'label' => '',
4675
+                'path' => 'folder',
4676
+                'item_type' => 'folder',
4677
+                'storage_id' => 'storageId',
4678
+                'storage' => 100,
4679
+                'item_source' => 2,
4680
+                'file_source' => 2,
4681
+                'file_parent' => 1,
4682
+                'file_target' => 'myTarget',
4683
+                'share_with' => 'Circle',
4684
+                'share_with_displayname' => 'Circle (Public circle, circleOwner)',
4685
+                'share_with_avatar' => '',
4686
+                'mail_send' => 0,
4687
+                'mimetype' => 'myFolderMimeType',
4688
+                'has_preview' => false,
4689
+                'hide_download' => 0,
4690
+                'can_edit' => false,
4691
+                'can_delete' => false,
4692
+                'item_size' => 123456,
4693
+                'item_mtime' => 1234567890,
4694
+                'is-mount-root' => false,
4695
+                'mount-type' => '',
4696
+                'attributes' => null,
4697
+                'item_permissions' => 1,
4698
+            ], $share, [], false
4699
+        ];
4700
+
4701
+        $share = Server::get(IManager::class)->newShare();
4702
+        $share->setShareType(IShare::TYPE_USER)
4703
+            ->setSharedBy('initiator')
4704
+            ->setSharedWith('recipient')
4705
+            ->setShareOwner('owner')
4706
+            ->setPermissions(Constants::PERMISSION_READ)
4707
+            ->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4708
+            ->setTarget('myTarget')
4709
+            ->setNote('personal note')
4710
+            ->setId(42);
4711
+
4712
+        $result[] = [
4713
+            [], $share, [], true
4714
+        ];
4715
+
4716
+        $share = Server::get(IManager::class)->newShare();
4717
+        $share->setShareType(IShare::TYPE_EMAIL)
4718
+            ->setSharedBy('initiator')
4719
+            ->setSharedWith('[email protected]')
4720
+            ->setShareOwner('owner')
4721
+            ->setPermissions(Constants::PERMISSION_READ)
4722
+            ->setNode($folder)
4723
+            ->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4724
+            ->setTarget('myTarget')
4725
+            ->setId(42)
4726
+            ->setPassword('password');
4727
+
4728
+        $result[] = [
4729
+            [
4730
+                'id' => '42',
4731
+                'share_type' => IShare::TYPE_EMAIL,
4732
+                'uid_owner' => 'initiator',
4733
+                'displayname_owner' => 'initiator',
4734
+                'permissions' => 1,
4735
+                'stime' => 946684862,
4736
+                'parent' => null,
4737
+                'expiration' => null,
4738
+                'token' => null,
4739
+                'uid_file_owner' => 'owner',
4740
+                'displayname_file_owner' => 'owner',
4741
+                'note' => '',
4742
+                'label' => '',
4743
+                'path' => 'folder',
4744
+                'item_type' => 'folder',
4745
+                'storage_id' => 'storageId',
4746
+                'storage' => 100,
4747
+                'item_source' => 2,
4748
+                'file_source' => 2,
4749
+                'file_parent' => 1,
4750
+                'file_target' => 'myTarget',
4751
+                'share_with' => '[email protected]',
4752
+                'share_with_displayname' => 'mail display name',
4753
+                'mail_send' => 0,
4754
+                'mimetype' => 'myFolderMimeType',
4755
+                'has_preview' => false,
4756
+                'password' => 'password',
4757
+                'send_password_by_talk' => false,
4758
+                'hide_download' => 0,
4759
+                'can_edit' => false,
4760
+                'can_delete' => false,
4761
+                'password_expiration_time' => null,
4762
+                'item_size' => 123456,
4763
+                'item_mtime' => 1234567890,
4764
+                'is-mount-root' => false,
4765
+                'mount-type' => '',
4766
+                'attributes' => null,
4767
+                'item_permissions' => 1,
4768
+            ], $share, [], false
4769
+        ];
4770
+
4771
+        $share = Server::get(IManager::class)->newShare();
4772
+        $share->setShareType(IShare::TYPE_EMAIL)
4773
+            ->setSharedBy('initiator')
4774
+            ->setSharedWith('[email protected]')
4775
+            ->setShareOwner('owner')
4776
+            ->setPermissions(Constants::PERMISSION_READ)
4777
+            ->setNode($folder)
4778
+            ->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4779
+            ->setTarget('myTarget')
4780
+            ->setId(42)
4781
+            ->setPassword('password')
4782
+            ->setSendPasswordByTalk(true);
4783
+
4784
+        $result[] = [
4785
+            [
4786
+                'id' => '42',
4787
+                'share_type' => IShare::TYPE_EMAIL,
4788
+                'uid_owner' => 'initiator',
4789
+                'displayname_owner' => 'initiator',
4790
+                'permissions' => 1,
4791
+                'stime' => 946684862,
4792
+                'parent' => null,
4793
+                'expiration' => null,
4794
+                'token' => null,
4795
+                'uid_file_owner' => 'owner',
4796
+                'displayname_file_owner' => 'owner',
4797
+                'note' => '',
4798
+                'label' => '',
4799
+                'path' => 'folder',
4800
+                'item_type' => 'folder',
4801
+                'storage_id' => 'storageId',
4802
+                'storage' => 100,
4803
+                'item_source' => 2,
4804
+                'file_source' => 2,
4805
+                'file_parent' => 1,
4806
+                'file_target' => 'myTarget',
4807
+                'share_with' => '[email protected]',
4808
+                'share_with_displayname' => 'mail display name',
4809
+                'mail_send' => 0,
4810
+                'mimetype' => 'myFolderMimeType',
4811
+                'has_preview' => false,
4812
+                'password' => 'password',
4813
+                'send_password_by_talk' => true,
4814
+                'hide_download' => 0,
4815
+                'can_edit' => false,
4816
+                'can_delete' => false,
4817
+                'password_expiration_time' => null,
4818
+                'item_size' => 123456,
4819
+                'item_mtime' => 1234567890,
4820
+                'is-mount-root' => false,
4821
+                'mount-type' => '',
4822
+                'attributes' => null,
4823
+                'item_permissions' => 1,
4824
+            ], $share, [], false
4825
+        ];
4826
+
4827
+        // Preview is available
4828
+        $share = Server::get(IManager::class)->newShare();
4829
+        $share->setShareType(IShare::TYPE_USER)
4830
+            ->setSharedWith('recipient')
4831
+            ->setSharedBy('initiator')
4832
+            ->setShareOwner('currentUser')
4833
+            ->setPermissions(Constants::PERMISSION_READ)
4834
+            ->setNode($fileWithPreview)
4835
+            ->setShareTime(new \DateTime('2000-01-01T00:01:02'))
4836
+            ->setTarget('myTarget')
4837
+            ->setNote('personal note')
4838
+            ->setId(42);
4839
+
4840
+        $result[] = [
4841
+            [
4842
+                'id' => '42',
4843
+                'share_type' => IShare::TYPE_USER,
4844
+                'uid_owner' => 'initiator',
4845
+                'displayname_owner' => 'initiator',
4846
+                'permissions' => 1,
4847
+                'stime' => 946684862,
4848
+                'parent' => null,
4849
+                'expiration' => null,
4850
+                'token' => null,
4851
+                'uid_file_owner' => 'currentUser',
4852
+                'displayname_file_owner' => 'currentUser',
4853
+                'note' => 'personal note',
4854
+                'label' => '',
4855
+                'path' => 'fileWithPreview',
4856
+                'item_type' => 'file',
4857
+                'storage_id' => 'storageId',
4858
+                'storage' => 100,
4859
+                'item_source' => 4,
4860
+                'file_source' => 4,
4861
+                'file_parent' => 1,
4862
+                'file_target' => 'myTarget',
4863
+                'share_with' => 'recipient',
4864
+                'share_with_displayname' => 'recipient',
4865
+                'share_with_displayname_unique' => 'recipient',
4866
+                'mail_send' => 0,
4867
+                'mimetype' => 'mimeWithPreview',
4868
+                'has_preview' => true,
4869
+                'hide_download' => 0,
4870
+                'can_edit' => true,
4871
+                'can_delete' => true,
4872
+                'item_size' => 123456,
4873
+                'item_mtime' => 1234567890,
4874
+                'is-mount-root' => false,
4875
+                'mount-type' => '',
4876
+                'attributes' => null,
4877
+                'item_permissions' => 11,
4878
+            ], $share, [], false
4879
+        ];
4880
+
4881
+        return $result;
4882
+    }
4883
+
4884
+    /**
4885
+     *
4886
+     * @param array $expects
4887
+     * @param IShare $share
4888
+     * @param array $users
4889
+     * @param $exception
4890
+     */
4891
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataFormatShare')]
4892
+    public function testFormatShare(array $expects, IShare $share, array $users, $exception): void {
4893
+        $this->userManager->method('get')->willReturnMap($users);
4894
+
4895
+        $recipientGroup = $this->createMock(IGroup::class);
4896
+        $recipientGroup->method('getDisplayName')->willReturn('recipientGroupDisplayName');
4897
+        $this->groupManager->method('get')->willReturnMap([
4898
+            ['recipientGroup', $recipientGroup],
4899
+        ]);
4900
+
4901
+        $this->urlGenerator->method('linkToRouteAbsolute')
4902
+            ->with('files_sharing.sharecontroller.showShare', ['token' => 'myToken'])
4903
+            ->willReturn('myLink');
4904
+
4905
+        $this->rootFolder->method('getUserFolder')
4906
+            ->with($this->currentUser)
4907
+            ->willReturnSelf();
4908
+        $this->dateTimeZone->method('getTimezone')->willReturn(new \DateTimeZone('UTC'));
4909
+
4910
+        if (!$exception) {
4911
+            $this->rootFolder->method('getFirstNodeById')
4912
+                ->with($share->getNodeId())
4913
+                ->willReturn($share->getNode());
4914
+
4915
+            $this->rootFolder->method('getRelativePath')
4916
+                ->with($share->getNode()->getPath())
4917
+                ->willReturnArgument(0);
4918
+        }
4919
+
4920
+        $cm = $this->createMock(\OCP\Contacts\IManager::class);
4921
+        $this->overwriteService(\OCP\Contacts\IManager::class, $cm);
4922
+
4923
+        $cm->method('search')
4924
+            ->willReturnMap([
4925
+                ['[email protected]', ['CLOUD'], [
4926
+                    'limit' => 1,
4927
+                    'enumeration' => false,
4928
+                    'strict_search' => true,
4929
+                ],
4930
+                    [
4931
+                        [
4932
+                            'CLOUD' => [
4933
+                                '[email protected]',
4934
+                            ],
4935
+                            'FN' => 'foobar',
4936
+                        ],
4937
+                    ],
4938
+                ],
4939
+                ['[email protected]', ['EMAIL'], [
4940
+                    'limit' => 1,
4941
+                    'enumeration' => false,
4942
+                    'strict_search' => true,
4943
+                ],
4944
+                    [
4945
+                        [
4946
+                            'EMAIL' => [
4947
+                                '[email protected]',
4948
+                            ],
4949
+                            'FN' => 'mail display name',
4950
+                        ],
4951
+                    ],
4952
+                ],
4953
+            ]);
4954
+
4955
+        try {
4956
+            $result = $this->invokePrivate($this->ocs, 'formatShare', [$share]);
4957
+            $this->assertFalse($exception);
4958
+            $this->assertEquals($expects, $result);
4959
+        } catch (NotFoundException $e) {
4960
+            $this->assertTrue($exception);
4961
+        }
4962
+    }
4963
+
4964
+    public function dataFormatRoomShare() {
4965
+        $file = $this->getMockBuilder(File::class)->getMock();
4966
+        $parent = $this->getMockBuilder(Folder::class)->getMock();
4967
+
4968
+        $file->method('getMimeType')->willReturn('myMimeType');
4969
+
4970
+        $file->method('getPath')->willReturn('file');
4971
+
4972
+        $parent->method('getId')->willReturn(1);
4973
+        $file->method('getId')->willReturn(3);
4974
+
4975
+        $file->method('getParent')->willReturn($parent);
4976
+
4977
+        $file->method('getSize')->willReturn(123456);
4978
+        $file->method('getMTime')->willReturn(1234567890);
4979
+
4980
+        $mountPoint = $this->getMockBuilder(IMountPoint::class)->getMock();
4981
+        $mountPoint->method('getMountType')->willReturn('');
4982
+        $file->method('getMountPoint')->willReturn($mountPoint);
4983
+
4984
+        $cache = $this->getMockBuilder('OCP\Files\Cache\ICache')->getMock();
4985
+        $cache->method('getNumericStorageId')->willReturn(100);
4986
+        $storage = $this->createMock(IStorage::class);
4987
+        $storage->method('getId')->willReturn('storageId');
4988
+        $storage->method('getCache')->willReturn($cache);
4989
+
4990
+        $file->method('getStorage')->willReturn($storage);
4991
+
4992
+        $result = [];
4993
+
4994
+        $share = Server::get(IManager::class)->newShare();
4995
+        $share->setShareType(IShare::TYPE_ROOM)
4996
+            ->setSharedWith('recipientRoom')
4997
+            ->setSharedBy('initiator')
4998
+            ->setShareOwner('owner')
4999
+            ->setPermissions(Constants::PERMISSION_READ)
5000
+            ->setNode($file)
5001
+            ->setShareTime(new \DateTime('2000-01-01T00:01:02'))
5002
+            ->setTarget('myTarget')
5003
+            ->setNote('personal note')
5004
+            ->setId(42);
5005
+
5006
+        $result[] = [
5007
+            [
5008
+                'id' => '42',
5009
+                'share_type' => IShare::TYPE_ROOM,
5010
+                'uid_owner' => 'initiator',
5011
+                'displayname_owner' => 'initiator',
5012
+                'permissions' => 1,
5013
+                'stime' => 946684862,
5014
+                'parent' => null,
5015
+                'expiration' => null,
5016
+                'token' => null,
5017
+                'uid_file_owner' => 'owner',
5018
+                'displayname_file_owner' => 'owner',
5019
+                'note' => 'personal note',
5020
+                'path' => 'file',
5021
+                'item_type' => 'file',
5022
+                'storage_id' => 'storageId',
5023
+                'storage' => 100,
5024
+                'item_source' => 3,
5025
+                'file_source' => 3,
5026
+                'file_parent' => 1,
5027
+                'file_target' => 'myTarget',
5028
+                'share_with' => 'recipientRoom',
5029
+                'share_with_displayname' => '',
5030
+                'mail_send' => 0,
5031
+                'mimetype' => 'myMimeType',
5032
+                'has_preview' => false,
5033
+                'hide_download' => 0,
5034
+                'label' => '',
5035
+                'can_edit' => false,
5036
+                'can_delete' => false,
5037
+                'item_size' => 123456,
5038
+                'item_mtime' => 1234567890,
5039
+                'is-mount-root' => false,
5040
+                'mount-type' => '',
5041
+                'attributes' => null,
5042
+                'item_permissions' => 1,
5043
+            ], $share, false, []
5044
+        ];
5045
+
5046
+        $share = Server::get(IManager::class)->newShare();
5047
+        $share->setShareType(IShare::TYPE_ROOM)
5048
+            ->setSharedWith('recipientRoom')
5049
+            ->setSharedBy('initiator')
5050
+            ->setShareOwner('owner')
5051
+            ->setPermissions(Constants::PERMISSION_READ)
5052
+            ->setNode($file)
5053
+            ->setShareTime(new \DateTime('2000-01-01T00:01:02'))
5054
+            ->setTarget('myTarget')
5055
+            ->setNote('personal note')
5056
+            ->setId(42);
5057
+
5058
+        $result[] = [
5059
+            [
5060
+                'id' => '42',
5061
+                'share_type' => IShare::TYPE_ROOM,
5062
+                'uid_owner' => 'initiator',
5063
+                'displayname_owner' => 'initiator',
5064
+                'permissions' => 1,
5065
+                'stime' => 946684862,
5066
+                'parent' => null,
5067
+                'expiration' => null,
5068
+                'token' => null,
5069
+                'uid_file_owner' => 'owner',
5070
+                'displayname_file_owner' => 'owner',
5071
+                'note' => 'personal note',
5072
+                'path' => 'file',
5073
+                'item_type' => 'file',
5074
+                'storage_id' => 'storageId',
5075
+                'storage' => 100,
5076
+                'item_source' => 3,
5077
+                'file_source' => 3,
5078
+                'file_parent' => 1,
5079
+                'file_target' => 'myTarget',
5080
+                'share_with' => 'recipientRoom',
5081
+                'share_with_displayname' => 'recipientRoomName',
5082
+                'mail_send' => 0,
5083
+                'mimetype' => 'myMimeType',
5084
+                'has_preview' => false,
5085
+                'hide_download' => 0,
5086
+                'label' => '',
5087
+                'can_edit' => false,
5088
+                'can_delete' => false,
5089
+                'item_size' => 123456,
5090
+                'item_mtime' => 1234567890,
5091
+                'is-mount-root' => false,
5092
+                'mount-type' => '',
5093
+                'attributes' => null,
5094
+                'item_permissions' => 9,
5095
+            ], $share, true, [
5096
+                'share_with_displayname' => 'recipientRoomName'
5097
+            ]
5098
+        ];
5099
+
5100
+        return $result;
5101
+    }
5102
+
5103
+    /**
5104
+     *
5105
+     * @param array $expects
5106
+     * @param IShare $share
5107
+     * @param bool $helperAvailable
5108
+     * @param array $formatShareByHelper
5109
+     */
5110
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataFormatRoomShare')]
5111
+    public function testFormatRoomShare(array $expects, IShare $share, bool $helperAvailable, array $formatShareByHelper): void {
5112
+        $this->rootFolder->method('getUserFolder')
5113
+            ->with($this->currentUser)
5114
+            ->willReturnSelf();
5115
+
5116
+        $this->rootFolder->method('getFirstNodeById')
5117
+            ->with($share->getNodeId())
5118
+            ->willReturn($share->getNode());
5119
+
5120
+        $this->rootFolder->method('getRelativePath')
5121
+            ->with($share->getNode()->getPath())
5122
+            ->willReturnArgument(0);
5123
+
5124
+        if (!$helperAvailable) {
5125
+            $this->appManager->method('isEnabledForUser')
5126
+                ->with('spreed')
5127
+                ->willReturn(false);
5128
+        } else {
5129
+            $this->appManager->method('isEnabledForUser')
5130
+                ->with('spreed')
5131
+                ->willReturn(true);
5132
+
5133
+            // This is not possible anymore with PHPUnit 10+
5134
+            // as `setMethods` was removed and now real reflection is used, thus the class needs to exist.
5135
+            // $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
5136
+            $helper = $this->getMockBuilder(\stdClass::class)
5137
+                ->addMethods(['formatShare', 'canAccessShare'])
5138
+                ->getMock();
5139
+            $helper->method('formatShare')
5140
+                ->with($share)
5141
+                ->willReturn($formatShareByHelper);
5142
+            $helper->method('canAccessShare')
5143
+                ->with($share)
5144
+                ->willReturn(true);
5145
+
5146
+            $this->serverContainer->method('get')
5147
+                ->with('\OCA\Talk\Share\Helper\ShareAPIController')
5148
+                ->willReturn($helper);
5149
+        }
5150
+
5151
+        $result = $this->invokePrivate($this->ocs, 'formatShare', [$share]);
5152
+        $this->assertEquals($expects, $result);
5153
+    }
5154
+
5155
+    /**
5156
+     * @return list{Folder, Folder}
5157
+     */
5158
+    private function getNonSharedUserFolder(): array {
5159
+        $node = $this->getMockBuilder(Folder::class)->getMock();
5160
+        $userFolder = $this->getMockBuilder(Folder::class)->getMock();
5161
+        $storage = $this->createMock(IStorage::class);
5162
+        $storage->method('instanceOfStorage')
5163
+            ->willReturnMap([
5164
+                ['OCA\Files_Sharing\External\Storage', false],
5165
+                ['OCA\Files_Sharing\SharedStorage', false],
5166
+            ]);
5167
+        $userFolder->method('getStorage')->willReturn($storage);
5168
+        $node->method('getStorage')->willReturn($storage);
5169
+        $node->method('getId')->willReturn(42);
5170
+        $user = $this->createMock(IUser::class);
5171
+        $user->method('getUID')->willReturn($this->currentUser);
5172
+        $node->method('getOwner')->willReturn($user);
5173
+        return [$userFolder, $node];
5174
+    }
5175
+
5176
+    /**
5177
+     * @return list{Folder, File}
5178
+     */
5179
+    private function getNonSharedUserFile(): array {
5180
+        $node = $this->getMockBuilder(File::class)->getMock();
5181
+        $userFolder = $this->getMockBuilder(Folder::class)->getMock();
5182
+        $storage = $this->createMock(IStorage::class);
5183
+        $storage->method('instanceOfStorage')
5184
+            ->willReturnMap([
5185
+                ['OCA\Files_Sharing\External\Storage', false],
5186
+                ['OCA\Files_Sharing\SharedStorage', false],
5187
+            ]);
5188
+        $userFolder->method('getStorage')->willReturn($storage);
5189
+        $node->method('getStorage')->willReturn($storage);
5190
+        $node->method('getId')->willReturn(42);
5191
+        return [$userFolder, $node];
5192
+    }
5193
+
5194
+    public function testPopulateTags(): void {
5195
+        $tagger = $this->createMock(ITags::class);
5196
+        $this->tagManager->method('load')
5197
+            ->with('files')
5198
+            ->willReturn($tagger);
5199
+        $data = [
5200
+            ['file_source' => 10],
5201
+            ['file_source' => 22, 'foo' => 'bar'],
5202
+            ['file_source' => 42, 'x' => 'y'],
5203
+        ];
5204
+        $tags = [
5205
+            10 => ['tag3'],
5206
+            42 => ['tag1', 'tag2'],
5207
+        ];
5208
+        $tagger->method('getTagsForObjects')
5209
+            ->with([10, 22, 42])
5210
+            ->willReturn($tags);
5211
+
5212
+        $result = self::invokePrivate($this->ocs, 'populateTags', [$data]);
5213
+        $this->assertSame([
5214
+            ['file_source' => 10, 'tags' => ['tag3']],
5215
+            ['file_source' => 22, 'foo' => 'bar', 'tags' => []],
5216
+            ['file_source' => 42, 'x' => 'y', 'tags' => ['tag1', 'tag2']],
5217
+        ], $result);
5218
+    }
5219 5219
 }
Please login to merge, or discard this patch.
apps/files_sharing/tests/Middleware/OCSShareAPIMiddlewareTest.php 1 patch
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -19,106 +19,106 @@
 block discarded – undo
19 19
  */
20 20
 class OCSShareAPIMiddlewareTest extends \Test\TestCase {
21 21
 
22
-	/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
23
-	private $shareManager;
24
-	/** @var IL10N */
25
-	private $l;
26
-	/** @var OCSShareAPIMiddleware */
27
-	private $middleware;
22
+    /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
23
+    private $shareManager;
24
+    /** @var IL10N */
25
+    private $l;
26
+    /** @var OCSShareAPIMiddleware */
27
+    private $middleware;
28 28
 
29
-	protected function setUp(): void {
30
-		parent::setUp();
29
+    protected function setUp(): void {
30
+        parent::setUp();
31 31
 
32
-		$this->shareManager = $this->createMock(IManager::class);
33
-		$this->l = $this->createMock(IL10N::class);
32
+        $this->shareManager = $this->createMock(IManager::class);
33
+        $this->l = $this->createMock(IL10N::class);
34 34
 
35
-		$this->l->method('t')->willReturnArgument(0);
35
+        $this->l->method('t')->willReturnArgument(0);
36 36
 
37
-		$this->middleware = new OCSShareAPIMiddleware($this->shareManager, $this->l);
38
-	}
37
+        $this->middleware = new OCSShareAPIMiddleware($this->shareManager, $this->l);
38
+    }
39 39
 
40
-	public function dataBeforeController() {
41
-		return [
42
-			[
43
-				$this->createMock(Controller::class),
44
-				false,
45
-				false
46
-			],
47
-			[
48
-				$this->createMock(Controller::class),
49
-				true,
50
-				false
51
-			],
52
-			[
53
-				$this->createMock(OCSController::class),
54
-				false,
55
-				false
56
-			],
57
-			[
58
-				$this->createMock(OCSController::class),
59
-				true,
60
-				false
61
-			],
62
-			[
63
-				$this->createMock(ShareAPIController::class),
64
-				false,
65
-				true
66
-			],
67
-			[
68
-				$this->createMock(ShareAPIController::class),
69
-				true,
70
-				false
71
-			],
72
-		];
73
-	}
40
+    public function dataBeforeController() {
41
+        return [
42
+            [
43
+                $this->createMock(Controller::class),
44
+                false,
45
+                false
46
+            ],
47
+            [
48
+                $this->createMock(Controller::class),
49
+                true,
50
+                false
51
+            ],
52
+            [
53
+                $this->createMock(OCSController::class),
54
+                false,
55
+                false
56
+            ],
57
+            [
58
+                $this->createMock(OCSController::class),
59
+                true,
60
+                false
61
+            ],
62
+            [
63
+                $this->createMock(ShareAPIController::class),
64
+                false,
65
+                true
66
+            ],
67
+            [
68
+                $this->createMock(ShareAPIController::class),
69
+                true,
70
+                false
71
+            ],
72
+        ];
73
+    }
74 74
 
75
-	/**
76
-	 *
77
-	 * @param Controller $controller
78
-	 * @param bool $enabled
79
-	 * @param bool $exception
80
-	 */
81
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataBeforeController')]
82
-	public function testBeforeController(Controller $controller, $enabled, $exception): void {
83
-		$this->shareManager->method('shareApiEnabled')->willReturn($enabled);
75
+    /**
76
+     *
77
+     * @param Controller $controller
78
+     * @param bool $enabled
79
+     * @param bool $exception
80
+     */
81
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataBeforeController')]
82
+    public function testBeforeController(Controller $controller, $enabled, $exception): void {
83
+        $this->shareManager->method('shareApiEnabled')->willReturn($enabled);
84 84
 
85
-		try {
86
-			$this->middleware->beforeController($controller, 'foo');
87
-			$this->assertFalse($exception);
88
-		} catch (OCSNotFoundException $e) {
89
-			$this->assertTrue($exception);
90
-		}
91
-	}
85
+        try {
86
+            $this->middleware->beforeController($controller, 'foo');
87
+            $this->assertFalse($exception);
88
+        } catch (OCSNotFoundException $e) {
89
+            $this->assertTrue($exception);
90
+        }
91
+    }
92 92
 
93
-	public function dataAfterController() {
94
-		return [
95
-			[
96
-				$this->createMock(Controller::class),
97
-			],
98
-			[
99
-				$this->createMock(OCSController::class),
100
-			],
101
-			[
102
-				$this->createMock(ShareAPIController::class),
103
-			],
104
-		];
105
-	}
93
+    public function dataAfterController() {
94
+        return [
95
+            [
96
+                $this->createMock(Controller::class),
97
+            ],
98
+            [
99
+                $this->createMock(OCSController::class),
100
+            ],
101
+            [
102
+                $this->createMock(ShareAPIController::class),
103
+            ],
104
+        ];
105
+    }
106 106
 
107
-	/**
108
-	 *
109
-	 * @param Controller $controller
110
-	 * @param bool $called
111
-	 */
112
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataAfterController')]
113
-	public function testAfterController(Controller $controller): void {
114
-		if ($controller instanceof ShareAPIController) {
115
-			$controller->expects($this->once())->method('cleanup');
116
-		}
107
+    /**
108
+     *
109
+     * @param Controller $controller
110
+     * @param bool $called
111
+     */
112
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataAfterController')]
113
+    public function testAfterController(Controller $controller): void {
114
+        if ($controller instanceof ShareAPIController) {
115
+            $controller->expects($this->once())->method('cleanup');
116
+        }
117 117
 
118
-		$response = $this->getMockBuilder('OCP\AppFramework\Http\Response')
119
-			->disableOriginalConstructor()
120
-			->getMock();
121
-		$this->middleware->afterController($controller, 'foo', $response);
122
-		$this->addToAssertionCount(1);
123
-	}
118
+        $response = $this->getMockBuilder('OCP\AppFramework\Http\Response')
119
+            ->disableOriginalConstructor()
120
+            ->getMock();
121
+        $this->middleware->afterController($controller, 'foo', $response);
122
+        $this->addToAssertionCount(1);
123
+    }
124 124
 }
Please login to merge, or discard this patch.
apps/files_sharing/tests/Middleware/SharingCheckMiddlewareTest.php 1 patch
Indentation   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -26,180 +26,180 @@
 block discarded – undo
26 26
  */
27 27
 class SharingCheckMiddlewareTest extends \Test\TestCase {
28 28
 
29
-	/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
30
-	private $config;
31
-	/** @var IAppManager|\PHPUnit\Framework\MockObject\MockObject */
32
-	private $appManager;
33
-	/** @var SharingCheckMiddleware */
34
-	private $sharingCheckMiddleware;
35
-	/** @var Controller|\PHPUnit\Framework\MockObject\MockObject */
36
-	private $controllerMock;
37
-	/** @var IControllerMethodReflector|\PHPUnit\Framework\MockObject\MockObject */
38
-	private $reflector;
39
-	/** @var IManager | \PHPUnit\Framework\MockObject\MockObject */
40
-	private $shareManager;
41
-	/** @var IRequest | \PHPUnit\Framework\MockObject\MockObject */
42
-	private $request;
43
-
44
-	protected function setUp(): void {
45
-		parent::setUp();
46
-
47
-		$this->config = $this->createMock(IConfig::class);
48
-		$this->appManager = $this->createMock(IAppManager::class);
49
-		$this->controllerMock = $this->createMock(Controller::class);
50
-		$this->reflector = $this->createMock(IControllerMethodReflector::class);
51
-		$this->shareManager = $this->createMock(IManager::class);
52
-		$this->request = $this->createMock(IRequest::class);
53
-
54
-		$this->sharingCheckMiddleware = new SharingCheckMiddleware(
55
-			'files_sharing',
56
-			$this->config,
57
-			$this->appManager,
58
-			$this->reflector,
59
-			$this->shareManager,
60
-			$this->request);
61
-	}
62
-
63
-	public function testIsSharingEnabledWithAppEnabled(): void {
64
-		$this->appManager
65
-			->expects($this->once())
66
-			->method('isEnabledForUser')
67
-			->with('files_sharing')
68
-			->willReturn(true);
69
-
70
-		$this->assertTrue(self::invokePrivate($this->sharingCheckMiddleware, 'isSharingEnabled'));
71
-	}
72
-
73
-	public function testIsSharingEnabledWithAppDisabled(): void {
74
-		$this->appManager
75
-			->expects($this->once())
76
-			->method('isEnabledForUser')
77
-			->with('files_sharing')
78
-			->willReturn(false);
79
-
80
-		$this->assertFalse(self::invokePrivate($this->sharingCheckMiddleware, 'isSharingEnabled'));
81
-	}
82
-
83
-	public static function externalSharesChecksDataProvider() {
84
-		$data = [];
85
-
86
-		foreach ([false, true] as $annIn) {
87
-			foreach ([false, true] as $annOut) {
88
-				foreach ([false, true] as $confIn) {
89
-					foreach ([false, true] as $confOut) {
90
-						$res = true;
91
-						if (!$annIn && !$confIn) {
92
-							$res = false;
93
-						} elseif (!$annOut && !$confOut) {
94
-							$res = false;
95
-						}
96
-
97
-						$d = [
98
-							[
99
-								['NoIncomingFederatedSharingRequired', $annIn],
100
-								['NoOutgoingFederatedSharingRequired', $annOut],
101
-							],
102
-							[
103
-								['files_sharing', 'incoming_server2server_share_enabled', 'yes', $confIn ? 'yes' : 'no'],
104
-								['files_sharing', 'outgoing_server2server_share_enabled', 'yes', $confOut ? 'yes' : 'no'],
105
-							],
106
-							$res
107
-						];
108
-
109
-						$data[] = $d;
110
-					}
111
-				}
112
-			}
113
-		}
114
-
115
-		return $data;
116
-	}
117
-
118
-	#[\PHPUnit\Framework\Attributes\DataProvider('externalSharesChecksDataProvider')]
119
-	public function testExternalSharesChecks($annotations, $config, $expectedResult): void {
120
-		$this->reflector
121
-			->expects($this->atLeastOnce())
122
-			->method('hasAnnotation')
123
-			->willReturnMap($annotations);
124
-
125
-		$this->config
126
-			->method('getAppValue')
127
-			->willReturnMap($config);
128
-
129
-		$this->assertEquals($expectedResult, self::invokePrivate($this->sharingCheckMiddleware, 'externalSharesChecks'));
130
-	}
131
-
132
-	#[\PHPUnit\Framework\Attributes\DataProvider('externalSharesChecksDataProvider')]
133
-	public function testBeforeControllerWithExternalShareControllerWithSharingEnabled($annotations, $config, $noException): void {
134
-		$this->appManager
135
-			->expects($this->once())
136
-			->method('isEnabledForUser')
137
-			->with('files_sharing')
138
-			->willReturn(true);
139
-
140
-		$this->reflector
141
-			->expects($this->atLeastOnce())
142
-			->method('hasAnnotation')
143
-			->willReturnMap($annotations);
144
-
145
-		$this->config
146
-			->method('getAppValue')
147
-			->willReturnMap($config);
148
-
149
-		$controller = $this->createMock(ExternalSharesController::class);
150
-
151
-		$exceptionThrown = false;
152
-
153
-		try {
154
-			$this->sharingCheckMiddleware->beforeController($controller, 'myMethod');
155
-		} catch (S2SException $exception) {
156
-			$exceptionThrown = true;
157
-		}
158
-
159
-		$this->assertNotEquals($noException, $exceptionThrown);
160
-	}
161
-
162
-	public function testBeforeControllerWithShareControllerWithSharingEnabled(): void {
163
-		$share = $this->createMock(IShare::class);
164
-
165
-		$this->appManager
166
-			->expects($this->once())
167
-			->method('isEnabledForUser')
168
-			->with('files_sharing')
169
-			->willReturn(true);
170
-
171
-		$controller = $this->createMock(ShareController::class);
172
-
173
-		$this->sharingCheckMiddleware->beforeController($controller, 'myMethod');
174
-	}
175
-
176
-
177
-	public function testBeforeControllerWithSharingDisabled(): void {
178
-		$this->expectException(NotFoundException::class);
179
-		$this->expectExceptionMessage('Sharing is disabled.');
180
-
181
-		$this->appManager
182
-			->expects($this->once())
183
-			->method('isEnabledForUser')
184
-			->with('files_sharing')
185
-			->willReturn(false);
186
-
187
-		$this->sharingCheckMiddleware->beforeController($this->controllerMock, 'myMethod');
188
-	}
189
-
190
-
191
-	public function testAfterExceptionWithRegularException(): void {
192
-		$this->expectException(\Exception::class);
193
-		$this->expectExceptionMessage('My Exception message');
194
-
195
-		$this->sharingCheckMiddleware->afterException($this->controllerMock, 'myMethod', new \Exception('My Exception message'));
196
-	}
197
-
198
-	public function testAfterExceptionWithNotFoundException(): void {
199
-		$this->assertEquals(new NotFoundResponse(), $this->sharingCheckMiddleware->afterException($this->controllerMock, 'myMethod', new NotFoundException('My Exception message')));
200
-	}
201
-
202
-	public function testAfterExceptionWithS2SException(): void {
203
-		$this->assertEquals(new JSONResponse('My Exception message', 405), $this->sharingCheckMiddleware->afterException($this->controllerMock, 'myMethod', new S2SException('My Exception message')));
204
-	}
29
+    /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
30
+    private $config;
31
+    /** @var IAppManager|\PHPUnit\Framework\MockObject\MockObject */
32
+    private $appManager;
33
+    /** @var SharingCheckMiddleware */
34
+    private $sharingCheckMiddleware;
35
+    /** @var Controller|\PHPUnit\Framework\MockObject\MockObject */
36
+    private $controllerMock;
37
+    /** @var IControllerMethodReflector|\PHPUnit\Framework\MockObject\MockObject */
38
+    private $reflector;
39
+    /** @var IManager | \PHPUnit\Framework\MockObject\MockObject */
40
+    private $shareManager;
41
+    /** @var IRequest | \PHPUnit\Framework\MockObject\MockObject */
42
+    private $request;
43
+
44
+    protected function setUp(): void {
45
+        parent::setUp();
46
+
47
+        $this->config = $this->createMock(IConfig::class);
48
+        $this->appManager = $this->createMock(IAppManager::class);
49
+        $this->controllerMock = $this->createMock(Controller::class);
50
+        $this->reflector = $this->createMock(IControllerMethodReflector::class);
51
+        $this->shareManager = $this->createMock(IManager::class);
52
+        $this->request = $this->createMock(IRequest::class);
53
+
54
+        $this->sharingCheckMiddleware = new SharingCheckMiddleware(
55
+            'files_sharing',
56
+            $this->config,
57
+            $this->appManager,
58
+            $this->reflector,
59
+            $this->shareManager,
60
+            $this->request);
61
+    }
62
+
63
+    public function testIsSharingEnabledWithAppEnabled(): void {
64
+        $this->appManager
65
+            ->expects($this->once())
66
+            ->method('isEnabledForUser')
67
+            ->with('files_sharing')
68
+            ->willReturn(true);
69
+
70
+        $this->assertTrue(self::invokePrivate($this->sharingCheckMiddleware, 'isSharingEnabled'));
71
+    }
72
+
73
+    public function testIsSharingEnabledWithAppDisabled(): void {
74
+        $this->appManager
75
+            ->expects($this->once())
76
+            ->method('isEnabledForUser')
77
+            ->with('files_sharing')
78
+            ->willReturn(false);
79
+
80
+        $this->assertFalse(self::invokePrivate($this->sharingCheckMiddleware, 'isSharingEnabled'));
81
+    }
82
+
83
+    public static function externalSharesChecksDataProvider() {
84
+        $data = [];
85
+
86
+        foreach ([false, true] as $annIn) {
87
+            foreach ([false, true] as $annOut) {
88
+                foreach ([false, true] as $confIn) {
89
+                    foreach ([false, true] as $confOut) {
90
+                        $res = true;
91
+                        if (!$annIn && !$confIn) {
92
+                            $res = false;
93
+                        } elseif (!$annOut && !$confOut) {
94
+                            $res = false;
95
+                        }
96
+
97
+                        $d = [
98
+                            [
99
+                                ['NoIncomingFederatedSharingRequired', $annIn],
100
+                                ['NoOutgoingFederatedSharingRequired', $annOut],
101
+                            ],
102
+                            [
103
+                                ['files_sharing', 'incoming_server2server_share_enabled', 'yes', $confIn ? 'yes' : 'no'],
104
+                                ['files_sharing', 'outgoing_server2server_share_enabled', 'yes', $confOut ? 'yes' : 'no'],
105
+                            ],
106
+                            $res
107
+                        ];
108
+
109
+                        $data[] = $d;
110
+                    }
111
+                }
112
+            }
113
+        }
114
+
115
+        return $data;
116
+    }
117
+
118
+    #[\PHPUnit\Framework\Attributes\DataProvider('externalSharesChecksDataProvider')]
119
+    public function testExternalSharesChecks($annotations, $config, $expectedResult): void {
120
+        $this->reflector
121
+            ->expects($this->atLeastOnce())
122
+            ->method('hasAnnotation')
123
+            ->willReturnMap($annotations);
124
+
125
+        $this->config
126
+            ->method('getAppValue')
127
+            ->willReturnMap($config);
128
+
129
+        $this->assertEquals($expectedResult, self::invokePrivate($this->sharingCheckMiddleware, 'externalSharesChecks'));
130
+    }
131
+
132
+    #[\PHPUnit\Framework\Attributes\DataProvider('externalSharesChecksDataProvider')]
133
+    public function testBeforeControllerWithExternalShareControllerWithSharingEnabled($annotations, $config, $noException): void {
134
+        $this->appManager
135
+            ->expects($this->once())
136
+            ->method('isEnabledForUser')
137
+            ->with('files_sharing')
138
+            ->willReturn(true);
139
+
140
+        $this->reflector
141
+            ->expects($this->atLeastOnce())
142
+            ->method('hasAnnotation')
143
+            ->willReturnMap($annotations);
144
+
145
+        $this->config
146
+            ->method('getAppValue')
147
+            ->willReturnMap($config);
148
+
149
+        $controller = $this->createMock(ExternalSharesController::class);
150
+
151
+        $exceptionThrown = false;
152
+
153
+        try {
154
+            $this->sharingCheckMiddleware->beforeController($controller, 'myMethod');
155
+        } catch (S2SException $exception) {
156
+            $exceptionThrown = true;
157
+        }
158
+
159
+        $this->assertNotEquals($noException, $exceptionThrown);
160
+    }
161
+
162
+    public function testBeforeControllerWithShareControllerWithSharingEnabled(): void {
163
+        $share = $this->createMock(IShare::class);
164
+
165
+        $this->appManager
166
+            ->expects($this->once())
167
+            ->method('isEnabledForUser')
168
+            ->with('files_sharing')
169
+            ->willReturn(true);
170
+
171
+        $controller = $this->createMock(ShareController::class);
172
+
173
+        $this->sharingCheckMiddleware->beforeController($controller, 'myMethod');
174
+    }
175
+
176
+
177
+    public function testBeforeControllerWithSharingDisabled(): void {
178
+        $this->expectException(NotFoundException::class);
179
+        $this->expectExceptionMessage('Sharing is disabled.');
180
+
181
+        $this->appManager
182
+            ->expects($this->once())
183
+            ->method('isEnabledForUser')
184
+            ->with('files_sharing')
185
+            ->willReturn(false);
186
+
187
+        $this->sharingCheckMiddleware->beforeController($this->controllerMock, 'myMethod');
188
+    }
189
+
190
+
191
+    public function testAfterExceptionWithRegularException(): void {
192
+        $this->expectException(\Exception::class);
193
+        $this->expectExceptionMessage('My Exception message');
194
+
195
+        $this->sharingCheckMiddleware->afterException($this->controllerMock, 'myMethod', new \Exception('My Exception message'));
196
+    }
197
+
198
+    public function testAfterExceptionWithNotFoundException(): void {
199
+        $this->assertEquals(new NotFoundResponse(), $this->sharingCheckMiddleware->afterException($this->controllerMock, 'myMethod', new NotFoundException('My Exception message')));
200
+    }
201
+
202
+    public function testAfterExceptionWithS2SException(): void {
203
+        $this->assertEquals(new JSONResponse('My Exception message', 405), $this->sharingCheckMiddleware->afterException($this->controllerMock, 'myMethod', new S2SException('My Exception message')));
204
+    }
205 205
 }
Please login to merge, or discard this patch.
apps/files_sharing/tests/ExternalStorageTest.php 1 patch
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -20,99 +20,99 @@
 block discarded – undo
20 20
  * @group DB
21 21
  */
22 22
 class ExternalStorageTest extends \Test\TestCase {
23
-	public static function optionsProvider() {
24
-		return [
25
-			[
26
-				'http://remoteserver:8080/owncloud',
27
-				'http://remoteserver:8080/owncloud/public.php/webdav/',
28
-			],
29
-			// extra slash
30
-			[
31
-				'http://remoteserver:8080/owncloud/',
32
-				'http://remoteserver:8080/owncloud/public.php/webdav/',
33
-			],
34
-			// extra path
35
-			[
36
-				'http://remoteserver:8080/myservices/owncloud/',
37
-				'http://remoteserver:8080/myservices/owncloud/public.php/webdav/',
38
-			],
39
-			// root path
40
-			[
41
-				'http://remoteserver:8080/',
42
-				'http://remoteserver:8080/public.php/webdav/',
43
-			],
44
-			// without port
45
-			[
46
-				'http://remoteserver/oc.test',
47
-				'http://remoteserver/oc.test/public.php/webdav/',
48
-			],
49
-			// https
50
-			[
51
-				'https://remoteserver/',
52
-				'https://remoteserver/public.php/webdav/',
53
-			],
54
-		];
55
-	}
23
+    public static function optionsProvider() {
24
+        return [
25
+            [
26
+                'http://remoteserver:8080/owncloud',
27
+                'http://remoteserver:8080/owncloud/public.php/webdav/',
28
+            ],
29
+            // extra slash
30
+            [
31
+                'http://remoteserver:8080/owncloud/',
32
+                'http://remoteserver:8080/owncloud/public.php/webdav/',
33
+            ],
34
+            // extra path
35
+            [
36
+                'http://remoteserver:8080/myservices/owncloud/',
37
+                'http://remoteserver:8080/myservices/owncloud/public.php/webdav/',
38
+            ],
39
+            // root path
40
+            [
41
+                'http://remoteserver:8080/',
42
+                'http://remoteserver:8080/public.php/webdav/',
43
+            ],
44
+            // without port
45
+            [
46
+                'http://remoteserver/oc.test',
47
+                'http://remoteserver/oc.test/public.php/webdav/',
48
+            ],
49
+            // https
50
+            [
51
+                'https://remoteserver/',
52
+                'https://remoteserver/public.php/webdav/',
53
+            ],
54
+        ];
55
+    }
56 56
 
57
-	private function getTestStorage($uri) {
58
-		$certificateManager = \OC::$server->getCertificateManager();
59
-		$httpClientService = $this->createMock(IClientService::class);
60
-		$manager = $this->createMock(ExternalShareManager::class);
61
-		$client = $this->createMock(IClient::class);
62
-		$response = $this->createMock(IResponse::class);
63
-		$client
64
-			->expects($this->any())
65
-			->method('get')
66
-			->willReturn($response);
67
-		$client
68
-			->expects($this->any())
69
-			->method('post')
70
-			->willReturn($response);
71
-		$httpClientService
72
-			->expects($this->any())
73
-			->method('newClient')
74
-			->willReturn($client);
57
+    private function getTestStorage($uri) {
58
+        $certificateManager = \OC::$server->getCertificateManager();
59
+        $httpClientService = $this->createMock(IClientService::class);
60
+        $manager = $this->createMock(ExternalShareManager::class);
61
+        $client = $this->createMock(IClient::class);
62
+        $response = $this->createMock(IResponse::class);
63
+        $client
64
+            ->expects($this->any())
65
+            ->method('get')
66
+            ->willReturn($response);
67
+        $client
68
+            ->expects($this->any())
69
+            ->method('post')
70
+            ->willReturn($response);
71
+        $httpClientService
72
+            ->expects($this->any())
73
+            ->method('newClient')
74
+            ->willReturn($client);
75 75
 
76
-		return new TestSharingExternalStorage(
77
-			[
78
-				'cloudId' => new CloudId('testOwner@' . $uri, 'testOwner', $uri),
79
-				'remote' => $uri,
80
-				'owner' => 'testOwner',
81
-				'mountpoint' => 'remoteshare',
82
-				'token' => 'abcdef',
83
-				'password' => '',
84
-				'manager' => $manager,
85
-				'certificateManager' => $certificateManager,
86
-				'HttpClientService' => $httpClientService,
87
-			]
88
-		);
89
-	}
76
+        return new TestSharingExternalStorage(
77
+            [
78
+                'cloudId' => new CloudId('testOwner@' . $uri, 'testOwner', $uri),
79
+                'remote' => $uri,
80
+                'owner' => 'testOwner',
81
+                'mountpoint' => 'remoteshare',
82
+                'token' => 'abcdef',
83
+                'password' => '',
84
+                'manager' => $manager,
85
+                'certificateManager' => $certificateManager,
86
+                'HttpClientService' => $httpClientService,
87
+            ]
88
+        );
89
+    }
90 90
 
91
-	#[\PHPUnit\Framework\Attributes\DataProvider('optionsProvider')]
92
-	public function testStorageMountOptions($inputUri, $baseUri): void {
93
-		$storage = $this->getTestStorage($inputUri);
94
-		$this->assertEquals($baseUri, $storage->getBaseUri());
95
-	}
91
+    #[\PHPUnit\Framework\Attributes\DataProvider('optionsProvider')]
92
+    public function testStorageMountOptions($inputUri, $baseUri): void {
93
+        $storage = $this->getTestStorage($inputUri);
94
+        $this->assertEquals($baseUri, $storage->getBaseUri());
95
+    }
96 96
 
97
-	public function testIfTestReturnsTheValue(): void {
98
-		$storage = $this->getTestStorage('https://remoteserver');
99
-		$result = $storage->test();
100
-		$this->assertSame(true, $result);
101
-	}
97
+    public function testIfTestReturnsTheValue(): void {
98
+        $storage = $this->getTestStorage('https://remoteserver');
99
+        $result = $storage->test();
100
+        $this->assertSame(true, $result);
101
+    }
102 102
 }
103 103
 
104 104
 /**
105 105
  * Dummy subclass to make it possible to access private members
106 106
  */
107 107
 class TestSharingExternalStorage extends Storage {
108
-	public function getBaseUri() {
109
-		return $this->createBaseUri();
110
-	}
108
+    public function getBaseUri() {
109
+        return $this->createBaseUri();
110
+    }
111 111
 
112
-	public function stat(string $path): array|false {
113
-		if ($path === '') {
114
-			return ['key' => 'value'];
115
-		}
116
-		return parent::stat($path);
117
-	}
112
+    public function stat(string $path): array|false {
113
+        if ($path === '') {
114
+            return ['key' => 'value'];
115
+        }
116
+        return parent::stat($path);
117
+    }
118 118
 }
Please login to merge, or discard this patch.
apps/files_sharing/tests/SharesReminderJobTest.php 1 patch
Indentation   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -34,160 +34,160 @@
 block discarded – undo
34 34
  * @package OCA\Files_Sharing\Tests
35 35
  */
36 36
 class SharesReminderJobTest extends \Test\TestCase {
37
-	private SharesReminderJob $job;
38
-	private IDBConnection $db;
39
-	private IManager $shareManager;
40
-	private IUserManager $userManager;
41
-	private IMailer|MockObject $mailer;
42
-	private string $user1;
43
-	private string $user2;
44
-
45
-	protected function setUp(): void {
46
-		parent::setUp();
47
-
48
-		$this->db = Server::get(IDBConnection::class);
49
-		$this->shareManager = Server::get(IManager::class);
50
-		$this->userManager = Server::get(IUserManager::class);
51
-		$this->mailer = $this->createMock(IMailer::class);
52
-
53
-		// Clear occasional leftover shares from other tests
54
-		$this->db->executeUpdate('DELETE FROM `*PREFIX*share`');
55
-
56
-		$this->user1 = $this->getUniqueID('user1_');
57
-		$this->user2 = $this->getUniqueID('user2_');
58
-
59
-		$user1 = $this->userManager->createUser($this->user1, 'longrandompassword');
60
-		$user2 = $this->userManager->createUser($this->user2, 'longrandompassword');
61
-		$user1->setSystemEMailAddress('[email protected]');
62
-		$user2->setSystemEMailAddress('[email protected]');
63
-
64
-		\OC::registerShareHooks(Server::get(SystemConfig::class));
65
-
66
-		$this->job = new SharesReminderJob(
67
-			Server::get(ITimeFactory::class),
68
-			$this->db,
69
-			Server::get(IManager::class),
70
-			$this->userManager,
71
-			Server::get(LoggerInterface::class),
72
-			Server::get(IURLGenerator::class),
73
-			Server::get(IFactory::class),
74
-			$this->mailer,
75
-			Server::get(Defaults::class),
76
-			Server::get(IMimeTypeLoader::class),
77
-		);
78
-	}
79
-
80
-	protected function tearDown(): void {
81
-		$this->db->executeUpdate('DELETE FROM `*PREFIX*share`');
82
-
83
-		$userManager = Server::get(IUserManager::class);
84
-		$user1 = $userManager->get($this->user1);
85
-		if ($user1) {
86
-			$user1->delete();
87
-		}
88
-		$user2 = $userManager->get($this->user2);
89
-		if ($user2) {
90
-			$user2->delete();
91
-		}
92
-
93
-		$this->logout();
94
-
95
-		parent::tearDown();
96
-	}
97
-
98
-	public static function dataSharesReminder() {
99
-		$someMail = '[email protected]';
100
-		$noExpirationDate = null;
101
-		$today = new \DateTime();
102
-		// For expiration dates, the time is always automatically set to zero by ShareAPIController
103
-		$today->setTime(0, 0);
104
-		$nearFuture = new \DateTime();
105
-		$nearFuture->setTimestamp($today->getTimestamp() + 86400 * 1);
106
-		$farFuture = new \DateTime();
107
-		$farFuture->setTimestamp($today->getTimestamp() + 86400 * 2);
108
-		$permissionRead = Constants::PERMISSION_READ;
109
-		$permissionCreate = $permissionRead | Constants::PERMISSION_CREATE;
110
-		$permissionUpdate = $permissionRead | Constants::PERMISSION_UPDATE;
111
-		$permissionDelete = $permissionRead | Constants::PERMISSION_DELETE;
112
-		$permissionAll = Constants::PERMISSION_ALL;
113
-
114
-		return [
115
-			// No reminders for folders without expiration date
116
-			[$noExpirationDate, '', false, $permissionRead, false],
117
-			[$noExpirationDate, '', false, $permissionCreate, false],
118
-			[$noExpirationDate, '', true, $permissionDelete, false],
119
-			[$noExpirationDate, '', true, $permissionCreate, false],
120
-			[$noExpirationDate, $someMail, false, $permissionUpdate, false],
121
-			[$noExpirationDate, $someMail, false, $permissionCreate, false],
122
-			[$noExpirationDate, $someMail, true, $permissionRead, false],
123
-			[$noExpirationDate, $someMail, true, $permissionAll, false],
124
-			// No reminders for folders with expiration date in the far future
125
-			[$farFuture, '', false, $permissionRead, false],
126
-			[$farFuture, '', false, $permissionCreate, false],
127
-			[$farFuture, '', true, $permissionDelete, false],
128
-			[$farFuture, '', true, $permissionCreate, false],
129
-			[$farFuture, $someMail, false, $permissionUpdate, false],
130
-			[$farFuture, $someMail, false, $permissionCreate, false],
131
-			[$farFuture, $someMail, true, $permissionRead, false],
132
-			[$farFuture, $someMail, true, $permissionAll, false],
133
-			/* Should send reminders for folders with expiration date in the near future
37
+    private SharesReminderJob $job;
38
+    private IDBConnection $db;
39
+    private IManager $shareManager;
40
+    private IUserManager $userManager;
41
+    private IMailer|MockObject $mailer;
42
+    private string $user1;
43
+    private string $user2;
44
+
45
+    protected function setUp(): void {
46
+        parent::setUp();
47
+
48
+        $this->db = Server::get(IDBConnection::class);
49
+        $this->shareManager = Server::get(IManager::class);
50
+        $this->userManager = Server::get(IUserManager::class);
51
+        $this->mailer = $this->createMock(IMailer::class);
52
+
53
+        // Clear occasional leftover shares from other tests
54
+        $this->db->executeUpdate('DELETE FROM `*PREFIX*share`');
55
+
56
+        $this->user1 = $this->getUniqueID('user1_');
57
+        $this->user2 = $this->getUniqueID('user2_');
58
+
59
+        $user1 = $this->userManager->createUser($this->user1, 'longrandompassword');
60
+        $user2 = $this->userManager->createUser($this->user2, 'longrandompassword');
61
+        $user1->setSystemEMailAddress('[email protected]');
62
+        $user2->setSystemEMailAddress('[email protected]');
63
+
64
+        \OC::registerShareHooks(Server::get(SystemConfig::class));
65
+
66
+        $this->job = new SharesReminderJob(
67
+            Server::get(ITimeFactory::class),
68
+            $this->db,
69
+            Server::get(IManager::class),
70
+            $this->userManager,
71
+            Server::get(LoggerInterface::class),
72
+            Server::get(IURLGenerator::class),
73
+            Server::get(IFactory::class),
74
+            $this->mailer,
75
+            Server::get(Defaults::class),
76
+            Server::get(IMimeTypeLoader::class),
77
+        );
78
+    }
79
+
80
+    protected function tearDown(): void {
81
+        $this->db->executeUpdate('DELETE FROM `*PREFIX*share`');
82
+
83
+        $userManager = Server::get(IUserManager::class);
84
+        $user1 = $userManager->get($this->user1);
85
+        if ($user1) {
86
+            $user1->delete();
87
+        }
88
+        $user2 = $userManager->get($this->user2);
89
+        if ($user2) {
90
+            $user2->delete();
91
+        }
92
+
93
+        $this->logout();
94
+
95
+        parent::tearDown();
96
+    }
97
+
98
+    public static function dataSharesReminder() {
99
+        $someMail = '[email protected]';
100
+        $noExpirationDate = null;
101
+        $today = new \DateTime();
102
+        // For expiration dates, the time is always automatically set to zero by ShareAPIController
103
+        $today->setTime(0, 0);
104
+        $nearFuture = new \DateTime();
105
+        $nearFuture->setTimestamp($today->getTimestamp() + 86400 * 1);
106
+        $farFuture = new \DateTime();
107
+        $farFuture->setTimestamp($today->getTimestamp() + 86400 * 2);
108
+        $permissionRead = Constants::PERMISSION_READ;
109
+        $permissionCreate = $permissionRead | Constants::PERMISSION_CREATE;
110
+        $permissionUpdate = $permissionRead | Constants::PERMISSION_UPDATE;
111
+        $permissionDelete = $permissionRead | Constants::PERMISSION_DELETE;
112
+        $permissionAll = Constants::PERMISSION_ALL;
113
+
114
+        return [
115
+            // No reminders for folders without expiration date
116
+            [$noExpirationDate, '', false, $permissionRead, false],
117
+            [$noExpirationDate, '', false, $permissionCreate, false],
118
+            [$noExpirationDate, '', true, $permissionDelete, false],
119
+            [$noExpirationDate, '', true, $permissionCreate, false],
120
+            [$noExpirationDate, $someMail, false, $permissionUpdate, false],
121
+            [$noExpirationDate, $someMail, false, $permissionCreate, false],
122
+            [$noExpirationDate, $someMail, true, $permissionRead, false],
123
+            [$noExpirationDate, $someMail, true, $permissionAll, false],
124
+            // No reminders for folders with expiration date in the far future
125
+            [$farFuture, '', false, $permissionRead, false],
126
+            [$farFuture, '', false, $permissionCreate, false],
127
+            [$farFuture, '', true, $permissionDelete, false],
128
+            [$farFuture, '', true, $permissionCreate, false],
129
+            [$farFuture, $someMail, false, $permissionUpdate, false],
130
+            [$farFuture, $someMail, false, $permissionCreate, false],
131
+            [$farFuture, $someMail, true, $permissionRead, false],
132
+            [$farFuture, $someMail, true, $permissionAll, false],
133
+            /* Should send reminders for folders with expiration date in the near future
134 134
 			if the folder is empty and the user has write permission */
135
-			[$nearFuture, '', false, $permissionRead, false],
136
-			[$nearFuture, '', false, $permissionCreate, false],
137
-			[$nearFuture, '', true, $permissionDelete, false],
138
-			[$nearFuture, '', true, $permissionCreate, true],
139
-			[$nearFuture, $someMail, false, $permissionUpdate, false],
140
-			[$nearFuture, $someMail, false, $permissionCreate, false],
141
-			[$nearFuture, $someMail, true, $permissionRead, false],
142
-			[$nearFuture, $someMail, true, $permissionAll, true],
143
-		];
144
-	}
145
-
146
-	/**
147
-	 *
148
-	 * @param \DateTime|null $expirationDate Share expiration date
149
-	 * @param string $email Share with this email. If empty, the share is of type TYPE_USER and the sharee is user2
150
-	 * @param bool $isEmpty Is share folder empty?
151
-	 * @param int $permissions
152
-	 * @param bool $shouldBeReminded
153
-	 */
154
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataSharesReminder')]
155
-	public function testSharesReminder(
156
-		?\DateTime $expirationDate, string $email, bool $isEmpty, int $permissions, bool $shouldBeReminded,
157
-	): void {
158
-		$this->loginAsUser($this->user1);
159
-
160
-		$user1Folder = Server::get(IRootFolder::class)->getUserFolder($this->user1);
161
-		$testFolder = $user1Folder->newFolder('test');
162
-
163
-		if (!$isEmpty) {
164
-			$testFolder->newFile('some_file.txt', 'content');
165
-		}
166
-
167
-		$share = $this->shareManager->newShare();
168
-
169
-		$share->setNode($testFolder)
170
-			->setShareType(($email ? IShare::TYPE_EMAIL : IShare::TYPE_USER))
171
-			->setPermissions($permissions)
172
-			->setSharedBy($this->user1)
173
-			->setSharedWith(($email ?: $this->user2))
174
-			->setExpirationDate($expirationDate);
175
-		$share = $this->shareManager->createShare($share);
176
-
177
-		$this->logout();
178
-		$messageMock = $this->createMock(IMessage::class);
179
-		$this->mailer->method('createMessage')->willReturn($messageMock);
180
-		$this->mailer
181
-			->expects(($shouldBeReminded ? $this->once() : $this->never()))
182
-			->method('send')
183
-			->with($messageMock);
184
-		$messageMock
185
-			->expects(($shouldBeReminded ? $this->once() : $this->never()))
186
-			->method('setTo')
187
-			->with([$email ?: $this->userManager->get($this->user2)->getSystemEMailAddress()]);
188
-		$this->assertSame(false, $share->getReminderSent());
189
-		$this->job->run([]);
190
-		$share = $this->shareManager->getShareById($share->getFullId());
191
-		$this->assertEquals($shouldBeReminded, $share->getReminderSent());
192
-	}
135
+            [$nearFuture, '', false, $permissionRead, false],
136
+            [$nearFuture, '', false, $permissionCreate, false],
137
+            [$nearFuture, '', true, $permissionDelete, false],
138
+            [$nearFuture, '', true, $permissionCreate, true],
139
+            [$nearFuture, $someMail, false, $permissionUpdate, false],
140
+            [$nearFuture, $someMail, false, $permissionCreate, false],
141
+            [$nearFuture, $someMail, true, $permissionRead, false],
142
+            [$nearFuture, $someMail, true, $permissionAll, true],
143
+        ];
144
+    }
145
+
146
+    /**
147
+     *
148
+     * @param \DateTime|null $expirationDate Share expiration date
149
+     * @param string $email Share with this email. If empty, the share is of type TYPE_USER and the sharee is user2
150
+     * @param bool $isEmpty Is share folder empty?
151
+     * @param int $permissions
152
+     * @param bool $shouldBeReminded
153
+     */
154
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataSharesReminder')]
155
+    public function testSharesReminder(
156
+        ?\DateTime $expirationDate, string $email, bool $isEmpty, int $permissions, bool $shouldBeReminded,
157
+    ): void {
158
+        $this->loginAsUser($this->user1);
159
+
160
+        $user1Folder = Server::get(IRootFolder::class)->getUserFolder($this->user1);
161
+        $testFolder = $user1Folder->newFolder('test');
162
+
163
+        if (!$isEmpty) {
164
+            $testFolder->newFile('some_file.txt', 'content');
165
+        }
166
+
167
+        $share = $this->shareManager->newShare();
168
+
169
+        $share->setNode($testFolder)
170
+            ->setShareType(($email ? IShare::TYPE_EMAIL : IShare::TYPE_USER))
171
+            ->setPermissions($permissions)
172
+            ->setSharedBy($this->user1)
173
+            ->setSharedWith(($email ?: $this->user2))
174
+            ->setExpirationDate($expirationDate);
175
+        $share = $this->shareManager->createShare($share);
176
+
177
+        $this->logout();
178
+        $messageMock = $this->createMock(IMessage::class);
179
+        $this->mailer->method('createMessage')->willReturn($messageMock);
180
+        $this->mailer
181
+            ->expects(($shouldBeReminded ? $this->once() : $this->never()))
182
+            ->method('send')
183
+            ->with($messageMock);
184
+        $messageMock
185
+            ->expects(($shouldBeReminded ? $this->once() : $this->never()))
186
+            ->method('setTo')
187
+            ->with([$email ?: $this->userManager->get($this->user2)->getSystemEMailAddress()]);
188
+        $this->assertSame(false, $share->getReminderSent());
189
+        $this->job->run([]);
190
+        $share = $this->shareManager->getShareById($share->getFullId());
191
+        $this->assertEquals($shouldBeReminded, $share->getReminderSent());
192
+    }
193 193
 }
Please login to merge, or discard this patch.
apps/files_sharing/tests/SharedStorageTest.php 1 patch
Indentation   +562 added lines, -562 removed lines patch added patch discarded remove patch
@@ -29,584 +29,584 @@
 block discarded – undo
29 29
  * @group DB
30 30
  */
31 31
 class SharedStorageTest extends TestCase {
32
-	protected function setUp(): void {
33
-		parent::setUp();
34
-		// register trashbin hooks
35
-		$trashbinApp = new Application();
36
-		$trashbinApp->boot($this->createMock(IBootContext::class));
37
-		$this->folder = '/folder_share_storage_test';
38
-
39
-		$this->filename = '/share-api-storage.txt';
40
-
41
-
42
-		$this->view->mkdir($this->folder);
43
-
44
-		// save file with content
45
-		$this->view->file_put_contents($this->filename, 'root file');
46
-		$this->view->file_put_contents($this->folder . $this->filename, 'file in subfolder');
47
-	}
32
+    protected function setUp(): void {
33
+        parent::setUp();
34
+        // register trashbin hooks
35
+        $trashbinApp = new Application();
36
+        $trashbinApp->boot($this->createMock(IBootContext::class));
37
+        $this->folder = '/folder_share_storage_test';
38
+
39
+        $this->filename = '/share-api-storage.txt';
40
+
41
+
42
+        $this->view->mkdir($this->folder);
43
+
44
+        // save file with content
45
+        $this->view->file_put_contents($this->filename, 'root file');
46
+        $this->view->file_put_contents($this->folder . $this->filename, 'file in subfolder');
47
+    }
48 48
 
49
-	protected function tearDown(): void {
50
-		if ($this->view) {
51
-			if ($this->view->file_exists($this->folder)) {
52
-				$this->view->unlink($this->folder);
53
-			}
54
-			if ($this->view->file_exists($this->filename)) {
55
-				$this->view->unlink($this->filename);
56
-			}
57
-		}
49
+    protected function tearDown(): void {
50
+        if ($this->view) {
51
+            if ($this->view->file_exists($this->folder)) {
52
+                $this->view->unlink($this->folder);
53
+            }
54
+            if ($this->view->file_exists($this->filename)) {
55
+                $this->view->unlink($this->filename);
56
+            }
57
+        }
58 58
 
59
-		Filesystem::getLoader()->removeStorageWrapper('oc_trashbin');
60
-
61
-		parent::tearDown();
62
-	}
63
-
64
-	/**
65
-	 * if the parent of the mount point is gone then the mount point should move up
66
-	 *
67
-	 * @medium
68
-	 */
69
-	public function testParentOfMountPointIsGone(): void {
70
-
71
-		// share to user
72
-		$share = $this->share(
73
-			IShare::TYPE_USER,
74
-			$this->folder,
75
-			self::TEST_FILES_SHARING_API_USER1,
76
-			self::TEST_FILES_SHARING_API_USER2,
77
-			Constants::PERMISSION_ALL
78
-		);
79
-
80
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
81
-		$user2View = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
82
-		$this->assertTrue($user2View->file_exists($this->folder));
83
-
84
-		// create a local folder
85
-		$result = $user2View->mkdir('localfolder');
86
-		$this->assertTrue($result);
87
-
88
-		// move mount point to local folder
89
-		$result = $user2View->rename($this->folder, '/localfolder/' . $this->folder);
90
-		$this->assertTrue($result);
91
-
92
-		// mount point in the root folder should no longer exist
93
-		$this->assertFalse($user2View->is_dir($this->folder));
94
-
95
-		// delete the local folder
96
-		/** @var Storage $storage */
97
-		[$storage, $internalPath] = Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/localfolder');
98
-		$storage->rmdir($internalPath);
99
-
100
-		//enforce reload of the mount points
101
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
102
-
103
-		//mount point should be back at the root
104
-		$this->assertTrue($user2View->is_dir($this->folder));
105
-
106
-		//cleanup
107
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
108
-		$this->view->unlink($this->folder);
109
-	}
110
-
111
-	/**
112
-	 * @medium
113
-	 */
114
-	public function testRenamePartFile(): void {
115
-
116
-		// share to user
117
-		$share = $this->share(
118
-			IShare::TYPE_USER,
119
-			$this->folder,
120
-			self::TEST_FILES_SHARING_API_USER1,
121
-			self::TEST_FILES_SHARING_API_USER2,
122
-			Constants::PERMISSION_ALL
123
-		);
124
-
125
-
126
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
127
-		$user2View = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
128
-
129
-		$this->assertTrue($user2View->file_exists($this->folder));
130
-
131
-		// create part file
132
-		$result = $user2View->file_put_contents($this->folder . '/foo.txt.part', 'some test data');
133
-
134
-		$this->assertTrue(is_int($result));
135
-		// rename part file to real file
136
-		$result = $user2View->rename($this->folder . '/foo.txt.part', $this->folder . '/foo.txt');
59
+        Filesystem::getLoader()->removeStorageWrapper('oc_trashbin');
60
+
61
+        parent::tearDown();
62
+    }
63
+
64
+    /**
65
+     * if the parent of the mount point is gone then the mount point should move up
66
+     *
67
+     * @medium
68
+     */
69
+    public function testParentOfMountPointIsGone(): void {
70
+
71
+        // share to user
72
+        $share = $this->share(
73
+            IShare::TYPE_USER,
74
+            $this->folder,
75
+            self::TEST_FILES_SHARING_API_USER1,
76
+            self::TEST_FILES_SHARING_API_USER2,
77
+            Constants::PERMISSION_ALL
78
+        );
79
+
80
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
81
+        $user2View = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
82
+        $this->assertTrue($user2View->file_exists($this->folder));
83
+
84
+        // create a local folder
85
+        $result = $user2View->mkdir('localfolder');
86
+        $this->assertTrue($result);
87
+
88
+        // move mount point to local folder
89
+        $result = $user2View->rename($this->folder, '/localfolder/' . $this->folder);
90
+        $this->assertTrue($result);
91
+
92
+        // mount point in the root folder should no longer exist
93
+        $this->assertFalse($user2View->is_dir($this->folder));
94
+
95
+        // delete the local folder
96
+        /** @var Storage $storage */
97
+        [$storage, $internalPath] = Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/localfolder');
98
+        $storage->rmdir($internalPath);
99
+
100
+        //enforce reload of the mount points
101
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
102
+
103
+        //mount point should be back at the root
104
+        $this->assertTrue($user2View->is_dir($this->folder));
105
+
106
+        //cleanup
107
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
108
+        $this->view->unlink($this->folder);
109
+    }
110
+
111
+    /**
112
+     * @medium
113
+     */
114
+    public function testRenamePartFile(): void {
115
+
116
+        // share to user
117
+        $share = $this->share(
118
+            IShare::TYPE_USER,
119
+            $this->folder,
120
+            self::TEST_FILES_SHARING_API_USER1,
121
+            self::TEST_FILES_SHARING_API_USER2,
122
+            Constants::PERMISSION_ALL
123
+        );
124
+
125
+
126
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
127
+        $user2View = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
128
+
129
+        $this->assertTrue($user2View->file_exists($this->folder));
130
+
131
+        // create part file
132
+        $result = $user2View->file_put_contents($this->folder . '/foo.txt.part', 'some test data');
133
+
134
+        $this->assertTrue(is_int($result));
135
+        // rename part file to real file
136
+        $result = $user2View->rename($this->folder . '/foo.txt.part', $this->folder . '/foo.txt');
137 137
 
138
-		$this->assertTrue($result);
139
-
140
-		// check if the new file really exists
141
-		$this->assertTrue($user2View->file_exists($this->folder . '/foo.txt'));
142
-
143
-		// check if the rename also affected the owner
144
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
145
-
146
-		$this->assertTrue($this->view->file_exists($this->folder . '/foo.txt'));
147
-
148
-		//cleanup
149
-		$this->shareManager->deleteShare($share);
150
-	}
151
-
152
-	public function testFilesize(): void {
153
-		$folderSize = $this->view->filesize($this->folder);
154
-		$file1Size = $this->view->filesize($this->folder . $this->filename);
155
-		$file2Size = $this->view->filesize($this->filename);
156
-
157
-		$share1 = $this->share(
158
-			IShare::TYPE_USER,
159
-			$this->folder,
160
-			self::TEST_FILES_SHARING_API_USER1,
161
-			self::TEST_FILES_SHARING_API_USER2,
162
-			Constants::PERMISSION_ALL
163
-		);
164
-
165
-		$share2 = $this->share(
166
-			IShare::TYPE_USER,
167
-			$this->filename,
168
-			self::TEST_FILES_SHARING_API_USER1,
169
-			self::TEST_FILES_SHARING_API_USER2,
170
-			Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE | Constants::PERMISSION_SHARE
171
-		);
172
-
173
-
174
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
175
-
176
-		// compare file size between user1 and user2, should always be the same
177
-		$this->assertSame($folderSize, Filesystem::filesize($this->folder));
178
-		$this->assertSame($file1Size, Filesystem::filesize($this->folder . $this->filename));
179
-		$this->assertSame($file2Size, Filesystem::filesize($this->filename));
138
+        $this->assertTrue($result);
139
+
140
+        // check if the new file really exists
141
+        $this->assertTrue($user2View->file_exists($this->folder . '/foo.txt'));
142
+
143
+        // check if the rename also affected the owner
144
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
145
+
146
+        $this->assertTrue($this->view->file_exists($this->folder . '/foo.txt'));
147
+
148
+        //cleanup
149
+        $this->shareManager->deleteShare($share);
150
+    }
151
+
152
+    public function testFilesize(): void {
153
+        $folderSize = $this->view->filesize($this->folder);
154
+        $file1Size = $this->view->filesize($this->folder . $this->filename);
155
+        $file2Size = $this->view->filesize($this->filename);
156
+
157
+        $share1 = $this->share(
158
+            IShare::TYPE_USER,
159
+            $this->folder,
160
+            self::TEST_FILES_SHARING_API_USER1,
161
+            self::TEST_FILES_SHARING_API_USER2,
162
+            Constants::PERMISSION_ALL
163
+        );
164
+
165
+        $share2 = $this->share(
166
+            IShare::TYPE_USER,
167
+            $this->filename,
168
+            self::TEST_FILES_SHARING_API_USER1,
169
+            self::TEST_FILES_SHARING_API_USER2,
170
+            Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE | Constants::PERMISSION_SHARE
171
+        );
172
+
173
+
174
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
175
+
176
+        // compare file size between user1 and user2, should always be the same
177
+        $this->assertSame($folderSize, Filesystem::filesize($this->folder));
178
+        $this->assertSame($file1Size, Filesystem::filesize($this->folder . $this->filename));
179
+        $this->assertSame($file2Size, Filesystem::filesize($this->filename));
180 180
 
181
-		//cleanup
182
-		$this->shareManager->deleteShare($share1);
183
-		$this->shareManager->deleteShare($share2);
184
-	}
181
+        //cleanup
182
+        $this->shareManager->deleteShare($share1);
183
+        $this->shareManager->deleteShare($share2);
184
+    }
185 185
 
186
-	public function testGetPermissions(): void {
187
-		$share = $this->share(
188
-			IShare::TYPE_USER,
189
-			$this->folder,
190
-			self::TEST_FILES_SHARING_API_USER1,
191
-			self::TEST_FILES_SHARING_API_USER2,
192
-			Constants::PERMISSION_READ
193
-		);
186
+    public function testGetPermissions(): void {
187
+        $share = $this->share(
188
+            IShare::TYPE_USER,
189
+            $this->folder,
190
+            self::TEST_FILES_SHARING_API_USER1,
191
+            self::TEST_FILES_SHARING_API_USER2,
192
+            Constants::PERMISSION_READ
193
+        );
194 194
 
195 195
 
196
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
196
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
197 197
 
198
-		$this->assertTrue(Filesystem::is_dir($this->folder));
198
+        $this->assertTrue(Filesystem::is_dir($this->folder));
199 199
 
200
-		// for the share root we expect:
201
-		// the read permissions (1)
202
-		// the delete permission (8), to enable unshare
203
-		$rootInfo = Filesystem::getFileInfo($this->folder);
204
-		$this->assertSame(9, $rootInfo->getPermissions());
200
+        // for the share root we expect:
201
+        // the read permissions (1)
202
+        // the delete permission (8), to enable unshare
203
+        $rootInfo = Filesystem::getFileInfo($this->folder);
204
+        $this->assertSame(9, $rootInfo->getPermissions());
205 205
 
206
-		// for the file within the shared folder we expect:
207
-		// the read permissions (1)
208
-		$subfileInfo = Filesystem::getFileInfo($this->folder . $this->filename);
209
-		$this->assertSame(1, $subfileInfo->getPermissions());
206
+        // for the file within the shared folder we expect:
207
+        // the read permissions (1)
208
+        $subfileInfo = Filesystem::getFileInfo($this->folder . $this->filename);
209
+        $this->assertSame(1, $subfileInfo->getPermissions());
210 210
 
211 211
 
212
-		//cleanup
213
-		$this->shareManager->deleteShare($share);
214
-	}
215
-
216
-	public function testFopenWithReadOnlyPermission(): void {
217
-		$this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
212
+        //cleanup
213
+        $this->shareManager->deleteShare($share);
214
+    }
215
+
216
+    public function testFopenWithReadOnlyPermission(): void {
217
+        $this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
218 218
 
219
-		$share = $this->share(
220
-			IShare::TYPE_USER,
221
-			$this->folder,
222
-			self::TEST_FILES_SHARING_API_USER1,
223
-			self::TEST_FILES_SHARING_API_USER2,
224
-			Constants::PERMISSION_READ
225
-		);
219
+        $share = $this->share(
220
+            IShare::TYPE_USER,
221
+            $this->folder,
222
+            self::TEST_FILES_SHARING_API_USER1,
223
+            self::TEST_FILES_SHARING_API_USER2,
224
+            Constants::PERMISSION_READ
225
+        );
226 226
 
227
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
228
-		$user2View = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
227
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
228
+        $user2View = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
229 229
 
230
-		// part file should be forbidden
231
-		$handle = $user2View->fopen($this->folder . '/test.txt.part', 'w');
232
-		$this->assertFalse($handle);
230
+        // part file should be forbidden
231
+        $handle = $user2View->fopen($this->folder . '/test.txt.part', 'w');
232
+        $this->assertFalse($handle);
233 233
 
234
-		// regular file forbidden
235
-		$handle = $user2View->fopen($this->folder . '/test.txt', 'w');
236
-		$this->assertFalse($handle);
234
+        // regular file forbidden
235
+        $handle = $user2View->fopen($this->folder . '/test.txt', 'w');
236
+        $this->assertFalse($handle);
237 237
 
238
-		// rename forbidden
239
-		$this->assertFalse($user2View->rename($this->folder . '/existing.txt', $this->folder . '/existing2.txt'));
240
-
241
-		// delete forbidden
242
-		$this->assertFalse($user2View->unlink($this->folder . '/existing.txt'));
243
-
244
-		//cleanup
245
-		$this->shareManager->deleteShare($share);
246
-	}
247
-
248
-	public function testFopenWithCreateOnlyPermission(): void {
249
-		$this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
250
-		$fileinfoFolder = $this->view->getFileInfo($this->folder);
251
-
252
-		$share = $this->share(
253
-			IShare::TYPE_USER,
254
-			$this->folder,
255
-			self::TEST_FILES_SHARING_API_USER1,
256
-			self::TEST_FILES_SHARING_API_USER2,
257
-			Constants::PERMISSION_READ | Constants::PERMISSION_CREATE
258
-		);
259
-
260
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
261
-		$user2View = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
262
-
263
-		// create part file allowed
264
-		$handle = $user2View->fopen($this->folder . '/test.txt.part', 'w');
265
-		$this->assertNotFalse($handle);
266
-		fclose($handle);
267
-
268
-		// create regular file allowed
269
-		$handle = $user2View->fopen($this->folder . '/test-create.txt', 'w');
270
-		$this->assertNotFalse($handle);
271
-		fclose($handle);
238
+        // rename forbidden
239
+        $this->assertFalse($user2View->rename($this->folder . '/existing.txt', $this->folder . '/existing2.txt'));
240
+
241
+        // delete forbidden
242
+        $this->assertFalse($user2View->unlink($this->folder . '/existing.txt'));
243
+
244
+        //cleanup
245
+        $this->shareManager->deleteShare($share);
246
+    }
247
+
248
+    public function testFopenWithCreateOnlyPermission(): void {
249
+        $this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
250
+        $fileinfoFolder = $this->view->getFileInfo($this->folder);
251
+
252
+        $share = $this->share(
253
+            IShare::TYPE_USER,
254
+            $this->folder,
255
+            self::TEST_FILES_SHARING_API_USER1,
256
+            self::TEST_FILES_SHARING_API_USER2,
257
+            Constants::PERMISSION_READ | Constants::PERMISSION_CREATE
258
+        );
259
+
260
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
261
+        $user2View = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
262
+
263
+        // create part file allowed
264
+        $handle = $user2View->fopen($this->folder . '/test.txt.part', 'w');
265
+        $this->assertNotFalse($handle);
266
+        fclose($handle);
267
+
268
+        // create regular file allowed
269
+        $handle = $user2View->fopen($this->folder . '/test-create.txt', 'w');
270
+        $this->assertNotFalse($handle);
271
+        fclose($handle);
272 272
 
273
-		// rename file never allowed
274
-		$this->assertFalse($user2View->rename($this->folder . '/test-create.txt', $this->folder . '/newtarget.txt'));
275
-		$this->assertFalse($user2View->file_exists($this->folder . '/newtarget.txt'));
276
-
277
-		// rename file not allowed if target exists
278
-		$this->assertFalse($user2View->rename($this->folder . '/newtarget.txt', $this->folder . '/existing.txt'));
279
-
280
-		// overwriting file not allowed
281
-		$handle = $user2View->fopen($this->folder . '/existing.txt', 'w');
282
-		$this->assertFalse($handle);
283
-
284
-		// overwrite forbidden (no update permission)
285
-		$this->assertFalse($user2View->rename($this->folder . '/test.txt.part', $this->folder . '/existing.txt'));
286
-
287
-		// delete forbidden
288
-		$this->assertFalse($user2View->unlink($this->folder . '/existing.txt'));
289
-
290
-		//cleanup
291
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
292
-		$this->shareManager->deleteShare($share);
293
-	}
294
-
295
-	public function testFopenWithUpdateOnlyPermission(): void {
296
-		$this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
297
-
298
-		$share = $this->share(
299
-			IShare::TYPE_USER,
300
-			$this->folder,
301
-			self::TEST_FILES_SHARING_API_USER1,
302
-			self::TEST_FILES_SHARING_API_USER2,
303
-			Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE
304
-		);
305
-
306
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
307
-		$user2View = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
308
-
309
-		// create part file allowed
310
-		$handle = $user2View->fopen($this->folder . '/test.txt.part', 'w');
311
-		$this->assertNotFalse($handle);
312
-		fclose($handle);
313
-
314
-		// create regular file not allowed
315
-		$handle = $user2View->fopen($this->folder . '/test-create.txt', 'w');
316
-		$this->assertFalse($handle);
317
-
318
-		// rename part file not allowed to non-existing file
319
-		$this->assertFalse($user2View->rename($this->folder . '/test.txt.part', $this->folder . '/nonexist.txt'));
320
-
321
-		// rename part file allowed to target existing file
322
-		$this->assertTrue($user2View->rename($this->folder . '/test.txt.part', $this->folder . '/existing.txt'));
323
-		$this->assertTrue($user2View->file_exists($this->folder . '/existing.txt'));
324
-
325
-		// rename regular file allowed
326
-		$this->assertTrue($user2View->rename($this->folder . '/existing.txt', $this->folder . '/existing-renamed.txt'));
327
-		$this->assertTrue($user2View->file_exists($this->folder . '/existing-renamed.txt'));
328
-
329
-		// overwriting file directly is allowed
330
-		$handle = $user2View->fopen($this->folder . '/existing-renamed.txt', 'w');
331
-		$this->assertNotFalse($handle);
332
-		fclose($handle);
333
-
334
-		// delete forbidden
335
-		$this->assertFalse($user2View->unlink($this->folder . '/existing-renamed.txt'));
336
-
337
-		//cleanup
338
-		$this->shareManager->deleteShare($share);
339
-	}
340
-
341
-	public function testFopenWithDeleteOnlyPermission(): void {
342
-		$this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
343
-
344
-		$share = $this->share(
345
-			IShare::TYPE_USER,
346
-			$this->folder,
347
-			self::TEST_FILES_SHARING_API_USER1,
348
-			self::TEST_FILES_SHARING_API_USER2,
349
-			Constants::PERMISSION_READ | Constants::PERMISSION_DELETE
350
-		);
351
-
352
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
353
-		$user2View = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
354
-
355
-		// part file should be forbidden
356
-		$handle = $user2View->fopen($this->folder . '/test.txt.part', 'w');
357
-		$this->assertFalse($handle);
358
-
359
-		// regular file forbidden
360
-		$handle = $user2View->fopen($this->folder . '/test.txt', 'w');
361
-		$this->assertFalse($handle);
362
-
363
-		// rename forbidden
364
-		$this->assertFalse($user2View->rename($this->folder . '/existing.txt', $this->folder . '/existing2.txt'));
365
-
366
-		// delete allowed
367
-		$this->assertTrue($user2View->unlink($this->folder . '/existing.txt'));
368
-
369
-		//cleanup
370
-		$this->shareManager->deleteShare($share);
371
-	}
372
-
373
-	public function testMountSharesOtherUser(): void {
374
-		$rootView = new View('');
375
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
376
-
377
-		// share 2 different files with 2 different users
378
-		$share1 = $this->share(
379
-			IShare::TYPE_USER,
380
-			$this->folder,
381
-			self::TEST_FILES_SHARING_API_USER1,
382
-			self::TEST_FILES_SHARING_API_USER2,
383
-			Constants::PERMISSION_ALL
384
-		);
385
-		$share2 = $this->share(
386
-			IShare::TYPE_USER,
387
-			$this->filename,
388
-			self::TEST_FILES_SHARING_API_USER1,
389
-			self::TEST_FILES_SHARING_API_USER3,
390
-			Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE | Constants::PERMISSION_SHARE
391
-		);
392
-
393
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
394
-		$this->assertTrue($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->folder));
395
-
396
-		$mountConfigManager = Server::get(IMountProviderCollection::class);
397
-		$mounts = $mountConfigManager->getMountsForUser(Server::get(IUserManager::class)->get(self::TEST_FILES_SHARING_API_USER3));
398
-		array_walk($mounts, [Filesystem::getMountManager(), 'addMount']);
399
-
400
-		$this->assertTrue($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER3 . '/files/' . $this->filename));
401
-
402
-		// make sure we didn't double setup shares for user 2 or mounted the shares for user 3 in user's 2 home
403
-		$this->assertFalse($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->folder . ' (2)'));
404
-		$this->assertFalse($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->filename));
405
-
406
-		//cleanup
407
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
408
-		$this->view->unlink($this->folder);
409
-
410
-		$this->shareManager->deleteShare($share1);
411
-		$this->shareManager->deleteShare($share2);
412
-	}
413
-
414
-	public function testCopyFromStorage(): void {
415
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
416
-
417
-		$share = $this->share(
418
-			IShare::TYPE_USER,
419
-			$this->folder,
420
-			self::TEST_FILES_SHARING_API_USER1,
421
-			self::TEST_FILES_SHARING_API_USER2,
422
-			Constants::PERMISSION_ALL
423
-		);
424
-
425
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
426
-		$view = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
427
-		$this->assertTrue($view->file_exists($this->folder));
428
-
429
-		[$sharedStorage,] = $view->resolvePath($this->folder);
430
-		$this->assertTrue($sharedStorage->instanceOfStorage('OCA\Files_Sharing\ISharedStorage'));
431
-
432
-		$sourceStorage = new Temporary([]);
433
-		$sourceStorage->file_put_contents('foo.txt', 'asd');
434
-
435
-		$sharedStorage->copyFromStorage($sourceStorage, 'foo.txt', 'bar.txt');
436
-		$this->assertTrue($sharedStorage->file_exists('bar.txt'));
437
-		$this->assertEquals('asd', $sharedStorage->file_get_contents('bar.txt'));
438
-
439
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
440
-		$this->view->unlink($this->folder);
441
-		$this->shareManager->deleteShare($share);
442
-	}
443
-
444
-	public function testMoveFromStorage(): void {
445
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
446
-
447
-		$share = $this->share(
448
-			IShare::TYPE_USER,
449
-			$this->folder,
450
-			self::TEST_FILES_SHARING_API_USER1,
451
-			self::TEST_FILES_SHARING_API_USER2,
452
-			Constants::PERMISSION_ALL
453
-		);
454
-
455
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
456
-		$view = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
457
-		$this->assertTrue($view->file_exists($this->folder));
458
-
459
-		[$sharedStorage,] = $view->resolvePath($this->folder);
460
-		$this->assertTrue($sharedStorage->instanceOfStorage('OCA\Files_Sharing\ISharedStorage'));
461
-
462
-		$sourceStorage = new Temporary([]);
463
-		$sourceStorage->file_put_contents('foo.txt', 'asd');
464
-		$sourceStorage->getScanner()->scan('');
465
-
466
-		$sharedStorage->moveFromStorage($sourceStorage, 'foo.txt', 'bar.txt');
467
-		$this->assertTrue($sharedStorage->file_exists('bar.txt'));
468
-		$this->assertEquals('asd', $sharedStorage->file_get_contents('bar.txt'));
469
-
470
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
471
-		$this->view->unlink($this->folder);
472
-		$this->shareManager->deleteShare($share);
473
-	}
474
-
475
-	public function testNameConflict(): void {
476
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
477
-		$view1 = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
478
-		$view1->mkdir('foo');
479
-
480
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
481
-		$view3 = new View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
482
-		$view3->mkdir('foo');
483
-
484
-		// share a folder with the same name from two different users to the same user
485
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
486
-
487
-		$share1 = $this->share(
488
-			IShare::TYPE_GROUP,
489
-			'foo',
490
-			self::TEST_FILES_SHARING_API_USER1,
491
-			self::TEST_FILES_SHARING_API_GROUP1,
492
-			Constants::PERMISSION_ALL
493
-		);
494
-		$this->shareManager->acceptShare($share1, self::TEST_FILES_SHARING_API_USER2);
495
-
496
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
497
-
498
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
499
-
500
-		$share2 = $this->share(
501
-			IShare::TYPE_GROUP,
502
-			'foo',
503
-			self::TEST_FILES_SHARING_API_USER3,
504
-			self::TEST_FILES_SHARING_API_GROUP1,
505
-			Constants::PERMISSION_ALL
506
-		);
507
-		$this->shareManager->acceptShare($share2, self::TEST_FILES_SHARING_API_USER2);
508
-
509
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
510
-		$view2 = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
511
-
512
-		$this->assertTrue($view2->file_exists('/foo'));
513
-		$this->assertTrue($view2->file_exists('/foo (2)'));
514
-
515
-		$mount = $view2->getMount('/foo');
516
-		$this->assertInstanceOf('\OCA\Files_Sharing\SharedMount', $mount);
517
-		/** @var SharedStorage $storage */
518
-		$storage = $mount->getStorage();
519
-
520
-		$this->assertEquals(self::TEST_FILES_SHARING_API_USER1, $storage->getOwner(''));
521
-
522
-		$this->shareManager->deleteShare($share1);
523
-		$this->shareManager->deleteShare($share2);
524
-	}
525
-
526
-	public function testOwnerPermissions(): void {
527
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
528
-
529
-		$share = $this->share(
530
-			IShare::TYPE_USER,
531
-			$this->folder,
532
-			self::TEST_FILES_SHARING_API_USER1,
533
-			self::TEST_FILES_SHARING_API_USER2,
534
-			Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE
535
-		);
536
-
537
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
538
-		$view = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
539
-		$this->assertTrue($view->file_exists($this->folder));
540
-
541
-		$view->file_put_contents($this->folder . '/newfile.txt', 'asd');
542
-
543
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
544
-
545
-		$this->assertTrue($this->view->file_exists($this->folder . '/newfile.txt'));
546
-		$this->assertEquals(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE,
547
-			$this->view->getFileInfo($this->folder . '/newfile.txt')->getPermissions());
548
-
549
-		$this->view->unlink($this->folder);
550
-		$this->shareManager->deleteShare($share);
551
-	}
552
-
553
-	public function testInitWithNonExistingUser(): void {
554
-		$share = $this->createMock(IShare::class);
555
-		$share->method('getShareOwner')->willReturn('unexist');
556
-		$ownerView = $this->createMock(View::class);
557
-		$storage = new SharedStorage([
558
-			'ownerView' => $ownerView,
559
-			'superShare' => $share,
560
-			'groupedShares' => [$share],
561
-			'user' => 'user1',
562
-		]);
563
-
564
-		// trigger init
565
-		$this->assertInstanceOf(FailedStorage::class, $storage->getSourceStorage());
566
-		$this->assertInstanceOf(FailedCache::class, $storage->getCache());
567
-	}
568
-
569
-	public function testInitWithNotFoundSource(): void {
570
-		$share = $this->createMock(IShare::class);
571
-		$share->method('getShareOwner')->willReturn(self::TEST_FILES_SHARING_API_USER1);
572
-		$share->method('getNodeId')->willReturn(1);
573
-		$ownerView = $this->createMock(View::class);
574
-		$ownerView->method('getPath')->willThrowException(new NotFoundException());
575
-		$storage = new SharedStorage([
576
-			'ownerView' => $ownerView,
577
-			'superShare' => $share,
578
-			'groupedShares' => [$share],
579
-			'user' => 'user1',
580
-		]);
581
-
582
-		// trigger init
583
-		$this->assertInstanceOf(FailedStorage::class, $storage->getSourceStorage());
584
-		$this->assertInstanceOf(FailedCache::class, $storage->getCache());
585
-	}
586
-
587
-	public function testCopyPermissions(): void {
588
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
589
-
590
-		$share = $this->share(
591
-			IShare::TYPE_USER,
592
-			$this->filename,
593
-			self::TEST_FILES_SHARING_API_USER1,
594
-			self::TEST_FILES_SHARING_API_USER2,
595
-			Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE - Constants::PERMISSION_DELETE
596
-		);
597
-
598
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
599
-		$view = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
600
-		$this->assertTrue($view->file_exists($this->filename));
601
-
602
-		$this->assertTrue($view->copy($this->filename, '/target.txt'));
603
-
604
-		$this->assertTrue($view->file_exists('/target.txt'));
605
-
606
-		$info = $view->getFileInfo('/target.txt');
607
-		$this->assertEquals(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE, $info->getPermissions());
608
-
609
-		$this->view->unlink($this->filename);
610
-		$this->shareManager->deleteShare($share);
611
-	}
273
+        // rename file never allowed
274
+        $this->assertFalse($user2View->rename($this->folder . '/test-create.txt', $this->folder . '/newtarget.txt'));
275
+        $this->assertFalse($user2View->file_exists($this->folder . '/newtarget.txt'));
276
+
277
+        // rename file not allowed if target exists
278
+        $this->assertFalse($user2View->rename($this->folder . '/newtarget.txt', $this->folder . '/existing.txt'));
279
+
280
+        // overwriting file not allowed
281
+        $handle = $user2View->fopen($this->folder . '/existing.txt', 'w');
282
+        $this->assertFalse($handle);
283
+
284
+        // overwrite forbidden (no update permission)
285
+        $this->assertFalse($user2View->rename($this->folder . '/test.txt.part', $this->folder . '/existing.txt'));
286
+
287
+        // delete forbidden
288
+        $this->assertFalse($user2View->unlink($this->folder . '/existing.txt'));
289
+
290
+        //cleanup
291
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
292
+        $this->shareManager->deleteShare($share);
293
+    }
294
+
295
+    public function testFopenWithUpdateOnlyPermission(): void {
296
+        $this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
297
+
298
+        $share = $this->share(
299
+            IShare::TYPE_USER,
300
+            $this->folder,
301
+            self::TEST_FILES_SHARING_API_USER1,
302
+            self::TEST_FILES_SHARING_API_USER2,
303
+            Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE
304
+        );
305
+
306
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
307
+        $user2View = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
308
+
309
+        // create part file allowed
310
+        $handle = $user2View->fopen($this->folder . '/test.txt.part', 'w');
311
+        $this->assertNotFalse($handle);
312
+        fclose($handle);
313
+
314
+        // create regular file not allowed
315
+        $handle = $user2View->fopen($this->folder . '/test-create.txt', 'w');
316
+        $this->assertFalse($handle);
317
+
318
+        // rename part file not allowed to non-existing file
319
+        $this->assertFalse($user2View->rename($this->folder . '/test.txt.part', $this->folder . '/nonexist.txt'));
320
+
321
+        // rename part file allowed to target existing file
322
+        $this->assertTrue($user2View->rename($this->folder . '/test.txt.part', $this->folder . '/existing.txt'));
323
+        $this->assertTrue($user2View->file_exists($this->folder . '/existing.txt'));
324
+
325
+        // rename regular file allowed
326
+        $this->assertTrue($user2View->rename($this->folder . '/existing.txt', $this->folder . '/existing-renamed.txt'));
327
+        $this->assertTrue($user2View->file_exists($this->folder . '/existing-renamed.txt'));
328
+
329
+        // overwriting file directly is allowed
330
+        $handle = $user2View->fopen($this->folder . '/existing-renamed.txt', 'w');
331
+        $this->assertNotFalse($handle);
332
+        fclose($handle);
333
+
334
+        // delete forbidden
335
+        $this->assertFalse($user2View->unlink($this->folder . '/existing-renamed.txt'));
336
+
337
+        //cleanup
338
+        $this->shareManager->deleteShare($share);
339
+    }
340
+
341
+    public function testFopenWithDeleteOnlyPermission(): void {
342
+        $this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
343
+
344
+        $share = $this->share(
345
+            IShare::TYPE_USER,
346
+            $this->folder,
347
+            self::TEST_FILES_SHARING_API_USER1,
348
+            self::TEST_FILES_SHARING_API_USER2,
349
+            Constants::PERMISSION_READ | Constants::PERMISSION_DELETE
350
+        );
351
+
352
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
353
+        $user2View = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
354
+
355
+        // part file should be forbidden
356
+        $handle = $user2View->fopen($this->folder . '/test.txt.part', 'w');
357
+        $this->assertFalse($handle);
358
+
359
+        // regular file forbidden
360
+        $handle = $user2View->fopen($this->folder . '/test.txt', 'w');
361
+        $this->assertFalse($handle);
362
+
363
+        // rename forbidden
364
+        $this->assertFalse($user2View->rename($this->folder . '/existing.txt', $this->folder . '/existing2.txt'));
365
+
366
+        // delete allowed
367
+        $this->assertTrue($user2View->unlink($this->folder . '/existing.txt'));
368
+
369
+        //cleanup
370
+        $this->shareManager->deleteShare($share);
371
+    }
372
+
373
+    public function testMountSharesOtherUser(): void {
374
+        $rootView = new View('');
375
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
376
+
377
+        // share 2 different files with 2 different users
378
+        $share1 = $this->share(
379
+            IShare::TYPE_USER,
380
+            $this->folder,
381
+            self::TEST_FILES_SHARING_API_USER1,
382
+            self::TEST_FILES_SHARING_API_USER2,
383
+            Constants::PERMISSION_ALL
384
+        );
385
+        $share2 = $this->share(
386
+            IShare::TYPE_USER,
387
+            $this->filename,
388
+            self::TEST_FILES_SHARING_API_USER1,
389
+            self::TEST_FILES_SHARING_API_USER3,
390
+            Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE | Constants::PERMISSION_SHARE
391
+        );
392
+
393
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
394
+        $this->assertTrue($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->folder));
395
+
396
+        $mountConfigManager = Server::get(IMountProviderCollection::class);
397
+        $mounts = $mountConfigManager->getMountsForUser(Server::get(IUserManager::class)->get(self::TEST_FILES_SHARING_API_USER3));
398
+        array_walk($mounts, [Filesystem::getMountManager(), 'addMount']);
399
+
400
+        $this->assertTrue($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER3 . '/files/' . $this->filename));
401
+
402
+        // make sure we didn't double setup shares for user 2 or mounted the shares for user 3 in user's 2 home
403
+        $this->assertFalse($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->folder . ' (2)'));
404
+        $this->assertFalse($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->filename));
405
+
406
+        //cleanup
407
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
408
+        $this->view->unlink($this->folder);
409
+
410
+        $this->shareManager->deleteShare($share1);
411
+        $this->shareManager->deleteShare($share2);
412
+    }
413
+
414
+    public function testCopyFromStorage(): void {
415
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
416
+
417
+        $share = $this->share(
418
+            IShare::TYPE_USER,
419
+            $this->folder,
420
+            self::TEST_FILES_SHARING_API_USER1,
421
+            self::TEST_FILES_SHARING_API_USER2,
422
+            Constants::PERMISSION_ALL
423
+        );
424
+
425
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
426
+        $view = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
427
+        $this->assertTrue($view->file_exists($this->folder));
428
+
429
+        [$sharedStorage,] = $view->resolvePath($this->folder);
430
+        $this->assertTrue($sharedStorage->instanceOfStorage('OCA\Files_Sharing\ISharedStorage'));
431
+
432
+        $sourceStorage = new Temporary([]);
433
+        $sourceStorage->file_put_contents('foo.txt', 'asd');
434
+
435
+        $sharedStorage->copyFromStorage($sourceStorage, 'foo.txt', 'bar.txt');
436
+        $this->assertTrue($sharedStorage->file_exists('bar.txt'));
437
+        $this->assertEquals('asd', $sharedStorage->file_get_contents('bar.txt'));
438
+
439
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
440
+        $this->view->unlink($this->folder);
441
+        $this->shareManager->deleteShare($share);
442
+    }
443
+
444
+    public function testMoveFromStorage(): void {
445
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
446
+
447
+        $share = $this->share(
448
+            IShare::TYPE_USER,
449
+            $this->folder,
450
+            self::TEST_FILES_SHARING_API_USER1,
451
+            self::TEST_FILES_SHARING_API_USER2,
452
+            Constants::PERMISSION_ALL
453
+        );
454
+
455
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
456
+        $view = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
457
+        $this->assertTrue($view->file_exists($this->folder));
458
+
459
+        [$sharedStorage,] = $view->resolvePath($this->folder);
460
+        $this->assertTrue($sharedStorage->instanceOfStorage('OCA\Files_Sharing\ISharedStorage'));
461
+
462
+        $sourceStorage = new Temporary([]);
463
+        $sourceStorage->file_put_contents('foo.txt', 'asd');
464
+        $sourceStorage->getScanner()->scan('');
465
+
466
+        $sharedStorage->moveFromStorage($sourceStorage, 'foo.txt', 'bar.txt');
467
+        $this->assertTrue($sharedStorage->file_exists('bar.txt'));
468
+        $this->assertEquals('asd', $sharedStorage->file_get_contents('bar.txt'));
469
+
470
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
471
+        $this->view->unlink($this->folder);
472
+        $this->shareManager->deleteShare($share);
473
+    }
474
+
475
+    public function testNameConflict(): void {
476
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
477
+        $view1 = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
478
+        $view1->mkdir('foo');
479
+
480
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
481
+        $view3 = new View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
482
+        $view3->mkdir('foo');
483
+
484
+        // share a folder with the same name from two different users to the same user
485
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
486
+
487
+        $share1 = $this->share(
488
+            IShare::TYPE_GROUP,
489
+            'foo',
490
+            self::TEST_FILES_SHARING_API_USER1,
491
+            self::TEST_FILES_SHARING_API_GROUP1,
492
+            Constants::PERMISSION_ALL
493
+        );
494
+        $this->shareManager->acceptShare($share1, self::TEST_FILES_SHARING_API_USER2);
495
+
496
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
497
+
498
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
499
+
500
+        $share2 = $this->share(
501
+            IShare::TYPE_GROUP,
502
+            'foo',
503
+            self::TEST_FILES_SHARING_API_USER3,
504
+            self::TEST_FILES_SHARING_API_GROUP1,
505
+            Constants::PERMISSION_ALL
506
+        );
507
+        $this->shareManager->acceptShare($share2, self::TEST_FILES_SHARING_API_USER2);
508
+
509
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
510
+        $view2 = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
511
+
512
+        $this->assertTrue($view2->file_exists('/foo'));
513
+        $this->assertTrue($view2->file_exists('/foo (2)'));
514
+
515
+        $mount = $view2->getMount('/foo');
516
+        $this->assertInstanceOf('\OCA\Files_Sharing\SharedMount', $mount);
517
+        /** @var SharedStorage $storage */
518
+        $storage = $mount->getStorage();
519
+
520
+        $this->assertEquals(self::TEST_FILES_SHARING_API_USER1, $storage->getOwner(''));
521
+
522
+        $this->shareManager->deleteShare($share1);
523
+        $this->shareManager->deleteShare($share2);
524
+    }
525
+
526
+    public function testOwnerPermissions(): void {
527
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
528
+
529
+        $share = $this->share(
530
+            IShare::TYPE_USER,
531
+            $this->folder,
532
+            self::TEST_FILES_SHARING_API_USER1,
533
+            self::TEST_FILES_SHARING_API_USER2,
534
+            Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE
535
+        );
536
+
537
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
538
+        $view = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
539
+        $this->assertTrue($view->file_exists($this->folder));
540
+
541
+        $view->file_put_contents($this->folder . '/newfile.txt', 'asd');
542
+
543
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
544
+
545
+        $this->assertTrue($this->view->file_exists($this->folder . '/newfile.txt'));
546
+        $this->assertEquals(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE,
547
+            $this->view->getFileInfo($this->folder . '/newfile.txt')->getPermissions());
548
+
549
+        $this->view->unlink($this->folder);
550
+        $this->shareManager->deleteShare($share);
551
+    }
552
+
553
+    public function testInitWithNonExistingUser(): void {
554
+        $share = $this->createMock(IShare::class);
555
+        $share->method('getShareOwner')->willReturn('unexist');
556
+        $ownerView = $this->createMock(View::class);
557
+        $storage = new SharedStorage([
558
+            'ownerView' => $ownerView,
559
+            'superShare' => $share,
560
+            'groupedShares' => [$share],
561
+            'user' => 'user1',
562
+        ]);
563
+
564
+        // trigger init
565
+        $this->assertInstanceOf(FailedStorage::class, $storage->getSourceStorage());
566
+        $this->assertInstanceOf(FailedCache::class, $storage->getCache());
567
+    }
568
+
569
+    public function testInitWithNotFoundSource(): void {
570
+        $share = $this->createMock(IShare::class);
571
+        $share->method('getShareOwner')->willReturn(self::TEST_FILES_SHARING_API_USER1);
572
+        $share->method('getNodeId')->willReturn(1);
573
+        $ownerView = $this->createMock(View::class);
574
+        $ownerView->method('getPath')->willThrowException(new NotFoundException());
575
+        $storage = new SharedStorage([
576
+            'ownerView' => $ownerView,
577
+            'superShare' => $share,
578
+            'groupedShares' => [$share],
579
+            'user' => 'user1',
580
+        ]);
581
+
582
+        // trigger init
583
+        $this->assertInstanceOf(FailedStorage::class, $storage->getSourceStorage());
584
+        $this->assertInstanceOf(FailedCache::class, $storage->getCache());
585
+    }
586
+
587
+    public function testCopyPermissions(): void {
588
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
589
+
590
+        $share = $this->share(
591
+            IShare::TYPE_USER,
592
+            $this->filename,
593
+            self::TEST_FILES_SHARING_API_USER1,
594
+            self::TEST_FILES_SHARING_API_USER2,
595
+            Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE - Constants::PERMISSION_DELETE
596
+        );
597
+
598
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
599
+        $view = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
600
+        $this->assertTrue($view->file_exists($this->filename));
601
+
602
+        $this->assertTrue($view->copy($this->filename, '/target.txt'));
603
+
604
+        $this->assertTrue($view->file_exists('/target.txt'));
605
+
606
+        $info = $view->getFileInfo('/target.txt');
607
+        $this->assertEquals(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE, $info->getPermissions());
608
+
609
+        $this->view->unlink($this->filename);
610
+        $this->shareManager->deleteShare($share);
611
+    }
612 612
 }
Please login to merge, or discard this patch.
apps/files_sharing/tests/SharedMountTest.php 1 patch
Indentation   +402 added lines, -402 removed lines patch added patch discarded remove patch
@@ -27,410 +27,410 @@
 block discarded – undo
27 27
  */
28 28
 class SharedMountTest extends TestCase {
29 29
 
30
-	/** @var IGroupManager */
31
-	private $groupManager;
32
-
33
-	/** @var IUserManager */
34
-	private $userManager;
35
-
36
-	private $folder2;
37
-
38
-	protected function setUp(): void {
39
-		parent::setUp();
40
-
41
-		$this->folder = '/folder_share_storage_test';
42
-		$this->folder2 = '/folder_share_storage_test2';
43
-
44
-		$this->filename = '/share-api-storage.txt';
45
-
46
-
47
-		$this->view->mkdir($this->folder);
48
-		$this->view->mkdir($this->folder2);
49
-
50
-		// save file with content
51
-		$this->view->file_put_contents($this->filename, 'root file');
52
-		$this->view->file_put_contents($this->folder . $this->filename, 'file in subfolder');
53
-		$this->view->file_put_contents($this->folder2 . $this->filename, 'file in subfolder2');
54
-
55
-		$this->groupManager = Server::get(IGroupManager::class);
56
-		$this->userManager = Server::get(IUserManager::class);
57
-	}
58
-
59
-	protected function tearDown(): void {
60
-		if ($this->view) {
61
-			if ($this->view->file_exists($this->folder)) {
62
-				$this->view->unlink($this->folder);
63
-			}
64
-			if ($this->view->file_exists($this->filename)) {
65
-				$this->view->unlink($this->filename);
66
-			}
67
-		}
68
-
69
-		parent::tearDown();
70
-	}
71
-
72
-	/**
73
-	 * test if the mount point moves up if the parent folder no longer exists
74
-	 */
75
-	public function testShareMountLoseParentFolder(): void {
76
-
77
-		// share to user
78
-		$share = $this->share(
79
-			IShare::TYPE_USER,
80
-			$this->folder,
81
-			self::TEST_FILES_SHARING_API_USER1,
82
-			self::TEST_FILES_SHARING_API_USER2,
83
-			Constants::PERMISSION_ALL);
84
-		$this->shareManager->acceptShare($share, self::TEST_FILES_SHARING_API_USER2);
85
-
86
-		$share->setTarget('/foo/bar' . $this->folder);
87
-		$this->shareManager->moveShare($share, self::TEST_FILES_SHARING_API_USER2);
88
-
89
-		$share = $this->shareManager->getShareById($share->getFullId());
90
-		$this->assertSame('/foo/bar' . $this->folder, $share->getTarget());
91
-
92
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
93
-		// share should have moved up
94
-
95
-		$share = $this->shareManager->getShareById($share->getFullId());
96
-		$this->assertSame($this->folder, $share->getTarget());
97
-
98
-		//cleanup
99
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
100
-		$this->shareManager->deleteShare($share);
101
-		$this->view->unlink($this->folder);
102
-	}
103
-
104
-	/**
105
-	 * @medium
106
-	 */
107
-	public function testDeleteParentOfMountPoint(): void {
108
-		// share to user
109
-		$share = $this->share(
110
-			IShare::TYPE_USER,
111
-			$this->folder,
112
-			self::TEST_FILES_SHARING_API_USER1,
113
-			self::TEST_FILES_SHARING_API_USER2,
114
-			Constants::PERMISSION_ALL
115
-		);
116
-
117
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
118
-		$user2View = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
119
-		$this->assertTrue($user2View->file_exists($this->folder));
120
-
121
-		// create a local folder
122
-		$result = $user2View->mkdir('localfolder');
123
-		$this->assertTrue($result);
124
-
125
-		// move mount point to local folder
126
-		$result = $user2View->rename($this->folder, '/localfolder/' . $this->folder);
127
-		$this->assertTrue($result);
128
-
129
-		// mount point in the root folder should no longer exist
130
-		$this->assertFalse($user2View->is_dir($this->folder));
131
-
132
-		// delete the local folder
133
-		$result = $user2View->unlink('/localfolder');
134
-		$this->assertTrue($result);
135
-
136
-		//enforce reload of the mount points
137
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
138
-
139
-		//mount point should be back at the root
140
-		$this->assertTrue($user2View->is_dir($this->folder));
141
-
142
-		//cleanup
143
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
144
-		$this->view->unlink($this->folder);
145
-	}
146
-
147
-	public function testMoveSharedFile(): void {
148
-		$share = $this->share(
149
-			IShare::TYPE_USER,
150
-			$this->filename,
151
-			self::TEST_FILES_SHARING_API_USER1,
152
-			self::TEST_FILES_SHARING_API_USER2,
153
-			Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE | Constants::PERMISSION_SHARE
154
-		);
155
-
156
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
157
-
158
-		Filesystem::rename($this->filename, $this->filename . '_renamed');
159
-
160
-		$this->assertTrue(Filesystem::file_exists($this->filename . '_renamed'));
161
-		$this->assertFalse(Filesystem::file_exists($this->filename));
162
-
163
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
164
-		$this->assertTrue(Filesystem::file_exists($this->filename));
165
-		$this->assertFalse(Filesystem::file_exists($this->filename . '_renamed'));
166
-
167
-		// rename back to original name
168
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
169
-		Filesystem::rename($this->filename . '_renamed', $this->filename);
170
-		$this->assertFalse(Filesystem::file_exists($this->filename . '_renamed'));
171
-		$this->assertTrue(Filesystem::file_exists($this->filename));
172
-
173
-		//cleanup
174
-		$this->shareManager->deleteShare($share);
175
-	}
176
-
177
-	/**
178
-	 * share file with a group if a user renames the file the filename should not change
179
-	 * for the other users
180
-	 */
181
-	public function testMoveGroupShare(): void {
182
-		$testGroup = $this->groupManager->createGroup('testGroup');
183
-		$user1 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER1);
184
-		$user2 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER2);
185
-		$user3 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER3);
186
-		$testGroup->addUser($user1);
187
-		$testGroup->addUser($user2);
188
-		$testGroup->addUser($user3);
189
-
190
-		$fileinfo = $this->view->getFileInfo($this->filename);
191
-		$share = $this->share(
192
-			IShare::TYPE_GROUP,
193
-			$this->filename,
194
-			self::TEST_FILES_SHARING_API_USER1,
195
-			'testGroup',
196
-			Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE | Constants::PERMISSION_SHARE
197
-		);
198
-		$this->shareManager->acceptShare($share, $user1->getUID());
199
-		$this->shareManager->acceptShare($share, $user2->getUID());
200
-		$this->shareManager->acceptShare($share, $user3->getUID());
201
-
202
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
203
-
204
-		$this->assertTrue(Filesystem::file_exists($this->filename));
205
-
206
-		Filesystem::rename($this->filename, 'newFileName');
207
-
208
-		$this->assertTrue(Filesystem::file_exists('newFileName'));
209
-		$this->assertFalse(Filesystem::file_exists($this->filename));
210
-
211
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
212
-		$this->assertTrue(Filesystem::file_exists($this->filename));
213
-		$this->assertFalse(Filesystem::file_exists('newFileName'));
214
-
215
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
216
-		$this->assertTrue(Filesystem::file_exists($this->filename));
217
-		$this->assertFalse(Filesystem::file_exists('newFileName'));
218
-
219
-		//cleanup
220
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
221
-		$this->shareManager->deleteShare($share);
222
-		$testGroup->removeUser($user1);
223
-		$testGroup->removeUser($user2);
224
-		$testGroup->removeUser($user3);
225
-	}
226
-
227
-	/**
228
-	 * @param string $path
229
-	 * @param string $expectedResult
230
-	 * @param bool $exception if a exception is expected
231
-	 */
232
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataProviderTestStripUserFilesPath')]
233
-	public function testStripUserFilesPath($path, $expectedResult, $exception): void {
234
-		$testClass = new DummyTestClassSharedMount(null, null);
235
-		try {
236
-			$result = $testClass->stripUserFilesPathDummy($path);
237
-			$this->assertSame($expectedResult, $result);
238
-		} catch (\Exception $e) {
239
-			if ($exception) {
240
-				$this->assertSame(10, $e->getCode());
241
-			} else {
242
-				$this->assertTrue(false, 'Exception caught, but expected: ' . $expectedResult);
243
-			}
244
-		}
245
-	}
246
-
247
-	public static function dataProviderTestStripUserFilesPath() {
248
-		return [
249
-			['/user/files/foo.txt', '/foo.txt', false],
250
-			['/user/files/folder/foo.txt', '/folder/foo.txt', false],
251
-			['/data/user/files/foo.txt', null, true],
252
-			['/data/user/files/', null, true],
253
-			['/files/foo.txt', null, true],
254
-			['/foo.txt', null, true],
255
-		];
256
-	}
257
-
258
-	/**
259
-	 * If the permissions on a group share are upgraded be sure to still respect
260
-	 * removed shares by a member of that group
261
-	 */
262
-	public function testPermissionUpgradeOnUserDeletedGroupShare(): void {
263
-		$testGroup = $this->groupManager->createGroup('testGroup');
264
-		$user1 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER1);
265
-		$user2 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER2);
266
-		$user3 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER3);
267
-		$testGroup->addUser($user1);
268
-		$testGroup->addUser($user2);
269
-		$testGroup->addUser($user3);
270
-
271
-		$connection = Server::get(IDBConnection::class);
272
-
273
-		// Share item with group
274
-		$fileinfo = $this->view->getFileInfo($this->folder);
275
-		$share = $this->share(
276
-			IShare::TYPE_GROUP,
277
-			$this->folder,
278
-			self::TEST_FILES_SHARING_API_USER1,
279
-			'testGroup',
280
-			Constants::PERMISSION_READ
281
-		);
282
-		$this->shareManager->acceptShare($share, $user1->getUID());
283
-		$this->shareManager->acceptShare($share, $user2->getUID());
284
-		$this->shareManager->acceptShare($share, $user3->getUID());
285
-
286
-		// Login as user 2 and verify the item exists
287
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
288
-		$this->assertTrue(Filesystem::file_exists($this->folder));
289
-		$result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
290
-		$this->assertNotEmpty($result);
291
-		$this->assertEquals(Constants::PERMISSION_READ, $result->getPermissions());
292
-
293
-		// Delete the share
294
-		$this->assertTrue(Filesystem::rmdir($this->folder));
295
-		$this->assertFalse(Filesystem::file_exists($this->folder));
296
-
297
-		// Verify we do not get a share
298
-		$result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
299
-		$this->assertEquals(0, $result->getPermissions());
300
-
301
-		// Login as user 1 again and change permissions
302
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
303
-		$share->setPermissions(Constants::PERMISSION_ALL);
304
-		$share = $this->shareManager->updateShare($share);
305
-
306
-		// Login as user 2 and verify
307
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
308
-		$this->assertFalse(Filesystem::file_exists($this->folder));
309
-		$result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
310
-		$this->assertEquals(0, $result->getPermissions());
311
-
312
-		$this->shareManager->deleteShare($share);
313
-
314
-		//cleanup
315
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
316
-		$testGroup->removeUser($user1);
317
-		$testGroup->removeUser($user2);
318
-		$testGroup->removeUser($user3);
319
-	}
320
-
321
-	/**
322
-	 * test if the mount point gets renamed if a folder exists at the target
323
-	 */
324
-	public function testShareMountOverFolder(): void {
325
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
326
-		$this->view2->mkdir('bar');
327
-
328
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
329
-
330
-		// share to user
331
-		$share = $this->share(
332
-			IShare::TYPE_USER,
333
-			$this->folder,
334
-			self::TEST_FILES_SHARING_API_USER1,
335
-			self::TEST_FILES_SHARING_API_USER2,
336
-			Constants::PERMISSION_ALL);
337
-		$this->shareManager->acceptShare($share, self::TEST_FILES_SHARING_API_USER2);
338
-
339
-		$share->setTarget('/bar');
340
-		$this->shareManager->moveShare($share, self::TEST_FILES_SHARING_API_USER2);
341
-
342
-		$share = $this->shareManager->getShareById($share->getFullId());
343
-
344
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
345
-		// share should have been moved
346
-
347
-		$share = $this->shareManager->getShareById($share->getFullId());
348
-		$this->assertSame('/bar (2)', $share->getTarget());
349
-
350
-		//cleanup
351
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
352
-		$this->shareManager->deleteShare($share);
353
-		$this->view->unlink($this->folder);
354
-	}
355
-
356
-	/**
357
-	 * test if the mount point gets renamed if another share exists at the target
358
-	 */
359
-	public function testShareMountOverShare(): void {
360
-		// create a shared cache
361
-		$caches = [];
362
-		$cacheFactory = $this->createMock(ICacheFactory::class);
363
-		$cacheFactory->method('createLocal')
364
-			->willReturnCallback(function (string $prefix) use (&$caches) {
365
-				if (!isset($caches[$prefix])) {
366
-					$caches[$prefix] = new ArrayCache($prefix);
367
-				}
368
-				return $caches[$prefix];
369
-			});
370
-		$cacheFactory->method('createDistributed')
371
-			->willReturnCallback(function (string $prefix) use (&$caches) {
372
-				if (!isset($caches[$prefix])) {
373
-					$caches[$prefix] = new ArrayCache($prefix);
374
-				}
375
-				return $caches[$prefix];
376
-			});
377
-
378
-		// hack to overwrite the cache factory, we can't use the proper "overwriteService" since the mount provider is created before this test is called
379
-		$mountProvider = Server::get(MountProvider::class);
380
-		$reflectionClass = new \ReflectionClass($mountProvider);
381
-		$reflectionCacheFactory = $reflectionClass->getProperty('cacheFactory');
382
-		$reflectionCacheFactory->setAccessible(true);
383
-		$reflectionCacheFactory->setValue($mountProvider, $cacheFactory);
384
-
385
-		// share to user
386
-		$share = $this->share(
387
-			IShare::TYPE_USER,
388
-			$this->folder,
389
-			self::TEST_FILES_SHARING_API_USER1,
390
-			self::TEST_FILES_SHARING_API_USER2,
391
-			Constants::PERMISSION_ALL);
392
-		$this->shareManager->acceptShare($share, self::TEST_FILES_SHARING_API_USER2);
393
-
394
-		$share->setTarget('/foobar');
395
-		$this->shareManager->moveShare($share, self::TEST_FILES_SHARING_API_USER2);
396
-
397
-
398
-		// share to user
399
-		$share2 = $this->share(
400
-			IShare::TYPE_USER,
401
-			$this->folder2,
402
-			self::TEST_FILES_SHARING_API_USER1,
403
-			self::TEST_FILES_SHARING_API_USER2,
404
-			Constants::PERMISSION_ALL);
405
-		$this->shareManager->acceptShare($share2, self::TEST_FILES_SHARING_API_USER2);
406
-
407
-		$share2->setTarget('/foobar');
408
-		$this->shareManager->moveShare($share2, self::TEST_FILES_SHARING_API_USER2);
409
-
410
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
411
-		// one of the shares should have been moved
412
-
413
-		$share = $this->shareManager->getShareById($share->getFullId());
414
-		$share2 = $this->shareManager->getShareById($share2->getFullId());
415
-
416
-		// we don't know or care which share got the "(2)" just that one of them did
417
-		$this->assertNotEquals($share->getTarget(), $share2->getTarget());
418
-		$this->assertSame('/foobar', min($share->getTarget(), $share2->getTarget()));
419
-		$this->assertSame('/foobar (2)', max($share->getTarget(), $share2->getTarget()));
420
-
421
-		//cleanup
422
-		self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
423
-		$this->shareManager->deleteShare($share);
424
-		$this->view->unlink($this->folder);
425
-	}
30
+    /** @var IGroupManager */
31
+    private $groupManager;
32
+
33
+    /** @var IUserManager */
34
+    private $userManager;
35
+
36
+    private $folder2;
37
+
38
+    protected function setUp(): void {
39
+        parent::setUp();
40
+
41
+        $this->folder = '/folder_share_storage_test';
42
+        $this->folder2 = '/folder_share_storage_test2';
43
+
44
+        $this->filename = '/share-api-storage.txt';
45
+
46
+
47
+        $this->view->mkdir($this->folder);
48
+        $this->view->mkdir($this->folder2);
49
+
50
+        // save file with content
51
+        $this->view->file_put_contents($this->filename, 'root file');
52
+        $this->view->file_put_contents($this->folder . $this->filename, 'file in subfolder');
53
+        $this->view->file_put_contents($this->folder2 . $this->filename, 'file in subfolder2');
54
+
55
+        $this->groupManager = Server::get(IGroupManager::class);
56
+        $this->userManager = Server::get(IUserManager::class);
57
+    }
58
+
59
+    protected function tearDown(): void {
60
+        if ($this->view) {
61
+            if ($this->view->file_exists($this->folder)) {
62
+                $this->view->unlink($this->folder);
63
+            }
64
+            if ($this->view->file_exists($this->filename)) {
65
+                $this->view->unlink($this->filename);
66
+            }
67
+        }
68
+
69
+        parent::tearDown();
70
+    }
71
+
72
+    /**
73
+     * test if the mount point moves up if the parent folder no longer exists
74
+     */
75
+    public function testShareMountLoseParentFolder(): void {
76
+
77
+        // share to user
78
+        $share = $this->share(
79
+            IShare::TYPE_USER,
80
+            $this->folder,
81
+            self::TEST_FILES_SHARING_API_USER1,
82
+            self::TEST_FILES_SHARING_API_USER2,
83
+            Constants::PERMISSION_ALL);
84
+        $this->shareManager->acceptShare($share, self::TEST_FILES_SHARING_API_USER2);
85
+
86
+        $share->setTarget('/foo/bar' . $this->folder);
87
+        $this->shareManager->moveShare($share, self::TEST_FILES_SHARING_API_USER2);
88
+
89
+        $share = $this->shareManager->getShareById($share->getFullId());
90
+        $this->assertSame('/foo/bar' . $this->folder, $share->getTarget());
91
+
92
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
93
+        // share should have moved up
94
+
95
+        $share = $this->shareManager->getShareById($share->getFullId());
96
+        $this->assertSame($this->folder, $share->getTarget());
97
+
98
+        //cleanup
99
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
100
+        $this->shareManager->deleteShare($share);
101
+        $this->view->unlink($this->folder);
102
+    }
103
+
104
+    /**
105
+     * @medium
106
+     */
107
+    public function testDeleteParentOfMountPoint(): void {
108
+        // share to user
109
+        $share = $this->share(
110
+            IShare::TYPE_USER,
111
+            $this->folder,
112
+            self::TEST_FILES_SHARING_API_USER1,
113
+            self::TEST_FILES_SHARING_API_USER2,
114
+            Constants::PERMISSION_ALL
115
+        );
116
+
117
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
118
+        $user2View = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
119
+        $this->assertTrue($user2View->file_exists($this->folder));
120
+
121
+        // create a local folder
122
+        $result = $user2View->mkdir('localfolder');
123
+        $this->assertTrue($result);
124
+
125
+        // move mount point to local folder
126
+        $result = $user2View->rename($this->folder, '/localfolder/' . $this->folder);
127
+        $this->assertTrue($result);
128
+
129
+        // mount point in the root folder should no longer exist
130
+        $this->assertFalse($user2View->is_dir($this->folder));
131
+
132
+        // delete the local folder
133
+        $result = $user2View->unlink('/localfolder');
134
+        $this->assertTrue($result);
135
+
136
+        //enforce reload of the mount points
137
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
138
+
139
+        //mount point should be back at the root
140
+        $this->assertTrue($user2View->is_dir($this->folder));
141
+
142
+        //cleanup
143
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
144
+        $this->view->unlink($this->folder);
145
+    }
146
+
147
+    public function testMoveSharedFile(): void {
148
+        $share = $this->share(
149
+            IShare::TYPE_USER,
150
+            $this->filename,
151
+            self::TEST_FILES_SHARING_API_USER1,
152
+            self::TEST_FILES_SHARING_API_USER2,
153
+            Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE | Constants::PERMISSION_SHARE
154
+        );
155
+
156
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
157
+
158
+        Filesystem::rename($this->filename, $this->filename . '_renamed');
159
+
160
+        $this->assertTrue(Filesystem::file_exists($this->filename . '_renamed'));
161
+        $this->assertFalse(Filesystem::file_exists($this->filename));
162
+
163
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
164
+        $this->assertTrue(Filesystem::file_exists($this->filename));
165
+        $this->assertFalse(Filesystem::file_exists($this->filename . '_renamed'));
166
+
167
+        // rename back to original name
168
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
169
+        Filesystem::rename($this->filename . '_renamed', $this->filename);
170
+        $this->assertFalse(Filesystem::file_exists($this->filename . '_renamed'));
171
+        $this->assertTrue(Filesystem::file_exists($this->filename));
172
+
173
+        //cleanup
174
+        $this->shareManager->deleteShare($share);
175
+    }
176
+
177
+    /**
178
+     * share file with a group if a user renames the file the filename should not change
179
+     * for the other users
180
+     */
181
+    public function testMoveGroupShare(): void {
182
+        $testGroup = $this->groupManager->createGroup('testGroup');
183
+        $user1 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER1);
184
+        $user2 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER2);
185
+        $user3 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER3);
186
+        $testGroup->addUser($user1);
187
+        $testGroup->addUser($user2);
188
+        $testGroup->addUser($user3);
189
+
190
+        $fileinfo = $this->view->getFileInfo($this->filename);
191
+        $share = $this->share(
192
+            IShare::TYPE_GROUP,
193
+            $this->filename,
194
+            self::TEST_FILES_SHARING_API_USER1,
195
+            'testGroup',
196
+            Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE | Constants::PERMISSION_SHARE
197
+        );
198
+        $this->shareManager->acceptShare($share, $user1->getUID());
199
+        $this->shareManager->acceptShare($share, $user2->getUID());
200
+        $this->shareManager->acceptShare($share, $user3->getUID());
201
+
202
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
203
+
204
+        $this->assertTrue(Filesystem::file_exists($this->filename));
205
+
206
+        Filesystem::rename($this->filename, 'newFileName');
207
+
208
+        $this->assertTrue(Filesystem::file_exists('newFileName'));
209
+        $this->assertFalse(Filesystem::file_exists($this->filename));
210
+
211
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
212
+        $this->assertTrue(Filesystem::file_exists($this->filename));
213
+        $this->assertFalse(Filesystem::file_exists('newFileName'));
214
+
215
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
216
+        $this->assertTrue(Filesystem::file_exists($this->filename));
217
+        $this->assertFalse(Filesystem::file_exists('newFileName'));
218
+
219
+        //cleanup
220
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
221
+        $this->shareManager->deleteShare($share);
222
+        $testGroup->removeUser($user1);
223
+        $testGroup->removeUser($user2);
224
+        $testGroup->removeUser($user3);
225
+    }
226
+
227
+    /**
228
+     * @param string $path
229
+     * @param string $expectedResult
230
+     * @param bool $exception if a exception is expected
231
+     */
232
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataProviderTestStripUserFilesPath')]
233
+    public function testStripUserFilesPath($path, $expectedResult, $exception): void {
234
+        $testClass = new DummyTestClassSharedMount(null, null);
235
+        try {
236
+            $result = $testClass->stripUserFilesPathDummy($path);
237
+            $this->assertSame($expectedResult, $result);
238
+        } catch (\Exception $e) {
239
+            if ($exception) {
240
+                $this->assertSame(10, $e->getCode());
241
+            } else {
242
+                $this->assertTrue(false, 'Exception caught, but expected: ' . $expectedResult);
243
+            }
244
+        }
245
+    }
246
+
247
+    public static function dataProviderTestStripUserFilesPath() {
248
+        return [
249
+            ['/user/files/foo.txt', '/foo.txt', false],
250
+            ['/user/files/folder/foo.txt', '/folder/foo.txt', false],
251
+            ['/data/user/files/foo.txt', null, true],
252
+            ['/data/user/files/', null, true],
253
+            ['/files/foo.txt', null, true],
254
+            ['/foo.txt', null, true],
255
+        ];
256
+    }
257
+
258
+    /**
259
+     * If the permissions on a group share are upgraded be sure to still respect
260
+     * removed shares by a member of that group
261
+     */
262
+    public function testPermissionUpgradeOnUserDeletedGroupShare(): void {
263
+        $testGroup = $this->groupManager->createGroup('testGroup');
264
+        $user1 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER1);
265
+        $user2 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER2);
266
+        $user3 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER3);
267
+        $testGroup->addUser($user1);
268
+        $testGroup->addUser($user2);
269
+        $testGroup->addUser($user3);
270
+
271
+        $connection = Server::get(IDBConnection::class);
272
+
273
+        // Share item with group
274
+        $fileinfo = $this->view->getFileInfo($this->folder);
275
+        $share = $this->share(
276
+            IShare::TYPE_GROUP,
277
+            $this->folder,
278
+            self::TEST_FILES_SHARING_API_USER1,
279
+            'testGroup',
280
+            Constants::PERMISSION_READ
281
+        );
282
+        $this->shareManager->acceptShare($share, $user1->getUID());
283
+        $this->shareManager->acceptShare($share, $user2->getUID());
284
+        $this->shareManager->acceptShare($share, $user3->getUID());
285
+
286
+        // Login as user 2 and verify the item exists
287
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
288
+        $this->assertTrue(Filesystem::file_exists($this->folder));
289
+        $result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
290
+        $this->assertNotEmpty($result);
291
+        $this->assertEquals(Constants::PERMISSION_READ, $result->getPermissions());
292
+
293
+        // Delete the share
294
+        $this->assertTrue(Filesystem::rmdir($this->folder));
295
+        $this->assertFalse(Filesystem::file_exists($this->folder));
296
+
297
+        // Verify we do not get a share
298
+        $result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
299
+        $this->assertEquals(0, $result->getPermissions());
300
+
301
+        // Login as user 1 again and change permissions
302
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
303
+        $share->setPermissions(Constants::PERMISSION_ALL);
304
+        $share = $this->shareManager->updateShare($share);
305
+
306
+        // Login as user 2 and verify
307
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
308
+        $this->assertFalse(Filesystem::file_exists($this->folder));
309
+        $result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
310
+        $this->assertEquals(0, $result->getPermissions());
311
+
312
+        $this->shareManager->deleteShare($share);
313
+
314
+        //cleanup
315
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
316
+        $testGroup->removeUser($user1);
317
+        $testGroup->removeUser($user2);
318
+        $testGroup->removeUser($user3);
319
+    }
320
+
321
+    /**
322
+     * test if the mount point gets renamed if a folder exists at the target
323
+     */
324
+    public function testShareMountOverFolder(): void {
325
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
326
+        $this->view2->mkdir('bar');
327
+
328
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
329
+
330
+        // share to user
331
+        $share = $this->share(
332
+            IShare::TYPE_USER,
333
+            $this->folder,
334
+            self::TEST_FILES_SHARING_API_USER1,
335
+            self::TEST_FILES_SHARING_API_USER2,
336
+            Constants::PERMISSION_ALL);
337
+        $this->shareManager->acceptShare($share, self::TEST_FILES_SHARING_API_USER2);
338
+
339
+        $share->setTarget('/bar');
340
+        $this->shareManager->moveShare($share, self::TEST_FILES_SHARING_API_USER2);
341
+
342
+        $share = $this->shareManager->getShareById($share->getFullId());
343
+
344
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
345
+        // share should have been moved
346
+
347
+        $share = $this->shareManager->getShareById($share->getFullId());
348
+        $this->assertSame('/bar (2)', $share->getTarget());
349
+
350
+        //cleanup
351
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
352
+        $this->shareManager->deleteShare($share);
353
+        $this->view->unlink($this->folder);
354
+    }
355
+
356
+    /**
357
+     * test if the mount point gets renamed if another share exists at the target
358
+     */
359
+    public function testShareMountOverShare(): void {
360
+        // create a shared cache
361
+        $caches = [];
362
+        $cacheFactory = $this->createMock(ICacheFactory::class);
363
+        $cacheFactory->method('createLocal')
364
+            ->willReturnCallback(function (string $prefix) use (&$caches) {
365
+                if (!isset($caches[$prefix])) {
366
+                    $caches[$prefix] = new ArrayCache($prefix);
367
+                }
368
+                return $caches[$prefix];
369
+            });
370
+        $cacheFactory->method('createDistributed')
371
+            ->willReturnCallback(function (string $prefix) use (&$caches) {
372
+                if (!isset($caches[$prefix])) {
373
+                    $caches[$prefix] = new ArrayCache($prefix);
374
+                }
375
+                return $caches[$prefix];
376
+            });
377
+
378
+        // hack to overwrite the cache factory, we can't use the proper "overwriteService" since the mount provider is created before this test is called
379
+        $mountProvider = Server::get(MountProvider::class);
380
+        $reflectionClass = new \ReflectionClass($mountProvider);
381
+        $reflectionCacheFactory = $reflectionClass->getProperty('cacheFactory');
382
+        $reflectionCacheFactory->setAccessible(true);
383
+        $reflectionCacheFactory->setValue($mountProvider, $cacheFactory);
384
+
385
+        // share to user
386
+        $share = $this->share(
387
+            IShare::TYPE_USER,
388
+            $this->folder,
389
+            self::TEST_FILES_SHARING_API_USER1,
390
+            self::TEST_FILES_SHARING_API_USER2,
391
+            Constants::PERMISSION_ALL);
392
+        $this->shareManager->acceptShare($share, self::TEST_FILES_SHARING_API_USER2);
393
+
394
+        $share->setTarget('/foobar');
395
+        $this->shareManager->moveShare($share, self::TEST_FILES_SHARING_API_USER2);
396
+
397
+
398
+        // share to user
399
+        $share2 = $this->share(
400
+            IShare::TYPE_USER,
401
+            $this->folder2,
402
+            self::TEST_FILES_SHARING_API_USER1,
403
+            self::TEST_FILES_SHARING_API_USER2,
404
+            Constants::PERMISSION_ALL);
405
+        $this->shareManager->acceptShare($share2, self::TEST_FILES_SHARING_API_USER2);
406
+
407
+        $share2->setTarget('/foobar');
408
+        $this->shareManager->moveShare($share2, self::TEST_FILES_SHARING_API_USER2);
409
+
410
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
411
+        // one of the shares should have been moved
412
+
413
+        $share = $this->shareManager->getShareById($share->getFullId());
414
+        $share2 = $this->shareManager->getShareById($share2->getFullId());
415
+
416
+        // we don't know or care which share got the "(2)" just that one of them did
417
+        $this->assertNotEquals($share->getTarget(), $share2->getTarget());
418
+        $this->assertSame('/foobar', min($share->getTarget(), $share2->getTarget()));
419
+        $this->assertSame('/foobar (2)', max($share->getTarget(), $share2->getTarget()));
420
+
421
+        //cleanup
422
+        self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
423
+        $this->shareManager->deleteShare($share);
424
+        $this->view->unlink($this->folder);
425
+    }
426 426
 }
427 427
 
428 428
 class DummyTestClassSharedMount extends SharedMount {
429
-	public function __construct($storage, $mountpoint, $arguments = null, $loader = null) {
430
-		// noop
431
-	}
429
+    public function __construct($storage, $mountpoint, $arguments = null, $loader = null) {
430
+        // noop
431
+    }
432 432
 
433
-	public function stripUserFilesPathDummy($path) {
434
-		return $this->stripUserFilesPath($path);
435
-	}
433
+    public function stripUserFilesPathDummy($path) {
434
+        return $this->stripUserFilesPath($path);
435
+    }
436 436
 }
Please login to merge, or discard this patch.