Completed
Push — master ( 5d14f8...2337bd )
by Robin
27:19 queued 16s
created
apps/dav/tests/unit/CalDAV/Reminder/NotifierTest.php 1 patch
Indentation   +239 added lines, -239 removed lines patch added patch discarded remove patch
@@ -21,243 +21,243 @@
 block discarded – undo
21 21
 use Test\TestCase;
22 22
 
23 23
 class NotifierTest extends TestCase {
24
-	protected IFactory&MockObject $factory;
25
-	protected IURLGenerator&MockObject $urlGenerator;
26
-	protected IL10N&MockObject $l10n;
27
-	protected ITimeFactory&MockObject $timeFactory;
28
-	protected Notifier $notifier;
29
-
30
-	protected function setUp(): void {
31
-		parent::setUp();
32
-
33
-		$this->urlGenerator = $this->createMock(IURLGenerator::class);
34
-		$this->l10n = $this->createMock(IL10N::class);
35
-		$this->l10n->expects($this->any())
36
-			->method('t')
37
-			->willReturnCallback(function ($string, $args) {
38
-				if (!is_array($args)) {
39
-					$args = [$args];
40
-				}
41
-				return vsprintf($string, $args);
42
-			});
43
-		$this->l10n->expects($this->any())
44
-			->method('l')
45
-			->willReturnCallback(function ($string, $args) {
46
-				/** \DateTime $args */
47
-				return $args->format(\DateTime::ATOM);
48
-			});
49
-		$this->l10n->expects($this->any())
50
-			->method('n')
51
-			->willReturnCallback(function ($textSingular, $textPlural, $count, $args) {
52
-				$text = $count === 1 ? $textSingular : $textPlural;
53
-				$text = str_replace('%n', (string)$count, $text);
54
-				return vsprintf($text, $args);
55
-			});
56
-		$this->factory = $this->createMock(IFactory::class);
57
-		$this->factory->expects($this->any())
58
-			->method('get')
59
-			->willReturn($this->l10n);
60
-
61
-		$this->timeFactory = $this->createMock(ITimeFactory::class);
62
-		$this->timeFactory
63
-			->method('getDateTime')
64
-			->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2005-08-15T14:00:00+02:00'));
65
-
66
-		$this->notifier = new Notifier(
67
-			$this->factory,
68
-			$this->urlGenerator,
69
-			$this->timeFactory
70
-		);
71
-	}
72
-
73
-	public function testGetId():void {
74
-		$this->assertEquals($this->notifier->getID(), 'dav');
75
-	}
76
-
77
-	public function testGetName():void {
78
-		$this->assertEquals($this->notifier->getName(), 'Calendar');
79
-	}
80
-
81
-
82
-	public function testPrepareWrongApp(): void {
83
-		$this->expectException(UnknownNotificationException::class);
84
-		$this->expectExceptionMessage('Notification not from this app');
85
-
86
-		/** @var INotification&MockObject $notification */
87
-		$notification = $this->createMock(INotification::class);
88
-
89
-		$notification->expects($this->once())
90
-			->method('getApp')
91
-			->willReturn('notifications');
92
-		$notification->expects($this->never())
93
-			->method('getSubject');
94
-
95
-		$this->notifier->prepare($notification, 'en');
96
-	}
97
-
98
-
99
-	public function testPrepareWrongSubject(): void {
100
-		$this->expectException(UnknownNotificationException::class);
101
-		$this->expectExceptionMessage('Unknown subject');
102
-
103
-		/** @var INotification&MockObject $notification */
104
-		$notification = $this->createMock(INotification::class);
105
-
106
-		$notification->expects($this->once())
107
-			->method('getApp')
108
-			->willReturn(Application::APP_ID);
109
-		$notification->expects($this->once())
110
-			->method('getSubject')
111
-			->willReturn('wrong subject');
112
-
113
-		$this->notifier->prepare($notification, 'en');
114
-	}
115
-
116
-	private static function hasPhpDatetimeDiffBug(): bool {
117
-		$d1 = \DateTime::createFromFormat(\DateTimeInterface::ATOM, '2023-11-22T11:52:00+01:00');
118
-		$d2 = new \DateTime('2023-11-22T10:52:03', new \DateTimeZone('UTC'));
119
-
120
-		// The difference is 3 seconds, not -1year+11months+…
121
-		return $d1->diff($d2)->y < 0;
122
-	}
123
-
124
-	public static function dataPrepare(): array {
125
-		return [
126
-			[
127
-				'calendar_reminder',
128
-				[
129
-					'title' => 'Title of this event',
130
-					'start_atom' => '2005-08-15T15:52:01+02:00'
131
-				],
132
-				self::hasPhpDatetimeDiffBug() ? 'Title of this event' : 'Title of this event (in 1 hour, 52 minutes)',
133
-				[
134
-					'title' => 'Title of this event',
135
-					'description' => null,
136
-					'location' => 'NC Headquarters',
137
-					'all_day' => false,
138
-					'start_atom' => '2005-08-15T15:52:01+02:00',
139
-					'start_is_floating' => false,
140
-					'start_timezone' => 'Europe/Berlin',
141
-					'end_atom' => '2005-08-15T17:52:01+02:00',
142
-					'end_is_floating' => false,
143
-					'end_timezone' => 'Europe/Berlin',
144
-					'calendar_displayname' => 'Personal',
145
-				],
146
-				"Calendar: Personal\r\nDate: 2005-08-15T15:52:01+02:00, 2005-08-15T15:52:01+02:00 - 2005-08-15T17:52:01+02:00 (Europe/Berlin)\r\nWhere: NC Headquarters"
147
-			],
148
-			[
149
-				'calendar_reminder',
150
-				[
151
-					'title' => 'Title of this event',
152
-					'start_atom' => '2005-08-15T13:00:00+02:00',
153
-				],
154
-				self::hasPhpDatetimeDiffBug() ? 'Title of this event' : 'Title of this event (1 hour ago)',
155
-				[
156
-					'title' => 'Title of this event',
157
-					'description' => null,
158
-					'location' => 'NC Headquarters',
159
-					'all_day' => false,
160
-					'start_atom' => '2005-08-15T13:00:00+02:00',
161
-					'start_is_floating' => false,
162
-					'start_timezone' => 'Europe/Berlin',
163
-					'end_atom' => '2005-08-15T15:00:00+02:00',
164
-					'end_is_floating' => false,
165
-					'end_timezone' => 'Europe/Berlin',
166
-					'calendar_displayname' => 'Personal',
167
-				],
168
-				"Calendar: Personal\r\nDate: 2005-08-15T13:00:00+02:00, 2005-08-15T13:00:00+02:00 - 2005-08-15T15:00:00+02:00 (Europe/Berlin)\r\nWhere: NC Headquarters"
169
-			],
170
-		];
171
-	}
172
-
173
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataPrepare')]
174
-	public function testPrepare(string $subjectType, array $subjectParams, string $subject, array $messageParams, string $message): void {
175
-		/** @var INotification&MockObject $notification */
176
-		$notification = $this->createMock(INotification::class);
177
-
178
-		$notification->expects($this->once())
179
-			->method('getApp')
180
-			->willReturn(Application::APP_ID);
181
-		$notification->expects($this->once())
182
-			->method('getSubject')
183
-			->willReturn($subjectType);
184
-		$notification->expects($this->once())
185
-			->method('getSubjectParameters')
186
-			->willReturn($subjectParams);
187
-		$notification->expects($this->once())
188
-			->method('getMessageParameters')
189
-			->willReturn($messageParams);
190
-
191
-		$notification->expects($this->once())
192
-			->method('setParsedSubject')
193
-			->with($subject)
194
-			->willReturnSelf();
195
-
196
-		$notification->expects($this->once())
197
-			->method('setParsedMessage')
198
-			->with($message)
199
-			->willReturnSelf();
200
-
201
-		$this->urlGenerator->expects($this->once())
202
-			->method('imagePath')
203
-			->with('core', 'places/calendar.svg')
204
-			->willReturn('icon-url');
205
-		$this->urlGenerator->expects($this->once())
206
-			->method('getAbsoluteURL')
207
-			->with('icon-url')
208
-			->willReturn('absolute-icon-url');
209
-		$notification->expects($this->once())
210
-			->method('setIcon')
211
-			->with('absolute-icon-url')
212
-			->willReturnSelf();
213
-
214
-		$return = $this->notifier->prepare($notification, 'en');
215
-
216
-		$this->assertEquals($notification, $return);
217
-	}
218
-
219
-	public function testPassedEvent(): void {
220
-		/** @var INotification&MockObject $notification */
221
-		$notification = $this->createMock(INotification::class);
222
-
223
-		$notification->expects($this->once())
224
-			->method('getApp')
225
-			->willReturn(Application::APP_ID);
226
-		$notification->expects($this->once())
227
-			->method('getSubject')
228
-			->willReturn('calendar_reminder');
229
-		$notification->expects($this->once())
230
-			->method('getSubjectParameters')
231
-			->willReturn([
232
-				'title' => 'Title of this event',
233
-				'start_atom' => '2005-08-15T08:00:00+02:00'
234
-			]);
235
-
236
-		$notification->expects($this->once())
237
-			->method('getMessageParameters')
238
-			->willReturn([
239
-				'title' => 'Title of this event',
240
-				'description' => null,
241
-				'location' => 'NC Headquarters',
242
-				'all_day' => false,
243
-				'start_atom' => '2005-08-15T08:00:00+02:00',
244
-				'start_is_floating' => false,
245
-				'start_timezone' => 'Europe/Berlin',
246
-				'end_atom' => '2005-08-15T13:00:00+02:00',
247
-				'end_is_floating' => false,
248
-				'end_timezone' => 'Europe/Berlin',
249
-				'calendar_displayname' => 'Personal',
250
-			]);
251
-
252
-		$notification->expects($this->once())
253
-			->method('setParsedSubject')
254
-			->with(self::hasPhpDatetimeDiffBug() ? 'Title of this event' : 'Title of this event (6 hours ago)')
255
-			->willReturnSelf();
256
-
257
-		$this->expectException(AlreadyProcessedException::class);
258
-
259
-		$return = $this->notifier->prepare($notification, 'en');
260
-
261
-		$this->assertEquals($notification, $return);
262
-	}
24
+    protected IFactory&MockObject $factory;
25
+    protected IURLGenerator&MockObject $urlGenerator;
26
+    protected IL10N&MockObject $l10n;
27
+    protected ITimeFactory&MockObject $timeFactory;
28
+    protected Notifier $notifier;
29
+
30
+    protected function setUp(): void {
31
+        parent::setUp();
32
+
33
+        $this->urlGenerator = $this->createMock(IURLGenerator::class);
34
+        $this->l10n = $this->createMock(IL10N::class);
35
+        $this->l10n->expects($this->any())
36
+            ->method('t')
37
+            ->willReturnCallback(function ($string, $args) {
38
+                if (!is_array($args)) {
39
+                    $args = [$args];
40
+                }
41
+                return vsprintf($string, $args);
42
+            });
43
+        $this->l10n->expects($this->any())
44
+            ->method('l')
45
+            ->willReturnCallback(function ($string, $args) {
46
+                /** \DateTime $args */
47
+                return $args->format(\DateTime::ATOM);
48
+            });
49
+        $this->l10n->expects($this->any())
50
+            ->method('n')
51
+            ->willReturnCallback(function ($textSingular, $textPlural, $count, $args) {
52
+                $text = $count === 1 ? $textSingular : $textPlural;
53
+                $text = str_replace('%n', (string)$count, $text);
54
+                return vsprintf($text, $args);
55
+            });
56
+        $this->factory = $this->createMock(IFactory::class);
57
+        $this->factory->expects($this->any())
58
+            ->method('get')
59
+            ->willReturn($this->l10n);
60
+
61
+        $this->timeFactory = $this->createMock(ITimeFactory::class);
62
+        $this->timeFactory
63
+            ->method('getDateTime')
64
+            ->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2005-08-15T14:00:00+02:00'));
65
+
66
+        $this->notifier = new Notifier(
67
+            $this->factory,
68
+            $this->urlGenerator,
69
+            $this->timeFactory
70
+        );
71
+    }
72
+
73
+    public function testGetId():void {
74
+        $this->assertEquals($this->notifier->getID(), 'dav');
75
+    }
76
+
77
+    public function testGetName():void {
78
+        $this->assertEquals($this->notifier->getName(), 'Calendar');
79
+    }
80
+
81
+
82
+    public function testPrepareWrongApp(): void {
83
+        $this->expectException(UnknownNotificationException::class);
84
+        $this->expectExceptionMessage('Notification not from this app');
85
+
86
+        /** @var INotification&MockObject $notification */
87
+        $notification = $this->createMock(INotification::class);
88
+
89
+        $notification->expects($this->once())
90
+            ->method('getApp')
91
+            ->willReturn('notifications');
92
+        $notification->expects($this->never())
93
+            ->method('getSubject');
94
+
95
+        $this->notifier->prepare($notification, 'en');
96
+    }
97
+
98
+
99
+    public function testPrepareWrongSubject(): void {
100
+        $this->expectException(UnknownNotificationException::class);
101
+        $this->expectExceptionMessage('Unknown subject');
102
+
103
+        /** @var INotification&MockObject $notification */
104
+        $notification = $this->createMock(INotification::class);
105
+
106
+        $notification->expects($this->once())
107
+            ->method('getApp')
108
+            ->willReturn(Application::APP_ID);
109
+        $notification->expects($this->once())
110
+            ->method('getSubject')
111
+            ->willReturn('wrong subject');
112
+
113
+        $this->notifier->prepare($notification, 'en');
114
+    }
115
+
116
+    private static function hasPhpDatetimeDiffBug(): bool {
117
+        $d1 = \DateTime::createFromFormat(\DateTimeInterface::ATOM, '2023-11-22T11:52:00+01:00');
118
+        $d2 = new \DateTime('2023-11-22T10:52:03', new \DateTimeZone('UTC'));
119
+
120
+        // The difference is 3 seconds, not -1year+11months+…
121
+        return $d1->diff($d2)->y < 0;
122
+    }
123
+
124
+    public static function dataPrepare(): array {
125
+        return [
126
+            [
127
+                'calendar_reminder',
128
+                [
129
+                    'title' => 'Title of this event',
130
+                    'start_atom' => '2005-08-15T15:52:01+02:00'
131
+                ],
132
+                self::hasPhpDatetimeDiffBug() ? 'Title of this event' : 'Title of this event (in 1 hour, 52 minutes)',
133
+                [
134
+                    'title' => 'Title of this event',
135
+                    'description' => null,
136
+                    'location' => 'NC Headquarters',
137
+                    'all_day' => false,
138
+                    'start_atom' => '2005-08-15T15:52:01+02:00',
139
+                    'start_is_floating' => false,
140
+                    'start_timezone' => 'Europe/Berlin',
141
+                    'end_atom' => '2005-08-15T17:52:01+02:00',
142
+                    'end_is_floating' => false,
143
+                    'end_timezone' => 'Europe/Berlin',
144
+                    'calendar_displayname' => 'Personal',
145
+                ],
146
+                "Calendar: Personal\r\nDate: 2005-08-15T15:52:01+02:00, 2005-08-15T15:52:01+02:00 - 2005-08-15T17:52:01+02:00 (Europe/Berlin)\r\nWhere: NC Headquarters"
147
+            ],
148
+            [
149
+                'calendar_reminder',
150
+                [
151
+                    'title' => 'Title of this event',
152
+                    'start_atom' => '2005-08-15T13:00:00+02:00',
153
+                ],
154
+                self::hasPhpDatetimeDiffBug() ? 'Title of this event' : 'Title of this event (1 hour ago)',
155
+                [
156
+                    'title' => 'Title of this event',
157
+                    'description' => null,
158
+                    'location' => 'NC Headquarters',
159
+                    'all_day' => false,
160
+                    'start_atom' => '2005-08-15T13:00:00+02:00',
161
+                    'start_is_floating' => false,
162
+                    'start_timezone' => 'Europe/Berlin',
163
+                    'end_atom' => '2005-08-15T15:00:00+02:00',
164
+                    'end_is_floating' => false,
165
+                    'end_timezone' => 'Europe/Berlin',
166
+                    'calendar_displayname' => 'Personal',
167
+                ],
168
+                "Calendar: Personal\r\nDate: 2005-08-15T13:00:00+02:00, 2005-08-15T13:00:00+02:00 - 2005-08-15T15:00:00+02:00 (Europe/Berlin)\r\nWhere: NC Headquarters"
169
+            ],
170
+        ];
171
+    }
172
+
173
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataPrepare')]
174
+    public function testPrepare(string $subjectType, array $subjectParams, string $subject, array $messageParams, string $message): void {
175
+        /** @var INotification&MockObject $notification */
176
+        $notification = $this->createMock(INotification::class);
177
+
178
+        $notification->expects($this->once())
179
+            ->method('getApp')
180
+            ->willReturn(Application::APP_ID);
181
+        $notification->expects($this->once())
182
+            ->method('getSubject')
183
+            ->willReturn($subjectType);
184
+        $notification->expects($this->once())
185
+            ->method('getSubjectParameters')
186
+            ->willReturn($subjectParams);
187
+        $notification->expects($this->once())
188
+            ->method('getMessageParameters')
189
+            ->willReturn($messageParams);
190
+
191
+        $notification->expects($this->once())
192
+            ->method('setParsedSubject')
193
+            ->with($subject)
194
+            ->willReturnSelf();
195
+
196
+        $notification->expects($this->once())
197
+            ->method('setParsedMessage')
198
+            ->with($message)
199
+            ->willReturnSelf();
200
+
201
+        $this->urlGenerator->expects($this->once())
202
+            ->method('imagePath')
203
+            ->with('core', 'places/calendar.svg')
204
+            ->willReturn('icon-url');
205
+        $this->urlGenerator->expects($this->once())
206
+            ->method('getAbsoluteURL')
207
+            ->with('icon-url')
208
+            ->willReturn('absolute-icon-url');
209
+        $notification->expects($this->once())
210
+            ->method('setIcon')
211
+            ->with('absolute-icon-url')
212
+            ->willReturnSelf();
213
+
214
+        $return = $this->notifier->prepare($notification, 'en');
215
+
216
+        $this->assertEquals($notification, $return);
217
+    }
218
+
219
+    public function testPassedEvent(): void {
220
+        /** @var INotification&MockObject $notification */
221
+        $notification = $this->createMock(INotification::class);
222
+
223
+        $notification->expects($this->once())
224
+            ->method('getApp')
225
+            ->willReturn(Application::APP_ID);
226
+        $notification->expects($this->once())
227
+            ->method('getSubject')
228
+            ->willReturn('calendar_reminder');
229
+        $notification->expects($this->once())
230
+            ->method('getSubjectParameters')
231
+            ->willReturn([
232
+                'title' => 'Title of this event',
233
+                'start_atom' => '2005-08-15T08:00:00+02:00'
234
+            ]);
235
+
236
+        $notification->expects($this->once())
237
+            ->method('getMessageParameters')
238
+            ->willReturn([
239
+                'title' => 'Title of this event',
240
+                'description' => null,
241
+                'location' => 'NC Headquarters',
242
+                'all_day' => false,
243
+                'start_atom' => '2005-08-15T08:00:00+02:00',
244
+                'start_is_floating' => false,
245
+                'start_timezone' => 'Europe/Berlin',
246
+                'end_atom' => '2005-08-15T13:00:00+02:00',
247
+                'end_is_floating' => false,
248
+                'end_timezone' => 'Europe/Berlin',
249
+                'calendar_displayname' => 'Personal',
250
+            ]);
251
+
252
+        $notification->expects($this->once())
253
+            ->method('setParsedSubject')
254
+            ->with(self::hasPhpDatetimeDiffBug() ? 'Title of this event' : 'Title of this event (6 hours ago)')
255
+            ->willReturnSelf();
256
+
257
+        $this->expectException(AlreadyProcessedException::class);
258
+
259
+        $return = $this->notifier->prepare($notification, 'en');
260
+
261
+        $this->assertEquals($notification, $return);
262
+    }
263 263
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/CalDAV/Reminder/ReminderServiceTest.php 2 patches
Indentation   +541 added lines, -541 removed lines patch added patch discarded remove patch
@@ -26,18 +26,18 @@  discard block
 block discarded – undo
26 26
 use Test\TestCase;
27 27
 
28 28
 class ReminderServiceTest extends TestCase {
29
-	private Backend&MockObject $backend;
30
-	private NotificationProviderManager&MockObject $notificationProviderManager;
31
-	private IUserManager&MockObject $userManager;
32
-	private IGroupManager&MockObject $groupManager;
33
-	private CalDavBackend&MockObject $caldavBackend;
34
-	private ITimeFactory&MockObject $timeFactory;
35
-	private IConfig&MockObject $config;
36
-	private LoggerInterface&MockObject $logger;
37
-	private Principal&MockObject $principalConnector;
38
-	private ReminderService $reminderService;
39
-
40
-	public const CALENDAR_DATA = <<<EOD
29
+    private Backend&MockObject $backend;
30
+    private NotificationProviderManager&MockObject $notificationProviderManager;
31
+    private IUserManager&MockObject $userManager;
32
+    private IGroupManager&MockObject $groupManager;
33
+    private CalDavBackend&MockObject $caldavBackend;
34
+    private ITimeFactory&MockObject $timeFactory;
35
+    private IConfig&MockObject $config;
36
+    private LoggerInterface&MockObject $logger;
37
+    private Principal&MockObject $principalConnector;
38
+    private ReminderService $reminderService;
39
+
40
+    public const CALENDAR_DATA = <<<EOD
41 41
 BEGIN:VCALENDAR
42 42
 PRODID:-//Nextcloud calendar v1.6.4
43 43
 BEGIN:VEVENT
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 END:VCALENDAR
63 63
 EOD;
64 64
 
65
-	public const CALENDAR_DATA_REPEAT = <<<EOD
65
+    public const CALENDAR_DATA_REPEAT = <<<EOD
66 66
 BEGIN:VCALENDAR
67 67
 PRODID:-//Nextcloud calendar v1.6.4
68 68
 BEGIN:VEVENT
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 END:VCALENDAR
86 86
 EOD;
87 87
 
88
-	public const CALENDAR_DATA_RECURRING = <<<EOD
88
+    public const CALENDAR_DATA_RECURRING = <<<EOD
89 89
 BEGIN:VCALENDAR
90 90
 PRODID:-//Nextcloud calendar v1.6.4
91 91
 BEGIN:VEVENT
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 END:VCALENDAR
112 112
 EOD;
113 113
 
114
-	public const CALENDAR_DATA_RECURRING_REPEAT = <<<EOD
114
+    public const CALENDAR_DATA_RECURRING_REPEAT = <<<EOD
115 115
 BEGIN:VCALENDAR
116 116
 PRODID:-//Nextcloud calendar v1.6.4
117 117
 BEGIN:VEVENT
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 END:VCALENDAR
140 140
 EOD;
141 141
 
142
-	public const CALENDAR_DATA_NO_ALARM = <<<EOD
142
+    public const CALENDAR_DATA_NO_ALARM = <<<EOD
143 143
 BEGIN:VCALENDAR
144 144
 PRODID:-//Nextcloud calendar v1.6.4
145 145
 BEGIN:VEVENT
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 END:VCALENDAR
157 157
 EOD;
158 158
 
159
-	private const CALENDAR_DATA_ONE_TIME = <<<EOD
159
+    private const CALENDAR_DATA_ONE_TIME = <<<EOD
160 160
 BEGIN:VCALENDAR
161 161
 PRODID:-//IDN nextcloud.com//Calendar app 4.3.0-alpha.0//EN
162 162
 CALSCALE:GREGORIAN
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 END:VCALENDAR
197 197
 EOD;
198 198
 
199
-	private const CALENDAR_DATA_ALL_DAY = <<<EOD
199
+    private const CALENDAR_DATA_ALL_DAY = <<<EOD
200 200
 BEGIN:VCALENDAR
201 201
 PRODID:-//IDN nextcloud.com//Calendar app 4.3.0-alpha.0//EN
202 202
 CALSCALE:GREGORIAN
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 END:VCALENDAR
220 220
 EOD;
221 221
 
222
-	private const PAGO_PAGO_VTIMEZONE_ICS = <<<ICS
222
+    private const PAGO_PAGO_VTIMEZONE_ICS = <<<ICS
223 223
 BEGIN:VCALENDAR
224 224
 BEGIN:VTIMEZONE
225 225
 TZID:Pacific/Pago_Pago
@@ -233,82 +233,82 @@  discard block
 block discarded – undo
233 233
 END:VCALENDAR
234 234
 ICS;
235 235
 
236
-	private ?string $oldTimezone;
237
-
238
-	protected function setUp(): void {
239
-		parent::setUp();
240
-
241
-		$this->backend = $this->createMock(Backend::class);
242
-		$this->notificationProviderManager = $this->createMock(NotificationProviderManager::class);
243
-		$this->userManager = $this->createMock(IUserManager::class);
244
-		$this->groupManager = $this->createMock(IGroupManager::class);
245
-		$this->caldavBackend = $this->createMock(CalDavBackend::class);
246
-		$this->timeFactory = $this->createMock(ITimeFactory::class);
247
-		$this->config = $this->createMock(IConfig::class);
248
-		$this->logger = $this->createMock(LoggerInterface::class);
249
-		$this->principalConnector = $this->createMock(Principal::class);
250
-
251
-		$this->caldavBackend->method('getShares')->willReturn([]);
252
-
253
-		$this->reminderService = new ReminderService(
254
-			$this->backend,
255
-			$this->notificationProviderManager,
256
-			$this->userManager,
257
-			$this->groupManager,
258
-			$this->caldavBackend,
259
-			$this->timeFactory,
260
-			$this->config,
261
-			$this->logger,
262
-			$this->principalConnector,
263
-		);
264
-	}
265
-
266
-	public function testOnCalendarObjectDelete():void {
267
-		$this->backend->expects($this->once())
268
-			->method('cleanRemindersForEvent')
269
-			->with(44);
270
-
271
-		$objectData = [
272
-			'id' => '44',
273
-			'component' => 'vevent',
274
-		];
275
-
276
-		$this->reminderService->onCalendarObjectDelete($objectData);
277
-	}
278
-
279
-	public function testOnCalendarObjectCreateSingleEntry():void {
280
-		$objectData = [
281
-			'calendardata' => self::CALENDAR_DATA,
282
-			'id' => '42',
283
-			'calendarid' => '1337',
284
-			'component' => 'vevent',
285
-		];
286
-
287
-		$calls = [
288
-			[1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'de919af7429d3b5c11e8b9d289b411a6', 'EMAIL', true, 1465429500, false],
289
-			[1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', '35b3eae8e792aa2209f0b4e1a302f105', 'DISPLAY', false, 1465344000, false]
290
-		];
291
-		$this->backend->expects($this->exactly(count($calls)))
292
-			->method('insertReminder')
293
-			->willReturnCallback(function () use (&$calls) {
294
-				$expected = array_shift($calls);
295
-				$this->assertEquals($expected, func_get_args());
296
-				return 1;
297
-			});
298
-
299
-		$this->timeFactory->expects($this->once())
300
-			->method('getDateTime')
301
-			->with()
302
-			->willReturn(DateTime::createFromFormat(DateTime::ATOM, '2016-06-08T00:00:00+00:00'));
303
-
304
-		$this->reminderService->onCalendarObjectCreate($objectData);
305
-	}
306
-
307
-	/**
308
-	 * RFC5545 says DTSTART is REQUIRED, but we have seen event without the prop
309
-	 */
310
-	public function testOnCalendarObjectCreateNoDtstart(): void {
311
-		$calendarData = <<<EOD
236
+    private ?string $oldTimezone;
237
+
238
+    protected function setUp(): void {
239
+        parent::setUp();
240
+
241
+        $this->backend = $this->createMock(Backend::class);
242
+        $this->notificationProviderManager = $this->createMock(NotificationProviderManager::class);
243
+        $this->userManager = $this->createMock(IUserManager::class);
244
+        $this->groupManager = $this->createMock(IGroupManager::class);
245
+        $this->caldavBackend = $this->createMock(CalDavBackend::class);
246
+        $this->timeFactory = $this->createMock(ITimeFactory::class);
247
+        $this->config = $this->createMock(IConfig::class);
248
+        $this->logger = $this->createMock(LoggerInterface::class);
249
+        $this->principalConnector = $this->createMock(Principal::class);
250
+
251
+        $this->caldavBackend->method('getShares')->willReturn([]);
252
+
253
+        $this->reminderService = new ReminderService(
254
+            $this->backend,
255
+            $this->notificationProviderManager,
256
+            $this->userManager,
257
+            $this->groupManager,
258
+            $this->caldavBackend,
259
+            $this->timeFactory,
260
+            $this->config,
261
+            $this->logger,
262
+            $this->principalConnector,
263
+        );
264
+    }
265
+
266
+    public function testOnCalendarObjectDelete():void {
267
+        $this->backend->expects($this->once())
268
+            ->method('cleanRemindersForEvent')
269
+            ->with(44);
270
+
271
+        $objectData = [
272
+            'id' => '44',
273
+            'component' => 'vevent',
274
+        ];
275
+
276
+        $this->reminderService->onCalendarObjectDelete($objectData);
277
+    }
278
+
279
+    public function testOnCalendarObjectCreateSingleEntry():void {
280
+        $objectData = [
281
+            'calendardata' => self::CALENDAR_DATA,
282
+            'id' => '42',
283
+            'calendarid' => '1337',
284
+            'component' => 'vevent',
285
+        ];
286
+
287
+        $calls = [
288
+            [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'de919af7429d3b5c11e8b9d289b411a6', 'EMAIL', true, 1465429500, false],
289
+            [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', '35b3eae8e792aa2209f0b4e1a302f105', 'DISPLAY', false, 1465344000, false]
290
+        ];
291
+        $this->backend->expects($this->exactly(count($calls)))
292
+            ->method('insertReminder')
293
+            ->willReturnCallback(function () use (&$calls) {
294
+                $expected = array_shift($calls);
295
+                $this->assertEquals($expected, func_get_args());
296
+                return 1;
297
+            });
298
+
299
+        $this->timeFactory->expects($this->once())
300
+            ->method('getDateTime')
301
+            ->with()
302
+            ->willReturn(DateTime::createFromFormat(DateTime::ATOM, '2016-06-08T00:00:00+00:00'));
303
+
304
+        $this->reminderService->onCalendarObjectCreate($objectData);
305
+    }
306
+
307
+    /**
308
+     * RFC5545 says DTSTART is REQUIRED, but we have seen event without the prop
309
+     */
310
+    public function testOnCalendarObjectCreateNoDtstart(): void {
311
+        $calendarData = <<<EOD
312 312
 BEGIN:VCALENDAR
313 313
 PRODID:-//Nextcloud calendar v1.6.4
314 314
 BEGIN:VEVENT
@@ -328,450 +328,450 @@  discard block
 block discarded – undo
328 328
 END:VEVENT
329 329
 END:VCALENDAR
330 330
 EOD;
331
-		$objectData = [
332
-			'calendardata' => $calendarData,
333
-			'id' => '42',
334
-			'calendarid' => '1337',
335
-			'component' => 'vevent',
336
-		];
337
-
338
-		$this->backend->expects($this->never())
339
-			->method('insertReminder');
340
-
341
-		$this->reminderService->onCalendarObjectCreate($objectData);
342
-	}
343
-
344
-	public function testOnCalendarObjectCreateSingleEntryWithRepeat(): void {
345
-		$objectData = [
346
-			'calendardata' => self::CALENDAR_DATA_REPEAT,
347
-			'id' => '42',
348
-			'calendarid' => '1337',
349
-			'component' => 'vevent',
350
-		];
351
-
352
-		$calls = [
353
-			[1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429500, false],
354
-			[1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429620, true],
355
-			[1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429740, true],
356
-			[1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429860, true],
357
-			[1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429980, true]
358
-		];
359
-		$this->backend->expects($this->exactly(count($calls)))
360
-			->method('insertReminder')
361
-			->willReturnCallback(function () use (&$calls) {
362
-				$expected = array_shift($calls);
363
-				$this->assertEquals($expected, func_get_args());
364
-				return 1;
365
-			});
366
-
367
-		$this->timeFactory->expects($this->once())
368
-			->method('getDateTime')
369
-			->with()
370
-			->willReturn(DateTime::createFromFormat(DateTime::ATOM, '2016-06-08T00:00:00+00:00'));
371
-
372
-		$this->reminderService->onCalendarObjectCreate($objectData);
373
-	}
374
-
375
-	public function testOnCalendarObjectCreateRecurringEntry(): void {
376
-		$objectData = [
377
-			'calendardata' => self::CALENDAR_DATA_RECURRING,
378
-			'id' => '42',
379
-			'calendarid' => '1337',
380
-			'component' => 'vevent',
381
-		];
382
-
383
-		$calls = [
384
-			[1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'de919af7429d3b5c11e8b9d289b411a6', 'EMAIL', true, 1467243900, false],
385
-			[1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', '8996992118817f9f311ac5cc56d1cc97', 'EMAIL', true, 1467158400, false]
386
-		];
387
-		$this->backend->expects($this->exactly(count($calls)))
388
-			->method('insertReminder')
389
-			->willReturnCallback(function () use (&$calls) {
390
-				$expected = array_shift($calls);
391
-				$this->assertEquals($expected, func_get_args());
392
-				return 1;
393
-			});
394
-
395
-		$this->timeFactory->expects($this->once())
396
-			->method('getDateTime')
397
-			->willReturn(DateTime::createFromFormat(DateTime::ATOM, '2016-06-29T00:00:00+00:00'));
398
-
399
-		$this->reminderService->onCalendarObjectCreate($objectData);
400
-	}
401
-
402
-	public function testOnCalendarObjectCreateEmpty():void {
403
-		$objectData = [
404
-			'calendardata' => self::CALENDAR_DATA_NO_ALARM,
405
-			'id' => '42',
406
-			'calendarid' => '1337',
407
-			'component' => 'vevent',
408
-		];
409
-
410
-		$this->backend->expects($this->never())
411
-			->method('insertReminder');
412
-
413
-		$this->reminderService->onCalendarObjectCreate($objectData);
414
-	}
415
-
416
-	public function testOnCalendarObjectCreateAllDayWithNullTimezone(): void {
417
-		$objectData = [
418
-			'calendardata' => self::CALENDAR_DATA_ALL_DAY,
419
-			'id' => '42',
420
-			'calendarid' => '1337',
421
-			'component' => 'vevent',
422
-		];
423
-		$this->timeFactory->expects($this->once())
424
-			->method('getDateTime')
425
-			->with()
426
-			->willReturn(DateTime::createFromFormat(DateTime::ATOM, '2023-02-03T13:28:00+00:00'));
427
-		$this->caldavBackend->expects(self::once())
428
-			->method('getCalendarById')
429
-			->with(1337)
430
-			->willReturn([
431
-				'{urn:ietf:params:xml:ns:caldav}calendar-timezone' => null,
432
-			]);
433
-
434
-		// One hour before midnight relative to the server's time
435
-		$expectedReminderTimstamp = (new DateTime('2023-02-03T23:00:00'))->getTimestamp();
436
-		$this->backend->expects(self::once())
437
-			->method('insertReminder')
438
-			->with(1337, 42, self::anything(), false, 1675468800, false, self::anything(), self::anything(), 'EMAIL', true, $expectedReminderTimstamp, false);
439
-
440
-		$this->reminderService->onCalendarObjectCreate($objectData);
441
-	}
442
-
443
-	public function testOnCalendarObjectCreateAllDayWithBlankTimezone(): void {
444
-		$objectData = [
445
-			'calendardata' => self::CALENDAR_DATA_ALL_DAY,
446
-			'id' => '42',
447
-			'calendarid' => '1337',
448
-			'component' => 'vevent',
449
-		];
450
-		$this->timeFactory->expects($this->once())
451
-			->method('getDateTime')
452
-			->with()
453
-			->willReturn(DateTime::createFromFormat(DateTime::ATOM, '2023-02-03T13:28:00+00:00'));
454
-		$this->caldavBackend->expects(self::once())
455
-			->method('getCalendarById')
456
-			->with(1337)
457
-			->willReturn([
458
-				'{urn:ietf:params:xml:ns:caldav}calendar-timezone' => '',
459
-			]);
460
-
461
-		// One hour before midnight relative to the server's time
462
-		$expectedReminderTimstamp = (new DateTime('2023-02-03T23:00:00'))->getTimestamp();
463
-		$this->backend->expects(self::once())
464
-			->method('insertReminder')
465
-			->with(1337, 42, self::anything(), false, 1675468800, false, self::anything(), self::anything(), 'EMAIL', true, $expectedReminderTimstamp, false);
466
-
467
-		$this->reminderService->onCalendarObjectCreate($objectData);
468
-	}
469
-
470
-	public function testOnCalendarObjectCreateAllDayWithTimezone(): void {
471
-		$objectData = [
472
-			'calendardata' => self::CALENDAR_DATA_ALL_DAY,
473
-			'id' => '42',
474
-			'calendarid' => '1337',
475
-			'component' => 'vevent',
476
-		];
477
-		$this->timeFactory->expects($this->once())
478
-			->method('getDateTime')
479
-			->with()
480
-			->willReturn(DateTime::createFromFormat(DateTime::ATOM, '2023-02-03T13:28:00+00:00'));
481
-		$this->caldavBackend->expects(self::once())
482
-			->method('getCalendarById')
483
-			->with(1337)
484
-			->willReturn([
485
-				'{urn:ietf:params:xml:ns:caldav}calendar-timezone' => self::PAGO_PAGO_VTIMEZONE_ICS,
486
-			]);
487
-
488
-		// One hour before midnight relative to the timezone
489
-		$expectedReminderTimstamp = (new DateTime('2023-02-03T23:00:00', new DateTimeZone('Pacific/Pago_Pago')))->getTimestamp();
490
-		$this->backend->expects(self::once())
491
-			->method('insertReminder')
492
-			->with(1337, 42, 'a163a056-ba26-44a2-8080-955f19611a8f', false, self::anything(), false, self::anything(), self::anything(), 'EMAIL', true, $expectedReminderTimstamp, false);
493
-
494
-		$this->reminderService->onCalendarObjectCreate($objectData);
495
-	}
496
-
497
-	public function testOnCalendarObjectCreateRecurringEntryWithRepeat():void {
498
-		$objectData = [
499
-			'calendardata' => self::CALENDAR_DATA_RECURRING_REPEAT,
500
-			'id' => '42',
501
-			'calendarid' => '1337',
502
-			'component' => 'vevent',
503
-		];
504
-		$this->caldavBackend->expects(self::once())
505
-			->method('getCalendarById')
506
-			->with(1337)
507
-			->willReturn([
508
-				'{urn:ietf:params:xml:ns:caldav}calendar-timezone' => null,
509
-			]);
510
-
511
-		$calls = [
512
-			[1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467243900, false],
513
-			[1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467244020, true],
514
-			[1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467244140, true],
515
-			[1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467244260, true],
516
-			[1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467244380, true],
517
-			[1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', '8996992118817f9f311ac5cc56d1cc97', 'EMAIL', true, 1467158400, false]
518
-		];
519
-		$this->backend->expects($this->exactly(count($calls)))
520
-			->method('insertReminder')
521
-			->willReturnCallback(function () use (&$calls) {
522
-				$expected = array_shift($calls);
523
-				$this->assertEquals($expected, func_get_args());
524
-				return 1;
525
-			});
526
-
527
-		$this->timeFactory->expects($this->once())
528
-			->method('getDateTime')
529
-			->with()
530
-			->willReturn(DateTime::createFromFormat(DateTime::ATOM, '2016-06-29T00:00:00+00:00'));
531
-
532
-		$this->reminderService->onCalendarObjectCreate($objectData);
533
-	}
534
-
535
-	public function testOnCalendarObjectCreateWithEventTimezoneAndCalendarTimezone():void {
536
-		$objectData = [
537
-			'calendardata' => self::CALENDAR_DATA_ONE_TIME,
538
-			'id' => '42',
539
-			'calendarid' => '1337',
540
-			'component' => 'vevent',
541
-		];
542
-		$this->caldavBackend->expects(self::once())
543
-			->method('getCalendarById')
544
-			->with(1337)
545
-			->willReturn([
546
-				'{urn:ietf:params:xml:ns:caldav}calendar-timezone' => self::PAGO_PAGO_VTIMEZONE_ICS,
547
-			]);
548
-		$expectedReminderTimstamp = (new DateTime('2023-02-04T08:00:00', new DateTimeZone('Europe/Vienna')))->getTimestamp();
549
-		$this->backend->expects(self::once())
550
-			->method('insertReminder')
551
-			->with(1337, 42, self::anything(), false, self::anything(), false, self::anything(), self::anything(), self::anything(), true, $expectedReminderTimstamp, false)
552
-			->willReturn(1);
553
-		$this->caldavBackend->expects(self::once())
554
-			->method('getCalendarById')
555
-			->with(1337)
556
-			->willReturn([
557
-				'{urn:ietf:params:xml:ns:caldav}calendar-timezone' => null,
558
-			]);
559
-		$this->timeFactory->expects($this->once())
560
-			->method('getDateTime')
561
-			->with()
562
-			->willReturn(DateTime::createFromFormat(DateTime::ATOM, '2023-02-03T13:28:00+00:00'));
563
-		;
564
-
565
-		$this->reminderService->onCalendarObjectCreate($objectData);
566
-	}
567
-
568
-	public function testProcessReminders():void {
569
-		$this->backend->expects($this->once())
570
-			->method('getRemindersToProcess')
571
-			->with()
572
-			->willReturn([
573
-				[
574
-					'id' => 1,
575
-					'calendar_id' => 1337,
576
-					'object_id' => 42,
577
-					'uid' => 'wej2z68l9h',
578
-					'is_recurring' => false,
579
-					'recurrence_id' => 1465430400,
580
-					'is_recurrence_exception' => false,
581
-					'event_hash' => '5c70531aab15c92b52518ae10a2f78a4',
582
-					'alarm_hash' => 'de919af7429d3b5c11e8b9d289b411a6',
583
-					'type' => 'EMAIL',
584
-					'is_relative' => true,
585
-					'notification_date' => 1465429500,
586
-					'is_repeat_based' => false,
587
-					'calendardata' => self::CALENDAR_DATA,
588
-					'displayname' => 'Displayname 123',
589
-					'principaluri' => 'principals/users/user001',
590
-				],
591
-				[
592
-					'id' => 2,
593
-					'calendar_id' => 1337,
594
-					'object_id' => 42,
595
-					'uid' => 'wej2z68l9h',
596
-					'is_recurring' => false,
597
-					'recurrence_id' => 1465430400,
598
-					'is_recurrence_exception' => false,
599
-					'event_hash' => '5c70531aab15c92b52518ae10a2f78a4',
600
-					'alarm_hash' => 'ecacbf07d413c3c78d1ac7ad8c469602',
601
-					'type' => 'EMAIL',
602
-					'is_relative' => true,
603
-					'notification_date' => 1465429740,
604
-					'is_repeat_based' => true,
605
-					'calendardata' => self::CALENDAR_DATA_REPEAT,
606
-					'displayname' => 'Displayname 123',
607
-					'principaluri' => 'principals/users/user001',
608
-				],
609
-				[
610
-					'id' => 3,
611
-					'calendar_id' => 1337,
612
-					'object_id' => 42,
613
-					'uid' => 'wej2z68l9h',
614
-					'is_recurring' => false,
615
-					'recurrence_id' => 1465430400,
616
-					'is_recurrence_exception' => false,
617
-					'event_hash' => '5c70531aab15c92b52518ae10a2f78a4',
618
-					'alarm_hash' => '35b3eae8e792aa2209f0b4e1a302f105',
619
-					'type' => 'DISPLAY',
620
-					'is_relative' => false,
621
-					'notification_date' => 1465344000,
622
-					'is_repeat_based' => false,
623
-					'calendardata' => self::CALENDAR_DATA,
624
-					'displayname' => 'Displayname 123',
625
-					'principaluri' => 'principals/users/user001',
626
-				],
627
-				[
628
-					'id' => 4,
629
-					'calendar_id' => 1337,
630
-					'object_id' => 42,
631
-					'uid' => 'wej2z68l9h',
632
-					'is_recurring' => true,
633
-					'recurrence_id' => 1467244800,
634
-					'is_recurrence_exception' => false,
635
-					'event_hash' => 'fbdb2726bc0f7dfacac1d881c1453e20',
636
-					'alarm_hash' => 'ecacbf07d413c3c78d1ac7ad8c469602',
637
-					'type' => 'EMAIL',
638
-					'is_relative' => true,
639
-					'notification_date' => 1467243900,
640
-					'is_repeat_based' => false,
641
-					'calendardata' => self::CALENDAR_DATA_RECURRING_REPEAT,
642
-					'displayname' => 'Displayname 123',
643
-					'principaluri' => 'principals/users/user001',
644
-				],
645
-				[
646
-					'id' => 5,
647
-					'calendar_id' => 1337,
648
-					'object_id' => 42,
649
-					'uid' => 'wej2z68l9h',
650
-					'is_recurring' => true,
651
-					'recurrence_id' => 1467849600,
652
-					'is_recurrence_exception' => false,
653
-					'event_hash' => 'fbdb2726bc0f7dfacac1d881c1453e20',
654
-					'alarm_hash' => '8996992118817f9f311ac5cc56d1cc97',
655
-					'type' => 'EMAIL',
656
-					'is_relative' => true,
657
-					'notification_date' => 1467158400,
658
-					'is_repeat_based' => false,
659
-					'calendardata' => self::CALENDAR_DATA_RECURRING,
660
-					'displayname' => 'Displayname 123',
661
-					'principaluri' => 'principals/users/user001',
662
-				]
663
-			]);
664
-
665
-		$this->notificationProviderManager->expects($this->exactly(5))
666
-			->method('hasProvider')
667
-			->willReturnMap([
668
-				['EMAIL', true],
669
-				['DISPLAY', true],
670
-			]);
671
-
672
-		$provider1 = $this->createMock(INotificationProvider::class);
673
-		$provider2 = $this->createMock(INotificationProvider::class);
674
-		$provider3 = $this->createMock(INotificationProvider::class);
675
-		$provider4 = $this->createMock(INotificationProvider::class);
676
-		$provider5 = $this->createMock(INotificationProvider::class);
677
-
678
-		$getProviderCalls = [
679
-			['EMAIL', $provider1],
680
-			['EMAIL', $provider2],
681
-			['DISPLAY', $provider3],
682
-			['EMAIL', $provider4],
683
-			['EMAIL', $provider5],
684
-		];
685
-		$this->notificationProviderManager->expects($this->exactly(count($getProviderCalls)))
686
-			->method('getProvider')
687
-			->willReturnCallback(function () use (&$getProviderCalls) {
688
-				$expected = array_shift($getProviderCalls);
689
-				$return = array_pop($expected);
690
-				$this->assertEquals($expected, func_get_args());
691
-				return $return;
692
-			});
693
-
694
-		$user = $this->createMock(IUser::class);
695
-		$this->userManager->expects($this->exactly(5))
696
-			->method('get')
697
-			->with('user001')
698
-			->willReturn($user);
699
-
700
-		$provider1->expects($this->once())
701
-			->method('send')
702
-			->with($this->callback(function ($vevent) {
703
-				if ($vevent->DTSTART->getDateTime()->format(DateTime::ATOM) !== '2016-06-09T00:00:00+00:00') {
704
-					return false;
705
-				}
706
-				return true;
707
-			}, 'Displayname 123', $user));
708
-		$provider2->expects($this->once())
709
-			->method('send')
710
-			->with($this->callback(function ($vevent) {
711
-				if ($vevent->DTSTART->getDateTime()->format(DateTime::ATOM) !== '2016-06-09T00:00:00+00:00') {
712
-					return false;
713
-				}
714
-				return true;
715
-			}, 'Displayname 123', $user));
716
-		$provider3->expects($this->once())
717
-			->method('send')
718
-			->with($this->callback(function ($vevent) {
719
-				if ($vevent->DTSTART->getDateTime()->format(DateTime::ATOM) !== '2016-06-09T00:00:00+00:00') {
720
-					return false;
721
-				}
722
-				return true;
723
-			}, 'Displayname 123', $user));
724
-		$provider4->expects($this->once())
725
-			->method('send')
726
-			->with($this->callback(function ($vevent) {
727
-				if ($vevent->DTSTART->getDateTime()->format(DateTime::ATOM) !== '2016-06-30T00:00:00+00:00') {
728
-					return false;
729
-				}
730
-				return true;
731
-			}, 'Displayname 123', $user));
732
-		$provider5->expects($this->once())
733
-			->method('send')
734
-			->with($this->callback(function ($vevent) {
735
-				if ($vevent->DTSTART->getDateTime()->format(DateTime::ATOM) !== '2016-07-07T00:00:00+00:00') {
736
-					return false;
737
-				}
738
-				return true;
739
-			}, 'Displayname 123', $user));
740
-
741
-		$removeReminderCalls = [
742
-			[1],
743
-			[2],
744
-			[3],
745
-			[4],
746
-			[5],
747
-		];
748
-		$this->backend->expects($this->exactly(5))
749
-			->method('removeReminder')
750
-			->willReturnCallback(function () use (&$removeReminderCalls): void {
751
-				$expected = array_shift($removeReminderCalls);
752
-				$this->assertEquals($expected, func_get_args());
753
-			});
754
-
755
-
756
-		$insertReminderCalls = [
757
-			[1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467848700, false],
758
-			[1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467848820, true],
759
-			[1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467848940, true],
760
-			[1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467849060, true],
761
-			[1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467849180, true],
762
-			[1337, 42, 'wej2z68l9h', true, 1468454400, false, 'fbdb2726bc0f7dfacac1d881c1453e20', '8996992118817f9f311ac5cc56d1cc97', 'EMAIL', true, 1467763200, false],
763
-		];
764
-		$this->backend->expects($this->exactly(count($insertReminderCalls)))
765
-			->method('insertReminder')
766
-			->willReturnCallback(function () use (&$insertReminderCalls) {
767
-				$expected = array_shift($insertReminderCalls);
768
-				$this->assertEquals($expected, func_get_args());
769
-				return 99;
770
-			});
771
-
772
-		$this->timeFactory->method('getDateTime')
773
-			->willReturn(DateTime::createFromFormat(DateTime::ATOM, '2016-06-08T00:00:00+00:00'));
774
-
775
-		$this->reminderService->processReminders();
776
-	}
331
+        $objectData = [
332
+            'calendardata' => $calendarData,
333
+            'id' => '42',
334
+            'calendarid' => '1337',
335
+            'component' => 'vevent',
336
+        ];
337
+
338
+        $this->backend->expects($this->never())
339
+            ->method('insertReminder');
340
+
341
+        $this->reminderService->onCalendarObjectCreate($objectData);
342
+    }
343
+
344
+    public function testOnCalendarObjectCreateSingleEntryWithRepeat(): void {
345
+        $objectData = [
346
+            'calendardata' => self::CALENDAR_DATA_REPEAT,
347
+            'id' => '42',
348
+            'calendarid' => '1337',
349
+            'component' => 'vevent',
350
+        ];
351
+
352
+        $calls = [
353
+            [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429500, false],
354
+            [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429620, true],
355
+            [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429740, true],
356
+            [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429860, true],
357
+            [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429980, true]
358
+        ];
359
+        $this->backend->expects($this->exactly(count($calls)))
360
+            ->method('insertReminder')
361
+            ->willReturnCallback(function () use (&$calls) {
362
+                $expected = array_shift($calls);
363
+                $this->assertEquals($expected, func_get_args());
364
+                return 1;
365
+            });
366
+
367
+        $this->timeFactory->expects($this->once())
368
+            ->method('getDateTime')
369
+            ->with()
370
+            ->willReturn(DateTime::createFromFormat(DateTime::ATOM, '2016-06-08T00:00:00+00:00'));
371
+
372
+        $this->reminderService->onCalendarObjectCreate($objectData);
373
+    }
374
+
375
+    public function testOnCalendarObjectCreateRecurringEntry(): void {
376
+        $objectData = [
377
+            'calendardata' => self::CALENDAR_DATA_RECURRING,
378
+            'id' => '42',
379
+            'calendarid' => '1337',
380
+            'component' => 'vevent',
381
+        ];
382
+
383
+        $calls = [
384
+            [1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'de919af7429d3b5c11e8b9d289b411a6', 'EMAIL', true, 1467243900, false],
385
+            [1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', '8996992118817f9f311ac5cc56d1cc97', 'EMAIL', true, 1467158400, false]
386
+        ];
387
+        $this->backend->expects($this->exactly(count($calls)))
388
+            ->method('insertReminder')
389
+            ->willReturnCallback(function () use (&$calls) {
390
+                $expected = array_shift($calls);
391
+                $this->assertEquals($expected, func_get_args());
392
+                return 1;
393
+            });
394
+
395
+        $this->timeFactory->expects($this->once())
396
+            ->method('getDateTime')
397
+            ->willReturn(DateTime::createFromFormat(DateTime::ATOM, '2016-06-29T00:00:00+00:00'));
398
+
399
+        $this->reminderService->onCalendarObjectCreate($objectData);
400
+    }
401
+
402
+    public function testOnCalendarObjectCreateEmpty():void {
403
+        $objectData = [
404
+            'calendardata' => self::CALENDAR_DATA_NO_ALARM,
405
+            'id' => '42',
406
+            'calendarid' => '1337',
407
+            'component' => 'vevent',
408
+        ];
409
+
410
+        $this->backend->expects($this->never())
411
+            ->method('insertReminder');
412
+
413
+        $this->reminderService->onCalendarObjectCreate($objectData);
414
+    }
415
+
416
+    public function testOnCalendarObjectCreateAllDayWithNullTimezone(): void {
417
+        $objectData = [
418
+            'calendardata' => self::CALENDAR_DATA_ALL_DAY,
419
+            'id' => '42',
420
+            'calendarid' => '1337',
421
+            'component' => 'vevent',
422
+        ];
423
+        $this->timeFactory->expects($this->once())
424
+            ->method('getDateTime')
425
+            ->with()
426
+            ->willReturn(DateTime::createFromFormat(DateTime::ATOM, '2023-02-03T13:28:00+00:00'));
427
+        $this->caldavBackend->expects(self::once())
428
+            ->method('getCalendarById')
429
+            ->with(1337)
430
+            ->willReturn([
431
+                '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => null,
432
+            ]);
433
+
434
+        // One hour before midnight relative to the server's time
435
+        $expectedReminderTimstamp = (new DateTime('2023-02-03T23:00:00'))->getTimestamp();
436
+        $this->backend->expects(self::once())
437
+            ->method('insertReminder')
438
+            ->with(1337, 42, self::anything(), false, 1675468800, false, self::anything(), self::anything(), 'EMAIL', true, $expectedReminderTimstamp, false);
439
+
440
+        $this->reminderService->onCalendarObjectCreate($objectData);
441
+    }
442
+
443
+    public function testOnCalendarObjectCreateAllDayWithBlankTimezone(): void {
444
+        $objectData = [
445
+            'calendardata' => self::CALENDAR_DATA_ALL_DAY,
446
+            'id' => '42',
447
+            'calendarid' => '1337',
448
+            'component' => 'vevent',
449
+        ];
450
+        $this->timeFactory->expects($this->once())
451
+            ->method('getDateTime')
452
+            ->with()
453
+            ->willReturn(DateTime::createFromFormat(DateTime::ATOM, '2023-02-03T13:28:00+00:00'));
454
+        $this->caldavBackend->expects(self::once())
455
+            ->method('getCalendarById')
456
+            ->with(1337)
457
+            ->willReturn([
458
+                '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => '',
459
+            ]);
460
+
461
+        // One hour before midnight relative to the server's time
462
+        $expectedReminderTimstamp = (new DateTime('2023-02-03T23:00:00'))->getTimestamp();
463
+        $this->backend->expects(self::once())
464
+            ->method('insertReminder')
465
+            ->with(1337, 42, self::anything(), false, 1675468800, false, self::anything(), self::anything(), 'EMAIL', true, $expectedReminderTimstamp, false);
466
+
467
+        $this->reminderService->onCalendarObjectCreate($objectData);
468
+    }
469
+
470
+    public function testOnCalendarObjectCreateAllDayWithTimezone(): void {
471
+        $objectData = [
472
+            'calendardata' => self::CALENDAR_DATA_ALL_DAY,
473
+            'id' => '42',
474
+            'calendarid' => '1337',
475
+            'component' => 'vevent',
476
+        ];
477
+        $this->timeFactory->expects($this->once())
478
+            ->method('getDateTime')
479
+            ->with()
480
+            ->willReturn(DateTime::createFromFormat(DateTime::ATOM, '2023-02-03T13:28:00+00:00'));
481
+        $this->caldavBackend->expects(self::once())
482
+            ->method('getCalendarById')
483
+            ->with(1337)
484
+            ->willReturn([
485
+                '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => self::PAGO_PAGO_VTIMEZONE_ICS,
486
+            ]);
487
+
488
+        // One hour before midnight relative to the timezone
489
+        $expectedReminderTimstamp = (new DateTime('2023-02-03T23:00:00', new DateTimeZone('Pacific/Pago_Pago')))->getTimestamp();
490
+        $this->backend->expects(self::once())
491
+            ->method('insertReminder')
492
+            ->with(1337, 42, 'a163a056-ba26-44a2-8080-955f19611a8f', false, self::anything(), false, self::anything(), self::anything(), 'EMAIL', true, $expectedReminderTimstamp, false);
493
+
494
+        $this->reminderService->onCalendarObjectCreate($objectData);
495
+    }
496
+
497
+    public function testOnCalendarObjectCreateRecurringEntryWithRepeat():void {
498
+        $objectData = [
499
+            'calendardata' => self::CALENDAR_DATA_RECURRING_REPEAT,
500
+            'id' => '42',
501
+            'calendarid' => '1337',
502
+            'component' => 'vevent',
503
+        ];
504
+        $this->caldavBackend->expects(self::once())
505
+            ->method('getCalendarById')
506
+            ->with(1337)
507
+            ->willReturn([
508
+                '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => null,
509
+            ]);
510
+
511
+        $calls = [
512
+            [1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467243900, false],
513
+            [1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467244020, true],
514
+            [1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467244140, true],
515
+            [1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467244260, true],
516
+            [1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467244380, true],
517
+            [1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', '8996992118817f9f311ac5cc56d1cc97', 'EMAIL', true, 1467158400, false]
518
+        ];
519
+        $this->backend->expects($this->exactly(count($calls)))
520
+            ->method('insertReminder')
521
+            ->willReturnCallback(function () use (&$calls) {
522
+                $expected = array_shift($calls);
523
+                $this->assertEquals($expected, func_get_args());
524
+                return 1;
525
+            });
526
+
527
+        $this->timeFactory->expects($this->once())
528
+            ->method('getDateTime')
529
+            ->with()
530
+            ->willReturn(DateTime::createFromFormat(DateTime::ATOM, '2016-06-29T00:00:00+00:00'));
531
+
532
+        $this->reminderService->onCalendarObjectCreate($objectData);
533
+    }
534
+
535
+    public function testOnCalendarObjectCreateWithEventTimezoneAndCalendarTimezone():void {
536
+        $objectData = [
537
+            'calendardata' => self::CALENDAR_DATA_ONE_TIME,
538
+            'id' => '42',
539
+            'calendarid' => '1337',
540
+            'component' => 'vevent',
541
+        ];
542
+        $this->caldavBackend->expects(self::once())
543
+            ->method('getCalendarById')
544
+            ->with(1337)
545
+            ->willReturn([
546
+                '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => self::PAGO_PAGO_VTIMEZONE_ICS,
547
+            ]);
548
+        $expectedReminderTimstamp = (new DateTime('2023-02-04T08:00:00', new DateTimeZone('Europe/Vienna')))->getTimestamp();
549
+        $this->backend->expects(self::once())
550
+            ->method('insertReminder')
551
+            ->with(1337, 42, self::anything(), false, self::anything(), false, self::anything(), self::anything(), self::anything(), true, $expectedReminderTimstamp, false)
552
+            ->willReturn(1);
553
+        $this->caldavBackend->expects(self::once())
554
+            ->method('getCalendarById')
555
+            ->with(1337)
556
+            ->willReturn([
557
+                '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => null,
558
+            ]);
559
+        $this->timeFactory->expects($this->once())
560
+            ->method('getDateTime')
561
+            ->with()
562
+            ->willReturn(DateTime::createFromFormat(DateTime::ATOM, '2023-02-03T13:28:00+00:00'));
563
+        ;
564
+
565
+        $this->reminderService->onCalendarObjectCreate($objectData);
566
+    }
567
+
568
+    public function testProcessReminders():void {
569
+        $this->backend->expects($this->once())
570
+            ->method('getRemindersToProcess')
571
+            ->with()
572
+            ->willReturn([
573
+                [
574
+                    'id' => 1,
575
+                    'calendar_id' => 1337,
576
+                    'object_id' => 42,
577
+                    'uid' => 'wej2z68l9h',
578
+                    'is_recurring' => false,
579
+                    'recurrence_id' => 1465430400,
580
+                    'is_recurrence_exception' => false,
581
+                    'event_hash' => '5c70531aab15c92b52518ae10a2f78a4',
582
+                    'alarm_hash' => 'de919af7429d3b5c11e8b9d289b411a6',
583
+                    'type' => 'EMAIL',
584
+                    'is_relative' => true,
585
+                    'notification_date' => 1465429500,
586
+                    'is_repeat_based' => false,
587
+                    'calendardata' => self::CALENDAR_DATA,
588
+                    'displayname' => 'Displayname 123',
589
+                    'principaluri' => 'principals/users/user001',
590
+                ],
591
+                [
592
+                    'id' => 2,
593
+                    'calendar_id' => 1337,
594
+                    'object_id' => 42,
595
+                    'uid' => 'wej2z68l9h',
596
+                    'is_recurring' => false,
597
+                    'recurrence_id' => 1465430400,
598
+                    'is_recurrence_exception' => false,
599
+                    'event_hash' => '5c70531aab15c92b52518ae10a2f78a4',
600
+                    'alarm_hash' => 'ecacbf07d413c3c78d1ac7ad8c469602',
601
+                    'type' => 'EMAIL',
602
+                    'is_relative' => true,
603
+                    'notification_date' => 1465429740,
604
+                    'is_repeat_based' => true,
605
+                    'calendardata' => self::CALENDAR_DATA_REPEAT,
606
+                    'displayname' => 'Displayname 123',
607
+                    'principaluri' => 'principals/users/user001',
608
+                ],
609
+                [
610
+                    'id' => 3,
611
+                    'calendar_id' => 1337,
612
+                    'object_id' => 42,
613
+                    'uid' => 'wej2z68l9h',
614
+                    'is_recurring' => false,
615
+                    'recurrence_id' => 1465430400,
616
+                    'is_recurrence_exception' => false,
617
+                    'event_hash' => '5c70531aab15c92b52518ae10a2f78a4',
618
+                    'alarm_hash' => '35b3eae8e792aa2209f0b4e1a302f105',
619
+                    'type' => 'DISPLAY',
620
+                    'is_relative' => false,
621
+                    'notification_date' => 1465344000,
622
+                    'is_repeat_based' => false,
623
+                    'calendardata' => self::CALENDAR_DATA,
624
+                    'displayname' => 'Displayname 123',
625
+                    'principaluri' => 'principals/users/user001',
626
+                ],
627
+                [
628
+                    'id' => 4,
629
+                    'calendar_id' => 1337,
630
+                    'object_id' => 42,
631
+                    'uid' => 'wej2z68l9h',
632
+                    'is_recurring' => true,
633
+                    'recurrence_id' => 1467244800,
634
+                    'is_recurrence_exception' => false,
635
+                    'event_hash' => 'fbdb2726bc0f7dfacac1d881c1453e20',
636
+                    'alarm_hash' => 'ecacbf07d413c3c78d1ac7ad8c469602',
637
+                    'type' => 'EMAIL',
638
+                    'is_relative' => true,
639
+                    'notification_date' => 1467243900,
640
+                    'is_repeat_based' => false,
641
+                    'calendardata' => self::CALENDAR_DATA_RECURRING_REPEAT,
642
+                    'displayname' => 'Displayname 123',
643
+                    'principaluri' => 'principals/users/user001',
644
+                ],
645
+                [
646
+                    'id' => 5,
647
+                    'calendar_id' => 1337,
648
+                    'object_id' => 42,
649
+                    'uid' => 'wej2z68l9h',
650
+                    'is_recurring' => true,
651
+                    'recurrence_id' => 1467849600,
652
+                    'is_recurrence_exception' => false,
653
+                    'event_hash' => 'fbdb2726bc0f7dfacac1d881c1453e20',
654
+                    'alarm_hash' => '8996992118817f9f311ac5cc56d1cc97',
655
+                    'type' => 'EMAIL',
656
+                    'is_relative' => true,
657
+                    'notification_date' => 1467158400,
658
+                    'is_repeat_based' => false,
659
+                    'calendardata' => self::CALENDAR_DATA_RECURRING,
660
+                    'displayname' => 'Displayname 123',
661
+                    'principaluri' => 'principals/users/user001',
662
+                ]
663
+            ]);
664
+
665
+        $this->notificationProviderManager->expects($this->exactly(5))
666
+            ->method('hasProvider')
667
+            ->willReturnMap([
668
+                ['EMAIL', true],
669
+                ['DISPLAY', true],
670
+            ]);
671
+
672
+        $provider1 = $this->createMock(INotificationProvider::class);
673
+        $provider2 = $this->createMock(INotificationProvider::class);
674
+        $provider3 = $this->createMock(INotificationProvider::class);
675
+        $provider4 = $this->createMock(INotificationProvider::class);
676
+        $provider5 = $this->createMock(INotificationProvider::class);
677
+
678
+        $getProviderCalls = [
679
+            ['EMAIL', $provider1],
680
+            ['EMAIL', $provider2],
681
+            ['DISPLAY', $provider3],
682
+            ['EMAIL', $provider4],
683
+            ['EMAIL', $provider5],
684
+        ];
685
+        $this->notificationProviderManager->expects($this->exactly(count($getProviderCalls)))
686
+            ->method('getProvider')
687
+            ->willReturnCallback(function () use (&$getProviderCalls) {
688
+                $expected = array_shift($getProviderCalls);
689
+                $return = array_pop($expected);
690
+                $this->assertEquals($expected, func_get_args());
691
+                return $return;
692
+            });
693
+
694
+        $user = $this->createMock(IUser::class);
695
+        $this->userManager->expects($this->exactly(5))
696
+            ->method('get')
697
+            ->with('user001')
698
+            ->willReturn($user);
699
+
700
+        $provider1->expects($this->once())
701
+            ->method('send')
702
+            ->with($this->callback(function ($vevent) {
703
+                if ($vevent->DTSTART->getDateTime()->format(DateTime::ATOM) !== '2016-06-09T00:00:00+00:00') {
704
+                    return false;
705
+                }
706
+                return true;
707
+            }, 'Displayname 123', $user));
708
+        $provider2->expects($this->once())
709
+            ->method('send')
710
+            ->with($this->callback(function ($vevent) {
711
+                if ($vevent->DTSTART->getDateTime()->format(DateTime::ATOM) !== '2016-06-09T00:00:00+00:00') {
712
+                    return false;
713
+                }
714
+                return true;
715
+            }, 'Displayname 123', $user));
716
+        $provider3->expects($this->once())
717
+            ->method('send')
718
+            ->with($this->callback(function ($vevent) {
719
+                if ($vevent->DTSTART->getDateTime()->format(DateTime::ATOM) !== '2016-06-09T00:00:00+00:00') {
720
+                    return false;
721
+                }
722
+                return true;
723
+            }, 'Displayname 123', $user));
724
+        $provider4->expects($this->once())
725
+            ->method('send')
726
+            ->with($this->callback(function ($vevent) {
727
+                if ($vevent->DTSTART->getDateTime()->format(DateTime::ATOM) !== '2016-06-30T00:00:00+00:00') {
728
+                    return false;
729
+                }
730
+                return true;
731
+            }, 'Displayname 123', $user));
732
+        $provider5->expects($this->once())
733
+            ->method('send')
734
+            ->with($this->callback(function ($vevent) {
735
+                if ($vevent->DTSTART->getDateTime()->format(DateTime::ATOM) !== '2016-07-07T00:00:00+00:00') {
736
+                    return false;
737
+                }
738
+                return true;
739
+            }, 'Displayname 123', $user));
740
+
741
+        $removeReminderCalls = [
742
+            [1],
743
+            [2],
744
+            [3],
745
+            [4],
746
+            [5],
747
+        ];
748
+        $this->backend->expects($this->exactly(5))
749
+            ->method('removeReminder')
750
+            ->willReturnCallback(function () use (&$removeReminderCalls): void {
751
+                $expected = array_shift($removeReminderCalls);
752
+                $this->assertEquals($expected, func_get_args());
753
+            });
754
+
755
+
756
+        $insertReminderCalls = [
757
+            [1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467848700, false],
758
+            [1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467848820, true],
759
+            [1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467848940, true],
760
+            [1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467849060, true],
761
+            [1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467849180, true],
762
+            [1337, 42, 'wej2z68l9h', true, 1468454400, false, 'fbdb2726bc0f7dfacac1d881c1453e20', '8996992118817f9f311ac5cc56d1cc97', 'EMAIL', true, 1467763200, false],
763
+        ];
764
+        $this->backend->expects($this->exactly(count($insertReminderCalls)))
765
+            ->method('insertReminder')
766
+            ->willReturnCallback(function () use (&$insertReminderCalls) {
767
+                $expected = array_shift($insertReminderCalls);
768
+                $this->assertEquals($expected, func_get_args());
769
+                return 99;
770
+            });
771
+
772
+        $this->timeFactory->method('getDateTime')
773
+            ->willReturn(DateTime::createFromFormat(DateTime::ATOM, '2016-06-08T00:00:00+00:00'));
774
+
775
+        $this->reminderService->processReminders();
776
+    }
777 777
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 		];
291 291
 		$this->backend->expects($this->exactly(count($calls)))
292 292
 			->method('insertReminder')
293
-			->willReturnCallback(function () use (&$calls) {
293
+			->willReturnCallback(function() use (&$calls) {
294 294
 				$expected = array_shift($calls);
295 295
 				$this->assertEquals($expected, func_get_args());
296 296
 				return 1;
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 		];
359 359
 		$this->backend->expects($this->exactly(count($calls)))
360 360
 			->method('insertReminder')
361
-			->willReturnCallback(function () use (&$calls) {
361
+			->willReturnCallback(function() use (&$calls) {
362 362
 				$expected = array_shift($calls);
363 363
 				$this->assertEquals($expected, func_get_args());
364 364
 				return 1;
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
 		];
387 387
 		$this->backend->expects($this->exactly(count($calls)))
388 388
 			->method('insertReminder')
389
-			->willReturnCallback(function () use (&$calls) {
389
+			->willReturnCallback(function() use (&$calls) {
390 390
 				$expected = array_shift($calls);
391 391
 				$this->assertEquals($expected, func_get_args());
392 392
 				return 1;
@@ -518,7 +518,7 @@  discard block
 block discarded – undo
518 518
 		];
519 519
 		$this->backend->expects($this->exactly(count($calls)))
520 520
 			->method('insertReminder')
521
-			->willReturnCallback(function () use (&$calls) {
521
+			->willReturnCallback(function() use (&$calls) {
522 522
 				$expected = array_shift($calls);
523 523
 				$this->assertEquals($expected, func_get_args());
524 524
 				return 1;
@@ -684,7 +684,7 @@  discard block
 block discarded – undo
684 684
 		];
685 685
 		$this->notificationProviderManager->expects($this->exactly(count($getProviderCalls)))
686 686
 			->method('getProvider')
687
-			->willReturnCallback(function () use (&$getProviderCalls) {
687
+			->willReturnCallback(function() use (&$getProviderCalls) {
688 688
 				$expected = array_shift($getProviderCalls);
689 689
 				$return = array_pop($expected);
690 690
 				$this->assertEquals($expected, func_get_args());
@@ -699,7 +699,7 @@  discard block
 block discarded – undo
699 699
 
700 700
 		$provider1->expects($this->once())
701 701
 			->method('send')
702
-			->with($this->callback(function ($vevent) {
702
+			->with($this->callback(function($vevent) {
703 703
 				if ($vevent->DTSTART->getDateTime()->format(DateTime::ATOM) !== '2016-06-09T00:00:00+00:00') {
704 704
 					return false;
705 705
 				}
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
 			}, 'Displayname 123', $user));
708 708
 		$provider2->expects($this->once())
709 709
 			->method('send')
710
-			->with($this->callback(function ($vevent) {
710
+			->with($this->callback(function($vevent) {
711 711
 				if ($vevent->DTSTART->getDateTime()->format(DateTime::ATOM) !== '2016-06-09T00:00:00+00:00') {
712 712
 					return false;
713 713
 				}
@@ -715,7 +715,7 @@  discard block
 block discarded – undo
715 715
 			}, 'Displayname 123', $user));
716 716
 		$provider3->expects($this->once())
717 717
 			->method('send')
718
-			->with($this->callback(function ($vevent) {
718
+			->with($this->callback(function($vevent) {
719 719
 				if ($vevent->DTSTART->getDateTime()->format(DateTime::ATOM) !== '2016-06-09T00:00:00+00:00') {
720 720
 					return false;
721 721
 				}
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
 			}, 'Displayname 123', $user));
724 724
 		$provider4->expects($this->once())
725 725
 			->method('send')
726
-			->with($this->callback(function ($vevent) {
726
+			->with($this->callback(function($vevent) {
727 727
 				if ($vevent->DTSTART->getDateTime()->format(DateTime::ATOM) !== '2016-06-30T00:00:00+00:00') {
728 728
 					return false;
729 729
 				}
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
 			}, 'Displayname 123', $user));
732 732
 		$provider5->expects($this->once())
733 733
 			->method('send')
734
-			->with($this->callback(function ($vevent) {
734
+			->with($this->callback(function($vevent) {
735 735
 				if ($vevent->DTSTART->getDateTime()->format(DateTime::ATOM) !== '2016-07-07T00:00:00+00:00') {
736 736
 					return false;
737 737
 				}
@@ -747,7 +747,7 @@  discard block
 block discarded – undo
747 747
 		];
748 748
 		$this->backend->expects($this->exactly(5))
749 749
 			->method('removeReminder')
750
-			->willReturnCallback(function () use (&$removeReminderCalls): void {
750
+			->willReturnCallback(function() use (&$removeReminderCalls): void {
751 751
 				$expected = array_shift($removeReminderCalls);
752 752
 				$this->assertEquals($expected, func_get_args());
753 753
 			});
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
 		];
764 764
 		$this->backend->expects($this->exactly(count($insertReminderCalls)))
765 765
 			->method('insertReminder')
766
-			->willReturnCallback(function () use (&$insertReminderCalls) {
766
+			->willReturnCallback(function() use (&$insertReminderCalls) {
767 767
 				$expected = array_shift($insertReminderCalls);
768 768
 				$this->assertEquals($expected, func_get_args());
769 769
 				return 99;
Please login to merge, or discard this patch.
dav/tests/unit/CalDAV/Reminder/NotificationProvider/PushProviderTest.php 2 patches
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -16,158 +16,158 @@
 block discarded – undo
16 16
 use PHPUnit\Framework\MockObject\MockObject;
17 17
 
18 18
 class PushProviderTest extends AbstractNotificationProviderTestCase {
19
-	private IManager&MockObject $manager;
20
-	private ITimeFactory&MockObject $timeFactory;
21
-
22
-	protected function setUp(): void {
23
-		parent::setUp();
24
-
25
-		$this->manager = $this->createMock(IManager::class);
26
-		$this->timeFactory = $this->createMock(ITimeFactory::class);
27
-
28
-		$this->provider = new PushProvider(
29
-			$this->config,
30
-			$this->manager,
31
-			$this->logger,
32
-			$this->l10nFactory,
33
-			$this->urlGenerator,
34
-			$this->timeFactory
35
-		);
36
-	}
37
-
38
-	public function testNotificationType():void {
39
-		$this->assertEquals(PushProvider::NOTIFICATION_TYPE, 'DISPLAY');
40
-	}
41
-
42
-	public function testNotSend(): void {
43
-		$this->config->expects($this->once())
44
-			->method('getAppValue')
45
-			->with('dav', 'sendEventRemindersPush', 'yes')
46
-			->willReturn('no');
47
-
48
-		$this->manager->expects($this->never())
49
-			->method('createNotification');
50
-		$this->manager->expects($this->never())
51
-			->method('notify');
52
-
53
-		$user1 = $this->createMock(IUser::class);
54
-		$user1->method('getUID')
55
-			->willReturn('uid1');
56
-		$user2 = $this->createMock(IUser::class);
57
-		$user2->method('getUID')
58
-			->willReturn('uid2');
59
-		$user3 = $this->createMock(IUser::class);
60
-		$user3->method('getUID')
61
-			->willReturn('uid3');
62
-
63
-		$users = [$user1, $user2, $user3];
64
-
65
-		$this->provider->send($this->vcalendar->VEVENT, $this->calendarDisplayName, [], $users);
66
-	}
67
-
68
-	public function testSend(): void {
69
-		$this->config->expects($this->once())
70
-			->method('getAppValue')
71
-			->with('dav', 'sendEventRemindersPush', 'yes')
72
-			->willReturn('yes');
73
-
74
-		$user1 = $this->createMock(IUser::class);
75
-		$user1->method('getUID')
76
-			->willReturn('uid1');
77
-		$user2 = $this->createMock(IUser::class);
78
-		$user2->method('getUID')
79
-			->willReturn('uid2');
80
-		$user3 = $this->createMock(IUser::class);
81
-		$user3->method('getUID')
82
-			->willReturn('uid3');
83
-
84
-		$users = [$user1, $user2, $user3];
85
-
86
-		$dateTime = new \DateTime('@946684800');
87
-		$this->timeFactory->method('getDateTime')
88
-			->with()
89
-			->willReturn($dateTime);
90
-
91
-		$notification1 = $this->createNotificationMock('uid1', $dateTime);
92
-		$notification2 = $this->createNotificationMock('uid2', $dateTime);
93
-		$notification3 = $this->createNotificationMock('uid3', $dateTime);
94
-
95
-		$this->manager->expects($this->exactly(3))
96
-			->method('createNotification')
97
-			->willReturnOnConsecutiveCalls(
98
-				$notification1,
99
-				$notification2,
100
-				$notification3
101
-			);
102
-
103
-		$calls = [
104
-			$notification1,
105
-			$notification2,
106
-			$notification3,
107
-		];
108
-		$this->manager->expects($this->exactly(3))
109
-			->method('notify')
110
-			->willReturnCallback(function ($notification) use (&$calls): void {
111
-				$expected = array_shift($calls);
112
-				$this->assertEquals($expected, $notification);
113
-			});
114
-
115
-		$this->provider->send($this->vcalendar->VEVENT, $this->calendarDisplayName, [], $users);
116
-	}
117
-
118
-	/**
119
-	 * @param string $uid
120
-	 * @param \DateTime $dt
121
-	 */
122
-	private function createNotificationMock(string $uid, \DateTime $dt):INotification {
123
-		$notification = $this->createMock(INotification::class);
124
-		$notification
125
-			->expects($this->once())
126
-			->method('setApp')
127
-			->with('dav')
128
-			->willReturn($notification);
129
-
130
-		$notification->expects($this->once())
131
-			->method('setUser')
132
-			->with($uid)
133
-			->willReturn($notification);
134
-
135
-		$notification->expects($this->once())
136
-			->method('setDateTime')
137
-			->with($dt)
138
-			->willReturn($notification);
139
-
140
-		$notification->expects($this->once())
141
-			->method('setObject')
142
-			->with('dav', hash('sha256', 'uid1234', false))
143
-			->willReturn($notification);
144
-
145
-		$notification->expects($this->once())
146
-			->method('setSubject')
147
-			->with('calendar_reminder', [
148
-				'title' => 'Fellowship meeting',
149
-				'start_atom' => '2017-01-01T00:00:00+00:00',
150
-			])
151
-			->willReturn($notification);
152
-
153
-		$notification
154
-			->expects($this->once())
155
-			->method('setMessage')
156
-			->with('calendar_reminder', [
157
-				'title' => 'Fellowship meeting',
158
-				'start_atom' => '2017-01-01T00:00:00+00:00',
159
-				'description' => null,
160
-				'location' => null,
161
-				'all_day' => false,
162
-				'start_is_floating' => false,
163
-				'start_timezone' => 'UTC',
164
-				'end_atom' => '2017-01-01T00:00:00+00:00',
165
-				'end_is_floating' => false,
166
-				'end_timezone' => 'UTC',
167
-				'calendar_displayname' => 'Personal',
168
-			])
169
-			->willReturn($notification);
170
-
171
-		return $notification;
172
-	}
19
+    private IManager&MockObject $manager;
20
+    private ITimeFactory&MockObject $timeFactory;
21
+
22
+    protected function setUp(): void {
23
+        parent::setUp();
24
+
25
+        $this->manager = $this->createMock(IManager::class);
26
+        $this->timeFactory = $this->createMock(ITimeFactory::class);
27
+
28
+        $this->provider = new PushProvider(
29
+            $this->config,
30
+            $this->manager,
31
+            $this->logger,
32
+            $this->l10nFactory,
33
+            $this->urlGenerator,
34
+            $this->timeFactory
35
+        );
36
+    }
37
+
38
+    public function testNotificationType():void {
39
+        $this->assertEquals(PushProvider::NOTIFICATION_TYPE, 'DISPLAY');
40
+    }
41
+
42
+    public function testNotSend(): void {
43
+        $this->config->expects($this->once())
44
+            ->method('getAppValue')
45
+            ->with('dav', 'sendEventRemindersPush', 'yes')
46
+            ->willReturn('no');
47
+
48
+        $this->manager->expects($this->never())
49
+            ->method('createNotification');
50
+        $this->manager->expects($this->never())
51
+            ->method('notify');
52
+
53
+        $user1 = $this->createMock(IUser::class);
54
+        $user1->method('getUID')
55
+            ->willReturn('uid1');
56
+        $user2 = $this->createMock(IUser::class);
57
+        $user2->method('getUID')
58
+            ->willReturn('uid2');
59
+        $user3 = $this->createMock(IUser::class);
60
+        $user3->method('getUID')
61
+            ->willReturn('uid3');
62
+
63
+        $users = [$user1, $user2, $user3];
64
+
65
+        $this->provider->send($this->vcalendar->VEVENT, $this->calendarDisplayName, [], $users);
66
+    }
67
+
68
+    public function testSend(): void {
69
+        $this->config->expects($this->once())
70
+            ->method('getAppValue')
71
+            ->with('dav', 'sendEventRemindersPush', 'yes')
72
+            ->willReturn('yes');
73
+
74
+        $user1 = $this->createMock(IUser::class);
75
+        $user1->method('getUID')
76
+            ->willReturn('uid1');
77
+        $user2 = $this->createMock(IUser::class);
78
+        $user2->method('getUID')
79
+            ->willReturn('uid2');
80
+        $user3 = $this->createMock(IUser::class);
81
+        $user3->method('getUID')
82
+            ->willReturn('uid3');
83
+
84
+        $users = [$user1, $user2, $user3];
85
+
86
+        $dateTime = new \DateTime('@946684800');
87
+        $this->timeFactory->method('getDateTime')
88
+            ->with()
89
+            ->willReturn($dateTime);
90
+
91
+        $notification1 = $this->createNotificationMock('uid1', $dateTime);
92
+        $notification2 = $this->createNotificationMock('uid2', $dateTime);
93
+        $notification3 = $this->createNotificationMock('uid3', $dateTime);
94
+
95
+        $this->manager->expects($this->exactly(3))
96
+            ->method('createNotification')
97
+            ->willReturnOnConsecutiveCalls(
98
+                $notification1,
99
+                $notification2,
100
+                $notification3
101
+            );
102
+
103
+        $calls = [
104
+            $notification1,
105
+            $notification2,
106
+            $notification3,
107
+        ];
108
+        $this->manager->expects($this->exactly(3))
109
+            ->method('notify')
110
+            ->willReturnCallback(function ($notification) use (&$calls): void {
111
+                $expected = array_shift($calls);
112
+                $this->assertEquals($expected, $notification);
113
+            });
114
+
115
+        $this->provider->send($this->vcalendar->VEVENT, $this->calendarDisplayName, [], $users);
116
+    }
117
+
118
+    /**
119
+     * @param string $uid
120
+     * @param \DateTime $dt
121
+     */
122
+    private function createNotificationMock(string $uid, \DateTime $dt):INotification {
123
+        $notification = $this->createMock(INotification::class);
124
+        $notification
125
+            ->expects($this->once())
126
+            ->method('setApp')
127
+            ->with('dav')
128
+            ->willReturn($notification);
129
+
130
+        $notification->expects($this->once())
131
+            ->method('setUser')
132
+            ->with($uid)
133
+            ->willReturn($notification);
134
+
135
+        $notification->expects($this->once())
136
+            ->method('setDateTime')
137
+            ->with($dt)
138
+            ->willReturn($notification);
139
+
140
+        $notification->expects($this->once())
141
+            ->method('setObject')
142
+            ->with('dav', hash('sha256', 'uid1234', false))
143
+            ->willReturn($notification);
144
+
145
+        $notification->expects($this->once())
146
+            ->method('setSubject')
147
+            ->with('calendar_reminder', [
148
+                'title' => 'Fellowship meeting',
149
+                'start_atom' => '2017-01-01T00:00:00+00:00',
150
+            ])
151
+            ->willReturn($notification);
152
+
153
+        $notification
154
+            ->expects($this->once())
155
+            ->method('setMessage')
156
+            ->with('calendar_reminder', [
157
+                'title' => 'Fellowship meeting',
158
+                'start_atom' => '2017-01-01T00:00:00+00:00',
159
+                'description' => null,
160
+                'location' => null,
161
+                'all_day' => false,
162
+                'start_is_floating' => false,
163
+                'start_timezone' => 'UTC',
164
+                'end_atom' => '2017-01-01T00:00:00+00:00',
165
+                'end_is_floating' => false,
166
+                'end_timezone' => 'UTC',
167
+                'calendar_displayname' => 'Personal',
168
+            ])
169
+            ->willReturn($notification);
170
+
171
+        return $notification;
172
+    }
173 173
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -107,7 +107,7 @@
 block discarded – undo
107 107
 		];
108 108
 		$this->manager->expects($this->exactly(3))
109 109
 			->method('notify')
110
-			->willReturnCallback(function ($notification) use (&$calls): void {
110
+			->willReturnCallback(function($notification) use (&$calls): void {
111 111
 				$expected = array_shift($calls);
112 112
 				$this->assertEquals($expected, $notification);
113 113
 			});
Please login to merge, or discard this patch.
apps/dav/tests/unit/BackgroundJob/UserStatusAutomationTest.php 1 patch
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -29,93 +29,93 @@  discard block
 block discarded – undo
29 29
  * @group DB
30 30
  */
31 31
 class UserStatusAutomationTest extends TestCase {
32
-	protected ITimeFactory&MockObject $time;
33
-	protected IJobList&MockObject $jobList;
34
-	protected LoggerInterface&MockObject $logger;
35
-	protected IManager&MockObject $statusManager;
36
-	protected IConfig&MockObject $config;
37
-	private IAvailabilityCoordinator&MockObject $coordinator;
38
-	private IUserManager&MockObject $userManager;
39
-
40
-	protected function setUp(): void {
41
-		parent::setUp();
42
-
43
-		$this->time = $this->createMock(ITimeFactory::class);
44
-		$this->jobList = $this->createMock(IJobList::class);
45
-		$this->logger = $this->createMock(LoggerInterface::class);
46
-		$this->statusManager = $this->createMock(IManager::class);
47
-		$this->config = $this->createMock(IConfig::class);
48
-		$this->coordinator = $this->createMock(IAvailabilityCoordinator::class);
49
-		$this->userManager = $this->createMock(IUserManager::class);
50
-
51
-	}
52
-
53
-	protected function getAutomationMock(array $methods): MockObject|UserStatusAutomation {
54
-		if (empty($methods)) {
55
-			return new UserStatusAutomation(
56
-				$this->time,
57
-				Server::get(IDBConnection::class),
58
-				$this->jobList,
59
-				$this->logger,
60
-				$this->statusManager,
61
-				$this->config,
62
-				$this->coordinator,
63
-				$this->userManager,
64
-			);
65
-		}
66
-
67
-		return $this->getMockBuilder(UserStatusAutomation::class)
68
-			->setConstructorArgs([
69
-				$this->time,
70
-				Server::get(IDBConnection::class),
71
-				$this->jobList,
72
-				$this->logger,
73
-				$this->statusManager,
74
-				$this->config,
75
-				$this->coordinator,
76
-				$this->userManager,
77
-			])
78
-			->onlyMethods($methods)
79
-			->getMock();
80
-	}
81
-
82
-	public static function dataRun(): array {
83
-		return [
84
-			['20230217', '2023-02-24 10:49:36.613834', true],
85
-			['20230224', '2023-02-24 10:49:36.613834', true],
86
-			['20230217', '2023-02-24 13:58:24.479357', false],
87
-			['20230224', '2023-02-24 13:58:24.479357', false],
88
-		];
89
-	}
90
-
91
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataRun')]
92
-	public function testRunNoOOO(string $ruleDay, string $currentTime, bool $isAvailable): void {
93
-		$user = $this->createConfiguredMock(IUser::class, [
94
-			'getUID' => 'user'
95
-		]);
96
-
97
-		$this->userManager->expects(self::once())
98
-			->method('get')
99
-			->willReturn($user);
100
-		$this->coordinator->expects(self::once())
101
-			->method('getCurrentOutOfOfficeData')
102
-			->willReturn(null);
103
-		$this->config->method('getUserValue')
104
-			->with('user', 'dav', 'user_status_automation', 'no')
105
-			->willReturn('yes');
106
-		$this->time->method('getDateTime')
107
-			->willReturn(new \DateTime($currentTime, new \DateTimeZone('UTC')));
108
-		$this->logger->expects(self::exactly(4))
109
-			->method('debug');
110
-		if (!$isAvailable) {
111
-			$this->statusManager->expects(self::once())
112
-				->method('setUserStatus')
113
-				->with('user', IUserStatus::MESSAGE_AVAILABILITY, IUserStatus::DND, true);
114
-		}
115
-		$automation = $this->getAutomationMock(['getAvailabilityFromPropertiesTable']);
116
-		$automation->method('getAvailabilityFromPropertiesTable')
117
-			->with('user')
118
-			->willReturn('BEGIN:VCALENDAR
32
+    protected ITimeFactory&MockObject $time;
33
+    protected IJobList&MockObject $jobList;
34
+    protected LoggerInterface&MockObject $logger;
35
+    protected IManager&MockObject $statusManager;
36
+    protected IConfig&MockObject $config;
37
+    private IAvailabilityCoordinator&MockObject $coordinator;
38
+    private IUserManager&MockObject $userManager;
39
+
40
+    protected function setUp(): void {
41
+        parent::setUp();
42
+
43
+        $this->time = $this->createMock(ITimeFactory::class);
44
+        $this->jobList = $this->createMock(IJobList::class);
45
+        $this->logger = $this->createMock(LoggerInterface::class);
46
+        $this->statusManager = $this->createMock(IManager::class);
47
+        $this->config = $this->createMock(IConfig::class);
48
+        $this->coordinator = $this->createMock(IAvailabilityCoordinator::class);
49
+        $this->userManager = $this->createMock(IUserManager::class);
50
+
51
+    }
52
+
53
+    protected function getAutomationMock(array $methods): MockObject|UserStatusAutomation {
54
+        if (empty($methods)) {
55
+            return new UserStatusAutomation(
56
+                $this->time,
57
+                Server::get(IDBConnection::class),
58
+                $this->jobList,
59
+                $this->logger,
60
+                $this->statusManager,
61
+                $this->config,
62
+                $this->coordinator,
63
+                $this->userManager,
64
+            );
65
+        }
66
+
67
+        return $this->getMockBuilder(UserStatusAutomation::class)
68
+            ->setConstructorArgs([
69
+                $this->time,
70
+                Server::get(IDBConnection::class),
71
+                $this->jobList,
72
+                $this->logger,
73
+                $this->statusManager,
74
+                $this->config,
75
+                $this->coordinator,
76
+                $this->userManager,
77
+            ])
78
+            ->onlyMethods($methods)
79
+            ->getMock();
80
+    }
81
+
82
+    public static function dataRun(): array {
83
+        return [
84
+            ['20230217', '2023-02-24 10:49:36.613834', true],
85
+            ['20230224', '2023-02-24 10:49:36.613834', true],
86
+            ['20230217', '2023-02-24 13:58:24.479357', false],
87
+            ['20230224', '2023-02-24 13:58:24.479357', false],
88
+        ];
89
+    }
90
+
91
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataRun')]
92
+    public function testRunNoOOO(string $ruleDay, string $currentTime, bool $isAvailable): void {
93
+        $user = $this->createConfiguredMock(IUser::class, [
94
+            'getUID' => 'user'
95
+        ]);
96
+
97
+        $this->userManager->expects(self::once())
98
+            ->method('get')
99
+            ->willReturn($user);
100
+        $this->coordinator->expects(self::once())
101
+            ->method('getCurrentOutOfOfficeData')
102
+            ->willReturn(null);
103
+        $this->config->method('getUserValue')
104
+            ->with('user', 'dav', 'user_status_automation', 'no')
105
+            ->willReturn('yes');
106
+        $this->time->method('getDateTime')
107
+            ->willReturn(new \DateTime($currentTime, new \DateTimeZone('UTC')));
108
+        $this->logger->expects(self::exactly(4))
109
+            ->method('debug');
110
+        if (!$isAvailable) {
111
+            $this->statusManager->expects(self::once())
112
+                ->method('setUserStatus')
113
+                ->with('user', IUserStatus::MESSAGE_AVAILABILITY, IUserStatus::DND, true);
114
+        }
115
+        $automation = $this->getAutomationMock(['getAvailabilityFromPropertiesTable']);
116
+        $automation->method('getAvailabilityFromPropertiesTable')
117
+            ->with('user')
118
+            ->willReturn('BEGIN:VCALENDAR
119 119
 PRODID:Nextcloud DAV app
120 120
 BEGIN:VTIMEZONE
121 121
 TZID:Europe/Berlin
@@ -150,71 +150,71 @@  discard block
 block discarded – undo
150 150
 END:VAVAILABILITY
151 151
 END:VCALENDAR');
152 152
 
153
-		self::invokePrivate($automation, 'run', [['userId' => 'user']]);
154
-	}
155
-
156
-	public function testRunNoAvailabilityNoOOO(): void {
157
-		$user = $this->createConfiguredMock(IUser::class, [
158
-			'getUID' => 'user'
159
-		]);
160
-
161
-		$this->userManager->expects(self::once())
162
-			->method('get')
163
-			->willReturn($user);
164
-		$this->coordinator->expects(self::once())
165
-			->method('getCurrentOutOfOfficeData')
166
-			->willReturn(null);
167
-		$this->config->method('getUserValue')
168
-			->with('user', 'dav', 'user_status_automation', 'no')
169
-			->willReturn('yes');
170
-		$this->time->method('getDateTime')
171
-			->willReturn(new \DateTime('2023-02-24 13:58:24.479357', new \DateTimeZone('UTC')));
172
-		$this->jobList->expects($this->once())
173
-			->method('remove')
174
-			->with(UserStatusAutomation::class, ['userId' => 'user']);
175
-		$this->logger->expects(self::once())
176
-			->method('debug');
177
-		$this->logger->expects(self::once())
178
-			->method('info');
179
-		$automation = $this->getAutomationMock(['getAvailabilityFromPropertiesTable']);
180
-		$automation->method('getAvailabilityFromPropertiesTable')
181
-			->with('user')
182
-			->willReturn(false);
183
-
184
-		self::invokePrivate($automation, 'run', [['userId' => 'user']]);
185
-	}
186
-
187
-	public function testRunNoAvailabilityWithOOO(): void {
188
-		$user = $this->createConfiguredMock(IUser::class, [
189
-			'getUID' => 'user'
190
-		]);
191
-		$ooo = $this->createConfiguredMock(OutOfOfficeData::class, [
192
-			'getShortMessage' => 'On Vacation',
193
-			'getEndDate' => 123456,
194
-		]);
195
-
196
-		$this->userManager->expects(self::once())
197
-			->method('get')
198
-			->willReturn($user);
199
-		$this->coordinator->expects(self::once())
200
-			->method('getCurrentOutOfOfficeData')
201
-			->willReturn($ooo);
202
-		$this->coordinator->expects(self::once())
203
-			->method('isInEffect')
204
-			->willReturn(true);
205
-		$this->statusManager->expects(self::once())
206
-			->method('setUserStatus')
207
-			->with('user', IUserStatus::MESSAGE_OUT_OF_OFFICE, IUserStatus::DND, true, $ooo->getShortMessage());
208
-		$this->config->expects(self::never())
209
-			->method('getUserValue');
210
-		$this->time->method('getDateTime')
211
-			->willReturn(new \DateTime('2023-02-24 13:58:24.479357', new \DateTimeZone('UTC')));
212
-		$this->jobList->expects($this->never())
213
-			->method('remove');
214
-		$this->logger->expects(self::exactly(2))
215
-			->method('debug');
216
-		$automation = $this->getAutomationMock([]);
217
-
218
-		self::invokePrivate($automation, 'run', [['userId' => 'user']]);
219
-	}
153
+        self::invokePrivate($automation, 'run', [['userId' => 'user']]);
154
+    }
155
+
156
+    public function testRunNoAvailabilityNoOOO(): void {
157
+        $user = $this->createConfiguredMock(IUser::class, [
158
+            'getUID' => 'user'
159
+        ]);
160
+
161
+        $this->userManager->expects(self::once())
162
+            ->method('get')
163
+            ->willReturn($user);
164
+        $this->coordinator->expects(self::once())
165
+            ->method('getCurrentOutOfOfficeData')
166
+            ->willReturn(null);
167
+        $this->config->method('getUserValue')
168
+            ->with('user', 'dav', 'user_status_automation', 'no')
169
+            ->willReturn('yes');
170
+        $this->time->method('getDateTime')
171
+            ->willReturn(new \DateTime('2023-02-24 13:58:24.479357', new \DateTimeZone('UTC')));
172
+        $this->jobList->expects($this->once())
173
+            ->method('remove')
174
+            ->with(UserStatusAutomation::class, ['userId' => 'user']);
175
+        $this->logger->expects(self::once())
176
+            ->method('debug');
177
+        $this->logger->expects(self::once())
178
+            ->method('info');
179
+        $automation = $this->getAutomationMock(['getAvailabilityFromPropertiesTable']);
180
+        $automation->method('getAvailabilityFromPropertiesTable')
181
+            ->with('user')
182
+            ->willReturn(false);
183
+
184
+        self::invokePrivate($automation, 'run', [['userId' => 'user']]);
185
+    }
186
+
187
+    public function testRunNoAvailabilityWithOOO(): void {
188
+        $user = $this->createConfiguredMock(IUser::class, [
189
+            'getUID' => 'user'
190
+        ]);
191
+        $ooo = $this->createConfiguredMock(OutOfOfficeData::class, [
192
+            'getShortMessage' => 'On Vacation',
193
+            'getEndDate' => 123456,
194
+        ]);
195
+
196
+        $this->userManager->expects(self::once())
197
+            ->method('get')
198
+            ->willReturn($user);
199
+        $this->coordinator->expects(self::once())
200
+            ->method('getCurrentOutOfOfficeData')
201
+            ->willReturn($ooo);
202
+        $this->coordinator->expects(self::once())
203
+            ->method('isInEffect')
204
+            ->willReturn(true);
205
+        $this->statusManager->expects(self::once())
206
+            ->method('setUserStatus')
207
+            ->with('user', IUserStatus::MESSAGE_OUT_OF_OFFICE, IUserStatus::DND, true, $ooo->getShortMessage());
208
+        $this->config->expects(self::never())
209
+            ->method('getUserValue');
210
+        $this->time->method('getDateTime')
211
+            ->willReturn(new \DateTime('2023-02-24 13:58:24.479357', new \DateTimeZone('UTC')));
212
+        $this->jobList->expects($this->never())
213
+            ->method('remove');
214
+        $this->logger->expects(self::exactly(2))
215
+            ->method('debug');
216
+        $automation = $this->getAutomationMock([]);
217
+
218
+        self::invokePrivate($automation, 'run', [['userId' => 'user']]);
219
+    }
220 220
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/BackgroundJob/PruneOutdatedSyncTokensJobTest.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -20,63 +20,63 @@
 block discarded – undo
20 20
 use Test\TestCase;
21 21
 
22 22
 class PruneOutdatedSyncTokensJobTest extends TestCase {
23
-	private ITimeFactory&MockObject $timeFactory;
24
-	private CalDavBackend&MockObject $calDavBackend;
25
-	private CardDavBackend&MockObject $cardDavBackend;
26
-	private IConfig&MockObject $config;
27
-	private LoggerInterface&MockObject $logger;
28
-	private PruneOutdatedSyncTokensJob $backgroundJob;
23
+    private ITimeFactory&MockObject $timeFactory;
24
+    private CalDavBackend&MockObject $calDavBackend;
25
+    private CardDavBackend&MockObject $cardDavBackend;
26
+    private IConfig&MockObject $config;
27
+    private LoggerInterface&MockObject $logger;
28
+    private PruneOutdatedSyncTokensJob $backgroundJob;
29 29
 
30
-	protected function setUp(): void {
31
-		parent::setUp();
30
+    protected function setUp(): void {
31
+        parent::setUp();
32 32
 
33
-		$this->timeFactory = $this->createMock(ITimeFactory::class);
34
-		$this->calDavBackend = $this->createMock(CalDavBackend::class);
35
-		$this->cardDavBackend = $this->createMock(CardDavBackend::class);
36
-		$this->config = $this->createMock(IConfig::class);
37
-		$this->logger = $this->createMock(LoggerInterface::class);
33
+        $this->timeFactory = $this->createMock(ITimeFactory::class);
34
+        $this->calDavBackend = $this->createMock(CalDavBackend::class);
35
+        $this->cardDavBackend = $this->createMock(CardDavBackend::class);
36
+        $this->config = $this->createMock(IConfig::class);
37
+        $this->logger = $this->createMock(LoggerInterface::class);
38 38
 
39
-		$this->backgroundJob = new PruneOutdatedSyncTokensJob($this->timeFactory, $this->calDavBackend, $this->cardDavBackend, $this->config, $this->logger);
40
-	}
39
+        $this->backgroundJob = new PruneOutdatedSyncTokensJob($this->timeFactory, $this->calDavBackend, $this->cardDavBackend, $this->config, $this->logger);
40
+    }
41 41
 
42
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataForTestRun')]
43
-	public function testRun(string $configToKeep, string $configRetentionDays, int $actualLimit, int $retentionDays, int $deletedCalendarSyncTokens, int $deletedAddressBookSyncTokens): void {
44
-		$this->config->expects($this->exactly(2))
45
-			->method('getAppValue')
46
-			->with(Application::APP_ID, self::anything(), self::anything())
47
-			->willReturnCallback(function ($app, $key) use ($configToKeep, $configRetentionDays) {
48
-				switch ($key) {
49
-					case 'totalNumberOfSyncTokensToKeep':
50
-						return $configToKeep;
51
-					case 'syncTokensRetentionDays':
52
-						return $configRetentionDays;
53
-					default:
54
-						throw new InvalidArgumentException();
55
-				}
56
-			});
57
-		$this->calDavBackend->expects($this->once())
58
-			->method('pruneOutdatedSyncTokens')
59
-			->with($actualLimit)
60
-			->willReturn($deletedCalendarSyncTokens);
61
-		$this->cardDavBackend->expects($this->once())
62
-			->method('pruneOutdatedSyncTokens')
63
-			->with($actualLimit, $retentionDays)
64
-			->willReturn($deletedAddressBookSyncTokens);
65
-		$this->logger->expects($this->once())
66
-			->method('info')
67
-			->with('Pruned {calendarSyncTokensNumber} calendar sync tokens and {addressBooksSyncTokensNumber} address book sync tokens', [
68
-				'calendarSyncTokensNumber' => $deletedCalendarSyncTokens,
69
-				'addressBooksSyncTokensNumber' => $deletedAddressBookSyncTokens
70
-			]);
42
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataForTestRun')]
43
+    public function testRun(string $configToKeep, string $configRetentionDays, int $actualLimit, int $retentionDays, int $deletedCalendarSyncTokens, int $deletedAddressBookSyncTokens): void {
44
+        $this->config->expects($this->exactly(2))
45
+            ->method('getAppValue')
46
+            ->with(Application::APP_ID, self::anything(), self::anything())
47
+            ->willReturnCallback(function ($app, $key) use ($configToKeep, $configRetentionDays) {
48
+                switch ($key) {
49
+                    case 'totalNumberOfSyncTokensToKeep':
50
+                        return $configToKeep;
51
+                    case 'syncTokensRetentionDays':
52
+                        return $configRetentionDays;
53
+                    default:
54
+                        throw new InvalidArgumentException();
55
+                }
56
+            });
57
+        $this->calDavBackend->expects($this->once())
58
+            ->method('pruneOutdatedSyncTokens')
59
+            ->with($actualLimit)
60
+            ->willReturn($deletedCalendarSyncTokens);
61
+        $this->cardDavBackend->expects($this->once())
62
+            ->method('pruneOutdatedSyncTokens')
63
+            ->with($actualLimit, $retentionDays)
64
+            ->willReturn($deletedAddressBookSyncTokens);
65
+        $this->logger->expects($this->once())
66
+            ->method('info')
67
+            ->with('Pruned {calendarSyncTokensNumber} calendar sync tokens and {addressBooksSyncTokensNumber} address book sync tokens', [
68
+                'calendarSyncTokensNumber' => $deletedCalendarSyncTokens,
69
+                'addressBooksSyncTokensNumber' => $deletedAddressBookSyncTokens
70
+            ]);
71 71
 
72
-		$this->backgroundJob->run(null);
73
-	}
72
+        $this->backgroundJob->run(null);
73
+    }
74 74
 
75
-	public static function dataForTestRun(): array {
76
-		return [
77
-			['100', '2', 100, 7 * 24 * 3600, 2, 3],
78
-			['100', '14', 100, 14 * 24 * 3600, 2, 3],
79
-			['0', '60', 1, 60 * 24 * 3600, 0, 0]
80
-		];
81
-	}
75
+    public static function dataForTestRun(): array {
76
+        return [
77
+            ['100', '2', 100, 7 * 24 * 3600, 2, 3],
78
+            ['100', '14', 100, 14 * 24 * 3600, 2, 3],
79
+            ['0', '60', 1, 60 * 24 * 3600, 0, 0]
80
+        ];
81
+    }
82 82
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/BackgroundJob/EventReminderJobTest.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -16,57 +16,57 @@
 block discarded – undo
16 16
 use Test\TestCase;
17 17
 
18 18
 class EventReminderJobTest extends TestCase {
19
-	private ITimeFactory&MockObject $time;
20
-	private ReminderService&MockObject $reminderService;
21
-	private IConfig&MockObject $config;
22
-	private EventReminderJob $backgroundJob;
19
+    private ITimeFactory&MockObject $time;
20
+    private ReminderService&MockObject $reminderService;
21
+    private IConfig&MockObject $config;
22
+    private EventReminderJob $backgroundJob;
23 23
 
24
-	protected function setUp(): void {
25
-		parent::setUp();
24
+    protected function setUp(): void {
25
+        parent::setUp();
26 26
 
27
-		$this->time = $this->createMock(ITimeFactory::class);
28
-		$this->reminderService = $this->createMock(ReminderService::class);
29
-		$this->config = $this->createMock(IConfig::class);
27
+        $this->time = $this->createMock(ITimeFactory::class);
28
+        $this->reminderService = $this->createMock(ReminderService::class);
29
+        $this->config = $this->createMock(IConfig::class);
30 30
 
31
-		$this->backgroundJob = new EventReminderJob(
32
-			$this->time,
33
-			$this->reminderService,
34
-			$this->config,
35
-		);
36
-	}
31
+        $this->backgroundJob = new EventReminderJob(
32
+            $this->time,
33
+            $this->reminderService,
34
+            $this->config,
35
+        );
36
+    }
37 37
 
38
-	public static function data(): array {
39
-		return [
40
-			[true, true, true],
41
-			[true, false, false],
42
-			[false, true, false],
43
-			[false, false, false],
44
-		];
45
-	}
38
+    public static function data(): array {
39
+        return [
40
+            [true, true, true],
41
+            [true, false, false],
42
+            [false, true, false],
43
+            [false, false, false],
44
+        ];
45
+    }
46 46
 
47
-	/**
48
-	 *
49
-	 * @param bool $sendEventReminders
50
-	 * @param bool $sendEventRemindersMode
51
-	 * @param bool $expectCall
52
-	 */
53
-	#[\PHPUnit\Framework\Attributes\DataProvider('data')]
54
-	public function testRun(bool $sendEventReminders, bool $sendEventRemindersMode, bool $expectCall): void {
55
-		$this->config->expects($this->exactly($sendEventReminders ? 2 : 1))
56
-			->method('getAppValue')
57
-			->willReturnMap([
58
-				['dav', 'sendEventReminders', 'yes', ($sendEventReminders ? 'yes' : 'no')],
59
-				['dav', 'sendEventRemindersMode', 'backgroundjob', ($sendEventRemindersMode ? 'backgroundjob' : 'cron')],
60
-			]);
47
+    /**
48
+     *
49
+     * @param bool $sendEventReminders
50
+     * @param bool $sendEventRemindersMode
51
+     * @param bool $expectCall
52
+     */
53
+    #[\PHPUnit\Framework\Attributes\DataProvider('data')]
54
+    public function testRun(bool $sendEventReminders, bool $sendEventRemindersMode, bool $expectCall): void {
55
+        $this->config->expects($this->exactly($sendEventReminders ? 2 : 1))
56
+            ->method('getAppValue')
57
+            ->willReturnMap([
58
+                ['dav', 'sendEventReminders', 'yes', ($sendEventReminders ? 'yes' : 'no')],
59
+                ['dav', 'sendEventRemindersMode', 'backgroundjob', ($sendEventRemindersMode ? 'backgroundjob' : 'cron')],
60
+            ]);
61 61
 
62
-		if ($expectCall) {
63
-			$this->reminderService->expects($this->once())
64
-				->method('processReminders');
65
-		} else {
66
-			$this->reminderService->expects($this->never())
67
-				->method('processReminders');
68
-		}
62
+        if ($expectCall) {
63
+            $this->reminderService->expects($this->once())
64
+                ->method('processReminders');
65
+        } else {
66
+            $this->reminderService->expects($this->never())
67
+                ->method('processReminders');
68
+        }
69 69
 
70
-		$this->backgroundJob->run([]);
71
-	}
70
+        $this->backgroundJob->run([]);
71
+    }
72 72
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php 1 patch
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -19,78 +19,78 @@
 block discarded – undo
19 19
 use Test\TestCase;
20 20
 
21 21
 class RefreshWebcalJobTest extends TestCase {
22
-	private RefreshWebcalService&MockObject $refreshWebcalService;
23
-	private IConfig&MockObject $config;
24
-	private LoggerInterface $logger;
25
-	private ITimeFactory&MockObject $timeFactory;
26
-	private IJobList&MockObject $jobList;
27
-
28
-	protected function setUp(): void {
29
-		parent::setUp();
30
-
31
-		$this->refreshWebcalService = $this->createMock(RefreshWebcalService::class);
32
-		$this->config = $this->createMock(IConfig::class);
33
-		$this->logger = $this->createMock(LoggerInterface::class);
34
-		$this->timeFactory = $this->createMock(ITimeFactory::class);
35
-
36
-		$this->jobList = $this->createMock(IJobList::class);
37
-	}
38
-
39
-	/**
40
-	 *
41
-	 * @param int $lastRun
42
-	 * @param int $time
43
-	 * @param bool $process
44
-	 */
45
-	#[\PHPUnit\Framework\Attributes\DataProvider('runDataProvider')]
46
-	public function testRun(int $lastRun, int $time, bool $process): void {
47
-		$backgroundJob = new RefreshWebcalJob($this->refreshWebcalService, $this->config, $this->logger, $this->timeFactory);
48
-		$backgroundJob->setId(42);
49
-
50
-		$backgroundJob->setArgument([
51
-			'principaluri' => 'principals/users/testuser',
52
-			'uri' => 'sub123',
53
-		]);
54
-		$backgroundJob->setLastRun($lastRun);
55
-
56
-		$this->refreshWebcalService->expects($this->once())
57
-			->method('getSubscription')
58
-			->with('principals/users/testuser', 'sub123')
59
-			->willReturn([
60
-				'id' => '99',
61
-				'uri' => 'sub456',
62
-				'{http://apple.com/ns/ical/}refreshrate' => 'P1D',
63
-				'{http://calendarserver.org/ns/}subscribed-strip-todos' => '1',
64
-				'{http://calendarserver.org/ns/}subscribed-strip-alarms' => '1',
65
-				'{http://calendarserver.org/ns/}subscribed-strip-attachments' => '1',
66
-				'source' => 'webcal://foo.bar/bla'
67
-			]);
68
-
69
-		$this->config->expects($this->once())
70
-			->method('getAppValue')
71
-			->with('dav', 'calendarSubscriptionRefreshRate', 'P1D')
72
-			->willReturn('P1W');
73
-
74
-		$this->timeFactory->method('getTime')
75
-			->willReturn($time);
76
-
77
-		if ($process) {
78
-			$this->refreshWebcalService->expects($this->once())
79
-				->method('refreshSubscription')
80
-				->with('principals/users/testuser', 'sub123');
81
-		} else {
82
-			$this->refreshWebcalService->expects($this->never())
83
-				->method('refreshSubscription')
84
-				->with('principals/users/testuser', 'sub123');
85
-		}
86
-
87
-		$backgroundJob->start($this->jobList);
88
-	}
89
-
90
-	public static function runDataProvider():array {
91
-		return [
92
-			[0, 100000, true],
93
-			[100000, 100000, false]
94
-		];
95
-	}
22
+    private RefreshWebcalService&MockObject $refreshWebcalService;
23
+    private IConfig&MockObject $config;
24
+    private LoggerInterface $logger;
25
+    private ITimeFactory&MockObject $timeFactory;
26
+    private IJobList&MockObject $jobList;
27
+
28
+    protected function setUp(): void {
29
+        parent::setUp();
30
+
31
+        $this->refreshWebcalService = $this->createMock(RefreshWebcalService::class);
32
+        $this->config = $this->createMock(IConfig::class);
33
+        $this->logger = $this->createMock(LoggerInterface::class);
34
+        $this->timeFactory = $this->createMock(ITimeFactory::class);
35
+
36
+        $this->jobList = $this->createMock(IJobList::class);
37
+    }
38
+
39
+    /**
40
+     *
41
+     * @param int $lastRun
42
+     * @param int $time
43
+     * @param bool $process
44
+     */
45
+    #[\PHPUnit\Framework\Attributes\DataProvider('runDataProvider')]
46
+    public function testRun(int $lastRun, int $time, bool $process): void {
47
+        $backgroundJob = new RefreshWebcalJob($this->refreshWebcalService, $this->config, $this->logger, $this->timeFactory);
48
+        $backgroundJob->setId(42);
49
+
50
+        $backgroundJob->setArgument([
51
+            'principaluri' => 'principals/users/testuser',
52
+            'uri' => 'sub123',
53
+        ]);
54
+        $backgroundJob->setLastRun($lastRun);
55
+
56
+        $this->refreshWebcalService->expects($this->once())
57
+            ->method('getSubscription')
58
+            ->with('principals/users/testuser', 'sub123')
59
+            ->willReturn([
60
+                'id' => '99',
61
+                'uri' => 'sub456',
62
+                '{http://apple.com/ns/ical/}refreshrate' => 'P1D',
63
+                '{http://calendarserver.org/ns/}subscribed-strip-todos' => '1',
64
+                '{http://calendarserver.org/ns/}subscribed-strip-alarms' => '1',
65
+                '{http://calendarserver.org/ns/}subscribed-strip-attachments' => '1',
66
+                'source' => 'webcal://foo.bar/bla'
67
+            ]);
68
+
69
+        $this->config->expects($this->once())
70
+            ->method('getAppValue')
71
+            ->with('dav', 'calendarSubscriptionRefreshRate', 'P1D')
72
+            ->willReturn('P1W');
73
+
74
+        $this->timeFactory->method('getTime')
75
+            ->willReturn($time);
76
+
77
+        if ($process) {
78
+            $this->refreshWebcalService->expects($this->once())
79
+                ->method('refreshSubscription')
80
+                ->with('principals/users/testuser', 'sub123');
81
+        } else {
82
+            $this->refreshWebcalService->expects($this->never())
83
+                ->method('refreshSubscription')
84
+                ->with('principals/users/testuser', 'sub123');
85
+        }
86
+
87
+        $backgroundJob->start($this->jobList);
88
+    }
89
+
90
+    public static function runDataProvider():array {
91
+        return [
92
+            [0, 100000, true],
93
+            [100000, 100000, false]
94
+        ];
95
+    }
96 96
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/Upload/UploadAutoMkcolPluginTest.php 1 patch
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -21,113 +21,113 @@
 block discarded – undo
21 21
 
22 22
 class UploadAutoMkcolPluginTest extends TestCase {
23 23
 
24
-	private Tree&MockObject $tree;
25
-	private RequestInterface&MockObject $request;
26
-	private ResponseInterface&MockObject $response;
27
-
28
-	public static function dataMissingHeaderShouldReturnTrue(): Generator {
29
-		yield 'missing X-NC-WebDAV-Auto-Mkcol header' => [null];
30
-		yield 'empty X-NC-WebDAV-Auto-Mkcol header' => [''];
31
-		yield 'invalid X-NC-WebDAV-Auto-Mkcol header' => ['enable'];
32
-	}
33
-
34
-	public function testBeforeMethodWithRootNodeNotAnICollectionShouldReturnTrue(): void {
35
-		$this->request->method('getHeader')->willReturn('1');
36
-		$this->request->expects(self::once())
37
-			->method('getPath')
38
-			->willReturn('/non-relevant/path.txt');
39
-		$this->tree->expects(self::once())
40
-			->method('nodeExists')
41
-			->with('/non-relevant')
42
-			->willReturn(false);
43
-
44
-		$mockNode = $this->getMockBuilder(INode::class);
45
-		$this->tree->expects(self::once())
46
-			->method('getNodeForPath')
47
-			->willReturn($mockNode);
48
-
49
-		$return = $this->plugin->beforeMethod($this->request, $this->response);
50
-		$this->assertTrue($return);
51
-	}
52
-
53
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataMissingHeaderShouldReturnTrue')]
54
-	public function testBeforeMethodWithMissingHeaderShouldReturnTrue(?string $header): void {
55
-		$this->request->expects(self::once())
56
-			->method('getHeader')
57
-			->with('X-NC-WebDAV-Auto-Mkcol')
58
-			->willReturn($header);
59
-
60
-		$this->request->expects(self::never())
61
-			->method('getPath');
62
-
63
-		$return = $this->plugin->beforeMethod($this->request, $this->response);
64
-		self::assertTrue($return);
65
-	}
66
-
67
-	public function testBeforeMethodWithExistingPathShouldReturnTrue(): void {
68
-		$this->request->method('getHeader')->willReturn('1');
69
-		$this->request->expects(self::once())
70
-			->method('getPath')
71
-			->willReturn('/files/user/deep/image.jpg');
72
-		$this->tree->expects(self::once())
73
-			->method('nodeExists')
74
-			->with('/files/user/deep')
75
-			->willReturn(true);
76
-
77
-		$this->tree->expects(self::never())
78
-			->method('getNodeForPath');
79
-
80
-		$return = $this->plugin->beforeMethod($this->request, $this->response);
81
-		self::assertTrue($return);
82
-	}
83
-
84
-	public function testBeforeMethodShouldSucceed(): void {
85
-		$this->request->method('getHeader')->willReturn('1');
86
-		$this->request->expects(self::once())
87
-			->method('getPath')
88
-			->willReturn('/files/user/my/deep/path/image.jpg');
89
-		$this->tree->expects(self::once())
90
-			->method('nodeExists')
91
-			->with('/files/user/my/deep/path')
92
-			->willReturn(false);
93
-
94
-		$mockNode = $this->createMock(ICollection::class);
95
-		$this->tree->expects(self::once())
96
-			->method('getNodeForPath')
97
-			->with('/files')
98
-			->willReturn($mockNode);
99
-		$mockNode->expects(self::exactly(4))
100
-			->method('childExists')
101
-			->willReturnMap([
102
-				['user', true],
103
-				['my', true],
104
-				['deep', false],
105
-				['path', false],
106
-			]);
107
-		$mockNode->expects(self::exactly(2))
108
-			->method('createDirectory');
109
-		$mockNode->expects(self::exactly(4))
110
-			->method('getChild')
111
-			->willReturn($mockNode);
112
-
113
-		$return = $this->plugin->beforeMethod($this->request, $this->response);
114
-		self::assertTrue($return);
115
-	}
116
-
117
-	protected function setUp(): void {
118
-		parent::setUp();
119
-
120
-		$server = $this->createMock(Server::class);
121
-		$this->tree = $this->createMock(Tree::class);
122
-
123
-		$server->tree = $this->tree;
124
-		$this->plugin = new UploadAutoMkcolPlugin();
125
-
126
-		$this->request = $this->createMock(RequestInterface::class);
127
-		$this->response = $this->createMock(ResponseInterface::class);
128
-		$server->httpRequest = $this->request;
129
-		$server->httpResponse = $this->response;
130
-
131
-		$this->plugin->initialize($server);
132
-	}
24
+    private Tree&MockObject $tree;
25
+    private RequestInterface&MockObject $request;
26
+    private ResponseInterface&MockObject $response;
27
+
28
+    public static function dataMissingHeaderShouldReturnTrue(): Generator {
29
+        yield 'missing X-NC-WebDAV-Auto-Mkcol header' => [null];
30
+        yield 'empty X-NC-WebDAV-Auto-Mkcol header' => [''];
31
+        yield 'invalid X-NC-WebDAV-Auto-Mkcol header' => ['enable'];
32
+    }
33
+
34
+    public function testBeforeMethodWithRootNodeNotAnICollectionShouldReturnTrue(): void {
35
+        $this->request->method('getHeader')->willReturn('1');
36
+        $this->request->expects(self::once())
37
+            ->method('getPath')
38
+            ->willReturn('/non-relevant/path.txt');
39
+        $this->tree->expects(self::once())
40
+            ->method('nodeExists')
41
+            ->with('/non-relevant')
42
+            ->willReturn(false);
43
+
44
+        $mockNode = $this->getMockBuilder(INode::class);
45
+        $this->tree->expects(self::once())
46
+            ->method('getNodeForPath')
47
+            ->willReturn($mockNode);
48
+
49
+        $return = $this->plugin->beforeMethod($this->request, $this->response);
50
+        $this->assertTrue($return);
51
+    }
52
+
53
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataMissingHeaderShouldReturnTrue')]
54
+    public function testBeforeMethodWithMissingHeaderShouldReturnTrue(?string $header): void {
55
+        $this->request->expects(self::once())
56
+            ->method('getHeader')
57
+            ->with('X-NC-WebDAV-Auto-Mkcol')
58
+            ->willReturn($header);
59
+
60
+        $this->request->expects(self::never())
61
+            ->method('getPath');
62
+
63
+        $return = $this->plugin->beforeMethod($this->request, $this->response);
64
+        self::assertTrue($return);
65
+    }
66
+
67
+    public function testBeforeMethodWithExistingPathShouldReturnTrue(): void {
68
+        $this->request->method('getHeader')->willReturn('1');
69
+        $this->request->expects(self::once())
70
+            ->method('getPath')
71
+            ->willReturn('/files/user/deep/image.jpg');
72
+        $this->tree->expects(self::once())
73
+            ->method('nodeExists')
74
+            ->with('/files/user/deep')
75
+            ->willReturn(true);
76
+
77
+        $this->tree->expects(self::never())
78
+            ->method('getNodeForPath');
79
+
80
+        $return = $this->plugin->beforeMethod($this->request, $this->response);
81
+        self::assertTrue($return);
82
+    }
83
+
84
+    public function testBeforeMethodShouldSucceed(): void {
85
+        $this->request->method('getHeader')->willReturn('1');
86
+        $this->request->expects(self::once())
87
+            ->method('getPath')
88
+            ->willReturn('/files/user/my/deep/path/image.jpg');
89
+        $this->tree->expects(self::once())
90
+            ->method('nodeExists')
91
+            ->with('/files/user/my/deep/path')
92
+            ->willReturn(false);
93
+
94
+        $mockNode = $this->createMock(ICollection::class);
95
+        $this->tree->expects(self::once())
96
+            ->method('getNodeForPath')
97
+            ->with('/files')
98
+            ->willReturn($mockNode);
99
+        $mockNode->expects(self::exactly(4))
100
+            ->method('childExists')
101
+            ->willReturnMap([
102
+                ['user', true],
103
+                ['my', true],
104
+                ['deep', false],
105
+                ['path', false],
106
+            ]);
107
+        $mockNode->expects(self::exactly(2))
108
+            ->method('createDirectory');
109
+        $mockNode->expects(self::exactly(4))
110
+            ->method('getChild')
111
+            ->willReturn($mockNode);
112
+
113
+        $return = $this->plugin->beforeMethod($this->request, $this->response);
114
+        self::assertTrue($return);
115
+    }
116
+
117
+    protected function setUp(): void {
118
+        parent::setUp();
119
+
120
+        $server = $this->createMock(Server::class);
121
+        $this->tree = $this->createMock(Tree::class);
122
+
123
+        $server->tree = $this->tree;
124
+        $this->plugin = new UploadAutoMkcolPlugin();
125
+
126
+        $this->request = $this->createMock(RequestInterface::class);
127
+        $this->response = $this->createMock(ResponseInterface::class);
128
+        $server->httpRequest = $this->request;
129
+        $server->httpResponse = $this->response;
130
+
131
+        $this->plugin->initialize($server);
132
+    }
133 133
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/Upload/AssemblyStreamTest.php 1 patch
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -12,155 +12,155 @@
 block discarded – undo
12 12
 
13 13
 class AssemblyStreamTest extends \Test\TestCase {
14 14
 
15
-	#[\PHPUnit\Framework\Attributes\DataProvider('providesNodes')]
16
-	public function testGetContents(string $expected, array $nodeData): void {
17
-		$nodes = [];
18
-		foreach ($nodeData as $data) {
19
-			$nodes[] = $this->buildNode(...$data);
20
-		}
21
-		$stream = AssemblyStream::wrap($nodes);
22
-		$content = stream_get_contents($stream);
23
-
24
-		$this->assertEquals($expected, $content);
25
-	}
26
-
27
-	#[\PHPUnit\Framework\Attributes\DataProvider('providesNodes')]
28
-	public function testGetContentsFread(string $expected, array $nodeData, int $chunkLength = 3): void {
29
-		$nodes = [];
30
-		foreach ($nodeData as $data) {
31
-			$nodes[] = $this->buildNode(...$data);
32
-		}
33
-		$stream = AssemblyStream::wrap($nodes);
34
-
35
-		$content = '';
36
-		while (!feof($stream)) {
37
-			$chunk = fread($stream, $chunkLength);
38
-			$content .= $chunk;
39
-			if ($chunkLength !== 3) {
40
-				$this->assertEquals($chunkLength, strlen($chunk));
41
-			}
42
-		}
43
-
44
-		$this->assertEquals($expected, $content);
45
-	}
46
-
47
-	#[\PHPUnit\Framework\Attributes\DataProvider('providesNodes')]
48
-	public function testSeek(string $expected, array $nodeData): void {
49
-		$nodes = [];
50
-		foreach ($nodeData as $data) {
51
-			$nodes[] = $this->buildNode(...$data);
52
-		}
53
-
54
-		$stream = AssemblyStream::wrap($nodes);
55
-
56
-		$offset = floor(strlen($expected) * 0.6);
57
-		if (fseek($stream, $offset) === -1) {
58
-			$this->fail('fseek failed');
59
-		}
60
-
61
-		$content = stream_get_contents($stream);
62
-		$this->assertEquals(substr($expected, $offset), $content);
63
-	}
64
-
65
-	public static function providesNodes(): array {
66
-		$data8k = self::makeData(8192);
67
-		$dataLess8k = self::makeData(8191);
68
-
69
-		$tonofnodes = [];
70
-		$tonofdata = '';
71
-		for ($i = 0; $i < 101; $i++) {
72
-			$thisdata = random_int(0, 100); // variable length and content
73
-			$tonofdata .= $thisdata;
74
-			$tonofnodes[] = [(string)$i, (string)$thisdata];
75
-		}
76
-
77
-		return[
78
-			'one node zero bytes' => [
79
-				'', [
80
-					['0', ''],
81
-				]],
82
-			'one node only' => [
83
-				'1234567890', [
84
-					['0', '1234567890'],
85
-				]],
86
-			'one node buffer boundary' => [
87
-				$data8k, [
88
-					['0', $data8k],
89
-				]],
90
-			'two nodes' => [
91
-				'1234567890', [
92
-					['1', '67890'],
93
-					['0', '12345'],
94
-				]],
95
-			'two nodes end on buffer boundary' => [
96
-				$data8k . $data8k, [
97
-					['1', $data8k],
98
-					['0', $data8k],
99
-				]],
100
-			'two nodes with one on buffer boundary' => [
101
-				$data8k . $dataLess8k, [
102
-					['1', $dataLess8k],
103
-					['0', $data8k],
104
-				]],
105
-			'two nodes on buffer boundary plus one byte' => [
106
-				$data8k . 'X' . $data8k, [
107
-					['1', $data8k],
108
-					['0', $data8k . 'X'],
109
-				]],
110
-			'two nodes on buffer boundary plus one byte at the end' => [
111
-				$data8k . $data8k . 'X', [
112
-					['1', $data8k . 'X'],
113
-					['0', $data8k],
114
-				]],
115
-			'a ton of nodes' => [
116
-				$tonofdata, $tonofnodes
117
-			],
118
-			'one read over multiple nodes' => [
119
-				'1234567890', [
120
-					['0', '1234'],
121
-					['1', '5678'],
122
-					['2', '90'],
123
-				], 10],
124
-			'two reads over multiple nodes' => [
125
-				'1234567890', [
126
-					['0', '1234'],
127
-					['1', '5678'],
128
-					['2', '90'],
129
-				], 5],
130
-		];
131
-	}
132
-
133
-	private static function makeData(int $count): string {
134
-		$data = '';
135
-		$base = '1234567890';
136
-		$j = 0;
137
-		for ($i = 0; $i < $count; $i++) {
138
-			$data .= $base[$j];
139
-			$j++;
140
-			if (!isset($base[$j])) {
141
-				$j = 0;
142
-			}
143
-		}
144
-		return $data;
145
-	}
146
-
147
-	private function buildNode(string $name, string $data) {
148
-		$node = $this->getMockBuilder(File::class)
149
-			->onlyMethods(['getName', 'get', 'getSize'])
150
-			->getMock();
151
-
152
-		$node->expects($this->any())
153
-			->method('getName')
154
-			->willReturn($name);
155
-
156
-		$node->expects($this->any())
157
-			->method('get')
158
-			->willReturn($data);
159
-
160
-		$node->expects($this->any())
161
-			->method('getSize')
162
-			->willReturn(strlen($data));
163
-
164
-		return $node;
165
-	}
15
+    #[\PHPUnit\Framework\Attributes\DataProvider('providesNodes')]
16
+    public function testGetContents(string $expected, array $nodeData): void {
17
+        $nodes = [];
18
+        foreach ($nodeData as $data) {
19
+            $nodes[] = $this->buildNode(...$data);
20
+        }
21
+        $stream = AssemblyStream::wrap($nodes);
22
+        $content = stream_get_contents($stream);
23
+
24
+        $this->assertEquals($expected, $content);
25
+    }
26
+
27
+    #[\PHPUnit\Framework\Attributes\DataProvider('providesNodes')]
28
+    public function testGetContentsFread(string $expected, array $nodeData, int $chunkLength = 3): void {
29
+        $nodes = [];
30
+        foreach ($nodeData as $data) {
31
+            $nodes[] = $this->buildNode(...$data);
32
+        }
33
+        $stream = AssemblyStream::wrap($nodes);
34
+
35
+        $content = '';
36
+        while (!feof($stream)) {
37
+            $chunk = fread($stream, $chunkLength);
38
+            $content .= $chunk;
39
+            if ($chunkLength !== 3) {
40
+                $this->assertEquals($chunkLength, strlen($chunk));
41
+            }
42
+        }
43
+
44
+        $this->assertEquals($expected, $content);
45
+    }
46
+
47
+    #[\PHPUnit\Framework\Attributes\DataProvider('providesNodes')]
48
+    public function testSeek(string $expected, array $nodeData): void {
49
+        $nodes = [];
50
+        foreach ($nodeData as $data) {
51
+            $nodes[] = $this->buildNode(...$data);
52
+        }
53
+
54
+        $stream = AssemblyStream::wrap($nodes);
55
+
56
+        $offset = floor(strlen($expected) * 0.6);
57
+        if (fseek($stream, $offset) === -1) {
58
+            $this->fail('fseek failed');
59
+        }
60
+
61
+        $content = stream_get_contents($stream);
62
+        $this->assertEquals(substr($expected, $offset), $content);
63
+    }
64
+
65
+    public static function providesNodes(): array {
66
+        $data8k = self::makeData(8192);
67
+        $dataLess8k = self::makeData(8191);
68
+
69
+        $tonofnodes = [];
70
+        $tonofdata = '';
71
+        for ($i = 0; $i < 101; $i++) {
72
+            $thisdata = random_int(0, 100); // variable length and content
73
+            $tonofdata .= $thisdata;
74
+            $tonofnodes[] = [(string)$i, (string)$thisdata];
75
+        }
76
+
77
+        return[
78
+            'one node zero bytes' => [
79
+                '', [
80
+                    ['0', ''],
81
+                ]],
82
+            'one node only' => [
83
+                '1234567890', [
84
+                    ['0', '1234567890'],
85
+                ]],
86
+            'one node buffer boundary' => [
87
+                $data8k, [
88
+                    ['0', $data8k],
89
+                ]],
90
+            'two nodes' => [
91
+                '1234567890', [
92
+                    ['1', '67890'],
93
+                    ['0', '12345'],
94
+                ]],
95
+            'two nodes end on buffer boundary' => [
96
+                $data8k . $data8k, [
97
+                    ['1', $data8k],
98
+                    ['0', $data8k],
99
+                ]],
100
+            'two nodes with one on buffer boundary' => [
101
+                $data8k . $dataLess8k, [
102
+                    ['1', $dataLess8k],
103
+                    ['0', $data8k],
104
+                ]],
105
+            'two nodes on buffer boundary plus one byte' => [
106
+                $data8k . 'X' . $data8k, [
107
+                    ['1', $data8k],
108
+                    ['0', $data8k . 'X'],
109
+                ]],
110
+            'two nodes on buffer boundary plus one byte at the end' => [
111
+                $data8k . $data8k . 'X', [
112
+                    ['1', $data8k . 'X'],
113
+                    ['0', $data8k],
114
+                ]],
115
+            'a ton of nodes' => [
116
+                $tonofdata, $tonofnodes
117
+            ],
118
+            'one read over multiple nodes' => [
119
+                '1234567890', [
120
+                    ['0', '1234'],
121
+                    ['1', '5678'],
122
+                    ['2', '90'],
123
+                ], 10],
124
+            'two reads over multiple nodes' => [
125
+                '1234567890', [
126
+                    ['0', '1234'],
127
+                    ['1', '5678'],
128
+                    ['2', '90'],
129
+                ], 5],
130
+        ];
131
+    }
132
+
133
+    private static function makeData(int $count): string {
134
+        $data = '';
135
+        $base = '1234567890';
136
+        $j = 0;
137
+        for ($i = 0; $i < $count; $i++) {
138
+            $data .= $base[$j];
139
+            $j++;
140
+            if (!isset($base[$j])) {
141
+                $j = 0;
142
+            }
143
+        }
144
+        return $data;
145
+    }
146
+
147
+    private function buildNode(string $name, string $data) {
148
+        $node = $this->getMockBuilder(File::class)
149
+            ->onlyMethods(['getName', 'get', 'getSize'])
150
+            ->getMock();
151
+
152
+        $node->expects($this->any())
153
+            ->method('getName')
154
+            ->willReturn($name);
155
+
156
+        $node->expects($this->any())
157
+            ->method('get')
158
+            ->willReturn($data);
159
+
160
+        $node->expects($this->any())
161
+            ->method('getSize')
162
+            ->willReturn(strlen($data));
163
+
164
+        return $node;
165
+    }
166 166
 }
Please login to merge, or discard this patch.