@@ -233,41 +233,38 @@ public function testPublishNewSharedSubmission(int $shareType, string $shareWith
233233 $ form ->setOwnerId ('formOwner ' );
234234 $ submitterId = 'submittingUser ' ;
235235
236- if ($ shareType === IShare::TYPE_CIRCLE ) {
237- $ this ->circlesService ->expects ($ this ->once ())
238- ->method ('getCircleUsers ' )
239- ->with ('sharedCircle ' )
240- ->willReturn ($ sharedUsers );
241- } elseif ($ shareType === IShare::TYPE_GROUP ) {
242- $ users = array_map (function ($ name ) {
243- $ user = $ this ->createMock (IUser::class);
244- $ user ->expects ($ this ->once ())->method ('getUID ' )->willReturn ($ name );
245- return $ user ;
246- }, $ sharedUsers );
247- $ group = $ this ->createMock (IGroup::class);
248- $ group ->expects ($ this ->once ())->method ('getUsers ' )->willReturn ($ users );
249- $ this ->groupManager ->expects ($ this ->once ())->method ('get ' )->willReturn ($ group );
250- }
251-
252236 $ event = $ this ->createMock (IEvent::class);
253- $ this ->manager ->expects ($ this ->exactly (count ($ expected )))
237+ $ expectedCount = count ($ sharedUsers ?? []);
238+
239+ $ this ->manager ->expects ($ this ->exactly ($ expectedCount ))
254240 ->method ('generateEvent ' )
255241 ->willReturn ($ event );
256- $ event ->expects ($ this ->exactly (count ($ expected )))->method ('setApp ' )->with ('forms ' )->willReturn ($ event );
257- $ event ->expects ($ this ->exactly (count ($ expected )))->method ('setType ' )->with ('forms_newsharedsubmission ' )->willReturn ($ event );
258- $ event ->expects ($ this ->exactly (count ($ expected )))->method ('setAffectedUser ' )->withConsecutive (...[...$ expected ])->willReturn ($ event );
259- $ event ->expects ($ this ->exactly (count ($ expected )))->method ('setAuthor ' )->with ('submittingUser ' )->willReturn ($ event );
260- $ event ->expects ($ this ->exactly (count ($ expected )))->method ('setObject ' )->with ('form ' , 5 )->willReturn ($ event );
261- $ event ->expects ($ this ->exactly (count ($ expected )))->method ('setSubject ' )->with ('newsubmission ' , [
242+ $ event ->expects ($ this ->exactly ($ expectedCount ))->method ('setApp ' )->with ('forms ' )->willReturn ($ event );
243+ $ event ->expects ($ this ->exactly ($ expectedCount ))->method ('setType ' )->with ('forms_newsharedsubmission ' )->willReturn ($ event );
244+ $ event ->expects ($ this ->exactly ($ expectedCount ))->method ('setAuthor ' )->with ('submittingUser ' )->willReturn ($ event );
245+ $ event ->expects ($ this ->exactly ($ expectedCount ))->method ('setObject ' )->with ('form ' , 5 )->willReturn ($ event );
246+ $ event ->expects ($ this ->exactly ($ expectedCount ))->method ('setSubject ' )->with ('newsubmission ' , [
262247 'userId ' => 'submittingUser ' ,
263248 'formTitle ' => 'TestForm-Title ' ,
264249 'formHash ' => 'abcdefg12345 '
265250 ])->willReturn ($ event );
266-
267- $ this ->manager ->expects ($ this ->exactly (count ($ expected )))
251+ $ affectedUsers = [];
252+ $ event ->expects ($ this ->exactly ($ expectedCount ))
253+ ->method ('setAffectedUser ' )
254+ ->willReturnCallback (function (string $ userId ) use (&$ affectedUsers , &$ event ) {
255+ $ affectedUsers [] = $ userId ;
256+ return $ event ;
257+ });
258+
259+ $ this ->manager ->expects ($ this ->exactly ($ expectedCount ))
268260 ->method ('publish ' )
269261 ->with ($ event );
270262
271- $ this ->activityManager ->publishNewSharedSubmission ($ form , $ shareType , $ shareWith , $ submitterId );
263+ // Call per-user publisher for each expected shared user (new API)
264+ foreach ($ sharedUsers ?? [] as $ userId ) {
265+ $ this ->activityManager ->publishNewSharedSubmission ($ form , $ userId , $ submitterId );
266+ }
267+
268+ $ this ->assertEquals ($ sharedUsers ?? [], $ affectedUsers );
272269 }
273270}
0 commit comments