9
9
use Ibexa \Contracts \Core \Repository \Events \Notification \BeforeCreateNotificationEvent ;
10
10
use Ibexa \Contracts \Core \Repository \Events \Notification \BeforeDeleteNotificationEvent ;
11
11
use Ibexa \Contracts \Core \Repository \Events \Notification \BeforeMarkNotificationAsReadEvent ;
12
+ use Ibexa \Contracts \Core \Repository \Events \Notification \BeforeMarkNotificationAsUnreadEvent ;
12
13
use Ibexa \Contracts \Core \Repository \Events \Notification \CreateNotificationEvent ;
13
14
use Ibexa \Contracts \Core \Repository \Events \Notification \DeleteNotificationEvent ;
14
15
use Ibexa \Contracts \Core \Repository \Events \Notification \MarkNotificationAsReadEvent ;
16
+ use Ibexa \Contracts \Core \Repository \Events \Notification \MarkNotificationAsUnreadEvent ;
15
17
use Ibexa \Contracts \Core \Repository \NotificationService as NotificationServiceInterface ;
16
18
use Ibexa \Contracts \Core \Repository \Values \Notification \CreateStruct ;
17
19
use Ibexa \Contracts \Core \Repository \Values \Notification \Notification ;
@@ -63,9 +65,13 @@ public function testReturnCreateNotificationResultInBeforeEvents()
63
65
$ innerServiceMock = $ this ->createMock (NotificationServiceInterface::class);
64
66
$ innerServiceMock ->method ('createNotification ' )->willReturn ($ notification );
65
67
66
- $ traceableEventDispatcher ->addListener (BeforeCreateNotificationEvent::class, static function (BeforeCreateNotificationEvent $ event ) use ($ eventNotification ) {
67
- $ event ->setNotification ($ eventNotification );
68
- }, 10 );
68
+ $ traceableEventDispatcher ->addListener (
69
+ BeforeCreateNotificationEvent::class,
70
+ static function (BeforeCreateNotificationEvent $ event ) use ($ eventNotification ): void {
71
+ $ event ->setNotification ($ eventNotification );
72
+ },
73
+ 10
74
+ );
69
75
70
76
$ service = new NotificationService ($ innerServiceMock , $ traceableEventDispatcher );
71
77
$ result = $ service ->createNotification (...$ parameters );
@@ -97,10 +103,14 @@ public function testCreateNotificationStopPropagationInBeforeEvents()
97
103
$ innerServiceMock = $ this ->createMock (NotificationServiceInterface::class);
98
104
$ innerServiceMock ->method ('createNotification ' )->willReturn ($ notification );
99
105
100
- $ traceableEventDispatcher ->addListener (BeforeCreateNotificationEvent::class, static function (BeforeCreateNotificationEvent $ event ) use ($ eventNotification ) {
101
- $ event ->setNotification ($ eventNotification );
102
- $ event ->stopPropagation ();
103
- }, 10 );
106
+ $ traceableEventDispatcher ->addListener (
107
+ BeforeCreateNotificationEvent::class,
108
+ static function (BeforeCreateNotificationEvent $ event ) use ($ eventNotification ): void {
109
+ $ event ->setNotification ($ eventNotification );
110
+ $ event ->stopPropagation ();
111
+ },
112
+ 10
113
+ );
104
114
105
115
$ service = new NotificationService ($ innerServiceMock , $ traceableEventDispatcher );
106
116
$ result = $ service ->createNotification (...$ parameters );
@@ -156,9 +166,13 @@ public function testDeleteNotificationStopPropagationInBeforeEvents()
156
166
157
167
$ innerServiceMock = $ this ->createMock (NotificationServiceInterface::class);
158
168
159
- $ traceableEventDispatcher ->addListener (BeforeDeleteNotificationEvent::class, static function (BeforeDeleteNotificationEvent $ event ) {
160
- $ event ->stopPropagation ();
161
- }, 10 );
169
+ $ traceableEventDispatcher ->addListener (
170
+ BeforeDeleteNotificationEvent::class,
171
+ static function (BeforeDeleteNotificationEvent $ event ): void {
172
+ $ event ->stopPropagation ();
173
+ },
174
+ 10
175
+ );
162
176
163
177
$ service = new NotificationService ($ innerServiceMock , $ traceableEventDispatcher );
164
178
$ service ->deleteNotification (...$ parameters );
@@ -200,6 +214,31 @@ public function testMarkNotificationAsReadEvents()
200
214
$ this ->assertSame ([], $ traceableEventDispatcher ->getNotCalledListeners ());
201
215
}
202
216
217
+ public function testMarkNotificationAsUnreadEvents (): void
218
+ {
219
+ $ traceableEventDispatcher = $ this ->getEventDispatcher (
220
+ BeforeMarkNotificationAsUnreadEvent::class,
221
+ MarkNotificationAsUnreadEvent::class
222
+ );
223
+
224
+ $ parameters = [
225
+ $ this ->createMock (Notification::class),
226
+ ];
227
+
228
+ $ innerServiceMock = $ this ->createMock (NotificationServiceInterface::class);
229
+
230
+ $ service = new NotificationService ($ innerServiceMock , $ traceableEventDispatcher );
231
+ $ service ->markNotificationAsUnread (...$ parameters );
232
+
233
+ $ calledListeners = $ this ->getListenersStack ($ traceableEventDispatcher ->getCalledListeners ());
234
+
235
+ self ::assertSame ($ calledListeners , [
236
+ [BeforeMarkNotificationAsUnreadEvent::class, 0 ],
237
+ [MarkNotificationAsUnreadEvent::class, 0 ],
238
+ ]);
239
+ self ::assertSame ([], $ traceableEventDispatcher ->getNotCalledListeners ());
240
+ }
241
+
203
242
public function testMarkNotificationAsReadStopPropagationInBeforeEvents ()
204
243
{
205
244
$ traceableEventDispatcher = $ this ->getEventDispatcher (
@@ -213,9 +252,13 @@ public function testMarkNotificationAsReadStopPropagationInBeforeEvents()
213
252
214
253
$ innerServiceMock = $ this ->createMock (NotificationServiceInterface::class);
215
254
216
- $ traceableEventDispatcher ->addListener (BeforeMarkNotificationAsReadEvent::class, static function (BeforeMarkNotificationAsReadEvent $ event ) {
217
- $ event ->stopPropagation ();
218
- }, 10 );
255
+ $ traceableEventDispatcher ->addListener (
256
+ BeforeMarkNotificationAsReadEvent::class,
257
+ static function (BeforeMarkNotificationAsReadEvent $ event ): void {
258
+ $ event ->stopPropagation ();
259
+ },
260
+ 10
261
+ );
219
262
220
263
$ service = new NotificationService ($ innerServiceMock , $ traceableEventDispatcher );
221
264
$ service ->markNotificationAsRead (...$ parameters );
@@ -231,6 +274,42 @@ public function testMarkNotificationAsReadStopPropagationInBeforeEvents()
231
274
[MarkNotificationAsReadEvent::class, 0 ],
232
275
]);
233
276
}
277
+
278
+ public function testMarkNotificationAsUnreadStopPropagationInBeforeEvents (): void
279
+ {
280
+ $ traceableEventDispatcher = $ this ->getEventDispatcher (
281
+ BeforeMarkNotificationAsUnreadEvent::class,
282
+ MarkNotificationAsUnreadEvent::class
283
+ );
284
+
285
+ $ parameters = [
286
+ $ this ->createMock (Notification::class),
287
+ ];
288
+
289
+ $ innerServiceMock = $ this ->createMock (NotificationServiceInterface::class);
290
+
291
+ $ traceableEventDispatcher ->addListener (
292
+ BeforeMarkNotificationAsUnreadEvent::class,
293
+ static function (BeforeMarkNotificationAsUnreadEvent $ event ): void {
294
+ $ event ->stopPropagation ();
295
+ },
296
+ 10
297
+ );
298
+
299
+ $ service = new NotificationService ($ innerServiceMock , $ traceableEventDispatcher );
300
+ $ service ->markNotificationAsUnread (...$ parameters );
301
+
302
+ $ calledListeners = $ this ->getListenersStack ($ traceableEventDispatcher ->getCalledListeners ());
303
+ $ notCalledListeners = $ this ->getListenersStack ($ traceableEventDispatcher ->getNotCalledListeners ());
304
+
305
+ self ::assertSame ($ calledListeners , [
306
+ [BeforeMarkNotificationAsUnreadEvent::class, 10 ],
307
+ ]);
308
+ self ::assertSame ($ notCalledListeners , [
309
+ [BeforeMarkNotificationAsUnreadEvent::class, 0 ],
310
+ [MarkNotificationAsUnreadEvent::class, 0 ],
311
+ ]);
312
+ }
234
313
}
235
314
236
315
class_alias (NotificationServiceTest::class, 'eZ\Publish\Core\Event\Tests\NotificationServiceTest ' );
0 commit comments