3636use OCP \IL10N ;
3737use OCP \IURLGenerator ;
3838use OCP \L10N \IFactory ;
39+ use OCP \Notification \AlreadyProcessedException ;
3940use OCP \Notification \INotification ;
41+ use PHPUnit \Framework \MockObject \MockObject ;
4042use Test \TestCase ;
4143
4244class NotifierTest extends TestCase {
4345 /** @var Notifier */
4446 protected $ notifier ;
4547
46- /** @var IFactory|\PHPUnit\Framework\MockObject\ MockObject */
48+ /** @var IFactory|MockObject */
4749 protected $ factory ;
4850
49- /** @var IURLGenerator|\PHPUnit\Framework\MockObject\ MockObject */
51+ /** @var IURLGenerator|MockObject */
5052 protected $ urlGenerator ;
5153
52- /** @var IL10N|\PHPUnit\Framework\MockObject\ MockObject */
54+ /** @var IL10N|MockObject */
5355 protected $ l10n ;
5456
55- /** @var ITimeFactory|\PHPUnit\Framework\MockObject\ MockObject */
57+ /** @var ITimeFactory|MockObject */
5658 protected $ timeFactory ;
5759
5860 protected function setUp (): void {
@@ -111,7 +113,7 @@ public function testPrepareWrongApp(): void {
111113 $ this ->expectException (\InvalidArgumentException::class);
112114 $ this ->expectExceptionMessage ('Notification not from this app ' );
113115
114- /** @var INotification|\PHPUnit\Framework\MockObject\ MockObject $notification */
116+ /** @var INotification|MockObject $notification */
115117 $ notification = $ this ->createMock (INotification::class);
116118
117119 $ notification ->expects ($ this ->once ())
@@ -128,7 +130,7 @@ public function testPrepareWrongSubject() {
128130 $ this ->expectException (\InvalidArgumentException::class);
129131 $ this ->expectExceptionMessage ('Unknown subject ' );
130132
131- /** @var INotification|\PHPUnit\Framework\MockObject\ MockObject $notification */
133+ /** @var INotification|MockObject $notification */
132134 $ notification = $ this ->createMock (INotification::class);
133135
134136 $ notification ->expects ($ this ->once ())
@@ -165,6 +167,28 @@ public function dataPrepare(): array {
165167 ],
166168 "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 "
167169 ],
170+ [
171+ 'calendar_reminder ' ,
172+ [
173+ 'title ' => 'Title of this event ' ,
174+ 'start_atom ' => '2005-08-15T13:00:00+02:00 ' ,
175+ ],
176+ 'Title of this event (1 hour ago) ' ,
177+ [
178+ 'title ' => 'Title of this event ' ,
179+ 'description ' => null ,
180+ 'location ' => 'NC Headquarters ' ,
181+ 'all_day ' => false ,
182+ 'start_atom ' => '2005-08-15T13:00:00+02:00 ' ,
183+ 'start_is_floating ' => false ,
184+ 'start_timezone ' => 'Europe/Berlin ' ,
185+ 'end_atom ' => '2005-08-15T15:00:00+02:00 ' ,
186+ 'end_is_floating ' => false ,
187+ 'end_timezone ' => 'Europe/Berlin ' ,
188+ 'calendar_displayname ' => 'Personal ' ,
189+ ],
190+ "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 "
191+ ],
168192 ];
169193 }
170194
@@ -179,7 +203,7 @@ public function dataPrepare(): array {
179203 * @throws \Exception
180204 */
181205 public function testPrepare (string $ subjectType , array $ subjectParams , string $ subject , array $ messageParams , string $ message ): void {
182- /** @var INotification|\PHPUnit\Framework\MockObject\ MockObject $notification */
206+ /** @var INotification|MockObject $notification */
183207 $ notification = $ this ->createMock (INotification::class);
184208
185209 $ notification ->expects ($ this ->once ())
@@ -222,4 +246,49 @@ public function testPrepare(string $subjectType, array $subjectParams, string $s
222246
223247 $ this ->assertEquals ($ notification , $ return );
224248 }
249+
250+ public function testPassedEvent (): void {
251+ /** @var INotification|MockObject $notification */
252+ $ notification = $ this ->createMock (INotification::class);
253+
254+ $ notification ->expects ($ this ->once ())
255+ ->method ('getApp ' )
256+ ->willReturn (Application::APP_ID );
257+ $ notification ->expects ($ this ->once ())
258+ ->method ('getSubject ' )
259+ ->willReturn ('calendar_reminder ' );
260+ $ notification ->expects ($ this ->once ())
261+ ->method ('getSubjectParameters ' )
262+ ->willReturn ([
263+ 'title ' => 'Title of this event ' ,
264+ 'start_atom ' => '2005-08-15T08:00:00+02:00 '
265+ ]);
266+
267+ $ notification ->expects ($ this ->once ())
268+ ->method ('getMessageParameters ' )
269+ ->willReturn ([
270+ 'title ' => 'Title of this event ' ,
271+ 'description ' => null ,
272+ 'location ' => 'NC Headquarters ' ,
273+ 'all_day ' => false ,
274+ 'start_atom ' => '2005-08-15T08:00:00+02:00 ' ,
275+ 'start_is_floating ' => false ,
276+ 'start_timezone ' => 'Europe/Berlin ' ,
277+ 'end_atom ' => '2005-08-15T13:00:00+02:00 ' ,
278+ 'end_is_floating ' => false ,
279+ 'end_timezone ' => 'Europe/Berlin ' ,
280+ 'calendar_displayname ' => 'Personal ' ,
281+ ]);
282+
283+ $ notification ->expects ($ this ->once ())
284+ ->method ('setParsedSubject ' )
285+ ->with ('Title of this event (6 hours ago) ' )
286+ ->willReturnSelf ();
287+
288+ $ this ->expectException (AlreadyProcessedException::class);
289+
290+ $ return = $ this ->notifier ->prepare ($ notification , 'en ' );
291+
292+ $ this ->assertEquals ($ notification , $ return );
293+ }
225294}
0 commit comments