Completed
Push — master ( d03f6d...56f3d1 )
by Joas
20:52 queued 17s
created
apps/dav/tests/unit/Search/TasksSearchProviderTest.php 2 patches
Indentation   +290 added lines, -290 removed lines patch added patch discarded remove patch
@@ -22,294 +22,294 @@
 block discarded – undo
22 22
 use Test\TestCase;
23 23
 
24 24
 class TasksSearchProviderTest extends TestCase {
25
-	private IAppManager&MockObject $appManager;
26
-	private IL10N&MockObject $l10n;
27
-	private IURLGenerator&MockObject $urlGenerator;
28
-	private CalDavBackend&MockObject $backend;
29
-	private TasksSearchProvider $provider;
30
-
31
-	// NO DUE NOR COMPLETED NOR SUMMARY
32
-	private static string $vTodo0 = 'BEGIN:VCALENDAR' . PHP_EOL .
33
-		'PRODID:TEST' . PHP_EOL .
34
-		'VERSION:2.0' . PHP_EOL .
35
-		'BEGIN:VTODO' . PHP_EOL .
36
-		'UID:[email protected]' . PHP_EOL .
37
-		'DTSTAMP:20070313T123432Z' . PHP_EOL .
38
-		'STATUS:NEEDS-ACTION' . PHP_EOL .
39
-		'END:VTODO' . PHP_EOL .
40
-		'END:VCALENDAR';
41
-
42
-	// DUE AND COMPLETED
43
-	private static string $vTodo1 = 'BEGIN:VCALENDAR' . PHP_EOL .
44
-		'PRODID:TEST' . PHP_EOL .
45
-		'VERSION:2.0' . PHP_EOL .
46
-		'BEGIN:VTODO' . PHP_EOL .
47
-		'UID:[email protected]' . PHP_EOL .
48
-		'DTSTAMP:20070313T123432Z' . PHP_EOL .
49
-		'COMPLETED:20070707T100000Z' . PHP_EOL .
50
-		'DUE;VALUE=DATE:20070501' . PHP_EOL .
51
-		'SUMMARY:Task title' . PHP_EOL .
52
-		'STATUS:NEEDS-ACTION' . PHP_EOL .
53
-		'END:VTODO' . PHP_EOL .
54
-		'END:VCALENDAR';
55
-
56
-	// COMPLETED ONLY
57
-	private static string $vTodo2 = 'BEGIN:VCALENDAR' . PHP_EOL .
58
-		'PRODID:TEST' . PHP_EOL .
59
-		'VERSION:2.0' . PHP_EOL .
60
-		'BEGIN:VTODO' . PHP_EOL .
61
-		'UID:[email protected]' . PHP_EOL .
62
-		'DTSTAMP:20070313T123432Z' . PHP_EOL .
63
-		'COMPLETED:20070707T100000Z' . PHP_EOL .
64
-		'SUMMARY:Task title' . PHP_EOL .
65
-		'STATUS:NEEDS-ACTION' . PHP_EOL .
66
-		'END:VTODO' . PHP_EOL .
67
-		'END:VCALENDAR';
68
-
69
-	// DUE DATE
70
-	private static string $vTodo3 = 'BEGIN:VCALENDAR' . PHP_EOL .
71
-		'PRODID:TEST' . PHP_EOL .
72
-		'VERSION:2.0' . PHP_EOL .
73
-		'BEGIN:VTODO' . PHP_EOL .
74
-		'UID:[email protected]' . PHP_EOL .
75
-		'DTSTAMP:20070313T123432Z' . PHP_EOL .
76
-		'DUE;VALUE=DATE:20070501' . PHP_EOL .
77
-		'SUMMARY:Task title' . PHP_EOL .
78
-		'STATUS:NEEDS-ACTION' . PHP_EOL .
79
-		'END:VTODO' . PHP_EOL .
80
-		'END:VCALENDAR';
81
-
82
-	// DUE DATETIME
83
-	private static string $vTodo4 = 'BEGIN:VCALENDAR' . PHP_EOL .
84
-		'PRODID:TEST' . PHP_EOL .
85
-		'VERSION:2.0' . PHP_EOL .
86
-		'BEGIN:VTODO' . PHP_EOL .
87
-		'UID:[email protected]' . PHP_EOL .
88
-		'DTSTAMP:20070313T123432Z' . PHP_EOL .
89
-		'DUE:20070709T130000Z' . PHP_EOL .
90
-		'SUMMARY:Task title' . PHP_EOL .
91
-		'STATUS:NEEDS-ACTION' . PHP_EOL .
92
-		'END:VTODO' . PHP_EOL .
93
-		'END:VCALENDAR';
94
-
95
-	protected function setUp(): void {
96
-		parent::setUp();
97
-
98
-		$this->appManager = $this->createMock(IAppManager::class);
99
-		$this->l10n = $this->createMock(IL10N::class);
100
-		$this->urlGenerator = $this->createMock(IURLGenerator::class);
101
-		$this->backend = $this->createMock(CalDavBackend::class);
102
-
103
-		$this->provider = new TasksSearchProvider(
104
-			$this->appManager,
105
-			$this->l10n,
106
-			$this->urlGenerator,
107
-			$this->backend
108
-		);
109
-	}
110
-
111
-	public function testGetId(): void {
112
-		$this->assertEquals('tasks', $this->provider->getId());
113
-	}
114
-
115
-	public function testGetName(): void {
116
-		$this->l10n->expects($this->exactly(1))
117
-			->method('t')
118
-			->with('Tasks')
119
-			->willReturnArgument(0);
120
-
121
-		$this->assertEquals('Tasks', $this->provider->getName());
122
-	}
123
-
124
-	public function testSearchAppDisabled(): void {
125
-		$user = $this->createMock(IUser::class);
126
-		$query = $this->createMock(ISearchQuery::class);
127
-		$this->appManager->expects($this->once())
128
-			->method('isEnabledForUser')
129
-			->with('tasks', $user)
130
-			->willReturn(false);
131
-		$this->l10n->expects($this->exactly(1))
132
-			->method('t')
133
-			->willReturnArgument(0);
134
-		$this->backend->expects($this->never())
135
-			->method('getCalendarsForUser');
136
-		$this->backend->expects($this->never())
137
-			->method('getSubscriptionsForUser');
138
-		$this->backend->expects($this->never())
139
-			->method('searchPrincipalUri');
140
-
141
-		$actual = $this->provider->search($user, $query);
142
-		$data = $actual->jsonSerialize();
143
-		$this->assertInstanceOf(SearchResult::class, $actual);
144
-		$this->assertEquals('Tasks', $data['name']);
145
-		$this->assertEmpty($data['entries']);
146
-		$this->assertFalse($data['isPaginated']);
147
-		$this->assertNull($data['cursor']);
148
-	}
149
-
150
-	public function testSearch(): void {
151
-		$user = $this->createMock(IUser::class);
152
-		$user->method('getUID')->willReturn('john.doe');
153
-		$query = $this->createMock(ISearchQuery::class);
154
-		$query->method('getTerm')->willReturn('search term');
155
-		$query->method('getLimit')->willReturn(5);
156
-		$query->method('getCursor')->willReturn(20);
157
-		$this->appManager->expects($this->once())
158
-			->method('isEnabledForUser')
159
-			->with('tasks', $user)
160
-			->willReturn(true);
161
-		$this->l10n->method('t')->willReturnArgument(0);
162
-
163
-		$this->backend->expects($this->once())
164
-			->method('getCalendarsForUser')
165
-			->with('principals/users/john.doe')
166
-			->willReturn([
167
-				[
168
-					'id' => 99,
169
-					'principaluri' => 'principals/users/john.doe',
170
-					'uri' => 'calendar-uri-99',
171
-				], [
172
-					'id' => 123,
173
-					'principaluri' => 'principals/users/john.doe',
174
-					'uri' => 'calendar-uri-123',
175
-				]
176
-			]);
177
-		$this->backend->expects($this->once())
178
-			->method('getSubscriptionsForUser')
179
-			->with('principals/users/john.doe')
180
-			->willReturn([
181
-				[
182
-					'id' => 1337,
183
-					'principaluri' => 'principals/users/john.doe',
184
-					'uri' => 'subscription-uri-1337',
185
-				]
186
-			]);
187
-		$this->backend->expects($this->once())
188
-			->method('searchPrincipalUri')
189
-			->with('principals/users/john.doe', '', ['VTODO'],
190
-				['SUMMARY', 'DESCRIPTION', 'CATEGORIES'],
191
-				[],
192
-				['limit' => 5, 'offset' => 20, 'since' => null, 'until' => null])
193
-			->willReturn([
194
-				[
195
-					'calendarid' => 99,
196
-					'calendartype' => CalDavBackend::CALENDAR_TYPE_CALENDAR,
197
-					'uri' => 'todo0.ics',
198
-					'calendardata' => self::$vTodo0,
199
-				],
200
-				[
201
-					'calendarid' => 123,
202
-					'calendartype' => CalDavBackend::CALENDAR_TYPE_CALENDAR,
203
-					'uri' => 'todo1.ics',
204
-					'calendardata' => self::$vTodo1,
205
-				],
206
-				[
207
-					'calendarid' => 1337,
208
-					'calendartype' => CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION,
209
-					'uri' => 'todo2.ics',
210
-					'calendardata' => self::$vTodo2,
211
-				]
212
-			]);
213
-
214
-		$provider = $this->getMockBuilder(TasksSearchProvider::class)
215
-			->setConstructorArgs([
216
-				$this->appManager,
217
-				$this->l10n,
218
-				$this->urlGenerator,
219
-				$this->backend,
220
-			])
221
-			->onlyMethods([
222
-				'getDeepLinkToTasksApp',
223
-				'generateSubline',
224
-			])
225
-			->getMock();
226
-
227
-		$provider->expects($this->exactly(3))
228
-			->method('generateSubline')
229
-			->willReturn('subline');
230
-		$provider->expects($this->exactly(3))
231
-			->method('getDeepLinkToTasksApp')
232
-			->willReturnMap([
233
-				['calendar-uri-99', 'todo0.ics', 'deep-link-to-tasks'],
234
-				['calendar-uri-123', 'todo1.ics', 'deep-link-to-tasks'],
235
-				['subscription-uri-1337', 'todo2.ics', 'deep-link-to-tasks']
236
-			]);
237
-
238
-		$actual = $provider->search($user, $query);
239
-		$data = $actual->jsonSerialize();
240
-		$this->assertInstanceOf(SearchResult::class, $actual);
241
-		$this->assertEquals('Tasks', $data['name']);
242
-		$this->assertCount(3, $data['entries']);
243
-		$this->assertTrue($data['isPaginated']);
244
-		$this->assertEquals(23, $data['cursor']);
245
-
246
-		$result0 = $data['entries'][0];
247
-		$result0Data = $result0->jsonSerialize();
248
-		$result1 = $data['entries'][1];
249
-		$result1Data = $result1->jsonSerialize();
250
-		$result2 = $data['entries'][2];
251
-		$result2Data = $result2->jsonSerialize();
252
-
253
-		$this->assertInstanceOf(SearchResultEntry::class, $result0);
254
-		$this->assertEmpty($result0Data['thumbnailUrl']);
255
-		$this->assertEquals('Untitled task', $result0Data['title']);
256
-		$this->assertEquals('subline', $result0Data['subline']);
257
-		$this->assertEquals('deep-link-to-tasks', $result0Data['resourceUrl']);
258
-		$this->assertEquals('icon-checkmark', $result0Data['icon']);
259
-		$this->assertFalse($result0Data['rounded']);
260
-
261
-		$this->assertInstanceOf(SearchResultEntry::class, $result1);
262
-		$this->assertEmpty($result1Data['thumbnailUrl']);
263
-		$this->assertEquals('Task title', $result1Data['title']);
264
-		$this->assertEquals('subline', $result1Data['subline']);
265
-		$this->assertEquals('deep-link-to-tasks', $result1Data['resourceUrl']);
266
-		$this->assertEquals('icon-checkmark', $result1Data['icon']);
267
-		$this->assertFalse($result1Data['rounded']);
268
-
269
-		$this->assertInstanceOf(SearchResultEntry::class, $result2);
270
-		$this->assertEmpty($result2Data['thumbnailUrl']);
271
-		$this->assertEquals('Task title', $result2Data['title']);
272
-		$this->assertEquals('subline', $result2Data['subline']);
273
-		$this->assertEquals('deep-link-to-tasks', $result2Data['resourceUrl']);
274
-		$this->assertEquals('icon-checkmark', $result2Data['icon']);
275
-		$this->assertFalse($result2Data['rounded']);
276
-	}
277
-
278
-	public function testGetDeepLinkToTasksApp(): void {
279
-		$this->urlGenerator->expects($this->once())
280
-			->method('linkToRoute')
281
-			->with('tasks.page.index')
282
-			->willReturn('link-to-route-tasks.index');
283
-		$this->urlGenerator->expects($this->once())
284
-			->method('getAbsoluteURL')
285
-			->with('link-to-route-tasks.indexcalendars/uri-john.doe/tasks/task-uri.ics')
286
-			->willReturn('absolute-url-link-to-route-tasks.indexcalendars/uri-john.doe/tasks/task-uri.ics');
287
-
288
-		$actual = self::invokePrivate($this->provider, 'getDeepLinkToTasksApp', ['uri-john.doe', 'task-uri.ics']);
289
-		$this->assertEquals('absolute-url-link-to-route-tasks.indexcalendars/uri-john.doe/tasks/task-uri.ics', $actual);
290
-	}
291
-
292
-	/**
293
-	 * @dataProvider generateSublineDataProvider
294
-	 */
295
-	public function testGenerateSubline(string $ics, string $expectedSubline): void {
296
-		$vCalendar = Reader::read($ics, Reader::OPTION_FORGIVING);
297
-		$taskComponent = $vCalendar->VTODO;
298
-
299
-		$this->l10n->method('t')->willReturnArgument(0);
300
-		$this->l10n->method('l')->willReturnArgument(0);
301
-
302
-		$actual = self::invokePrivate($this->provider, 'generateSubline', [$taskComponent]);
303
-		$this->assertEquals($expectedSubline, $actual);
304
-	}
305
-
306
-	public static function generateSublineDataProvider(): array {
307
-		return [
308
-			[self::$vTodo0, ''],
309
-			[self::$vTodo1, 'Completed on %s'],
310
-			[self::$vTodo2, 'Completed on %s'],
311
-			[self::$vTodo3, 'Due on %s'],
312
-			[self::$vTodo4, 'Due on %s by %s'],
313
-		];
314
-	}
25
+    private IAppManager&MockObject $appManager;
26
+    private IL10N&MockObject $l10n;
27
+    private IURLGenerator&MockObject $urlGenerator;
28
+    private CalDavBackend&MockObject $backend;
29
+    private TasksSearchProvider $provider;
30
+
31
+    // NO DUE NOR COMPLETED NOR SUMMARY
32
+    private static string $vTodo0 = 'BEGIN:VCALENDAR' . PHP_EOL .
33
+        'PRODID:TEST' . PHP_EOL .
34
+        'VERSION:2.0' . PHP_EOL .
35
+        'BEGIN:VTODO' . PHP_EOL .
36
+        'UID:[email protected]' . PHP_EOL .
37
+        'DTSTAMP:20070313T123432Z' . PHP_EOL .
38
+        'STATUS:NEEDS-ACTION' . PHP_EOL .
39
+        'END:VTODO' . PHP_EOL .
40
+        'END:VCALENDAR';
41
+
42
+    // DUE AND COMPLETED
43
+    private static string $vTodo1 = 'BEGIN:VCALENDAR' . PHP_EOL .
44
+        'PRODID:TEST' . PHP_EOL .
45
+        'VERSION:2.0' . PHP_EOL .
46
+        'BEGIN:VTODO' . PHP_EOL .
47
+        'UID:[email protected]' . PHP_EOL .
48
+        'DTSTAMP:20070313T123432Z' . PHP_EOL .
49
+        'COMPLETED:20070707T100000Z' . PHP_EOL .
50
+        'DUE;VALUE=DATE:20070501' . PHP_EOL .
51
+        'SUMMARY:Task title' . PHP_EOL .
52
+        'STATUS:NEEDS-ACTION' . PHP_EOL .
53
+        'END:VTODO' . PHP_EOL .
54
+        'END:VCALENDAR';
55
+
56
+    // COMPLETED ONLY
57
+    private static string $vTodo2 = 'BEGIN:VCALENDAR' . PHP_EOL .
58
+        'PRODID:TEST' . PHP_EOL .
59
+        'VERSION:2.0' . PHP_EOL .
60
+        'BEGIN:VTODO' . PHP_EOL .
61
+        'UID:[email protected]' . PHP_EOL .
62
+        'DTSTAMP:20070313T123432Z' . PHP_EOL .
63
+        'COMPLETED:20070707T100000Z' . PHP_EOL .
64
+        'SUMMARY:Task title' . PHP_EOL .
65
+        'STATUS:NEEDS-ACTION' . PHP_EOL .
66
+        'END:VTODO' . PHP_EOL .
67
+        'END:VCALENDAR';
68
+
69
+    // DUE DATE
70
+    private static string $vTodo3 = 'BEGIN:VCALENDAR' . PHP_EOL .
71
+        'PRODID:TEST' . PHP_EOL .
72
+        'VERSION:2.0' . PHP_EOL .
73
+        'BEGIN:VTODO' . PHP_EOL .
74
+        'UID:[email protected]' . PHP_EOL .
75
+        'DTSTAMP:20070313T123432Z' . PHP_EOL .
76
+        'DUE;VALUE=DATE:20070501' . PHP_EOL .
77
+        'SUMMARY:Task title' . PHP_EOL .
78
+        'STATUS:NEEDS-ACTION' . PHP_EOL .
79
+        'END:VTODO' . PHP_EOL .
80
+        'END:VCALENDAR';
81
+
82
+    // DUE DATETIME
83
+    private static string $vTodo4 = 'BEGIN:VCALENDAR' . PHP_EOL .
84
+        'PRODID:TEST' . PHP_EOL .
85
+        'VERSION:2.0' . PHP_EOL .
86
+        'BEGIN:VTODO' . PHP_EOL .
87
+        'UID:[email protected]' . PHP_EOL .
88
+        'DTSTAMP:20070313T123432Z' . PHP_EOL .
89
+        'DUE:20070709T130000Z' . PHP_EOL .
90
+        'SUMMARY:Task title' . PHP_EOL .
91
+        'STATUS:NEEDS-ACTION' . PHP_EOL .
92
+        'END:VTODO' . PHP_EOL .
93
+        'END:VCALENDAR';
94
+
95
+    protected function setUp(): void {
96
+        parent::setUp();
97
+
98
+        $this->appManager = $this->createMock(IAppManager::class);
99
+        $this->l10n = $this->createMock(IL10N::class);
100
+        $this->urlGenerator = $this->createMock(IURLGenerator::class);
101
+        $this->backend = $this->createMock(CalDavBackend::class);
102
+
103
+        $this->provider = new TasksSearchProvider(
104
+            $this->appManager,
105
+            $this->l10n,
106
+            $this->urlGenerator,
107
+            $this->backend
108
+        );
109
+    }
110
+
111
+    public function testGetId(): void {
112
+        $this->assertEquals('tasks', $this->provider->getId());
113
+    }
114
+
115
+    public function testGetName(): void {
116
+        $this->l10n->expects($this->exactly(1))
117
+            ->method('t')
118
+            ->with('Tasks')
119
+            ->willReturnArgument(0);
120
+
121
+        $this->assertEquals('Tasks', $this->provider->getName());
122
+    }
123
+
124
+    public function testSearchAppDisabled(): void {
125
+        $user = $this->createMock(IUser::class);
126
+        $query = $this->createMock(ISearchQuery::class);
127
+        $this->appManager->expects($this->once())
128
+            ->method('isEnabledForUser')
129
+            ->with('tasks', $user)
130
+            ->willReturn(false);
131
+        $this->l10n->expects($this->exactly(1))
132
+            ->method('t')
133
+            ->willReturnArgument(0);
134
+        $this->backend->expects($this->never())
135
+            ->method('getCalendarsForUser');
136
+        $this->backend->expects($this->never())
137
+            ->method('getSubscriptionsForUser');
138
+        $this->backend->expects($this->never())
139
+            ->method('searchPrincipalUri');
140
+
141
+        $actual = $this->provider->search($user, $query);
142
+        $data = $actual->jsonSerialize();
143
+        $this->assertInstanceOf(SearchResult::class, $actual);
144
+        $this->assertEquals('Tasks', $data['name']);
145
+        $this->assertEmpty($data['entries']);
146
+        $this->assertFalse($data['isPaginated']);
147
+        $this->assertNull($data['cursor']);
148
+    }
149
+
150
+    public function testSearch(): void {
151
+        $user = $this->createMock(IUser::class);
152
+        $user->method('getUID')->willReturn('john.doe');
153
+        $query = $this->createMock(ISearchQuery::class);
154
+        $query->method('getTerm')->willReturn('search term');
155
+        $query->method('getLimit')->willReturn(5);
156
+        $query->method('getCursor')->willReturn(20);
157
+        $this->appManager->expects($this->once())
158
+            ->method('isEnabledForUser')
159
+            ->with('tasks', $user)
160
+            ->willReturn(true);
161
+        $this->l10n->method('t')->willReturnArgument(0);
162
+
163
+        $this->backend->expects($this->once())
164
+            ->method('getCalendarsForUser')
165
+            ->with('principals/users/john.doe')
166
+            ->willReturn([
167
+                [
168
+                    'id' => 99,
169
+                    'principaluri' => 'principals/users/john.doe',
170
+                    'uri' => 'calendar-uri-99',
171
+                ], [
172
+                    'id' => 123,
173
+                    'principaluri' => 'principals/users/john.doe',
174
+                    'uri' => 'calendar-uri-123',
175
+                ]
176
+            ]);
177
+        $this->backend->expects($this->once())
178
+            ->method('getSubscriptionsForUser')
179
+            ->with('principals/users/john.doe')
180
+            ->willReturn([
181
+                [
182
+                    'id' => 1337,
183
+                    'principaluri' => 'principals/users/john.doe',
184
+                    'uri' => 'subscription-uri-1337',
185
+                ]
186
+            ]);
187
+        $this->backend->expects($this->once())
188
+            ->method('searchPrincipalUri')
189
+            ->with('principals/users/john.doe', '', ['VTODO'],
190
+                ['SUMMARY', 'DESCRIPTION', 'CATEGORIES'],
191
+                [],
192
+                ['limit' => 5, 'offset' => 20, 'since' => null, 'until' => null])
193
+            ->willReturn([
194
+                [
195
+                    'calendarid' => 99,
196
+                    'calendartype' => CalDavBackend::CALENDAR_TYPE_CALENDAR,
197
+                    'uri' => 'todo0.ics',
198
+                    'calendardata' => self::$vTodo0,
199
+                ],
200
+                [
201
+                    'calendarid' => 123,
202
+                    'calendartype' => CalDavBackend::CALENDAR_TYPE_CALENDAR,
203
+                    'uri' => 'todo1.ics',
204
+                    'calendardata' => self::$vTodo1,
205
+                ],
206
+                [
207
+                    'calendarid' => 1337,
208
+                    'calendartype' => CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION,
209
+                    'uri' => 'todo2.ics',
210
+                    'calendardata' => self::$vTodo2,
211
+                ]
212
+            ]);
213
+
214
+        $provider = $this->getMockBuilder(TasksSearchProvider::class)
215
+            ->setConstructorArgs([
216
+                $this->appManager,
217
+                $this->l10n,
218
+                $this->urlGenerator,
219
+                $this->backend,
220
+            ])
221
+            ->onlyMethods([
222
+                'getDeepLinkToTasksApp',
223
+                'generateSubline',
224
+            ])
225
+            ->getMock();
226
+
227
+        $provider->expects($this->exactly(3))
228
+            ->method('generateSubline')
229
+            ->willReturn('subline');
230
+        $provider->expects($this->exactly(3))
231
+            ->method('getDeepLinkToTasksApp')
232
+            ->willReturnMap([
233
+                ['calendar-uri-99', 'todo0.ics', 'deep-link-to-tasks'],
234
+                ['calendar-uri-123', 'todo1.ics', 'deep-link-to-tasks'],
235
+                ['subscription-uri-1337', 'todo2.ics', 'deep-link-to-tasks']
236
+            ]);
237
+
238
+        $actual = $provider->search($user, $query);
239
+        $data = $actual->jsonSerialize();
240
+        $this->assertInstanceOf(SearchResult::class, $actual);
241
+        $this->assertEquals('Tasks', $data['name']);
242
+        $this->assertCount(3, $data['entries']);
243
+        $this->assertTrue($data['isPaginated']);
244
+        $this->assertEquals(23, $data['cursor']);
245
+
246
+        $result0 = $data['entries'][0];
247
+        $result0Data = $result0->jsonSerialize();
248
+        $result1 = $data['entries'][1];
249
+        $result1Data = $result1->jsonSerialize();
250
+        $result2 = $data['entries'][2];
251
+        $result2Data = $result2->jsonSerialize();
252
+
253
+        $this->assertInstanceOf(SearchResultEntry::class, $result0);
254
+        $this->assertEmpty($result0Data['thumbnailUrl']);
255
+        $this->assertEquals('Untitled task', $result0Data['title']);
256
+        $this->assertEquals('subline', $result0Data['subline']);
257
+        $this->assertEquals('deep-link-to-tasks', $result0Data['resourceUrl']);
258
+        $this->assertEquals('icon-checkmark', $result0Data['icon']);
259
+        $this->assertFalse($result0Data['rounded']);
260
+
261
+        $this->assertInstanceOf(SearchResultEntry::class, $result1);
262
+        $this->assertEmpty($result1Data['thumbnailUrl']);
263
+        $this->assertEquals('Task title', $result1Data['title']);
264
+        $this->assertEquals('subline', $result1Data['subline']);
265
+        $this->assertEquals('deep-link-to-tasks', $result1Data['resourceUrl']);
266
+        $this->assertEquals('icon-checkmark', $result1Data['icon']);
267
+        $this->assertFalse($result1Data['rounded']);
268
+
269
+        $this->assertInstanceOf(SearchResultEntry::class, $result2);
270
+        $this->assertEmpty($result2Data['thumbnailUrl']);
271
+        $this->assertEquals('Task title', $result2Data['title']);
272
+        $this->assertEquals('subline', $result2Data['subline']);
273
+        $this->assertEquals('deep-link-to-tasks', $result2Data['resourceUrl']);
274
+        $this->assertEquals('icon-checkmark', $result2Data['icon']);
275
+        $this->assertFalse($result2Data['rounded']);
276
+    }
277
+
278
+    public function testGetDeepLinkToTasksApp(): void {
279
+        $this->urlGenerator->expects($this->once())
280
+            ->method('linkToRoute')
281
+            ->with('tasks.page.index')
282
+            ->willReturn('link-to-route-tasks.index');
283
+        $this->urlGenerator->expects($this->once())
284
+            ->method('getAbsoluteURL')
285
+            ->with('link-to-route-tasks.indexcalendars/uri-john.doe/tasks/task-uri.ics')
286
+            ->willReturn('absolute-url-link-to-route-tasks.indexcalendars/uri-john.doe/tasks/task-uri.ics');
287
+
288
+        $actual = self::invokePrivate($this->provider, 'getDeepLinkToTasksApp', ['uri-john.doe', 'task-uri.ics']);
289
+        $this->assertEquals('absolute-url-link-to-route-tasks.indexcalendars/uri-john.doe/tasks/task-uri.ics', $actual);
290
+    }
291
+
292
+    /**
293
+     * @dataProvider generateSublineDataProvider
294
+     */
295
+    public function testGenerateSubline(string $ics, string $expectedSubline): void {
296
+        $vCalendar = Reader::read($ics, Reader::OPTION_FORGIVING);
297
+        $taskComponent = $vCalendar->VTODO;
298
+
299
+        $this->l10n->method('t')->willReturnArgument(0);
300
+        $this->l10n->method('l')->willReturnArgument(0);
301
+
302
+        $actual = self::invokePrivate($this->provider, 'generateSubline', [$taskComponent]);
303
+        $this->assertEquals($expectedSubline, $actual);
304
+    }
305
+
306
+    public static function generateSublineDataProvider(): array {
307
+        return [
308
+            [self::$vTodo0, ''],
309
+            [self::$vTodo1, 'Completed on %s'],
310
+            [self::$vTodo2, 'Completed on %s'],
311
+            [self::$vTodo3, 'Due on %s'],
312
+            [self::$vTodo4, 'Due on %s by %s'],
313
+        ];
314
+    }
315 315
 }
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -29,67 +29,67 @@
 block discarded – undo
29 29
 	private TasksSearchProvider $provider;
30 30
 
31 31
 	// NO DUE NOR COMPLETED NOR SUMMARY
32
-	private static string $vTodo0 = 'BEGIN:VCALENDAR' . PHP_EOL .
33
-		'PRODID:TEST' . PHP_EOL .
34
-		'VERSION:2.0' . PHP_EOL .
35
-		'BEGIN:VTODO' . PHP_EOL .
36
-		'UID:[email protected]' . PHP_EOL .
37
-		'DTSTAMP:20070313T123432Z' . PHP_EOL .
38
-		'STATUS:NEEDS-ACTION' . PHP_EOL .
39
-		'END:VTODO' . PHP_EOL .
32
+	private static string $vTodo0 = 'BEGIN:VCALENDAR'.PHP_EOL.
33
+		'PRODID:TEST'.PHP_EOL.
34
+		'VERSION:2.0'.PHP_EOL.
35
+		'BEGIN:VTODO'.PHP_EOL.
36
+		'UID:[email protected]'.PHP_EOL.
37
+		'DTSTAMP:20070313T123432Z'.PHP_EOL.
38
+		'STATUS:NEEDS-ACTION'.PHP_EOL.
39
+		'END:VTODO'.PHP_EOL.
40 40
 		'END:VCALENDAR';
41 41
 
42 42
 	// DUE AND COMPLETED
43
-	private static string $vTodo1 = 'BEGIN:VCALENDAR' . PHP_EOL .
44
-		'PRODID:TEST' . PHP_EOL .
45
-		'VERSION:2.0' . PHP_EOL .
46
-		'BEGIN:VTODO' . PHP_EOL .
47
-		'UID:[email protected]' . PHP_EOL .
48
-		'DTSTAMP:20070313T123432Z' . PHP_EOL .
49
-		'COMPLETED:20070707T100000Z' . PHP_EOL .
50
-		'DUE;VALUE=DATE:20070501' . PHP_EOL .
51
-		'SUMMARY:Task title' . PHP_EOL .
52
-		'STATUS:NEEDS-ACTION' . PHP_EOL .
53
-		'END:VTODO' . PHP_EOL .
43
+	private static string $vTodo1 = 'BEGIN:VCALENDAR'.PHP_EOL.
44
+		'PRODID:TEST'.PHP_EOL.
45
+		'VERSION:2.0'.PHP_EOL.
46
+		'BEGIN:VTODO'.PHP_EOL.
47
+		'UID:[email protected]'.PHP_EOL.
48
+		'DTSTAMP:20070313T123432Z'.PHP_EOL.
49
+		'COMPLETED:20070707T100000Z'.PHP_EOL.
50
+		'DUE;VALUE=DATE:20070501'.PHP_EOL.
51
+		'SUMMARY:Task title'.PHP_EOL.
52
+		'STATUS:NEEDS-ACTION'.PHP_EOL.
53
+		'END:VTODO'.PHP_EOL.
54 54
 		'END:VCALENDAR';
55 55
 
56 56
 	// COMPLETED ONLY
57
-	private static string $vTodo2 = 'BEGIN:VCALENDAR' . PHP_EOL .
58
-		'PRODID:TEST' . PHP_EOL .
59
-		'VERSION:2.0' . PHP_EOL .
60
-		'BEGIN:VTODO' . PHP_EOL .
61
-		'UID:[email protected]' . PHP_EOL .
62
-		'DTSTAMP:20070313T123432Z' . PHP_EOL .
63
-		'COMPLETED:20070707T100000Z' . PHP_EOL .
64
-		'SUMMARY:Task title' . PHP_EOL .
65
-		'STATUS:NEEDS-ACTION' . PHP_EOL .
66
-		'END:VTODO' . PHP_EOL .
57
+	private static string $vTodo2 = 'BEGIN:VCALENDAR'.PHP_EOL.
58
+		'PRODID:TEST'.PHP_EOL.
59
+		'VERSION:2.0'.PHP_EOL.
60
+		'BEGIN:VTODO'.PHP_EOL.
61
+		'UID:[email protected]'.PHP_EOL.
62
+		'DTSTAMP:20070313T123432Z'.PHP_EOL.
63
+		'COMPLETED:20070707T100000Z'.PHP_EOL.
64
+		'SUMMARY:Task title'.PHP_EOL.
65
+		'STATUS:NEEDS-ACTION'.PHP_EOL.
66
+		'END:VTODO'.PHP_EOL.
67 67
 		'END:VCALENDAR';
68 68
 
69 69
 	// DUE DATE
70
-	private static string $vTodo3 = 'BEGIN:VCALENDAR' . PHP_EOL .
71
-		'PRODID:TEST' . PHP_EOL .
72
-		'VERSION:2.0' . PHP_EOL .
73
-		'BEGIN:VTODO' . PHP_EOL .
74
-		'UID:[email protected]' . PHP_EOL .
75
-		'DTSTAMP:20070313T123432Z' . PHP_EOL .
76
-		'DUE;VALUE=DATE:20070501' . PHP_EOL .
77
-		'SUMMARY:Task title' . PHP_EOL .
78
-		'STATUS:NEEDS-ACTION' . PHP_EOL .
79
-		'END:VTODO' . PHP_EOL .
70
+	private static string $vTodo3 = 'BEGIN:VCALENDAR'.PHP_EOL.
71
+		'PRODID:TEST'.PHP_EOL.
72
+		'VERSION:2.0'.PHP_EOL.
73
+		'BEGIN:VTODO'.PHP_EOL.
74
+		'UID:[email protected]'.PHP_EOL.
75
+		'DTSTAMP:20070313T123432Z'.PHP_EOL.
76
+		'DUE;VALUE=DATE:20070501'.PHP_EOL.
77
+		'SUMMARY:Task title'.PHP_EOL.
78
+		'STATUS:NEEDS-ACTION'.PHP_EOL.
79
+		'END:VTODO'.PHP_EOL.
80 80
 		'END:VCALENDAR';
81 81
 
82 82
 	// DUE DATETIME
83
-	private static string $vTodo4 = 'BEGIN:VCALENDAR' . PHP_EOL .
84
-		'PRODID:TEST' . PHP_EOL .
85
-		'VERSION:2.0' . PHP_EOL .
86
-		'BEGIN:VTODO' . PHP_EOL .
87
-		'UID:[email protected]' . PHP_EOL .
88
-		'DTSTAMP:20070313T123432Z' . PHP_EOL .
89
-		'DUE:20070709T130000Z' . PHP_EOL .
90
-		'SUMMARY:Task title' . PHP_EOL .
91
-		'STATUS:NEEDS-ACTION' . PHP_EOL .
92
-		'END:VTODO' . PHP_EOL .
83
+	private static string $vTodo4 = 'BEGIN:VCALENDAR'.PHP_EOL.
84
+		'PRODID:TEST'.PHP_EOL.
85
+		'VERSION:2.0'.PHP_EOL.
86
+		'BEGIN:VTODO'.PHP_EOL.
87
+		'UID:[email protected]'.PHP_EOL.
88
+		'DTSTAMP:20070313T123432Z'.PHP_EOL.
89
+		'DUE:20070709T130000Z'.PHP_EOL.
90
+		'SUMMARY:Task title'.PHP_EOL.
91
+		'STATUS:NEEDS-ACTION'.PHP_EOL.
92
+		'END:VTODO'.PHP_EOL.
93 93
 		'END:VCALENDAR';
94 94
 
95 95
 	protected function setUp(): void {
Please login to merge, or discard this patch.
apps/dav/tests/unit/Search/ContactsSearchProviderTest.php 2 patches
Indentation   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -22,238 +22,238 @@
 block discarded – undo
22 22
 use Test\TestCase;
23 23
 
24 24
 class ContactsSearchProviderTest extends TestCase {
25
-	private IAppManager&MockObject $appManager;
26
-	private IL10N&MockObject $l10n;
27
-	private IURLGenerator&MockObject $urlGenerator;
28
-	private CardDavBackend&MockObject $backend;
29
-	private ContactsSearchProvider $provider;
25
+    private IAppManager&MockObject $appManager;
26
+    private IL10N&MockObject $l10n;
27
+    private IURLGenerator&MockObject $urlGenerator;
28
+    private CardDavBackend&MockObject $backend;
29
+    private ContactsSearchProvider $provider;
30 30
 
31
-	private string $vcardTest0 = 'BEGIN:VCARD' . PHP_EOL .
32
-		'VERSION:3.0' . PHP_EOL .
33
-		'PRODID:-//Sabre//Sabre VObject 4.1.2//EN' . PHP_EOL .
34
-		'UID:Test' . PHP_EOL .
35
-		'FN:FN of Test' . PHP_EOL .
36
-		'N:Test;;;;' . PHP_EOL .
37
-		'EMAIL:[email protected]' . PHP_EOL .
38
-		'END:VCARD';
31
+    private string $vcardTest0 = 'BEGIN:VCARD' . PHP_EOL .
32
+        'VERSION:3.0' . PHP_EOL .
33
+        'PRODID:-//Sabre//Sabre VObject 4.1.2//EN' . PHP_EOL .
34
+        'UID:Test' . PHP_EOL .
35
+        'FN:FN of Test' . PHP_EOL .
36
+        'N:Test;;;;' . PHP_EOL .
37
+        'EMAIL:[email protected]' . PHP_EOL .
38
+        'END:VCARD';
39 39
 
40
-	private string $vcardTest1 = 'BEGIN:VCARD' . PHP_EOL .
41
-		'VERSION:3.0' . PHP_EOL .
42
-		'PRODID:-//Sabre//Sabre VObject 4.1.2//EN' . PHP_EOL .
43
-		'PHOTO;ENCODING=b;TYPE=image/jpeg:' . PHP_EOL .
44
-		'UID:Test2' . PHP_EOL .
45
-		'FN:FN of Test2' . PHP_EOL .
46
-		'N:Test2;;;;' . PHP_EOL .
47
-		'END:VCARD';
40
+    private string $vcardTest1 = 'BEGIN:VCARD' . PHP_EOL .
41
+        'VERSION:3.0' . PHP_EOL .
42
+        'PRODID:-//Sabre//Sabre VObject 4.1.2//EN' . PHP_EOL .
43
+        'PHOTO;ENCODING=b;TYPE=image/jpeg:' . PHP_EOL .
44
+        'UID:Test2' . PHP_EOL .
45
+        'FN:FN of Test2' . PHP_EOL .
46
+        'N:Test2;;;;' . PHP_EOL .
47
+        'END:VCARD';
48 48
 
49
-	protected function setUp(): void {
50
-		parent::setUp();
49
+    protected function setUp(): void {
50
+        parent::setUp();
51 51
 
52
-		$this->appManager = $this->createMock(IAppManager::class);
53
-		$this->l10n = $this->createMock(IL10N::class);
54
-		$this->urlGenerator = $this->createMock(IURLGenerator::class);
55
-		$this->backend = $this->createMock(CardDavBackend::class);
52
+        $this->appManager = $this->createMock(IAppManager::class);
53
+        $this->l10n = $this->createMock(IL10N::class);
54
+        $this->urlGenerator = $this->createMock(IURLGenerator::class);
55
+        $this->backend = $this->createMock(CardDavBackend::class);
56 56
 
57
-		$this->provider = new ContactsSearchProvider(
58
-			$this->appManager,
59
-			$this->l10n,
60
-			$this->urlGenerator,
61
-			$this->backend
62
-		);
63
-	}
57
+        $this->provider = new ContactsSearchProvider(
58
+            $this->appManager,
59
+            $this->l10n,
60
+            $this->urlGenerator,
61
+            $this->backend
62
+        );
63
+    }
64 64
 
65
-	public function testGetId(): void {
66
-		$this->assertEquals('contacts', $this->provider->getId());
67
-	}
65
+    public function testGetId(): void {
66
+        $this->assertEquals('contacts', $this->provider->getId());
67
+    }
68 68
 
69
-	public function testGetName(): void {
70
-		$this->l10n->expects($this->exactly(1))
71
-			->method('t')
72
-			->with('Contacts')
73
-			->willReturnArgument(0);
69
+    public function testGetName(): void {
70
+        $this->l10n->expects($this->exactly(1))
71
+            ->method('t')
72
+            ->with('Contacts')
73
+            ->willReturnArgument(0);
74 74
 
75
-		$this->assertEquals('Contacts', $this->provider->getName());
76
-	}
75
+        $this->assertEquals('Contacts', $this->provider->getName());
76
+    }
77 77
 
78
-	public function testSearchAppDisabled(): void {
79
-		$user = $this->createMock(IUser::class);
80
-		$query = $this->createMock(ISearchQuery::class);
81
-		$this->appManager->expects($this->once())
82
-			->method('isEnabledForUser')
83
-			->with('contacts', $user)
84
-			->willReturn(false);
85
-		$this->l10n->expects($this->exactly(1))
86
-			->method('t')
87
-			->with('Contacts')
88
-			->willReturnArgument(0);
89
-		$this->backend->expects($this->never())
90
-			->method('getAddressBooksForUser');
91
-		$this->backend->expects($this->never())
92
-			->method('searchPrincipalUri');
78
+    public function testSearchAppDisabled(): void {
79
+        $user = $this->createMock(IUser::class);
80
+        $query = $this->createMock(ISearchQuery::class);
81
+        $this->appManager->expects($this->once())
82
+            ->method('isEnabledForUser')
83
+            ->with('contacts', $user)
84
+            ->willReturn(false);
85
+        $this->l10n->expects($this->exactly(1))
86
+            ->method('t')
87
+            ->with('Contacts')
88
+            ->willReturnArgument(0);
89
+        $this->backend->expects($this->never())
90
+            ->method('getAddressBooksForUser');
91
+        $this->backend->expects($this->never())
92
+            ->method('searchPrincipalUri');
93 93
 
94
-		$actual = $this->provider->search($user, $query);
95
-		$data = $actual->jsonSerialize();
96
-		$this->assertInstanceOf(SearchResult::class, $actual);
97
-		$this->assertEquals('Contacts', $data['name']);
98
-		$this->assertEmpty($data['entries']);
99
-		$this->assertFalse($data['isPaginated']);
100
-		$this->assertNull($data['cursor']);
101
-	}
94
+        $actual = $this->provider->search($user, $query);
95
+        $data = $actual->jsonSerialize();
96
+        $this->assertInstanceOf(SearchResult::class, $actual);
97
+        $this->assertEquals('Contacts', $data['name']);
98
+        $this->assertEmpty($data['entries']);
99
+        $this->assertFalse($data['isPaginated']);
100
+        $this->assertNull($data['cursor']);
101
+    }
102 102
 
103
-	public function testSearch(): void {
104
-		$user = $this->createMock(IUser::class);
105
-		$user->method('getUID')->willReturn('john.doe');
106
-		$query = $this->createMock(ISearchQuery::class);
107
-		$query->method('getTerm')->willReturn('search term');
108
-		$query->method('getLimit')->willReturn(5);
109
-		$query->method('getCursor')->willReturn(20);
110
-		$this->appManager->expects($this->once())
111
-			->method('isEnabledForUser')
112
-			->with('contacts', $user)
113
-			->willReturn(true);
114
-		$this->l10n->expects($this->exactly(1))
115
-			->method('t')
116
-			->with('Contacts')
117
-			->willReturnArgument(0);
103
+    public function testSearch(): void {
104
+        $user = $this->createMock(IUser::class);
105
+        $user->method('getUID')->willReturn('john.doe');
106
+        $query = $this->createMock(ISearchQuery::class);
107
+        $query->method('getTerm')->willReturn('search term');
108
+        $query->method('getLimit')->willReturn(5);
109
+        $query->method('getCursor')->willReturn(20);
110
+        $this->appManager->expects($this->once())
111
+            ->method('isEnabledForUser')
112
+            ->with('contacts', $user)
113
+            ->willReturn(true);
114
+        $this->l10n->expects($this->exactly(1))
115
+            ->method('t')
116
+            ->with('Contacts')
117
+            ->willReturnArgument(0);
118 118
 
119
-		$this->backend->expects($this->once())
120
-			->method('getAddressBooksForUser')
121
-			->with('principals/users/john.doe')
122
-			->willReturn([
123
-				[
124
-					'id' => 99,
125
-					'principaluri' => 'principals/users/john.doe',
126
-					'uri' => 'addressbook-uri-99',
127
-				], [
128
-					'id' => 123,
129
-					'principaluri' => 'principals/users/john.doe',
130
-					'uri' => 'addressbook-uri-123',
131
-				]
132
-			]);
133
-		$this->backend->expects($this->once())
134
-			->method('searchPrincipalUri')
135
-			->with('principals/users/john.doe', '',
136
-				[
137
-					'N',
138
-					'FN',
139
-					'NICKNAME',
140
-					'EMAIL',
141
-					'TEL',
142
-					'ADR',
143
-					'TITLE',
144
-					'ORG',
145
-					'NOTE',
146
-				],
147
-				['limit' => 5, 'offset' => 20, 'since' => null, 'until' => null,  'person' => null, 'company' => null])
148
-			->willReturn([
149
-				[
150
-					'addressbookid' => 99,
151
-					'uri' => 'vcard0.vcf',
152
-					'carddata' => $this->vcardTest0,
153
-				],
154
-				[
155
-					'addressbookid' => 123,
156
-					'uri' => 'vcard1.vcf',
157
-					'carddata' => $this->vcardTest1,
158
-				],
159
-			]);
119
+        $this->backend->expects($this->once())
120
+            ->method('getAddressBooksForUser')
121
+            ->with('principals/users/john.doe')
122
+            ->willReturn([
123
+                [
124
+                    'id' => 99,
125
+                    'principaluri' => 'principals/users/john.doe',
126
+                    'uri' => 'addressbook-uri-99',
127
+                ], [
128
+                    'id' => 123,
129
+                    'principaluri' => 'principals/users/john.doe',
130
+                    'uri' => 'addressbook-uri-123',
131
+                ]
132
+            ]);
133
+        $this->backend->expects($this->once())
134
+            ->method('searchPrincipalUri')
135
+            ->with('principals/users/john.doe', '',
136
+                [
137
+                    'N',
138
+                    'FN',
139
+                    'NICKNAME',
140
+                    'EMAIL',
141
+                    'TEL',
142
+                    'ADR',
143
+                    'TITLE',
144
+                    'ORG',
145
+                    'NOTE',
146
+                ],
147
+                ['limit' => 5, 'offset' => 20, 'since' => null, 'until' => null,  'person' => null, 'company' => null])
148
+            ->willReturn([
149
+                [
150
+                    'addressbookid' => 99,
151
+                    'uri' => 'vcard0.vcf',
152
+                    'carddata' => $this->vcardTest0,
153
+                ],
154
+                [
155
+                    'addressbookid' => 123,
156
+                    'uri' => 'vcard1.vcf',
157
+                    'carddata' => $this->vcardTest1,
158
+                ],
159
+            ]);
160 160
 
161
-		$provider = $this->getMockBuilder(ContactsSearchProvider::class)
162
-			->setConstructorArgs([
163
-				$this->appManager,
164
-				$this->l10n,
165
-				$this->urlGenerator,
166
-				$this->backend,
167
-			])
168
-			->onlyMethods([
169
-				'getDavUrlForContact',
170
-				'getDeepLinkToContactsApp',
171
-				'generateSubline',
172
-			])
173
-			->getMock();
161
+        $provider = $this->getMockBuilder(ContactsSearchProvider::class)
162
+            ->setConstructorArgs([
163
+                $this->appManager,
164
+                $this->l10n,
165
+                $this->urlGenerator,
166
+                $this->backend,
167
+            ])
168
+            ->onlyMethods([
169
+                'getDavUrlForContact',
170
+                'getDeepLinkToContactsApp',
171
+                'generateSubline',
172
+            ])
173
+            ->getMock();
174 174
 
175
-		$provider->expects($this->once())
176
-			->method('getDavUrlForContact')
177
-			->with('principals/users/john.doe', 'addressbook-uri-123', 'vcard1.vcf')
178
-			->willReturn('absolute-thumbnail-url');
175
+        $provider->expects($this->once())
176
+            ->method('getDavUrlForContact')
177
+            ->with('principals/users/john.doe', 'addressbook-uri-123', 'vcard1.vcf')
178
+            ->willReturn('absolute-thumbnail-url');
179 179
 
180
-		$provider->expects($this->exactly(2))
181
-			->method('generateSubline')
182
-			->willReturn('subline');
183
-		$provider->expects($this->exactly(2))
184
-			->method('getDeepLinkToContactsApp')
185
-			->willReturnMap([
186
-				['addressbook-uri-99', 'Test', 'deep-link-to-contacts'],
187
-				['addressbook-uri-123', 'Test2', 'deep-link-to-contacts'],
188
-			]);
180
+        $provider->expects($this->exactly(2))
181
+            ->method('generateSubline')
182
+            ->willReturn('subline');
183
+        $provider->expects($this->exactly(2))
184
+            ->method('getDeepLinkToContactsApp')
185
+            ->willReturnMap([
186
+                ['addressbook-uri-99', 'Test', 'deep-link-to-contacts'],
187
+                ['addressbook-uri-123', 'Test2', 'deep-link-to-contacts'],
188
+            ]);
189 189
 
190
-		$actual = $provider->search($user, $query);
191
-		$data = $actual->jsonSerialize();
192
-		$this->assertInstanceOf(SearchResult::class, $actual);
193
-		$this->assertEquals('Contacts', $data['name']);
194
-		$this->assertCount(2, $data['entries']);
195
-		$this->assertTrue($data['isPaginated']);
196
-		$this->assertEquals(22, $data['cursor']);
190
+        $actual = $provider->search($user, $query);
191
+        $data = $actual->jsonSerialize();
192
+        $this->assertInstanceOf(SearchResult::class, $actual);
193
+        $this->assertEquals('Contacts', $data['name']);
194
+        $this->assertCount(2, $data['entries']);
195
+        $this->assertTrue($data['isPaginated']);
196
+        $this->assertEquals(22, $data['cursor']);
197 197
 
198
-		$result0 = $data['entries'][0];
199
-		$result0Data = $result0->jsonSerialize();
200
-		$result1 = $data['entries'][1];
201
-		$result1Data = $result1->jsonSerialize();
198
+        $result0 = $data['entries'][0];
199
+        $result0Data = $result0->jsonSerialize();
200
+        $result1 = $data['entries'][1];
201
+        $result1Data = $result1->jsonSerialize();
202 202
 
203
-		$this->assertInstanceOf(SearchResultEntry::class, $result0);
204
-		$this->assertEquals('', $result0Data['thumbnailUrl']);
205
-		$this->assertEquals('FN of Test', $result0Data['title']);
206
-		$this->assertEquals('subline', $result0Data['subline']);
207
-		$this->assertEquals('deep-link-to-contacts', $result0Data['resourceUrl']);
208
-		$this->assertEquals('icon-contacts-dark', $result0Data['icon']);
209
-		$this->assertTrue($result0Data['rounded']);
203
+        $this->assertInstanceOf(SearchResultEntry::class, $result0);
204
+        $this->assertEquals('', $result0Data['thumbnailUrl']);
205
+        $this->assertEquals('FN of Test', $result0Data['title']);
206
+        $this->assertEquals('subline', $result0Data['subline']);
207
+        $this->assertEquals('deep-link-to-contacts', $result0Data['resourceUrl']);
208
+        $this->assertEquals('icon-contacts-dark', $result0Data['icon']);
209
+        $this->assertTrue($result0Data['rounded']);
210 210
 
211
-		$this->assertInstanceOf(SearchResultEntry::class, $result1);
212
-		$this->assertEquals('absolute-thumbnail-url?photo', $result1Data['thumbnailUrl']);
213
-		$this->assertEquals('FN of Test2', $result1Data['title']);
214
-		$this->assertEquals('subline', $result1Data['subline']);
215
-		$this->assertEquals('deep-link-to-contacts', $result1Data['resourceUrl']);
216
-		$this->assertEquals('icon-contacts-dark', $result1Data['icon']);
217
-		$this->assertTrue($result1Data['rounded']);
218
-	}
211
+        $this->assertInstanceOf(SearchResultEntry::class, $result1);
212
+        $this->assertEquals('absolute-thumbnail-url?photo', $result1Data['thumbnailUrl']);
213
+        $this->assertEquals('FN of Test2', $result1Data['title']);
214
+        $this->assertEquals('subline', $result1Data['subline']);
215
+        $this->assertEquals('deep-link-to-contacts', $result1Data['resourceUrl']);
216
+        $this->assertEquals('icon-contacts-dark', $result1Data['icon']);
217
+        $this->assertTrue($result1Data['rounded']);
218
+    }
219 219
 
220
-	public function testGetDavUrlForContact(): void {
221
-		$this->urlGenerator->expects($this->once())
222
-			->method('linkTo')
223
-			->with('', 'remote.php')
224
-			->willReturn('link-to-remote.php');
225
-		$this->urlGenerator->expects($this->once())
226
-			->method('getAbsoluteURL')
227
-			->with('link-to-remote.php/dav/addressbooks/users/john.doe/foo/bar.vcf')
228
-			->willReturn('absolute-url-link-to-remote.php/dav/addressbooks/users/john.doe/foo/bar.vcf');
220
+    public function testGetDavUrlForContact(): void {
221
+        $this->urlGenerator->expects($this->once())
222
+            ->method('linkTo')
223
+            ->with('', 'remote.php')
224
+            ->willReturn('link-to-remote.php');
225
+        $this->urlGenerator->expects($this->once())
226
+            ->method('getAbsoluteURL')
227
+            ->with('link-to-remote.php/dav/addressbooks/users/john.doe/foo/bar.vcf')
228
+            ->willReturn('absolute-url-link-to-remote.php/dav/addressbooks/users/john.doe/foo/bar.vcf');
229 229
 
230
-		$actual = self::invokePrivate($this->provider, 'getDavUrlForContact', ['principals/users/john.doe', 'foo', 'bar.vcf']);
230
+        $actual = self::invokePrivate($this->provider, 'getDavUrlForContact', ['principals/users/john.doe', 'foo', 'bar.vcf']);
231 231
 
232
-		$this->assertEquals('absolute-url-link-to-remote.php/dav/addressbooks/users/john.doe/foo/bar.vcf', $actual);
233
-	}
232
+        $this->assertEquals('absolute-url-link-to-remote.php/dav/addressbooks/users/john.doe/foo/bar.vcf', $actual);
233
+    }
234 234
 
235
-	public function testGetDeepLinkToContactsApp(): void {
236
-		$this->urlGenerator->expects($this->once())
237
-			->method('linkToRoute')
238
-			->with('contacts.contacts.direct', ['contact' => 'uid123~uri-john.doe'])
239
-			->willReturn('link-to-route-contacts.contacts.direct/direct/uid123~uri-john.doe');
240
-		$this->urlGenerator->expects($this->once())
241
-			->method('getAbsoluteURL')
242
-			->with('link-to-route-contacts.contacts.direct/direct/uid123~uri-john.doe')
243
-			->willReturn('absolute-url-link-to-route-contacts.contacts.direct/direct/uid123~uri-john.doe');
235
+    public function testGetDeepLinkToContactsApp(): void {
236
+        $this->urlGenerator->expects($this->once())
237
+            ->method('linkToRoute')
238
+            ->with('contacts.contacts.direct', ['contact' => 'uid123~uri-john.doe'])
239
+            ->willReturn('link-to-route-contacts.contacts.direct/direct/uid123~uri-john.doe');
240
+        $this->urlGenerator->expects($this->once())
241
+            ->method('getAbsoluteURL')
242
+            ->with('link-to-route-contacts.contacts.direct/direct/uid123~uri-john.doe')
243
+            ->willReturn('absolute-url-link-to-route-contacts.contacts.direct/direct/uid123~uri-john.doe');
244 244
 
245
-		$actual = self::invokePrivate($this->provider, 'getDeepLinkToContactsApp', ['uri-john.doe', 'uid123']);
246
-		$this->assertEquals('absolute-url-link-to-route-contacts.contacts.direct/direct/uid123~uri-john.doe', $actual);
247
-	}
245
+        $actual = self::invokePrivate($this->provider, 'getDeepLinkToContactsApp', ['uri-john.doe', 'uid123']);
246
+        $this->assertEquals('absolute-url-link-to-route-contacts.contacts.direct/direct/uid123~uri-john.doe', $actual);
247
+    }
248 248
 
249
-	public function testGenerateSubline(): void {
250
-		$vCard0 = Reader::read($this->vcardTest0);
251
-		$vCard1 = Reader::read($this->vcardTest1);
249
+    public function testGenerateSubline(): void {
250
+        $vCard0 = Reader::read($this->vcardTest0);
251
+        $vCard1 = Reader::read($this->vcardTest1);
252 252
 
253
-		$actual1 = self::invokePrivate($this->provider, 'generateSubline', [$vCard0]);
254
-		$actual2 = self::invokePrivate($this->provider, 'generateSubline', [$vCard1]);
253
+        $actual1 = self::invokePrivate($this->provider, 'generateSubline', [$vCard0]);
254
+        $actual2 = self::invokePrivate($this->provider, 'generateSubline', [$vCard1]);
255 255
 
256
-		$this->assertEquals('[email protected]', $actual1);
257
-		$this->assertEquals('', $actual2);
258
-	}
256
+        $this->assertEquals('[email protected]', $actual1);
257
+        $this->assertEquals('', $actual2);
258
+    }
259 259
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -28,22 +28,22 @@  discard block
 block discarded – undo
28 28
 	private CardDavBackend&MockObject $backend;
29 29
 	private ContactsSearchProvider $provider;
30 30
 
31
-	private string $vcardTest0 = 'BEGIN:VCARD' . PHP_EOL .
32
-		'VERSION:3.0' . PHP_EOL .
33
-		'PRODID:-//Sabre//Sabre VObject 4.1.2//EN' . PHP_EOL .
34
-		'UID:Test' . PHP_EOL .
35
-		'FN:FN of Test' . PHP_EOL .
36
-		'N:Test;;;;' . PHP_EOL .
37
-		'EMAIL:[email protected]' . PHP_EOL .
31
+	private string $vcardTest0 = 'BEGIN:VCARD'.PHP_EOL.
32
+		'VERSION:3.0'.PHP_EOL.
33
+		'PRODID:-//Sabre//Sabre VObject 4.1.2//EN'.PHP_EOL.
34
+		'UID:Test'.PHP_EOL.
35
+		'FN:FN of Test'.PHP_EOL.
36
+		'N:Test;;;;'.PHP_EOL.
37
+		'EMAIL:[email protected]'.PHP_EOL.
38 38
 		'END:VCARD';
39 39
 
40
-	private string $vcardTest1 = 'BEGIN:VCARD' . PHP_EOL .
41
-		'VERSION:3.0' . PHP_EOL .
42
-		'PRODID:-//Sabre//Sabre VObject 4.1.2//EN' . PHP_EOL .
43
-		'PHOTO;ENCODING=b;TYPE=image/jpeg:' . PHP_EOL .
44
-		'UID:Test2' . PHP_EOL .
45
-		'FN:FN of Test2' . PHP_EOL .
46
-		'N:Test2;;;;' . PHP_EOL .
40
+	private string $vcardTest1 = 'BEGIN:VCARD'.PHP_EOL.
41
+		'VERSION:3.0'.PHP_EOL.
42
+		'PRODID:-//Sabre//Sabre VObject 4.1.2//EN'.PHP_EOL.
43
+		'PHOTO;ENCODING=b;TYPE=image/jpeg:'.PHP_EOL.
44
+		'UID:Test2'.PHP_EOL.
45
+		'FN:FN of Test2'.PHP_EOL.
46
+		'N:Test2;;;;'.PHP_EOL.
47 47
 		'END:VCARD';
48 48
 
49 49
 	protected function setUp(): void {
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 					'ORG',
145 145
 					'NOTE',
146 146
 				],
147
-				['limit' => 5, 'offset' => 20, 'since' => null, 'until' => null,  'person' => null, 'company' => null])
147
+				['limit' => 5, 'offset' => 20, 'since' => null, 'until' => null, 'person' => null, 'company' => null])
148 148
 			->willReturn([
149 149
 				[
150 150
 					'addressbookid' => 99,
Please login to merge, or discard this patch.
apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php 1 patch
Indentation   +369 added lines, -369 removed lines patch added patch discarded remove patch
@@ -23,52 +23,52 @@  discard block
 block discarded – undo
23 23
 use Test\TestCase;
24 24
 
25 25
 class InvitationResponseControllerTest extends TestCase {
26
-	private IDBConnection&MockObject $dbConnection;
27
-	private IRequest&MockObject $request;
28
-	private ITimeFactory&MockObject $timeFactory;
29
-	private InvitationResponseServer&MockObject $responseServer;
30
-	private InvitationResponseController $controller;
31
-
32
-	protected function setUp(): void {
33
-		parent::setUp();
34
-
35
-		$this->dbConnection = $this->createMock(IDBConnection::class);
36
-		$this->request = $this->createMock(IRequest::class);
37
-		$this->timeFactory = $this->createMock(ITimeFactory::class);
38
-		$this->responseServer = $this->createMock(InvitationResponseServer::class);
39
-
40
-		$this->controller = new InvitationResponseController(
41
-			'appName',
42
-			$this->request,
43
-			$this->dbConnection,
44
-			$this->timeFactory,
45
-			$this->responseServer
46
-		);
47
-	}
48
-
49
-	public static function attendeeProvider(): array {
50
-		return [
51
-			'local attendee' => [false],
52
-			'external attendee' => [true]
53
-		];
54
-	}
55
-
56
-	/**
57
-	 * @dataProvider attendeeProvider
58
-	 */
59
-	public function testAccept(bool $isExternalAttendee): void {
60
-		$this->buildQueryExpects('TOKEN123', [
61
-			'id' => 0,
62
-			'uid' => 'this-is-the-events-uid',
63
-			'recurrenceid' => null,
64
-			'attendee' => 'mailto:[email protected]',
65
-			'organizer' => 'mailto:[email protected]',
66
-			'sequence' => null,
67
-			'token' => 'TOKEN123',
68
-			'expiration' => 420000,
69
-		], 1337);
70
-
71
-		$expected = <<<EOF
26
+    private IDBConnection&MockObject $dbConnection;
27
+    private IRequest&MockObject $request;
28
+    private ITimeFactory&MockObject $timeFactory;
29
+    private InvitationResponseServer&MockObject $responseServer;
30
+    private InvitationResponseController $controller;
31
+
32
+    protected function setUp(): void {
33
+        parent::setUp();
34
+
35
+        $this->dbConnection = $this->createMock(IDBConnection::class);
36
+        $this->request = $this->createMock(IRequest::class);
37
+        $this->timeFactory = $this->createMock(ITimeFactory::class);
38
+        $this->responseServer = $this->createMock(InvitationResponseServer::class);
39
+
40
+        $this->controller = new InvitationResponseController(
41
+            'appName',
42
+            $this->request,
43
+            $this->dbConnection,
44
+            $this->timeFactory,
45
+            $this->responseServer
46
+        );
47
+    }
48
+
49
+    public static function attendeeProvider(): array {
50
+        return [
51
+            'local attendee' => [false],
52
+            'external attendee' => [true]
53
+        ];
54
+    }
55
+
56
+    /**
57
+     * @dataProvider attendeeProvider
58
+     */
59
+    public function testAccept(bool $isExternalAttendee): void {
60
+        $this->buildQueryExpects('TOKEN123', [
61
+            'id' => 0,
62
+            'uid' => 'this-is-the-events-uid',
63
+            'recurrenceid' => null,
64
+            'attendee' => 'mailto:[email protected]',
65
+            'organizer' => 'mailto:[email protected]',
66
+            'sequence' => null,
67
+            'token' => 'TOKEN123',
68
+            'expiration' => 420000,
69
+        ], 1337);
70
+
71
+        $expected = <<<EOF
72 72
 BEGIN:VCALENDAR
73 73
 VERSION:2.0
74 74
 PRODID:-//Nextcloud/Nextcloud CalDAV Server//EN
@@ -84,55 +84,55 @@  discard block
 block discarded – undo
84 84
 END:VCALENDAR
85 85
 
86 86
 EOF;
87
-		$expected = preg_replace('~\R~u', "\r\n", $expected);
88
-
89
-		$called = false;
90
-		$this->responseServer->expects($this->once())
91
-			->method('handleITipMessage')
92
-			->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected): void {
93
-				$called = true;
94
-				$this->assertEquals('this-is-the-events-uid', $iTipMessage->uid);
95
-				$this->assertEquals('VEVENT', $iTipMessage->component);
96
-				$this->assertEquals('REPLY', $iTipMessage->method);
97
-				$this->assertEquals(null, $iTipMessage->sequence);
98
-				$this->assertEquals('mailto:[email protected]', $iTipMessage->sender);
99
-				if ($isExternalAttendee) {
100
-					$this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
101
-				} else {
102
-					$this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
103
-				}
104
-
105
-				$iTipMessage->scheduleStatus = '1.2;Message delivered locally';
106
-
107
-				$this->assertEquals($expected, $iTipMessage->message->serialize());
108
-			});
109
-		$this->responseServer->expects($this->once())
110
-			->method('isExternalAttendee')
111
-			->willReturn($isExternalAttendee);
112
-
113
-		$response = $this->controller->accept('TOKEN123');
114
-		$this->assertInstanceOf(TemplateResponse::class, $response);
115
-		$this->assertEquals('schedule-response-success', $response->getTemplateName());
116
-		$this->assertEquals([], $response->getParams());
117
-		$this->assertTrue($called);
118
-	}
119
-
120
-	/**
121
-	 * @dataProvider attendeeProvider
122
-	 */
123
-	public function testAcceptSequence(bool $isExternalAttendee): void {
124
-		$this->buildQueryExpects('TOKEN123', [
125
-			'id' => 0,
126
-			'uid' => 'this-is-the-events-uid',
127
-			'recurrenceid' => null,
128
-			'attendee' => 'mailto:[email protected]',
129
-			'organizer' => 'mailto:[email protected]',
130
-			'sequence' => 1337,
131
-			'token' => 'TOKEN123',
132
-			'expiration' => 420000,
133
-		], 1337);
134
-
135
-		$expected = <<<EOF
87
+        $expected = preg_replace('~\R~u', "\r\n", $expected);
88
+
89
+        $called = false;
90
+        $this->responseServer->expects($this->once())
91
+            ->method('handleITipMessage')
92
+            ->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected): void {
93
+                $called = true;
94
+                $this->assertEquals('this-is-the-events-uid', $iTipMessage->uid);
95
+                $this->assertEquals('VEVENT', $iTipMessage->component);
96
+                $this->assertEquals('REPLY', $iTipMessage->method);
97
+                $this->assertEquals(null, $iTipMessage->sequence);
98
+                $this->assertEquals('mailto:[email protected]', $iTipMessage->sender);
99
+                if ($isExternalAttendee) {
100
+                    $this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
101
+                } else {
102
+                    $this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
103
+                }
104
+
105
+                $iTipMessage->scheduleStatus = '1.2;Message delivered locally';
106
+
107
+                $this->assertEquals($expected, $iTipMessage->message->serialize());
108
+            });
109
+        $this->responseServer->expects($this->once())
110
+            ->method('isExternalAttendee')
111
+            ->willReturn($isExternalAttendee);
112
+
113
+        $response = $this->controller->accept('TOKEN123');
114
+        $this->assertInstanceOf(TemplateResponse::class, $response);
115
+        $this->assertEquals('schedule-response-success', $response->getTemplateName());
116
+        $this->assertEquals([], $response->getParams());
117
+        $this->assertTrue($called);
118
+    }
119
+
120
+    /**
121
+     * @dataProvider attendeeProvider
122
+     */
123
+    public function testAcceptSequence(bool $isExternalAttendee): void {
124
+        $this->buildQueryExpects('TOKEN123', [
125
+            'id' => 0,
126
+            'uid' => 'this-is-the-events-uid',
127
+            'recurrenceid' => null,
128
+            'attendee' => 'mailto:[email protected]',
129
+            'organizer' => 'mailto:[email protected]',
130
+            'sequence' => 1337,
131
+            'token' => 'TOKEN123',
132
+            'expiration' => 420000,
133
+        ], 1337);
134
+
135
+        $expected = <<<EOF
136 136
 BEGIN:VCALENDAR
137 137
 VERSION:2.0
138 138
 PRODID:-//Nextcloud/Nextcloud CalDAV Server//EN
@@ -148,55 +148,55 @@  discard block
 block discarded – undo
148 148
 END:VCALENDAR
149 149
 
150 150
 EOF;
151
-		$expected = preg_replace('~\R~u', "\r\n", $expected);
152
-
153
-		$called = false;
154
-		$this->responseServer->expects($this->once())
155
-			->method('handleITipMessage')
156
-			->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected): void {
157
-				$called = true;
158
-				$this->assertEquals('this-is-the-events-uid', $iTipMessage->uid);
159
-				$this->assertEquals('VEVENT', $iTipMessage->component);
160
-				$this->assertEquals('REPLY', $iTipMessage->method);
161
-				$this->assertEquals(1337, $iTipMessage->sequence);
162
-				$this->assertEquals('mailto:[email protected]', $iTipMessage->sender);
163
-				if ($isExternalAttendee) {
164
-					$this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
165
-				} else {
166
-					$this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
167
-				}
168
-
169
-				$iTipMessage->scheduleStatus = '1.2;Message delivered locally';
170
-
171
-				$this->assertEquals($expected, $iTipMessage->message->serialize());
172
-			});
173
-		$this->responseServer->expects($this->once())
174
-			->method('isExternalAttendee')
175
-			->willReturn($isExternalAttendee);
176
-
177
-		$response = $this->controller->accept('TOKEN123');
178
-		$this->assertInstanceOf(TemplateResponse::class, $response);
179
-		$this->assertEquals('schedule-response-success', $response->getTemplateName());
180
-		$this->assertEquals([], $response->getParams());
181
-		$this->assertTrue($called);
182
-	}
183
-
184
-	/**
185
-	 * @dataProvider attendeeProvider
186
-	 */
187
-	public function testAcceptRecurrenceId(bool $isExternalAttendee): void {
188
-		$this->buildQueryExpects('TOKEN123', [
189
-			'id' => 0,
190
-			'uid' => 'this-is-the-events-uid',
191
-			'recurrenceid' => "RECURRENCE-ID;TZID=Europe/Berlin:20180726T150000\n",
192
-			'attendee' => 'mailto:[email protected]',
193
-			'organizer' => 'mailto:[email protected]',
194
-			'sequence' => null,
195
-			'token' => 'TOKEN123',
196
-			'expiration' => 420000,
197
-		], 1337);
198
-
199
-		$expected = <<<EOF
151
+        $expected = preg_replace('~\R~u', "\r\n", $expected);
152
+
153
+        $called = false;
154
+        $this->responseServer->expects($this->once())
155
+            ->method('handleITipMessage')
156
+            ->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected): void {
157
+                $called = true;
158
+                $this->assertEquals('this-is-the-events-uid', $iTipMessage->uid);
159
+                $this->assertEquals('VEVENT', $iTipMessage->component);
160
+                $this->assertEquals('REPLY', $iTipMessage->method);
161
+                $this->assertEquals(1337, $iTipMessage->sequence);
162
+                $this->assertEquals('mailto:[email protected]', $iTipMessage->sender);
163
+                if ($isExternalAttendee) {
164
+                    $this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
165
+                } else {
166
+                    $this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
167
+                }
168
+
169
+                $iTipMessage->scheduleStatus = '1.2;Message delivered locally';
170
+
171
+                $this->assertEquals($expected, $iTipMessage->message->serialize());
172
+            });
173
+        $this->responseServer->expects($this->once())
174
+            ->method('isExternalAttendee')
175
+            ->willReturn($isExternalAttendee);
176
+
177
+        $response = $this->controller->accept('TOKEN123');
178
+        $this->assertInstanceOf(TemplateResponse::class, $response);
179
+        $this->assertEquals('schedule-response-success', $response->getTemplateName());
180
+        $this->assertEquals([], $response->getParams());
181
+        $this->assertTrue($called);
182
+    }
183
+
184
+    /**
185
+     * @dataProvider attendeeProvider
186
+     */
187
+    public function testAcceptRecurrenceId(bool $isExternalAttendee): void {
188
+        $this->buildQueryExpects('TOKEN123', [
189
+            'id' => 0,
190
+            'uid' => 'this-is-the-events-uid',
191
+            'recurrenceid' => "RECURRENCE-ID;TZID=Europe/Berlin:20180726T150000\n",
192
+            'attendee' => 'mailto:[email protected]',
193
+            'organizer' => 'mailto:[email protected]',
194
+            'sequence' => null,
195
+            'token' => 'TOKEN123',
196
+            'expiration' => 420000,
197
+        ], 1337);
198
+
199
+        $expected = <<<EOF
200 200
 BEGIN:VCALENDAR
201 201
 VERSION:2.0
202 202
 PRODID:-//Nextcloud/Nextcloud CalDAV Server//EN
@@ -213,82 +213,82 @@  discard block
 block discarded – undo
213 213
 END:VCALENDAR
214 214
 
215 215
 EOF;
216
-		$expected = preg_replace('~\R~u', "\r\n", $expected);
217
-
218
-		$called = false;
219
-		$this->responseServer->expects($this->once())
220
-			->method('handleITipMessage')
221
-			->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected): void {
222
-				$called = true;
223
-				$this->assertEquals('this-is-the-events-uid', $iTipMessage->uid);
224
-				$this->assertEquals('VEVENT', $iTipMessage->component);
225
-				$this->assertEquals('REPLY', $iTipMessage->method);
226
-				$this->assertEquals(0, $iTipMessage->sequence);
227
-				$this->assertEquals('mailto:[email protected]', $iTipMessage->sender);
228
-				if ($isExternalAttendee) {
229
-					$this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
230
-				} else {
231
-					$this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
232
-				}
233
-
234
-				$iTipMessage->scheduleStatus = '1.2;Message delivered locally';
235
-
236
-				$this->assertEquals($expected, $iTipMessage->message->serialize());
237
-			});
238
-		$this->responseServer->expects($this->once())
239
-			->method('isExternalAttendee')
240
-			->willReturn($isExternalAttendee);
241
-
242
-		$response = $this->controller->accept('TOKEN123');
243
-		$this->assertInstanceOf(TemplateResponse::class, $response);
244
-		$this->assertEquals('schedule-response-success', $response->getTemplateName());
245
-		$this->assertEquals([], $response->getParams());
246
-		$this->assertTrue($called);
247
-	}
248
-
249
-	public function testAcceptTokenNotFound(): void {
250
-		$this->buildQueryExpects('TOKEN123', null, 1337);
251
-
252
-		$response = $this->controller->accept('TOKEN123');
253
-		$this->assertInstanceOf(TemplateResponse::class, $response);
254
-		$this->assertEquals('schedule-response-error', $response->getTemplateName());
255
-		$this->assertEquals([], $response->getParams());
256
-	}
257
-
258
-	public function testAcceptExpiredToken(): void {
259
-		$this->buildQueryExpects('TOKEN123', [
260
-			'id' => 0,
261
-			'uid' => 'this-is-the-events-uid',
262
-			'recurrenceid' => null,
263
-			'attendee' => 'mailto:[email protected]',
264
-			'organizer' => 'mailto:[email protected]',
265
-			'sequence' => null,
266
-			'token' => 'TOKEN123',
267
-			'expiration' => 42,
268
-		], 1337);
269
-
270
-		$response = $this->controller->accept('TOKEN123');
271
-		$this->assertInstanceOf(TemplateResponse::class, $response);
272
-		$this->assertEquals('schedule-response-error', $response->getTemplateName());
273
-		$this->assertEquals([], $response->getParams());
274
-	}
275
-
276
-	/**
277
-	 * @dataProvider attendeeProvider
278
-	 */
279
-	public function testDecline(bool $isExternalAttendee): void {
280
-		$this->buildQueryExpects('TOKEN123', [
281
-			'id' => 0,
282
-			'uid' => 'this-is-the-events-uid',
283
-			'recurrenceid' => null,
284
-			'attendee' => 'mailto:[email protected]',
285
-			'organizer' => 'mailto:[email protected]',
286
-			'sequence' => null,
287
-			'token' => 'TOKEN123',
288
-			'expiration' => 420000,
289
-		], 1337);
290
-
291
-		$expected = <<<EOF
216
+        $expected = preg_replace('~\R~u', "\r\n", $expected);
217
+
218
+        $called = false;
219
+        $this->responseServer->expects($this->once())
220
+            ->method('handleITipMessage')
221
+            ->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected): void {
222
+                $called = true;
223
+                $this->assertEquals('this-is-the-events-uid', $iTipMessage->uid);
224
+                $this->assertEquals('VEVENT', $iTipMessage->component);
225
+                $this->assertEquals('REPLY', $iTipMessage->method);
226
+                $this->assertEquals(0, $iTipMessage->sequence);
227
+                $this->assertEquals('mailto:[email protected]', $iTipMessage->sender);
228
+                if ($isExternalAttendee) {
229
+                    $this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
230
+                } else {
231
+                    $this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
232
+                }
233
+
234
+                $iTipMessage->scheduleStatus = '1.2;Message delivered locally';
235
+
236
+                $this->assertEquals($expected, $iTipMessage->message->serialize());
237
+            });
238
+        $this->responseServer->expects($this->once())
239
+            ->method('isExternalAttendee')
240
+            ->willReturn($isExternalAttendee);
241
+
242
+        $response = $this->controller->accept('TOKEN123');
243
+        $this->assertInstanceOf(TemplateResponse::class, $response);
244
+        $this->assertEquals('schedule-response-success', $response->getTemplateName());
245
+        $this->assertEquals([], $response->getParams());
246
+        $this->assertTrue($called);
247
+    }
248
+
249
+    public function testAcceptTokenNotFound(): void {
250
+        $this->buildQueryExpects('TOKEN123', null, 1337);
251
+
252
+        $response = $this->controller->accept('TOKEN123');
253
+        $this->assertInstanceOf(TemplateResponse::class, $response);
254
+        $this->assertEquals('schedule-response-error', $response->getTemplateName());
255
+        $this->assertEquals([], $response->getParams());
256
+    }
257
+
258
+    public function testAcceptExpiredToken(): void {
259
+        $this->buildQueryExpects('TOKEN123', [
260
+            'id' => 0,
261
+            'uid' => 'this-is-the-events-uid',
262
+            'recurrenceid' => null,
263
+            'attendee' => 'mailto:[email protected]',
264
+            'organizer' => 'mailto:[email protected]',
265
+            'sequence' => null,
266
+            'token' => 'TOKEN123',
267
+            'expiration' => 42,
268
+        ], 1337);
269
+
270
+        $response = $this->controller->accept('TOKEN123');
271
+        $this->assertInstanceOf(TemplateResponse::class, $response);
272
+        $this->assertEquals('schedule-response-error', $response->getTemplateName());
273
+        $this->assertEquals([], $response->getParams());
274
+    }
275
+
276
+    /**
277
+     * @dataProvider attendeeProvider
278
+     */
279
+    public function testDecline(bool $isExternalAttendee): void {
280
+        $this->buildQueryExpects('TOKEN123', [
281
+            'id' => 0,
282
+            'uid' => 'this-is-the-events-uid',
283
+            'recurrenceid' => null,
284
+            'attendee' => 'mailto:[email protected]',
285
+            'organizer' => 'mailto:[email protected]',
286
+            'sequence' => null,
287
+            'token' => 'TOKEN123',
288
+            'expiration' => 420000,
289
+        ], 1337);
290
+
291
+        $expected = <<<EOF
292 292
 BEGIN:VCALENDAR
293 293
 VERSION:2.0
294 294
 PRODID:-//Nextcloud/Nextcloud CalDAV Server//EN
@@ -304,67 +304,67 @@  discard block
 block discarded – undo
304 304
 END:VCALENDAR
305 305
 
306 306
 EOF;
307
-		$expected = preg_replace('~\R~u', "\r\n", $expected);
308
-
309
-		$called = false;
310
-		$this->responseServer->expects($this->once())
311
-			->method('handleITipMessage')
312
-			->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected): void {
313
-				$called = true;
314
-				$this->assertEquals('this-is-the-events-uid', $iTipMessage->uid);
315
-				$this->assertEquals('VEVENT', $iTipMessage->component);
316
-				$this->assertEquals('REPLY', $iTipMessage->method);
317
-				$this->assertEquals(null, $iTipMessage->sequence);
318
-				$this->assertEquals('mailto:[email protected]', $iTipMessage->sender);
319
-				if ($isExternalAttendee) {
320
-					$this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
321
-				} else {
322
-					$this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
323
-				}
324
-
325
-				$iTipMessage->scheduleStatus = '1.2;Message delivered locally';
326
-
327
-				$this->assertEquals($expected, $iTipMessage->message->serialize());
328
-			});
329
-		$this->responseServer->expects($this->once())
330
-			->method('isExternalAttendee')
331
-			->willReturn($isExternalAttendee);
332
-
333
-		$response = $this->controller->decline('TOKEN123');
334
-		$this->assertInstanceOf(TemplateResponse::class, $response);
335
-		$this->assertEquals('schedule-response-success', $response->getTemplateName());
336
-		$this->assertEquals([], $response->getParams());
337
-		$this->assertTrue($called);
338
-	}
339
-
340
-	public function testOptions(): void {
341
-		$response = $this->controller->options('TOKEN123');
342
-		$this->assertInstanceOf(TemplateResponse::class, $response);
343
-		$this->assertEquals('schedule-response-options', $response->getTemplateName());
344
-		$this->assertEquals(['token' => 'TOKEN123'], $response->getParams());
345
-	}
346
-
347
-	/**
348
-	 * @dataProvider attendeeProvider
349
-	 */
350
-	public function testProcessMoreOptionsResult(bool $isExternalAttendee): void {
351
-		$this->request->expects($this->once())
352
-			->method('getParam')
353
-			->with('partStat')
354
-			->willReturn('TENTATIVE');
355
-
356
-		$this->buildQueryExpects('TOKEN123', [
357
-			'id' => 0,
358
-			'uid' => 'this-is-the-events-uid',
359
-			'recurrenceid' => null,
360
-			'attendee' => 'mailto:[email protected]',
361
-			'organizer' => 'mailto:[email protected]',
362
-			'sequence' => null,
363
-			'token' => 'TOKEN123',
364
-			'expiration' => 420000,
365
-		], 1337);
366
-
367
-		$expected = <<<EOF
307
+        $expected = preg_replace('~\R~u', "\r\n", $expected);
308
+
309
+        $called = false;
310
+        $this->responseServer->expects($this->once())
311
+            ->method('handleITipMessage')
312
+            ->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected): void {
313
+                $called = true;
314
+                $this->assertEquals('this-is-the-events-uid', $iTipMessage->uid);
315
+                $this->assertEquals('VEVENT', $iTipMessage->component);
316
+                $this->assertEquals('REPLY', $iTipMessage->method);
317
+                $this->assertEquals(null, $iTipMessage->sequence);
318
+                $this->assertEquals('mailto:[email protected]', $iTipMessage->sender);
319
+                if ($isExternalAttendee) {
320
+                    $this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
321
+                } else {
322
+                    $this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
323
+                }
324
+
325
+                $iTipMessage->scheduleStatus = '1.2;Message delivered locally';
326
+
327
+                $this->assertEquals($expected, $iTipMessage->message->serialize());
328
+            });
329
+        $this->responseServer->expects($this->once())
330
+            ->method('isExternalAttendee')
331
+            ->willReturn($isExternalAttendee);
332
+
333
+        $response = $this->controller->decline('TOKEN123');
334
+        $this->assertInstanceOf(TemplateResponse::class, $response);
335
+        $this->assertEquals('schedule-response-success', $response->getTemplateName());
336
+        $this->assertEquals([], $response->getParams());
337
+        $this->assertTrue($called);
338
+    }
339
+
340
+    public function testOptions(): void {
341
+        $response = $this->controller->options('TOKEN123');
342
+        $this->assertInstanceOf(TemplateResponse::class, $response);
343
+        $this->assertEquals('schedule-response-options', $response->getTemplateName());
344
+        $this->assertEquals(['token' => 'TOKEN123'], $response->getParams());
345
+    }
346
+
347
+    /**
348
+     * @dataProvider attendeeProvider
349
+     */
350
+    public function testProcessMoreOptionsResult(bool $isExternalAttendee): void {
351
+        $this->request->expects($this->once())
352
+            ->method('getParam')
353
+            ->with('partStat')
354
+            ->willReturn('TENTATIVE');
355
+
356
+        $this->buildQueryExpects('TOKEN123', [
357
+            'id' => 0,
358
+            'uid' => 'this-is-the-events-uid',
359
+            'recurrenceid' => null,
360
+            'attendee' => 'mailto:[email protected]',
361
+            'organizer' => 'mailto:[email protected]',
362
+            'sequence' => null,
363
+            'token' => 'TOKEN123',
364
+            'expiration' => 420000,
365
+        ], 1337);
366
+
367
+        $expected = <<<EOF
368 368
 BEGIN:VCALENDAR
369 369
 VERSION:2.0
370 370
 PRODID:-//Nextcloud/Nextcloud CalDAV Server//EN
@@ -380,92 +380,92 @@  discard block
 block discarded – undo
380 380
 END:VCALENDAR
381 381
 
382 382
 EOF;
383
-		$expected = preg_replace('~\R~u', "\r\n", $expected);
384
-
385
-		$called = false;
386
-		$this->responseServer->expects($this->once())
387
-			->method('handleITipMessage')
388
-			->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected): void {
389
-				$called = true;
390
-				$this->assertEquals('this-is-the-events-uid', $iTipMessage->uid);
391
-				$this->assertEquals('VEVENT', $iTipMessage->component);
392
-				$this->assertEquals('REPLY', $iTipMessage->method);
393
-				$this->assertEquals(null, $iTipMessage->sequence);
394
-				$this->assertEquals('mailto:[email protected]', $iTipMessage->sender);
395
-				if ($isExternalAttendee) {
396
-					$this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
397
-				} else {
398
-					$this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
399
-				}
400
-
401
-				$iTipMessage->scheduleStatus = '1.2;Message delivered locally';
402
-
403
-				$this->assertEquals($expected, $iTipMessage->message->serialize());
404
-			});
405
-		$this->responseServer->expects($this->once())
406
-			->method('isExternalAttendee')
407
-			->willReturn($isExternalAttendee);
408
-
409
-
410
-		$response = $this->controller->processMoreOptionsResult('TOKEN123');
411
-		$this->assertInstanceOf(TemplateResponse::class, $response);
412
-		$this->assertEquals('schedule-response-success', $response->getTemplateName());
413
-		$this->assertEquals([], $response->getParams());
414
-		$this->assertTrue($called);
415
-	}
416
-
417
-	private function buildQueryExpects(string $token, ?array $return, int $time): void {
418
-		$queryBuilder = $this->createMock(IQueryBuilder::class);
419
-		$stmt = $this->createMock(IResult::class);
420
-		$expr = $this->createMock(IExpressionBuilder::class);
421
-
422
-		$this->dbConnection->expects($this->once())
423
-			->method('getQueryBuilder')
424
-			->with()
425
-			->willReturn($queryBuilder);
426
-		$queryBuilder->method('expr')
427
-			->willReturn($expr);
428
-		$queryBuilder->method('createNamedParameter')
429
-			->willReturnMap([
430
-				[$token, \PDO::PARAM_STR, null, 'namedParameterToken']
431
-			]);
432
-
433
-		$stmt->expects($this->once())
434
-			->method('fetch')
435
-			->with(\PDO::FETCH_ASSOC)
436
-			->willReturn($return);
437
-		$stmt->expects($this->once())
438
-			->method('closeCursor');
439
-
440
-		$function = 'functionToken';
441
-		$expr->expects($this->once())
442
-			->method('eq')
443
-			->with('token', 'namedParameterToken')
444
-			->willReturn((string)$function);
445
-
446
-		$this->dbConnection->expects($this->once())
447
-			->method('getQueryBuilder')
448
-			->with()
449
-			->willReturn($queryBuilder);
450
-
451
-		$queryBuilder->expects($this->once())
452
-			->method('select')
453
-			->with('*')
454
-			->willReturn($queryBuilder);
455
-		$queryBuilder->expects($this->once())
456
-			->method('from')
457
-			->with('calendar_invitations')
458
-			->willReturn($queryBuilder);
459
-		$queryBuilder->expects($this->once())
460
-			->method('where')
461
-			->with($function)
462
-			->willReturn($queryBuilder);
463
-		$queryBuilder->expects($this->once())
464
-			->method('executeQuery')
465
-			->with()
466
-			->willReturn($stmt);
467
-
468
-		$this->timeFactory->method('getTime')
469
-			->willReturn($time);
470
-	}
383
+        $expected = preg_replace('~\R~u', "\r\n", $expected);
384
+
385
+        $called = false;
386
+        $this->responseServer->expects($this->once())
387
+            ->method('handleITipMessage')
388
+            ->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected): void {
389
+                $called = true;
390
+                $this->assertEquals('this-is-the-events-uid', $iTipMessage->uid);
391
+                $this->assertEquals('VEVENT', $iTipMessage->component);
392
+                $this->assertEquals('REPLY', $iTipMessage->method);
393
+                $this->assertEquals(null, $iTipMessage->sequence);
394
+                $this->assertEquals('mailto:[email protected]', $iTipMessage->sender);
395
+                if ($isExternalAttendee) {
396
+                    $this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
397
+                } else {
398
+                    $this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
399
+                }
400
+
401
+                $iTipMessage->scheduleStatus = '1.2;Message delivered locally';
402
+
403
+                $this->assertEquals($expected, $iTipMessage->message->serialize());
404
+            });
405
+        $this->responseServer->expects($this->once())
406
+            ->method('isExternalAttendee')
407
+            ->willReturn($isExternalAttendee);
408
+
409
+
410
+        $response = $this->controller->processMoreOptionsResult('TOKEN123');
411
+        $this->assertInstanceOf(TemplateResponse::class, $response);
412
+        $this->assertEquals('schedule-response-success', $response->getTemplateName());
413
+        $this->assertEquals([], $response->getParams());
414
+        $this->assertTrue($called);
415
+    }
416
+
417
+    private function buildQueryExpects(string $token, ?array $return, int $time): void {
418
+        $queryBuilder = $this->createMock(IQueryBuilder::class);
419
+        $stmt = $this->createMock(IResult::class);
420
+        $expr = $this->createMock(IExpressionBuilder::class);
421
+
422
+        $this->dbConnection->expects($this->once())
423
+            ->method('getQueryBuilder')
424
+            ->with()
425
+            ->willReturn($queryBuilder);
426
+        $queryBuilder->method('expr')
427
+            ->willReturn($expr);
428
+        $queryBuilder->method('createNamedParameter')
429
+            ->willReturnMap([
430
+                [$token, \PDO::PARAM_STR, null, 'namedParameterToken']
431
+            ]);
432
+
433
+        $stmt->expects($this->once())
434
+            ->method('fetch')
435
+            ->with(\PDO::FETCH_ASSOC)
436
+            ->willReturn($return);
437
+        $stmt->expects($this->once())
438
+            ->method('closeCursor');
439
+
440
+        $function = 'functionToken';
441
+        $expr->expects($this->once())
442
+            ->method('eq')
443
+            ->with('token', 'namedParameterToken')
444
+            ->willReturn((string)$function);
445
+
446
+        $this->dbConnection->expects($this->once())
447
+            ->method('getQueryBuilder')
448
+            ->with()
449
+            ->willReturn($queryBuilder);
450
+
451
+        $queryBuilder->expects($this->once())
452
+            ->method('select')
453
+            ->with('*')
454
+            ->willReturn($queryBuilder);
455
+        $queryBuilder->expects($this->once())
456
+            ->method('from')
457
+            ->with('calendar_invitations')
458
+            ->willReturn($queryBuilder);
459
+        $queryBuilder->expects($this->once())
460
+            ->method('where')
461
+            ->with($function)
462
+            ->willReturn($queryBuilder);
463
+        $queryBuilder->expects($this->once())
464
+            ->method('executeQuery')
465
+            ->with()
466
+            ->willReturn($stmt);
467
+
468
+        $this->timeFactory->method('getTime')
469
+            ->willReturn($time);
470
+    }
471 471
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/Controller/DirectControllerTest.php 1 patch
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -26,113 +26,113 @@
 block discarded – undo
26 26
 use Test\TestCase;
27 27
 
28 28
 class DirectControllerTest extends TestCase {
29
-	private IRootFolder&MockObject $rootFolder;
30
-	private DirectMapper&MockObject $directMapper;
31
-	private ISecureRandom&MockObject $random;
32
-	private ITimeFactory&MockObject $timeFactory;
33
-	private IURLGenerator&MockObject $urlGenerator;
34
-	private IEventDispatcher&MockObject $eventDispatcher;
35
-
36
-	private DirectController $controller;
37
-
38
-	protected function setUp(): void {
39
-		parent::setUp();
40
-
41
-		$this->rootFolder = $this->createMock(IRootFolder::class);
42
-		$this->directMapper = $this->createMock(DirectMapper::class);
43
-		$this->random = $this->createMock(ISecureRandom::class);
44
-		$this->timeFactory = $this->createMock(ITimeFactory::class);
45
-		$this->urlGenerator = $this->createMock(IURLGenerator::class);
46
-		$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
47
-
48
-		$this->controller = new DirectController(
49
-			'dav',
50
-			$this->createMock(IRequest::class),
51
-			$this->rootFolder,
52
-			'awesomeUser',
53
-			$this->directMapper,
54
-			$this->random,
55
-			$this->timeFactory,
56
-			$this->urlGenerator,
57
-			$this->eventDispatcher
58
-		);
59
-	}
60
-
61
-	public function testGetUrlNonExistingFileId(): void {
62
-		$userFolder = $this->createMock(Folder::class);
63
-		$this->rootFolder->method('getUserFolder')
64
-			->with('awesomeUser')
65
-			->willReturn($userFolder);
66
-
67
-		$userFolder->method('getById')
68
-			->with(101)
69
-			->willReturn([]);
70
-
71
-		$this->expectException(OCSNotFoundException::class);
72
-		$this->controller->getUrl(101);
73
-	}
74
-
75
-	public function testGetUrlForFolder(): void {
76
-		$userFolder = $this->createMock(Folder::class);
77
-		$this->rootFolder->method('getUserFolder')
78
-			->with('awesomeUser')
79
-			->willReturn($userFolder);
80
-
81
-		$folder = $this->createMock(Folder::class);
82
-
83
-		$userFolder->method('getFirstNodeById')
84
-			->with(101)
85
-			->willReturn($folder);
86
-
87
-		$this->expectException(OCSBadRequestException::class);
88
-		$this->controller->getUrl(101);
89
-	}
90
-
91
-	public function testGetUrlValid(): void {
92
-		$userFolder = $this->createMock(Folder::class);
93
-		$this->rootFolder->method('getUserFolder')
94
-			->with('awesomeUser')
95
-			->willReturn($userFolder);
96
-
97
-		$file = $this->createMock(File::class);
98
-
99
-		$this->timeFactory->method('getTime')
100
-			->willReturn(42);
101
-
102
-		$userFolder->method('getFirstNodeById')
103
-			->with(101)
104
-			->willReturn($file);
105
-
106
-		$userFolder->method('getRelativePath')
107
-			->willReturn('/path');
108
-
109
-		$this->random->method('generate')
110
-			->with(
111
-				60,
112
-				ISecureRandom::CHAR_ALPHANUMERIC
113
-			)->willReturn('superduperlongtoken');
114
-
115
-		$this->directMapper->expects($this->once())
116
-			->method('insert')
117
-			->willReturnCallback(function (Direct $direct) {
118
-				$this->assertSame('awesomeUser', $direct->getUserId());
119
-				$this->assertSame(101, $direct->getFileId());
120
-				$this->assertSame('superduperlongtoken', $direct->getToken());
121
-				$this->assertSame(42 + 60 * 60 * 8, $direct->getExpiration());
122
-
123
-				return $direct;
124
-			});
125
-
126
-		$this->urlGenerator->method('getAbsoluteURL')
127
-			->willReturnCallback(function (string $url) {
128
-				return 'https://my.nextcloud/' . $url;
129
-			});
130
-
131
-		$result = $this->controller->getUrl(101);
132
-
133
-		$this->assertInstanceOf(DataResponse::class, $result);
134
-		$this->assertSame([
135
-			'url' => 'https://my.nextcloud/remote.php/direct/superduperlongtoken',
136
-		], $result->getData());
137
-	}
29
+    private IRootFolder&MockObject $rootFolder;
30
+    private DirectMapper&MockObject $directMapper;
31
+    private ISecureRandom&MockObject $random;
32
+    private ITimeFactory&MockObject $timeFactory;
33
+    private IURLGenerator&MockObject $urlGenerator;
34
+    private IEventDispatcher&MockObject $eventDispatcher;
35
+
36
+    private DirectController $controller;
37
+
38
+    protected function setUp(): void {
39
+        parent::setUp();
40
+
41
+        $this->rootFolder = $this->createMock(IRootFolder::class);
42
+        $this->directMapper = $this->createMock(DirectMapper::class);
43
+        $this->random = $this->createMock(ISecureRandom::class);
44
+        $this->timeFactory = $this->createMock(ITimeFactory::class);
45
+        $this->urlGenerator = $this->createMock(IURLGenerator::class);
46
+        $this->eventDispatcher = $this->createMock(IEventDispatcher::class);
47
+
48
+        $this->controller = new DirectController(
49
+            'dav',
50
+            $this->createMock(IRequest::class),
51
+            $this->rootFolder,
52
+            'awesomeUser',
53
+            $this->directMapper,
54
+            $this->random,
55
+            $this->timeFactory,
56
+            $this->urlGenerator,
57
+            $this->eventDispatcher
58
+        );
59
+    }
60
+
61
+    public function testGetUrlNonExistingFileId(): void {
62
+        $userFolder = $this->createMock(Folder::class);
63
+        $this->rootFolder->method('getUserFolder')
64
+            ->with('awesomeUser')
65
+            ->willReturn($userFolder);
66
+
67
+        $userFolder->method('getById')
68
+            ->with(101)
69
+            ->willReturn([]);
70
+
71
+        $this->expectException(OCSNotFoundException::class);
72
+        $this->controller->getUrl(101);
73
+    }
74
+
75
+    public function testGetUrlForFolder(): void {
76
+        $userFolder = $this->createMock(Folder::class);
77
+        $this->rootFolder->method('getUserFolder')
78
+            ->with('awesomeUser')
79
+            ->willReturn($userFolder);
80
+
81
+        $folder = $this->createMock(Folder::class);
82
+
83
+        $userFolder->method('getFirstNodeById')
84
+            ->with(101)
85
+            ->willReturn($folder);
86
+
87
+        $this->expectException(OCSBadRequestException::class);
88
+        $this->controller->getUrl(101);
89
+    }
90
+
91
+    public function testGetUrlValid(): void {
92
+        $userFolder = $this->createMock(Folder::class);
93
+        $this->rootFolder->method('getUserFolder')
94
+            ->with('awesomeUser')
95
+            ->willReturn($userFolder);
96
+
97
+        $file = $this->createMock(File::class);
98
+
99
+        $this->timeFactory->method('getTime')
100
+            ->willReturn(42);
101
+
102
+        $userFolder->method('getFirstNodeById')
103
+            ->with(101)
104
+            ->willReturn($file);
105
+
106
+        $userFolder->method('getRelativePath')
107
+            ->willReturn('/path');
108
+
109
+        $this->random->method('generate')
110
+            ->with(
111
+                60,
112
+                ISecureRandom::CHAR_ALPHANUMERIC
113
+            )->willReturn('superduperlongtoken');
114
+
115
+        $this->directMapper->expects($this->once())
116
+            ->method('insert')
117
+            ->willReturnCallback(function (Direct $direct) {
118
+                $this->assertSame('awesomeUser', $direct->getUserId());
119
+                $this->assertSame(101, $direct->getFileId());
120
+                $this->assertSame('superduperlongtoken', $direct->getToken());
121
+                $this->assertSame(42 + 60 * 60 * 8, $direct->getExpiration());
122
+
123
+                return $direct;
124
+            });
125
+
126
+        $this->urlGenerator->method('getAbsoluteURL')
127
+            ->willReturnCallback(function (string $url) {
128
+                return 'https://my.nextcloud/' . $url;
129
+            });
130
+
131
+        $result = $this->controller->getUrl(101);
132
+
133
+        $this->assertInstanceOf(DataResponse::class, $result);
134
+        $this->assertSame([
135
+            'url' => 'https://my.nextcloud/remote.php/direct/superduperlongtoken',
136
+        ], $result->getData());
137
+    }
138 138
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/Controller/BirthdayCalendarControllerTest.php 2 patches
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -21,76 +21,76 @@
 block discarded – undo
21 21
 use Test\TestCase;
22 22
 
23 23
 class BirthdayCalendarControllerTest extends TestCase {
24
-	private IConfig&MockObject $config;
25
-	private IRequest&MockObject $request;
26
-	private IDBConnection&MockObject $db;
27
-	private IJobList&MockObject $jobList;
28
-	private IUserManager&MockObject $userManager;
29
-	private CalDavBackend&MockObject $caldav;
30
-	private BirthdayCalendarController $controller;
24
+    private IConfig&MockObject $config;
25
+    private IRequest&MockObject $request;
26
+    private IDBConnection&MockObject $db;
27
+    private IJobList&MockObject $jobList;
28
+    private IUserManager&MockObject $userManager;
29
+    private CalDavBackend&MockObject $caldav;
30
+    private BirthdayCalendarController $controller;
31 31
 
32
-	protected function setUp(): void {
33
-		parent::setUp();
32
+    protected function setUp(): void {
33
+        parent::setUp();
34 34
 
35
-		$this->config = $this->createMock(IConfig::class);
36
-		$this->request = $this->createMock(IRequest::class);
37
-		$this->db = $this->createMock(IDBConnection::class);
38
-		$this->jobList = $this->createMock(IJobList::class);
39
-		$this->userManager = $this->createMock(IUserManager::class);
40
-		$this->caldav = $this->createMock(CalDavBackend::class);
35
+        $this->config = $this->createMock(IConfig::class);
36
+        $this->request = $this->createMock(IRequest::class);
37
+        $this->db = $this->createMock(IDBConnection::class);
38
+        $this->jobList = $this->createMock(IJobList::class);
39
+        $this->userManager = $this->createMock(IUserManager::class);
40
+        $this->caldav = $this->createMock(CalDavBackend::class);
41 41
 
42
-		$this->controller = new BirthdayCalendarController('dav',
43
-			$this->request, $this->db, $this->config, $this->jobList,
44
-			$this->userManager, $this->caldav);
45
-	}
42
+        $this->controller = new BirthdayCalendarController('dav',
43
+            $this->request, $this->db, $this->config, $this->jobList,
44
+            $this->userManager, $this->caldav);
45
+    }
46 46
 
47
-	public function testEnable(): void {
48
-		$this->config->expects($this->once())
49
-			->method('setAppValue')
50
-			->with('dav', 'generateBirthdayCalendar', 'yes');
47
+    public function testEnable(): void {
48
+        $this->config->expects($this->once())
49
+            ->method('setAppValue')
50
+            ->with('dav', 'generateBirthdayCalendar', 'yes');
51 51
 
52
-		$this->userManager->expects($this->once())
53
-			->method('callForSeenUsers')
54
-			->willReturnCallback(function ($closure): void {
55
-				$user1 = $this->createMock(IUser::class);
56
-				$user1->method('getUID')->willReturn('uid1');
57
-				$user2 = $this->createMock(IUser::class);
58
-				$user2->method('getUID')->willReturn('uid2');
59
-				$user3 = $this->createMock(IUser::class);
60
-				$user3->method('getUID')->willReturn('uid3');
52
+        $this->userManager->expects($this->once())
53
+            ->method('callForSeenUsers')
54
+            ->willReturnCallback(function ($closure): void {
55
+                $user1 = $this->createMock(IUser::class);
56
+                $user1->method('getUID')->willReturn('uid1');
57
+                $user2 = $this->createMock(IUser::class);
58
+                $user2->method('getUID')->willReturn('uid2');
59
+                $user3 = $this->createMock(IUser::class);
60
+                $user3->method('getUID')->willReturn('uid3');
61 61
 
62
-				$closure($user1);
63
-				$closure($user2);
64
-				$closure($user3);
65
-			});
62
+                $closure($user1);
63
+                $closure($user2);
64
+                $closure($user3);
65
+            });
66 66
 
67
-		$calls = [
68
-			[GenerateBirthdayCalendarBackgroundJob::class, ['userId' => 'uid1']],
69
-			[GenerateBirthdayCalendarBackgroundJob::class, ['userId' => 'uid2']],
70
-			[GenerateBirthdayCalendarBackgroundJob::class, ['userId' => 'uid3']],
71
-		];
72
-		$this->jobList->expects($this->exactly(3))
73
-			->method('add')
74
-			->willReturnCallback(function () use (&$calls): void {
75
-				$expected = array_shift($calls);
76
-				$this->assertEquals($expected, func_get_args());
77
-			});
67
+        $calls = [
68
+            [GenerateBirthdayCalendarBackgroundJob::class, ['userId' => 'uid1']],
69
+            [GenerateBirthdayCalendarBackgroundJob::class, ['userId' => 'uid2']],
70
+            [GenerateBirthdayCalendarBackgroundJob::class, ['userId' => 'uid3']],
71
+        ];
72
+        $this->jobList->expects($this->exactly(3))
73
+            ->method('add')
74
+            ->willReturnCallback(function () use (&$calls): void {
75
+                $expected = array_shift($calls);
76
+                $this->assertEquals($expected, func_get_args());
77
+            });
78 78
 
79
-		$response = $this->controller->enable();
80
-		$this->assertInstanceOf(JSONResponse::class, $response);
81
-	}
79
+        $response = $this->controller->enable();
80
+        $this->assertInstanceOf(JSONResponse::class, $response);
81
+    }
82 82
 
83
-	public function testDisable(): void {
84
-		$this->config->expects($this->once())
85
-			->method('setAppValue')
86
-			->with('dav', 'generateBirthdayCalendar', 'no');
87
-		$this->jobList->expects($this->once())
88
-			->method('remove')
89
-			->with(GenerateBirthdayCalendarBackgroundJob::class);
90
-		$this->caldav->expects($this->once())
91
-			->method('deleteAllBirthdayCalendars');
83
+    public function testDisable(): void {
84
+        $this->config->expects($this->once())
85
+            ->method('setAppValue')
86
+            ->with('dav', 'generateBirthdayCalendar', 'no');
87
+        $this->jobList->expects($this->once())
88
+            ->method('remove')
89
+            ->with(GenerateBirthdayCalendarBackgroundJob::class);
90
+        $this->caldav->expects($this->once())
91
+            ->method('deleteAllBirthdayCalendars');
92 92
 
93
-		$response = $this->controller->disable();
94
-		$this->assertInstanceOf(JSONResponse::class, $response);
95
-	}
93
+        $response = $this->controller->disable();
94
+        $this->assertInstanceOf(JSONResponse::class, $response);
95
+    }
96 96
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 
52 52
 		$this->userManager->expects($this->once())
53 53
 			->method('callForSeenUsers')
54
-			->willReturnCallback(function ($closure): void {
54
+			->willReturnCallback(function($closure): void {
55 55
 				$user1 = $this->createMock(IUser::class);
56 56
 				$user1->method('getUID')->willReturn('uid1');
57 57
 				$user2 = $this->createMock(IUser::class);
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 		];
72 72
 		$this->jobList->expects($this->exactly(3))
73 73
 			->method('add')
74
-			->willReturnCallback(function () use (&$calls): void {
74
+			->willReturnCallback(function() use (&$calls): void {
75 75
 				$expected = array_shift($calls);
76 76
 				$this->assertEquals($expected, func_get_args());
77 77
 			});
Please login to merge, or discard this patch.
apps/dav/tests/unit/Controller/UpcomingEventsControllerTest.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -17,57 +17,57 @@
 block discarded – undo
17 17
 use PHPUnit\Framework\TestCase;
18 18
 
19 19
 class UpcomingEventsControllerTest extends TestCase {
20
-	private IRequest&MockObject $request;
21
-	private UpcomingEventsService&MockObject $service;
20
+    private IRequest&MockObject $request;
21
+    private UpcomingEventsService&MockObject $service;
22 22
 
23
-	protected function setUp(): void {
24
-		parent::setUp();
23
+    protected function setUp(): void {
24
+        parent::setUp();
25 25
 
26
-		$this->request = $this->createMock(IRequest::class);
27
-		$this->service = $this->createMock(UpcomingEventsService::class);
28
-	}
26
+        $this->request = $this->createMock(IRequest::class);
27
+        $this->service = $this->createMock(UpcomingEventsService::class);
28
+    }
29 29
 
30
-	public function testGetEventsAnonymously(): void {
31
-		$controller = new UpcomingEventsController(
32
-			$this->request,
33
-			null,
34
-			$this->service,
35
-		);
30
+    public function testGetEventsAnonymously(): void {
31
+        $controller = new UpcomingEventsController(
32
+            $this->request,
33
+            null,
34
+            $this->service,
35
+        );
36 36
 
37
-		$response = $controller->getEvents('https://cloud.example.com/call/123');
37
+        $response = $controller->getEvents('https://cloud.example.com/call/123');
38 38
 
39
-		self::assertNull($response->getData());
40
-		self::assertSame(401, $response->getStatus());
41
-	}
39
+        self::assertNull($response->getData());
40
+        self::assertSame(401, $response->getStatus());
41
+    }
42 42
 
43
-	public function testGetEventsByLocation(): void {
44
-		$controller = new UpcomingEventsController(
45
-			$this->request,
46
-			'u1',
47
-			$this->service,
48
-		);
49
-		$this->service->expects(self::once())
50
-			->method('getEvents')
51
-			->with('u1', 'https://cloud.example.com/call/123')
52
-			->willReturn([
53
-				new UpcomingEvent(
54
-					'abc-123',
55
-					null,
56
-					'personal',
57
-					123,
58
-					'Test',
59
-					'https://cloud.example.com/call/123',
60
-					null,
61
-				),
62
-			]);
43
+    public function testGetEventsByLocation(): void {
44
+        $controller = new UpcomingEventsController(
45
+            $this->request,
46
+            'u1',
47
+            $this->service,
48
+        );
49
+        $this->service->expects(self::once())
50
+            ->method('getEvents')
51
+            ->with('u1', 'https://cloud.example.com/call/123')
52
+            ->willReturn([
53
+                new UpcomingEvent(
54
+                    'abc-123',
55
+                    null,
56
+                    'personal',
57
+                    123,
58
+                    'Test',
59
+                    'https://cloud.example.com/call/123',
60
+                    null,
61
+                ),
62
+            ]);
63 63
 
64
-		$response = $controller->getEvents('https://cloud.example.com/call/123');
64
+        $response = $controller->getEvents('https://cloud.example.com/call/123');
65 65
 
66
-		self::assertNotNull($response->getData());
67
-		self::assertIsArray($response->getData());
68
-		self::assertCount(1, $response->getData()['events']);
69
-		self::assertSame(200, $response->getStatus());
70
-		$event1 = $response->getData()['events'][0];
71
-		self::assertEquals('abc-123', $event1['uri']);
72
-	}
66
+        self::assertNotNull($response->getData());
67
+        self::assertIsArray($response->getData());
68
+        self::assertCount(1, $response->getData()['events']);
69
+        self::assertSame(200, $response->getStatus());
70
+        $event1 = $response->getData()['events'][0];
71
+        self::assertEquals('abc-123', $event1['uri']);
72
+    }
73 73
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/Service/DefaultContactServiceTest.php 2 patches
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -24,142 +24,142 @@
 block discarded – undo
24 24
 use Test\TestCase;
25 25
 
26 26
 class DefaultContactServiceTest extends TestCase {
27
-	protected DefaultContactService $service;
28
-	protected CardDavBackend&MockObject $cardDav;
29
-	protected IAppManager&MockObject $appManager;
30
-	protected IAppDataFactory&MockObject $appDataFactory;
31
-	protected LoggerInterface&MockObject $logger;
32
-	protected IAppConfig&MockObject $config;
33
-
34
-	protected function setUp(): void {
35
-		parent::setUp();
36
-
37
-		$this->cardDav = $this->createMock(CardDavBackend::class);
38
-		$this->appManager = $this->createMock(IAppManager::class);
39
-		$this->appDataFactory = $this->createMock(IAppDataFactory::class);
40
-		$this->logger = $this->createMock(LoggerInterface::class);
41
-		$this->config = $this->createMock(IAppConfig::class);
42
-
43
-		$this->service = new DefaultContactService(
44
-			$this->cardDav,
45
-			$this->appManager,
46
-			$this->appDataFactory,
47
-			$this->config,
48
-			$this->logger,
49
-		);
50
-	}
51
-
52
-	public function testCreateDefaultContactWithInvalidCard(): void {
53
-		// Invalid vCard missing required FN property
54
-		$vcardContent = "BEGIN:VCARD\nVERSION:3.0\nEND:VCARD";
55
-		$this->config->method('getValueString')->willReturn('yes');
56
-		$appData = $this->createMock(IAppData::class);
57
-		$folder = $this->createMock(ISimpleFolder::class);
58
-		$file = $this->createMock(ISimpleFile::class);
59
-		$file->method('getContent')->willReturn($vcardContent);
60
-		$folder->method('getFile')->willReturn($file);
61
-		$appData->method('getFolder')->willReturn($folder);
62
-		$this->appDataFactory->method('get')->willReturn($appData);
63
-
64
-		$this->logger->expects($this->once())
65
-			->method('error')
66
-			->with('Default contact is invalid', $this->anything());
67
-
68
-		$this->cardDav->expects($this->never())
69
-			->method('createCard');
70
-
71
-		$this->service->createDefaultContact(123);
72
-	}
73
-
74
-	public function testUidAndRevAreUpdated(): void {
75
-		$originalUid = 'original-uid';
76
-		$originalRev = '20200101T000000Z';
77
-		$vcardContent = "BEGIN:VCARD\nVERSION:3.0\nFN:Test User\nUID:$originalUid\nREV:$originalRev\nEND:VCARD";
78
-
79
-		$this->config->method('getValueString')->willReturn('yes');
80
-		$appData = $this->createMock(IAppData::class);
81
-		$folder = $this->createMock(ISimpleFolder::class);
82
-		$file = $this->createMock(ISimpleFile::class);
83
-		$file->method('getContent')->willReturn($vcardContent);
84
-		$folder->method('getFile')->willReturn($file);
85
-		$appData->method('getFolder')->willReturn($folder);
86
-		$this->appDataFactory->method('get')->willReturn($appData);
87
-
88
-		$capturedCardData = null;
89
-		$this->cardDav->expects($this->once())
90
-			->method('createCard')
91
-			->with(
92
-				$this->anything(),
93
-				$this->anything(),
94
-				$this->callback(function ($cardData) use (&$capturedCardData) {
95
-					$capturedCardData = $cardData;
96
-					return true;
97
-				}),
98
-				$this->anything()
99
-			)->willReturn(null);
100
-
101
-		$this->service->createDefaultContact(123);
102
-
103
-		$vcard = \Sabre\VObject\Reader::read($capturedCardData);
104
-		$this->assertNotEquals($originalUid, $vcard->UID->getValue());
105
-		$this->assertTrue(Uuid::isValid($vcard->UID->getValue()));
106
-		$this->assertNotEquals($originalRev, $vcard->REV->getValue());
107
-	}
108
-
109
-	public function testDefaultContactFileDoesNotExist(): void {
110
-		$appData = $this->createMock(IAppData::class);
111
-		$this->config->method('getValueString')->willReturn('yes');
112
-		$appData->method('getFolder')->willThrowException(new NotFoundException());
113
-		$this->appDataFactory->method('get')->willReturn($appData);
114
-
115
-		$this->cardDav->expects($this->never())
116
-			->method('createCard');
117
-
118
-		$this->service->createDefaultContact(123);
119
-	}
120
-
121
-	public function testUidAndRevAreAddedIfMissing(): void {
122
-		$vcardContent = "BEGIN:VCARD\nVERSION:3.0\nFN:Test User\nEND:VCARD";
123
-
124
-		$this->config->method('getValueString')->willReturn('yes');
125
-		$appData = $this->createMock(IAppData::class);
126
-		$folder = $this->createMock(ISimpleFolder::class);
127
-		$file = $this->createMock(ISimpleFile::class);
128
-		$file->method('getContent')->willReturn($vcardContent);
129
-		$folder->method('getFile')->willReturn($file);
130
-		$appData->method('getFolder')->willReturn($folder);
131
-		$this->appDataFactory->method('get')->willReturn($appData);
132
-
133
-		$capturedCardData = 'new-card-data';
134
-
135
-		$this->cardDav
136
-			->expects($this->once())
137
-			->method('createCard')
138
-			->with(
139
-				$this->anything(),
140
-				$this->anything(),
141
-				$this->callback(function ($cardData) use (&$capturedCardData) {
142
-					$capturedCardData = $cardData;
143
-					return true;
144
-				}),
145
-				$this->anything()
146
-			);
147
-
148
-		$this->service->createDefaultContact(123);
149
-		$vcard = \Sabre\VObject\Reader::read($capturedCardData);
150
-
151
-		$this->assertNotNull($vcard->REV);
152
-		$this->assertNotNull($vcard->UID);
153
-		$this->assertTrue(Uuid::isValid($vcard->UID->getValue()));
154
-	}
155
-
156
-	public function testDefaultContactIsNotCreatedIfEnabled(): void {
157
-		$this->config->method('getValueString')->willReturn('no');
158
-		$this->logger->expects($this->never())
159
-			->method('error');
160
-		$this->cardDav->expects($this->never())
161
-			->method('createCard');
162
-
163
-		$this->service->createDefaultContact(123);
164
-	}
27
+    protected DefaultContactService $service;
28
+    protected CardDavBackend&MockObject $cardDav;
29
+    protected IAppManager&MockObject $appManager;
30
+    protected IAppDataFactory&MockObject $appDataFactory;
31
+    protected LoggerInterface&MockObject $logger;
32
+    protected IAppConfig&MockObject $config;
33
+
34
+    protected function setUp(): void {
35
+        parent::setUp();
36
+
37
+        $this->cardDav = $this->createMock(CardDavBackend::class);
38
+        $this->appManager = $this->createMock(IAppManager::class);
39
+        $this->appDataFactory = $this->createMock(IAppDataFactory::class);
40
+        $this->logger = $this->createMock(LoggerInterface::class);
41
+        $this->config = $this->createMock(IAppConfig::class);
42
+
43
+        $this->service = new DefaultContactService(
44
+            $this->cardDav,
45
+            $this->appManager,
46
+            $this->appDataFactory,
47
+            $this->config,
48
+            $this->logger,
49
+        );
50
+    }
51
+
52
+    public function testCreateDefaultContactWithInvalidCard(): void {
53
+        // Invalid vCard missing required FN property
54
+        $vcardContent = "BEGIN:VCARD\nVERSION:3.0\nEND:VCARD";
55
+        $this->config->method('getValueString')->willReturn('yes');
56
+        $appData = $this->createMock(IAppData::class);
57
+        $folder = $this->createMock(ISimpleFolder::class);
58
+        $file = $this->createMock(ISimpleFile::class);
59
+        $file->method('getContent')->willReturn($vcardContent);
60
+        $folder->method('getFile')->willReturn($file);
61
+        $appData->method('getFolder')->willReturn($folder);
62
+        $this->appDataFactory->method('get')->willReturn($appData);
63
+
64
+        $this->logger->expects($this->once())
65
+            ->method('error')
66
+            ->with('Default contact is invalid', $this->anything());
67
+
68
+        $this->cardDav->expects($this->never())
69
+            ->method('createCard');
70
+
71
+        $this->service->createDefaultContact(123);
72
+    }
73
+
74
+    public function testUidAndRevAreUpdated(): void {
75
+        $originalUid = 'original-uid';
76
+        $originalRev = '20200101T000000Z';
77
+        $vcardContent = "BEGIN:VCARD\nVERSION:3.0\nFN:Test User\nUID:$originalUid\nREV:$originalRev\nEND:VCARD";
78
+
79
+        $this->config->method('getValueString')->willReturn('yes');
80
+        $appData = $this->createMock(IAppData::class);
81
+        $folder = $this->createMock(ISimpleFolder::class);
82
+        $file = $this->createMock(ISimpleFile::class);
83
+        $file->method('getContent')->willReturn($vcardContent);
84
+        $folder->method('getFile')->willReturn($file);
85
+        $appData->method('getFolder')->willReturn($folder);
86
+        $this->appDataFactory->method('get')->willReturn($appData);
87
+
88
+        $capturedCardData = null;
89
+        $this->cardDav->expects($this->once())
90
+            ->method('createCard')
91
+            ->with(
92
+                $this->anything(),
93
+                $this->anything(),
94
+                $this->callback(function ($cardData) use (&$capturedCardData) {
95
+                    $capturedCardData = $cardData;
96
+                    return true;
97
+                }),
98
+                $this->anything()
99
+            )->willReturn(null);
100
+
101
+        $this->service->createDefaultContact(123);
102
+
103
+        $vcard = \Sabre\VObject\Reader::read($capturedCardData);
104
+        $this->assertNotEquals($originalUid, $vcard->UID->getValue());
105
+        $this->assertTrue(Uuid::isValid($vcard->UID->getValue()));
106
+        $this->assertNotEquals($originalRev, $vcard->REV->getValue());
107
+    }
108
+
109
+    public function testDefaultContactFileDoesNotExist(): void {
110
+        $appData = $this->createMock(IAppData::class);
111
+        $this->config->method('getValueString')->willReturn('yes');
112
+        $appData->method('getFolder')->willThrowException(new NotFoundException());
113
+        $this->appDataFactory->method('get')->willReturn($appData);
114
+
115
+        $this->cardDav->expects($this->never())
116
+            ->method('createCard');
117
+
118
+        $this->service->createDefaultContact(123);
119
+    }
120
+
121
+    public function testUidAndRevAreAddedIfMissing(): void {
122
+        $vcardContent = "BEGIN:VCARD\nVERSION:3.0\nFN:Test User\nEND:VCARD";
123
+
124
+        $this->config->method('getValueString')->willReturn('yes');
125
+        $appData = $this->createMock(IAppData::class);
126
+        $folder = $this->createMock(ISimpleFolder::class);
127
+        $file = $this->createMock(ISimpleFile::class);
128
+        $file->method('getContent')->willReturn($vcardContent);
129
+        $folder->method('getFile')->willReturn($file);
130
+        $appData->method('getFolder')->willReturn($folder);
131
+        $this->appDataFactory->method('get')->willReturn($appData);
132
+
133
+        $capturedCardData = 'new-card-data';
134
+
135
+        $this->cardDav
136
+            ->expects($this->once())
137
+            ->method('createCard')
138
+            ->with(
139
+                $this->anything(),
140
+                $this->anything(),
141
+                $this->callback(function ($cardData) use (&$capturedCardData) {
142
+                    $capturedCardData = $cardData;
143
+                    return true;
144
+                }),
145
+                $this->anything()
146
+            );
147
+
148
+        $this->service->createDefaultContact(123);
149
+        $vcard = \Sabre\VObject\Reader::read($capturedCardData);
150
+
151
+        $this->assertNotNull($vcard->REV);
152
+        $this->assertNotNull($vcard->UID);
153
+        $this->assertTrue(Uuid::isValid($vcard->UID->getValue()));
154
+    }
155
+
156
+    public function testDefaultContactIsNotCreatedIfEnabled(): void {
157
+        $this->config->method('getValueString')->willReturn('no');
158
+        $this->logger->expects($this->never())
159
+            ->method('error');
160
+        $this->cardDav->expects($this->never())
161
+            ->method('createCard');
162
+
163
+        $this->service->createDefaultContact(123);
164
+    }
165 165
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 			->with(
92 92
 				$this->anything(),
93 93
 				$this->anything(),
94
-				$this->callback(function ($cardData) use (&$capturedCardData) {
94
+				$this->callback(function($cardData) use (&$capturedCardData) {
95 95
 					$capturedCardData = $cardData;
96 96
 					return true;
97 97
 				}),
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 			->with(
139 139
 				$this->anything(),
140 140
 				$this->anything(),
141
-				$this->callback(function ($cardData) use (&$capturedCardData) {
141
+				$this->callback(function($cardData) use (&$capturedCardData) {
142 142
 					$capturedCardData = $cardData;
143 143
 					return true;
144 144
 				}),
Please login to merge, or discard this patch.
apps/dav/tests/unit/Service/UpcomingEventsServiceTest.php 1 patch
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -22,68 +22,68 @@
 block discarded – undo
22 22
 
23 23
 class UpcomingEventsServiceTest extends TestCase {
24 24
 
25
-	private IManager&MockObject $calendarManager;
26
-	private ITimeFactory&MockObject $timeFactory;
27
-	private IUserManager&MockObject $userManager;
28
-	private IAppManager&MockObject $appManager;
29
-	private IURLGenerator&MockObject $urlGenerator;
30
-	private UpcomingEventsService $service;
25
+    private IManager&MockObject $calendarManager;
26
+    private ITimeFactory&MockObject $timeFactory;
27
+    private IUserManager&MockObject $userManager;
28
+    private IAppManager&MockObject $appManager;
29
+    private IURLGenerator&MockObject $urlGenerator;
30
+    private UpcomingEventsService $service;
31 31
 
32
-	protected function setUp(): void {
33
-		parent::setUp();
32
+    protected function setUp(): void {
33
+        parent::setUp();
34 34
 
35
-		$this->calendarManager = $this->createMock(IManager::class);
36
-		$this->timeFactory = $this->createMock(ITimeFactory::class);
37
-		$this->userManager = $this->createMock(IUserManager::class);
38
-		$this->appManager = $this->createMock(IAppManager::class);
39
-		$this->urlGenerator = $this->createMock(IURLGenerator::class);
35
+        $this->calendarManager = $this->createMock(IManager::class);
36
+        $this->timeFactory = $this->createMock(ITimeFactory::class);
37
+        $this->userManager = $this->createMock(IUserManager::class);
38
+        $this->appManager = $this->createMock(IAppManager::class);
39
+        $this->urlGenerator = $this->createMock(IURLGenerator::class);
40 40
 
41
-		$this->service = new UpcomingEventsService(
42
-			$this->calendarManager,
43
-			$this->timeFactory,
44
-			$this->userManager,
45
-			$this->appManager,
46
-			$this->urlGenerator,
47
-		);
48
-	}
41
+        $this->service = new UpcomingEventsService(
42
+            $this->calendarManager,
43
+            $this->timeFactory,
44
+            $this->userManager,
45
+            $this->appManager,
46
+            $this->urlGenerator,
47
+        );
48
+    }
49 49
 
50
-	public function testGetEventsByLocation(): void {
51
-		$now = new DateTimeImmutable('2024-07-08T18:20:20Z');
52
-		$this->timeFactory->method('now')
53
-			->willReturn($now);
54
-		$query = $this->createMock(ICalendarQuery::class);
55
-		$this->appManager->method('isEnabledForUser')->willReturn(false);
56
-		$this->calendarManager->method('newQuery')
57
-			->with('principals/users/user1')
58
-			->willReturn($query);
59
-		$query->expects(self::once())
60
-			->method('addSearchProperty')
61
-			->with('LOCATION');
62
-		$query->expects(self::once())
63
-			->method('setSearchPattern')
64
-			->with('https://cloud.example.com/call/123');
65
-		$this->calendarManager->expects(self::once())
66
-			->method('searchForPrincipal')
67
-			->with($query)
68
-			->willReturn([
69
-				[
70
-					'uri' => 'ev1',
71
-					'calendar-key' => '1',
72
-					'calendar-uri' => 'personal',
73
-					'objects' => [
74
-						0 => [
75
-							'DTSTART' => [
76
-								new DateTimeImmutable('now'),
77
-							],
78
-						],
79
-					],
80
-				],
81
-			]);
50
+    public function testGetEventsByLocation(): void {
51
+        $now = new DateTimeImmutable('2024-07-08T18:20:20Z');
52
+        $this->timeFactory->method('now')
53
+            ->willReturn($now);
54
+        $query = $this->createMock(ICalendarQuery::class);
55
+        $this->appManager->method('isEnabledForUser')->willReturn(false);
56
+        $this->calendarManager->method('newQuery')
57
+            ->with('principals/users/user1')
58
+            ->willReturn($query);
59
+        $query->expects(self::once())
60
+            ->method('addSearchProperty')
61
+            ->with('LOCATION');
62
+        $query->expects(self::once())
63
+            ->method('setSearchPattern')
64
+            ->with('https://cloud.example.com/call/123');
65
+        $this->calendarManager->expects(self::once())
66
+            ->method('searchForPrincipal')
67
+            ->with($query)
68
+            ->willReturn([
69
+                [
70
+                    'uri' => 'ev1',
71
+                    'calendar-key' => '1',
72
+                    'calendar-uri' => 'personal',
73
+                    'objects' => [
74
+                        0 => [
75
+                            'DTSTART' => [
76
+                                new DateTimeImmutable('now'),
77
+                            ],
78
+                        ],
79
+                    ],
80
+                ],
81
+            ]);
82 82
 
83
-		$events = $this->service->getEvents('user1', 'https://cloud.example.com/call/123');
83
+        $events = $this->service->getEvents('user1', 'https://cloud.example.com/call/123');
84 84
 
85
-		self::assertCount(1, $events);
86
-		$event1 = $events[0];
87
-		self::assertEquals('ev1', $event1->getUri());
88
-	}
85
+        self::assertCount(1, $events);
86
+        $event1 = $events[0];
87
+        self::assertEquals('ev1', $event1->getUri());
88
+    }
89 89
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/Service/AbsenceServiceTest.php 1 patch
Indentation   +414 added lines, -414 removed lines patch added patch discarded remove patch
@@ -28,418 +28,418 @@
 block discarded – undo
28 28
 use PHPUnit\Framework\TestCase;
29 29
 
30 30
 class AbsenceServiceTest extends TestCase {
31
-	private AbsenceService $absenceService;
32
-	private AbsenceMapper&MockObject $absenceMapper;
33
-	private IEventDispatcher&MockObject $eventDispatcher;
34
-	private IJobList&MockObject $jobList;
35
-	private TimezoneService&MockObject $timezoneService;
36
-	private ITimeFactory&MockObject $timeFactory;
37
-
38
-	protected function setUp(): void {
39
-		parent::setUp();
40
-
41
-		$this->absenceMapper = $this->createMock(AbsenceMapper::class);
42
-		$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
43
-		$this->jobList = $this->createMock(IJobList::class);
44
-		$this->timezoneService = $this->createMock(TimezoneService::class);
45
-		$this->timeFactory = $this->createMock(ITimeFactory::class);
46
-
47
-		$this->absenceService = new AbsenceService(
48
-			$this->absenceMapper,
49
-			$this->eventDispatcher,
50
-			$this->jobList,
51
-			$this->timezoneService,
52
-			$this->timeFactory,
53
-		);
54
-	}
55
-
56
-	public function testCreateAbsenceEmitsScheduledEvent(): void {
57
-		$tz = new DateTimeZone('Europe/Berlin');
58
-		$user = $this->createMock(IUser::class);
59
-		$user->method('getUID')
60
-			->willReturn('user');
61
-
62
-		$this->absenceMapper->expects(self::once())
63
-			->method('findByUserId')
64
-			->with('user')
65
-			->willThrowException(new DoesNotExistException('foo bar'));
66
-		$this->absenceMapper->expects(self::once())
67
-			->method('insert')
68
-			->willReturnCallback(function (Absence $absence): Absence {
69
-				$absence->setId(1);
70
-				return $absence;
71
-			});
72
-		$this->timezoneService->expects(self::once())
73
-			->method('getUserTimezone')
74
-			->with('user')
75
-			->willReturn('Europe/Berlin');
76
-		$this->eventDispatcher->expects(self::once())
77
-			->method('dispatchTyped')
78
-			->with(self::callback(static function (Event $event) use ($user, $tz): bool {
79
-				self::assertInstanceOf(OutOfOfficeScheduledEvent::class, $event);
80
-				/** @var OutOfOfficeScheduledEvent $event */
81
-				$data = $event->getData();
82
-				self::assertEquals('1', $data->getId());
83
-				self::assertEquals($user, $data->getUser());
84
-				self::assertEquals(
85
-					(new DateTimeImmutable('2023-01-05', $tz))->getTimeStamp(),
86
-					$data->getStartDate(),
87
-				);
88
-				self::assertEquals(
89
-					(new DateTimeImmutable('2023-01-10', $tz))->getTimeStamp() + 3600 * 23 + 59 * 60,
90
-					$data->getEndDate(),
91
-				);
92
-				self::assertEquals('status', $data->getShortMessage());
93
-				self::assertEquals('message', $data->getMessage());
94
-				return true;
95
-			}));
96
-		$this->timeFactory->expects(self::once())
97
-			->method('getTime')
98
-			->willReturn(PHP_INT_MAX);
99
-		$this->jobList->expects(self::never())
100
-			->method('scheduleAfter');
101
-
102
-		$this->absenceService->createOrUpdateAbsence(
103
-			$user,
104
-			'2023-01-05',
105
-			'2023-01-10',
106
-			'status',
107
-			'message',
108
-		);
109
-	}
110
-
111
-	public function testUpdateAbsenceEmitsChangedEvent(): void {
112
-		$tz = new DateTimeZone('Europe/Berlin');
113
-		$user = $this->createMock(IUser::class);
114
-		$user->method('getUID')
115
-			->willReturn('user');
116
-		$absence = new Absence();
117
-		$absence->setId(1);
118
-		$absence->setFirstDay('1970-01-01');
119
-		$absence->setLastDay('1970-01-10');
120
-		$absence->setStatus('old status');
121
-		$absence->setMessage('old message');
122
-
123
-		$this->absenceMapper->expects(self::once())
124
-			->method('findByUserId')
125
-			->with('user')
126
-			->willReturn($absence);
127
-		$this->absenceMapper->expects(self::once())
128
-			->method('update')
129
-			->willReturnCallback(static function (Absence $absence): Absence {
130
-				self::assertEquals('2023-01-05', $absence->getFirstDay());
131
-				self::assertEquals('2023-01-10', $absence->getLastDay());
132
-				self::assertEquals('status', $absence->getStatus());
133
-				self::assertEquals('message', $absence->getMessage());
134
-				return $absence;
135
-			});
136
-		$this->timezoneService->expects(self::once())
137
-			->method('getUserTimezone')
138
-			->with('user')
139
-			->willReturn('Europe/Berlin');
140
-		$this->eventDispatcher->expects(self::once())
141
-			->method('dispatchTyped')
142
-			->with(self::callback(static function (Event $event) use ($user, $tz): bool {
143
-				self::assertInstanceOf(OutOfOfficeChangedEvent::class, $event);
144
-				/** @var OutOfOfficeChangedEvent $event */
145
-				$data = $event->getData();
146
-				self::assertEquals('1', $data->getId());
147
-				self::assertEquals($user, $data->getUser());
148
-				self::assertEquals(
149
-					(new DateTimeImmutable('2023-01-05', $tz))->getTimeStamp(),
150
-					$data->getStartDate(),
151
-				);
152
-				self::assertEquals(
153
-					(new DateTimeImmutable('2023-01-10', $tz))->getTimeStamp() + 3600 * 23 + 59 * 60,
154
-					$data->getEndDate(),
155
-				);
156
-				self::assertEquals('status', $data->getShortMessage());
157
-				self::assertEquals('message', $data->getMessage());
158
-				return true;
159
-			}));
160
-		$this->timeFactory->expects(self::once())
161
-			->method('getTime')
162
-			->willReturn(PHP_INT_MAX);
163
-		$this->jobList->expects(self::never())
164
-			->method('scheduleAfter');
165
-
166
-		$this->absenceService->createOrUpdateAbsence(
167
-			$user,
168
-			'2023-01-05',
169
-			'2023-01-10',
170
-			'status',
171
-			'message',
172
-		);
173
-	}
174
-
175
-	public function testCreateAbsenceSchedulesBothJobs(): void {
176
-		$tz = new DateTimeZone('Europe/Berlin');
177
-		$startDateString = '2023-01-05';
178
-		$startDate = new DateTimeImmutable($startDateString, $tz);
179
-		$endDateString = '2023-01-10';
180
-		$endDate = new DateTimeImmutable($endDateString, $tz);
181
-		$user = $this->createMock(IUser::class);
182
-		$user->method('getUID')
183
-			->willReturn('user');
184
-
185
-		$this->absenceMapper->expects(self::once())
186
-			->method('findByUserId')
187
-			->with('user')
188
-			->willThrowException(new DoesNotExistException('foo bar'));
189
-		$this->absenceMapper->expects(self::once())
190
-			->method('insert')
191
-			->willReturnCallback(function (Absence $absence): Absence {
192
-				$absence->setId(1);
193
-				return $absence;
194
-			});
195
-		$this->timezoneService->expects(self::once())
196
-			->method('getUserTimezone')
197
-			->with('user')
198
-			->willReturn($tz->getName());
199
-		$this->timeFactory->expects(self::once())
200
-			->method('getTime')
201
-			->willReturn((new DateTimeImmutable('2023-01-01', $tz))->getTimestamp());
202
-		$this->jobList->expects(self::exactly(2))
203
-			->method('scheduleAfter')
204
-			->willReturnMap([
205
-				[OutOfOfficeEventDispatcherJob::class, $startDate->getTimestamp(), [
206
-					'id' => '1',
207
-					'event' => OutOfOfficeEventDispatcherJob::EVENT_START,
208
-				]],
209
-				[OutOfOfficeEventDispatcherJob::class, $endDate->getTimestamp() + 3600 * 23 + 59 * 60, [
210
-					'id' => '1',
211
-					'event' => OutOfOfficeEventDispatcherJob::EVENT_END,
212
-				]],
213
-			]);
214
-
215
-		$this->absenceService->createOrUpdateAbsence(
216
-			$user,
217
-			$startDateString,
218
-			$endDateString,
219
-			'',
220
-			'',
221
-		);
222
-	}
223
-
224
-	public function testCreateAbsenceSchedulesOnlyEndJob(): void {
225
-		$tz = new DateTimeZone('Europe/Berlin');
226
-		$endDateString = '2023-01-10';
227
-		$endDate = new DateTimeImmutable($endDateString, $tz);
228
-		$user = $this->createMock(IUser::class);
229
-		$user->method('getUID')
230
-			->willReturn('user');
231
-
232
-		$this->absenceMapper->expects(self::once())
233
-			->method('findByUserId')
234
-			->with('user')
235
-			->willThrowException(new DoesNotExistException('foo bar'));
236
-		$this->absenceMapper->expects(self::once())
237
-			->method('insert')
238
-			->willReturnCallback(function (Absence $absence): Absence {
239
-				$absence->setId(1);
240
-				return $absence;
241
-			});
242
-		$this->timezoneService->expects(self::once())
243
-			->method('getUserTimezone')
244
-			->with('user')
245
-			->willReturn($tz->getName());
246
-		$this->timeFactory->expects(self::once())
247
-			->method('getTime')
248
-			->willReturn((new DateTimeImmutable('2023-01-07', $tz))->getTimestamp());
249
-		$this->jobList->expects(self::once())
250
-			->method('scheduleAfter')
251
-			->with(OutOfOfficeEventDispatcherJob::class, $endDate->getTimestamp() + 3600 * 23 + 59 * 60, [
252
-				'id' => '1',
253
-				'event' => OutOfOfficeEventDispatcherJob::EVENT_END,
254
-			]);
255
-
256
-		$this->absenceService->createOrUpdateAbsence(
257
-			$user,
258
-			'2023-01-05',
259
-			$endDateString,
260
-			'',
261
-			'',
262
-		);
263
-	}
264
-
265
-	public function testCreateAbsenceSchedulesNoJob(): void {
266
-		$tz = new DateTimeZone('Europe/Berlin');
267
-		$user = $this->createMock(IUser::class);
268
-		$user->method('getUID')
269
-			->willReturn('user');
270
-
271
-		$this->absenceMapper->expects(self::once())
272
-			->method('findByUserId')
273
-			->with('user')
274
-			->willThrowException(new DoesNotExistException('foo bar'));
275
-		$this->absenceMapper->expects(self::once())
276
-			->method('insert')
277
-			->willReturnCallback(function (Absence $absence): Absence {
278
-				$absence->setId(1);
279
-				return $absence;
280
-			});
281
-		$this->timezoneService->expects(self::once())
282
-			->method('getUserTimezone')
283
-			->with('user')
284
-			->willReturn($tz->getName());
285
-		$this->timeFactory->expects(self::once())
286
-			->method('getTime')
287
-			->willReturn((new DateTimeImmutable('2023-01-12', $tz))->getTimestamp());
288
-		$this->jobList->expects(self::never())
289
-			->method('scheduleAfter');
290
-
291
-		$this->absenceService->createOrUpdateAbsence(
292
-			$user,
293
-			'2023-01-05',
294
-			'2023-01-10',
295
-			'',
296
-			'',
297
-		);
298
-	}
299
-
300
-	public function testUpdateAbsenceSchedulesBothJobs(): void {
301
-		$tz = new DateTimeZone('Europe/Berlin');
302
-		$startDateString = '2023-01-05';
303
-		$startDate = new DateTimeImmutable($startDateString, $tz);
304
-		$endDateString = '2023-01-10';
305
-		$endDate = new DateTimeImmutable($endDateString, $tz);
306
-		$user = $this->createMock(IUser::class);
307
-		$user->method('getUID')
308
-			->willReturn('user');
309
-		$absence = new Absence();
310
-		$absence->setId(1);
311
-		$absence->setFirstDay('1970-01-01');
312
-		$absence->setLastDay('1970-01-10');
313
-		$absence->setStatus('old status');
314
-		$absence->setMessage('old message');
315
-
316
-		$this->absenceMapper->expects(self::once())
317
-			->method('findByUserId')
318
-			->with('user')
319
-			->willReturn($absence);
320
-		$this->absenceMapper->expects(self::once())
321
-			->method('update')
322
-			->willReturnCallback(static function (Absence $absence) use ($startDateString, $endDateString): Absence {
323
-				self::assertEquals($startDateString, $absence->getFirstDay());
324
-				self::assertEquals($endDateString, $absence->getLastDay());
325
-				return $absence;
326
-			});
327
-		$this->timezoneService->expects(self::once())
328
-			->method('getUserTimezone')
329
-			->with('user')
330
-			->willReturn($tz->getName());
331
-		$this->timeFactory->expects(self::once())
332
-			->method('getTime')
333
-			->willReturn((new DateTimeImmutable('2023-01-01', $tz))->getTimestamp());
334
-		$this->jobList->expects(self::exactly(2))
335
-			->method('scheduleAfter')
336
-			->willReturnMap([
337
-				[OutOfOfficeEventDispatcherJob::class, $startDate->getTimestamp(), [
338
-					'id' => '1',
339
-					'event' => OutOfOfficeEventDispatcherJob::EVENT_START,
340
-				]],
341
-				[OutOfOfficeEventDispatcherJob::class, $endDate->getTimestamp() + 3600 * 23 + 59 * 60, [
342
-					'id' => '1',
343
-					'event' => OutOfOfficeEventDispatcherJob::EVENT_END,
344
-				]],
345
-			]);
346
-
347
-		$this->absenceService->createOrUpdateAbsence(
348
-			$user,
349
-			$startDateString,
350
-			$endDateString,
351
-			'',
352
-			'',
353
-		);
354
-	}
355
-
356
-	public function testUpdateSchedulesOnlyEndJob(): void {
357
-		$tz = new DateTimeZone('Europe/Berlin');
358
-		$endDateString = '2023-01-10';
359
-		$endDate = new DateTimeImmutable($endDateString, $tz);
360
-		$user = $this->createMock(IUser::class);
361
-		$user->method('getUID')
362
-			->willReturn('user');
363
-		$absence = new Absence();
364
-		$absence->setId(1);
365
-		$absence->setFirstDay('1970-01-01');
366
-		$absence->setLastDay('1970-01-10');
367
-		$absence->setStatus('old status');
368
-		$absence->setMessage('old message');
369
-
370
-		$this->absenceMapper->expects(self::once())
371
-			->method('findByUserId')
372
-			->with('user')
373
-			->willReturn($absence);
374
-		$this->absenceMapper->expects(self::once())
375
-			->method('update')
376
-			->willReturnCallback(static function (Absence $absence) use ($endDateString): Absence {
377
-				self::assertEquals('2023-01-05', $absence->getFirstDay());
378
-				self::assertEquals($endDateString, $absence->getLastDay());
379
-				return $absence;
380
-			});
381
-		$this->timezoneService->expects(self::once())
382
-			->method('getUserTimezone')
383
-			->with('user')
384
-			->willReturn($tz->getName());
385
-		$this->timeFactory->expects(self::once())
386
-			->method('getTime')
387
-			->willReturn((new DateTimeImmutable('2023-01-07', $tz))->getTimestamp());
388
-		$this->jobList->expects(self::once())
389
-			->method('scheduleAfter')
390
-			->with(OutOfOfficeEventDispatcherJob::class, $endDate->getTimestamp() + 23 * 3600 + 59 * 60, [
391
-				'id' => '1',
392
-				'event' => OutOfOfficeEventDispatcherJob::EVENT_END,
393
-			]);
394
-
395
-		$this->absenceService->createOrUpdateAbsence(
396
-			$user,
397
-			'2023-01-05',
398
-			$endDateString,
399
-			'',
400
-			'',
401
-		);
402
-	}
403
-
404
-	public function testUpdateAbsenceSchedulesNoJob(): void {
405
-		$tz = new DateTimeZone('Europe/Berlin');
406
-		$user = $this->createMock(IUser::class);
407
-		$user->method('getUID')
408
-			->willReturn('user');
409
-		$absence = new Absence();
410
-		$absence->setId(1);
411
-		$absence->setFirstDay('1970-01-01');
412
-		$absence->setLastDay('1970-01-10');
413
-		$absence->setStatus('old status');
414
-		$absence->setMessage('old message');
415
-
416
-		$this->absenceMapper->expects(self::once())
417
-			->method('findByUserId')
418
-			->with('user')
419
-			->willReturn($absence);
420
-		$this->absenceMapper->expects(self::once())
421
-			->method('update')
422
-			->willReturnCallback(static function (Absence $absence): Absence {
423
-				self::assertEquals('2023-01-05', $absence->getFirstDay());
424
-				self::assertEquals('2023-01-10', $absence->getLastDay());
425
-				return $absence;
426
-			});
427
-		$this->timezoneService->expects(self::once())
428
-			->method('getUserTimezone')
429
-			->with('user')
430
-			->willReturn($tz->getName());
431
-		$this->timeFactory->expects(self::once())
432
-			->method('getTime')
433
-			->willReturn((new DateTimeImmutable('2023-01-12', $tz))->getTimestamp());
434
-		$this->jobList->expects(self::never())
435
-			->method('scheduleAfter');
436
-
437
-		$this->absenceService->createOrUpdateAbsence(
438
-			$user,
439
-			'2023-01-05',
440
-			'2023-01-10',
441
-			'',
442
-			'',
443
-		);
444
-	}
31
+    private AbsenceService $absenceService;
32
+    private AbsenceMapper&MockObject $absenceMapper;
33
+    private IEventDispatcher&MockObject $eventDispatcher;
34
+    private IJobList&MockObject $jobList;
35
+    private TimezoneService&MockObject $timezoneService;
36
+    private ITimeFactory&MockObject $timeFactory;
37
+
38
+    protected function setUp(): void {
39
+        parent::setUp();
40
+
41
+        $this->absenceMapper = $this->createMock(AbsenceMapper::class);
42
+        $this->eventDispatcher = $this->createMock(IEventDispatcher::class);
43
+        $this->jobList = $this->createMock(IJobList::class);
44
+        $this->timezoneService = $this->createMock(TimezoneService::class);
45
+        $this->timeFactory = $this->createMock(ITimeFactory::class);
46
+
47
+        $this->absenceService = new AbsenceService(
48
+            $this->absenceMapper,
49
+            $this->eventDispatcher,
50
+            $this->jobList,
51
+            $this->timezoneService,
52
+            $this->timeFactory,
53
+        );
54
+    }
55
+
56
+    public function testCreateAbsenceEmitsScheduledEvent(): void {
57
+        $tz = new DateTimeZone('Europe/Berlin');
58
+        $user = $this->createMock(IUser::class);
59
+        $user->method('getUID')
60
+            ->willReturn('user');
61
+
62
+        $this->absenceMapper->expects(self::once())
63
+            ->method('findByUserId')
64
+            ->with('user')
65
+            ->willThrowException(new DoesNotExistException('foo bar'));
66
+        $this->absenceMapper->expects(self::once())
67
+            ->method('insert')
68
+            ->willReturnCallback(function (Absence $absence): Absence {
69
+                $absence->setId(1);
70
+                return $absence;
71
+            });
72
+        $this->timezoneService->expects(self::once())
73
+            ->method('getUserTimezone')
74
+            ->with('user')
75
+            ->willReturn('Europe/Berlin');
76
+        $this->eventDispatcher->expects(self::once())
77
+            ->method('dispatchTyped')
78
+            ->with(self::callback(static function (Event $event) use ($user, $tz): bool {
79
+                self::assertInstanceOf(OutOfOfficeScheduledEvent::class, $event);
80
+                /** @var OutOfOfficeScheduledEvent $event */
81
+                $data = $event->getData();
82
+                self::assertEquals('1', $data->getId());
83
+                self::assertEquals($user, $data->getUser());
84
+                self::assertEquals(
85
+                    (new DateTimeImmutable('2023-01-05', $tz))->getTimeStamp(),
86
+                    $data->getStartDate(),
87
+                );
88
+                self::assertEquals(
89
+                    (new DateTimeImmutable('2023-01-10', $tz))->getTimeStamp() + 3600 * 23 + 59 * 60,
90
+                    $data->getEndDate(),
91
+                );
92
+                self::assertEquals('status', $data->getShortMessage());
93
+                self::assertEquals('message', $data->getMessage());
94
+                return true;
95
+            }));
96
+        $this->timeFactory->expects(self::once())
97
+            ->method('getTime')
98
+            ->willReturn(PHP_INT_MAX);
99
+        $this->jobList->expects(self::never())
100
+            ->method('scheduleAfter');
101
+
102
+        $this->absenceService->createOrUpdateAbsence(
103
+            $user,
104
+            '2023-01-05',
105
+            '2023-01-10',
106
+            'status',
107
+            'message',
108
+        );
109
+    }
110
+
111
+    public function testUpdateAbsenceEmitsChangedEvent(): void {
112
+        $tz = new DateTimeZone('Europe/Berlin');
113
+        $user = $this->createMock(IUser::class);
114
+        $user->method('getUID')
115
+            ->willReturn('user');
116
+        $absence = new Absence();
117
+        $absence->setId(1);
118
+        $absence->setFirstDay('1970-01-01');
119
+        $absence->setLastDay('1970-01-10');
120
+        $absence->setStatus('old status');
121
+        $absence->setMessage('old message');
122
+
123
+        $this->absenceMapper->expects(self::once())
124
+            ->method('findByUserId')
125
+            ->with('user')
126
+            ->willReturn($absence);
127
+        $this->absenceMapper->expects(self::once())
128
+            ->method('update')
129
+            ->willReturnCallback(static function (Absence $absence): Absence {
130
+                self::assertEquals('2023-01-05', $absence->getFirstDay());
131
+                self::assertEquals('2023-01-10', $absence->getLastDay());
132
+                self::assertEquals('status', $absence->getStatus());
133
+                self::assertEquals('message', $absence->getMessage());
134
+                return $absence;
135
+            });
136
+        $this->timezoneService->expects(self::once())
137
+            ->method('getUserTimezone')
138
+            ->with('user')
139
+            ->willReturn('Europe/Berlin');
140
+        $this->eventDispatcher->expects(self::once())
141
+            ->method('dispatchTyped')
142
+            ->with(self::callback(static function (Event $event) use ($user, $tz): bool {
143
+                self::assertInstanceOf(OutOfOfficeChangedEvent::class, $event);
144
+                /** @var OutOfOfficeChangedEvent $event */
145
+                $data = $event->getData();
146
+                self::assertEquals('1', $data->getId());
147
+                self::assertEquals($user, $data->getUser());
148
+                self::assertEquals(
149
+                    (new DateTimeImmutable('2023-01-05', $tz))->getTimeStamp(),
150
+                    $data->getStartDate(),
151
+                );
152
+                self::assertEquals(
153
+                    (new DateTimeImmutable('2023-01-10', $tz))->getTimeStamp() + 3600 * 23 + 59 * 60,
154
+                    $data->getEndDate(),
155
+                );
156
+                self::assertEquals('status', $data->getShortMessage());
157
+                self::assertEquals('message', $data->getMessage());
158
+                return true;
159
+            }));
160
+        $this->timeFactory->expects(self::once())
161
+            ->method('getTime')
162
+            ->willReturn(PHP_INT_MAX);
163
+        $this->jobList->expects(self::never())
164
+            ->method('scheduleAfter');
165
+
166
+        $this->absenceService->createOrUpdateAbsence(
167
+            $user,
168
+            '2023-01-05',
169
+            '2023-01-10',
170
+            'status',
171
+            'message',
172
+        );
173
+    }
174
+
175
+    public function testCreateAbsenceSchedulesBothJobs(): void {
176
+        $tz = new DateTimeZone('Europe/Berlin');
177
+        $startDateString = '2023-01-05';
178
+        $startDate = new DateTimeImmutable($startDateString, $tz);
179
+        $endDateString = '2023-01-10';
180
+        $endDate = new DateTimeImmutable($endDateString, $tz);
181
+        $user = $this->createMock(IUser::class);
182
+        $user->method('getUID')
183
+            ->willReturn('user');
184
+
185
+        $this->absenceMapper->expects(self::once())
186
+            ->method('findByUserId')
187
+            ->with('user')
188
+            ->willThrowException(new DoesNotExistException('foo bar'));
189
+        $this->absenceMapper->expects(self::once())
190
+            ->method('insert')
191
+            ->willReturnCallback(function (Absence $absence): Absence {
192
+                $absence->setId(1);
193
+                return $absence;
194
+            });
195
+        $this->timezoneService->expects(self::once())
196
+            ->method('getUserTimezone')
197
+            ->with('user')
198
+            ->willReturn($tz->getName());
199
+        $this->timeFactory->expects(self::once())
200
+            ->method('getTime')
201
+            ->willReturn((new DateTimeImmutable('2023-01-01', $tz))->getTimestamp());
202
+        $this->jobList->expects(self::exactly(2))
203
+            ->method('scheduleAfter')
204
+            ->willReturnMap([
205
+                [OutOfOfficeEventDispatcherJob::class, $startDate->getTimestamp(), [
206
+                    'id' => '1',
207
+                    'event' => OutOfOfficeEventDispatcherJob::EVENT_START,
208
+                ]],
209
+                [OutOfOfficeEventDispatcherJob::class, $endDate->getTimestamp() + 3600 * 23 + 59 * 60, [
210
+                    'id' => '1',
211
+                    'event' => OutOfOfficeEventDispatcherJob::EVENT_END,
212
+                ]],
213
+            ]);
214
+
215
+        $this->absenceService->createOrUpdateAbsence(
216
+            $user,
217
+            $startDateString,
218
+            $endDateString,
219
+            '',
220
+            '',
221
+        );
222
+    }
223
+
224
+    public function testCreateAbsenceSchedulesOnlyEndJob(): void {
225
+        $tz = new DateTimeZone('Europe/Berlin');
226
+        $endDateString = '2023-01-10';
227
+        $endDate = new DateTimeImmutable($endDateString, $tz);
228
+        $user = $this->createMock(IUser::class);
229
+        $user->method('getUID')
230
+            ->willReturn('user');
231
+
232
+        $this->absenceMapper->expects(self::once())
233
+            ->method('findByUserId')
234
+            ->with('user')
235
+            ->willThrowException(new DoesNotExistException('foo bar'));
236
+        $this->absenceMapper->expects(self::once())
237
+            ->method('insert')
238
+            ->willReturnCallback(function (Absence $absence): Absence {
239
+                $absence->setId(1);
240
+                return $absence;
241
+            });
242
+        $this->timezoneService->expects(self::once())
243
+            ->method('getUserTimezone')
244
+            ->with('user')
245
+            ->willReturn($tz->getName());
246
+        $this->timeFactory->expects(self::once())
247
+            ->method('getTime')
248
+            ->willReturn((new DateTimeImmutable('2023-01-07', $tz))->getTimestamp());
249
+        $this->jobList->expects(self::once())
250
+            ->method('scheduleAfter')
251
+            ->with(OutOfOfficeEventDispatcherJob::class, $endDate->getTimestamp() + 3600 * 23 + 59 * 60, [
252
+                'id' => '1',
253
+                'event' => OutOfOfficeEventDispatcherJob::EVENT_END,
254
+            ]);
255
+
256
+        $this->absenceService->createOrUpdateAbsence(
257
+            $user,
258
+            '2023-01-05',
259
+            $endDateString,
260
+            '',
261
+            '',
262
+        );
263
+    }
264
+
265
+    public function testCreateAbsenceSchedulesNoJob(): void {
266
+        $tz = new DateTimeZone('Europe/Berlin');
267
+        $user = $this->createMock(IUser::class);
268
+        $user->method('getUID')
269
+            ->willReturn('user');
270
+
271
+        $this->absenceMapper->expects(self::once())
272
+            ->method('findByUserId')
273
+            ->with('user')
274
+            ->willThrowException(new DoesNotExistException('foo bar'));
275
+        $this->absenceMapper->expects(self::once())
276
+            ->method('insert')
277
+            ->willReturnCallback(function (Absence $absence): Absence {
278
+                $absence->setId(1);
279
+                return $absence;
280
+            });
281
+        $this->timezoneService->expects(self::once())
282
+            ->method('getUserTimezone')
283
+            ->with('user')
284
+            ->willReturn($tz->getName());
285
+        $this->timeFactory->expects(self::once())
286
+            ->method('getTime')
287
+            ->willReturn((new DateTimeImmutable('2023-01-12', $tz))->getTimestamp());
288
+        $this->jobList->expects(self::never())
289
+            ->method('scheduleAfter');
290
+
291
+        $this->absenceService->createOrUpdateAbsence(
292
+            $user,
293
+            '2023-01-05',
294
+            '2023-01-10',
295
+            '',
296
+            '',
297
+        );
298
+    }
299
+
300
+    public function testUpdateAbsenceSchedulesBothJobs(): void {
301
+        $tz = new DateTimeZone('Europe/Berlin');
302
+        $startDateString = '2023-01-05';
303
+        $startDate = new DateTimeImmutable($startDateString, $tz);
304
+        $endDateString = '2023-01-10';
305
+        $endDate = new DateTimeImmutable($endDateString, $tz);
306
+        $user = $this->createMock(IUser::class);
307
+        $user->method('getUID')
308
+            ->willReturn('user');
309
+        $absence = new Absence();
310
+        $absence->setId(1);
311
+        $absence->setFirstDay('1970-01-01');
312
+        $absence->setLastDay('1970-01-10');
313
+        $absence->setStatus('old status');
314
+        $absence->setMessage('old message');
315
+
316
+        $this->absenceMapper->expects(self::once())
317
+            ->method('findByUserId')
318
+            ->with('user')
319
+            ->willReturn($absence);
320
+        $this->absenceMapper->expects(self::once())
321
+            ->method('update')
322
+            ->willReturnCallback(static function (Absence $absence) use ($startDateString, $endDateString): Absence {
323
+                self::assertEquals($startDateString, $absence->getFirstDay());
324
+                self::assertEquals($endDateString, $absence->getLastDay());
325
+                return $absence;
326
+            });
327
+        $this->timezoneService->expects(self::once())
328
+            ->method('getUserTimezone')
329
+            ->with('user')
330
+            ->willReturn($tz->getName());
331
+        $this->timeFactory->expects(self::once())
332
+            ->method('getTime')
333
+            ->willReturn((new DateTimeImmutable('2023-01-01', $tz))->getTimestamp());
334
+        $this->jobList->expects(self::exactly(2))
335
+            ->method('scheduleAfter')
336
+            ->willReturnMap([
337
+                [OutOfOfficeEventDispatcherJob::class, $startDate->getTimestamp(), [
338
+                    'id' => '1',
339
+                    'event' => OutOfOfficeEventDispatcherJob::EVENT_START,
340
+                ]],
341
+                [OutOfOfficeEventDispatcherJob::class, $endDate->getTimestamp() + 3600 * 23 + 59 * 60, [
342
+                    'id' => '1',
343
+                    'event' => OutOfOfficeEventDispatcherJob::EVENT_END,
344
+                ]],
345
+            ]);
346
+
347
+        $this->absenceService->createOrUpdateAbsence(
348
+            $user,
349
+            $startDateString,
350
+            $endDateString,
351
+            '',
352
+            '',
353
+        );
354
+    }
355
+
356
+    public function testUpdateSchedulesOnlyEndJob(): void {
357
+        $tz = new DateTimeZone('Europe/Berlin');
358
+        $endDateString = '2023-01-10';
359
+        $endDate = new DateTimeImmutable($endDateString, $tz);
360
+        $user = $this->createMock(IUser::class);
361
+        $user->method('getUID')
362
+            ->willReturn('user');
363
+        $absence = new Absence();
364
+        $absence->setId(1);
365
+        $absence->setFirstDay('1970-01-01');
366
+        $absence->setLastDay('1970-01-10');
367
+        $absence->setStatus('old status');
368
+        $absence->setMessage('old message');
369
+
370
+        $this->absenceMapper->expects(self::once())
371
+            ->method('findByUserId')
372
+            ->with('user')
373
+            ->willReturn($absence);
374
+        $this->absenceMapper->expects(self::once())
375
+            ->method('update')
376
+            ->willReturnCallback(static function (Absence $absence) use ($endDateString): Absence {
377
+                self::assertEquals('2023-01-05', $absence->getFirstDay());
378
+                self::assertEquals($endDateString, $absence->getLastDay());
379
+                return $absence;
380
+            });
381
+        $this->timezoneService->expects(self::once())
382
+            ->method('getUserTimezone')
383
+            ->with('user')
384
+            ->willReturn($tz->getName());
385
+        $this->timeFactory->expects(self::once())
386
+            ->method('getTime')
387
+            ->willReturn((new DateTimeImmutable('2023-01-07', $tz))->getTimestamp());
388
+        $this->jobList->expects(self::once())
389
+            ->method('scheduleAfter')
390
+            ->with(OutOfOfficeEventDispatcherJob::class, $endDate->getTimestamp() + 23 * 3600 + 59 * 60, [
391
+                'id' => '1',
392
+                'event' => OutOfOfficeEventDispatcherJob::EVENT_END,
393
+            ]);
394
+
395
+        $this->absenceService->createOrUpdateAbsence(
396
+            $user,
397
+            '2023-01-05',
398
+            $endDateString,
399
+            '',
400
+            '',
401
+        );
402
+    }
403
+
404
+    public function testUpdateAbsenceSchedulesNoJob(): void {
405
+        $tz = new DateTimeZone('Europe/Berlin');
406
+        $user = $this->createMock(IUser::class);
407
+        $user->method('getUID')
408
+            ->willReturn('user');
409
+        $absence = new Absence();
410
+        $absence->setId(1);
411
+        $absence->setFirstDay('1970-01-01');
412
+        $absence->setLastDay('1970-01-10');
413
+        $absence->setStatus('old status');
414
+        $absence->setMessage('old message');
415
+
416
+        $this->absenceMapper->expects(self::once())
417
+            ->method('findByUserId')
418
+            ->with('user')
419
+            ->willReturn($absence);
420
+        $this->absenceMapper->expects(self::once())
421
+            ->method('update')
422
+            ->willReturnCallback(static function (Absence $absence): Absence {
423
+                self::assertEquals('2023-01-05', $absence->getFirstDay());
424
+                self::assertEquals('2023-01-10', $absence->getLastDay());
425
+                return $absence;
426
+            });
427
+        $this->timezoneService->expects(self::once())
428
+            ->method('getUserTimezone')
429
+            ->with('user')
430
+            ->willReturn($tz->getName());
431
+        $this->timeFactory->expects(self::once())
432
+            ->method('getTime')
433
+            ->willReturn((new DateTimeImmutable('2023-01-12', $tz))->getTimestamp());
434
+        $this->jobList->expects(self::never())
435
+            ->method('scheduleAfter');
436
+
437
+        $this->absenceService->createOrUpdateAbsence(
438
+            $user,
439
+            '2023-01-05',
440
+            '2023-01-10',
441
+            '',
442
+            '',
443
+        );
444
+    }
445 445
 }
Please login to merge, or discard this patch.