1616use OCP \IGroupManager ;
1717use OCP \IUser ;
1818use OCP \Share \IShare ;
19+ use PHPUnit \Framework \Attributes \DataProvider ;
1920use PHPUnit \Framework \MockObject \MockObject ;
2021use Test \TestCase ;
2122
2223class ActivityManagerTest extends TestCase {
2324
24- /** @var ActivityManager */
25- private $ activityManager ;
26-
27- /** @var IManager|MockObject */
28- private $ manager ;
29-
30- /** @var IGroupManager|MockObject */
31- private $ groupManager ;
32-
33- /** @var CirclesService|MockObject */
34- private $ circlesService ;
25+ private ActivityManager $ activityManager ;
26+ private IManager &MockObject $ manager ;
27+ private IGroupManager &MockObject $ groupManager ;
28+ private CirclesService &MockObject $ circlesService ;
3529
3630 public function setUp (): void {
3731 parent ::setUp ();
@@ -43,7 +37,7 @@ public function setUp(): void {
4337 }
4438
4539 public function testPublishNewShare () {
46- // Can't mock the DB-Classes, as their Property-Methods are not explicitely defined.
40+ // Can't mock the DB-Classes, as their Property-Methods are not explicitly defined.
4741 $ form = new Form ();
4842 $ form ->setId (5 );
4943 $ form ->setTitle ('TestForm-Title ' );
@@ -73,22 +67,26 @@ public function testPublishNewShare() {
7367 }
7468
7569 public function testPublishNewGroupShare () {
76- // Can't mock the DB-Classes, as their Property-Methods are not explicitely defined.
70+ // Can't mock the DB-Classes, as their Property-Methods are not explicitly defined.
7771 $ form = new Form ();
7872 $ form ->setId (5 );
7973 $ form ->setTitle ('TestForm-Title ' );
8074 $ form ->setHash ('abcdefg12345 ' );
8175 $ groupId = 'sharedGroup ' ;
8276
8377 $ group = $ this ->createMock (IGroup::class);
84- $ user = $ this ->createMock (IUser::class);
78+ $ users = [
79+ $ this ->createMock (IUser::class),
80+ $ this ->createMock (IUser::class),
81+ $ this ->createMock (IUser::class)
82+ ];
8583
86- $ user -> expects ( $ this -> exactly ( 3 ))
87- ->method ('getUID ' )
88- -> will ( $ this -> onConsecutiveCalls ( ' user1 ' , ' user2 ' , ' user3 ') );
84+ $ users [ 0 ]-> method ( ' getUID ' )-> willReturn ( ' user1 ' );
85+ $ users [ 1 ] ->method ('getUID ' )-> willReturn ( ' user2 ' );
86+ $ users [ 2 ]-> method ( ' getUID ' )-> willReturn ( ' user3 ' );
8987 $ group ->expects ($ this ->once ())
9088 ->method ('getUsers ' )
91- ->willReturn ([ $ user , $ user , $ user ] );
89+ ->willReturn ($ users );
9290 $ this ->groupManager ->expects ($ this ->once ())
9391 ->method ('get ' )
9492 ->with ($ groupId )
@@ -100,7 +98,6 @@ public function testPublishNewGroupShare() {
10098 ->willReturn ($ event );
10199 $ event ->expects ($ this ->exactly (3 ))->method ('setApp ' )->with ('forms ' )->willReturn ($ event );
102100 $ event ->expects ($ this ->exactly (3 ))->method ('setType ' )->with ('forms_newshare ' )->willReturn ($ event );
103- $ event ->expects ($ this ->exactly (3 ))->method ('setAffectedUser ' )->withConsecutive (['user1 ' ], ['user2 ' ], ['user3 ' ])->willReturn ($ event );
104101 $ event ->expects ($ this ->exactly (3 ))->method ('setAuthor ' )->with ('currentUser ' )->willReturn ($ event );
105102 $ event ->expects ($ this ->exactly (3 ))->method ('setObject ' )->with ('form ' , 5 )->willReturn ($ event );
106103 $ event ->expects ($ this ->exactly (3 ))->method ('setSubject ' )->with ('newgroupshare ' , [
@@ -110,15 +107,24 @@ public function testPublishNewGroupShare() {
110107 'groupId ' => 'sharedGroup '
111108 ])->willReturn ($ event );
112109
110+ $ affectedUsers = [];
111+ $ event ->expects ($ this ->exactly (3 ))
112+ ->method ('setAffectedUser ' )
113+ ->willReturnCallback (function ($ userId ) use (&$ affectedUsers , &$ event ) {
114+ $ affectedUsers [] = $ userId ;
115+ return $ event ;
116+ });
117+
113118 $ this ->manager ->expects ($ this ->exactly (3 ))
114119 ->method ('publish ' )
115120 ->with ($ event );
116121
117122 $ this ->activityManager ->publishNewGroupShare ($ form , $ groupId );
123+ $ this ->assertEquals (['user1 ' , 'user2 ' , 'user3 ' ], $ affectedUsers );
118124 }
119125
120126 public function testPublishNewCircleShare () {
121- // Can't mock the DB-Classes, as their Property-Methods are not explicitely defined.
127+ // Can't mock the DB-Classes, as their Property-Methods are not explicitly defined.
122128 $ form = new Form ();
123129 $ form ->setId (5 );
124130 $ form ->setTitle ('TestForm-Title ' );
@@ -135,7 +141,6 @@ public function testPublishNewCircleShare() {
135141 ->willReturn ($ event );
136142 $ event ->expects ($ this ->exactly (4 ))->method ('setApp ' )->with ('forms ' )->willReturn ($ event );
137143 $ event ->expects ($ this ->exactly (4 ))->method ('setType ' )->with ('forms_newshare ' )->willReturn ($ event );
138- $ event ->expects ($ this ->exactly (4 ))->method ('setAffectedUser ' )->withConsecutive (['userId ' ], ['user1 ' ], ['user2 ' ], ['user3 ' ])->willReturn ($ event );
139144 $ event ->expects ($ this ->exactly (4 ))->method ('setAuthor ' )->with ('currentUser ' )->willReturn ($ event );
140145 $ event ->expects ($ this ->exactly (4 ))->method ('setObject ' )->with ('form ' , 5 )->willReturn ($ event );
141146 $ event ->expects ($ this ->exactly (4 ))->method ('setSubject ' )->with ('newcircleshare ' , [
@@ -144,12 +149,20 @@ public function testPublishNewCircleShare() {
144149 'formHash ' => 'abcdefg12345 ' ,
145150 'circleId ' => $ circleId
146151 ])->willReturn ($ event );
152+ $ affectedUsers = [];
153+ $ event ->expects ($ this ->exactly (4 ))
154+ ->method ('setAffectedUser ' )
155+ ->willReturnCallback (function (string $ userId ) use (&$ affectedUsers , &$ event ) {
156+ $ affectedUsers [] = $ userId ;
157+ return $ event ;
158+ });
147159
148160 $ this ->manager ->expects ($ this ->exactly (4 ))
149161 ->method ('publish ' )
150162 ->with ($ event );
151163
152164 $ this ->activityManager ->publishNewCircleShare ($ form , $ circleId );
165+ $ this ->assertEquals (['userId ' , 'user1 ' , 'user2 ' , 'user3 ' ], $ affectedUsers );
153166 }
154167
155168 public function testPublishNewCircleShare_circlesDisabled () {
@@ -167,7 +180,7 @@ public function testPublishNewCircleShare_circlesDisabled() {
167180 }
168181
169182 public function testPublishNewSubmission () {
170- // Can't mock the DB-Classes, as their Property-Methods are not explicitely defined.
183+ // Can't mock the DB-Classes, as their Property-Methods are not explicitly defined.
171184 $ form = new Form ();
172185 $ form ->setId (5 );
173186 $ form ->setTitle ('TestForm-Title ' );
@@ -197,12 +210,13 @@ public function testPublishNewSubmission() {
197210 $ this ->activityManager ->publishNewSubmission ($ form , $ submittorId );
198211 }
199212
200- public function dataPublichNewSharedSubmission () {
213+ public function dataPublishNewSharedSubmission () {
201214 return [
202215 'user-share ' => [
203216 'shareType ' => IShare::TYPE_USER ,
204217 'shareWith ' => 'sharedUser ' ,
205- 'expected ' => [['sharedUser ' ]]
218+ 'expected ' => [['sharedUser ' ]],
219+ 'sharedUsers ' => ['sharedUser ' ],
206220 ],
207221 'group-share ' => [
208222 IShare::TYPE_GROUP ,
@@ -221,9 +235,8 @@ public function dataPublichNewSharedSubmission() {
221235
222236 /**
223237 * Test notify shared results
224- *
225- * @dataProvider dataPublichNewSharedSubmission
226238 */
239+ #[DataProvider('dataPublishNewSharedSubmission ' )]
227240 public function testPublishNewSharedSubmission (int $ shareType , string $ shareWith , array $ expected , ?array $ sharedUsers = null ) {
228241 // Can't mock the DB-Classes, as their Property-Methods are not explicitely defined.
229242 $ form = new Form ();
@@ -255,19 +268,26 @@ public function testPublishNewSharedSubmission(int $shareType, string $shareWith
255268 ->willReturn ($ event );
256269 $ event ->expects ($ this ->exactly (count ($ expected )))->method ('setApp ' )->with ('forms ' )->willReturn ($ event );
257270 $ 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 );
259271 $ event ->expects ($ this ->exactly (count ($ expected )))->method ('setAuthor ' )->with ('submittingUser ' )->willReturn ($ event );
260272 $ event ->expects ($ this ->exactly (count ($ expected )))->method ('setObject ' )->with ('form ' , 5 )->willReturn ($ event );
261273 $ event ->expects ($ this ->exactly (count ($ expected )))->method ('setSubject ' )->with ('newsubmission ' , [
262274 'userId ' => 'submittingUser ' ,
263275 'formTitle ' => 'TestForm-Title ' ,
264276 'formHash ' => 'abcdefg12345 '
265277 ])->willReturn ($ event );
278+ $ affectedUsers = [];
279+ $ event ->expects ($ this ->exactly (count ($ sharedUsers )))
280+ ->method ('setAffectedUser ' )
281+ ->willReturnCallback (function (string $ userId ) use (&$ affectedUsers , &$ event ) {
282+ $ affectedUsers [] = $ userId ;
283+ return $ event ;
284+ });
266285
267286 $ this ->manager ->expects ($ this ->exactly (count ($ expected )))
268287 ->method ('publish ' )
269288 ->with ($ event );
270289
271290 $ this ->activityManager ->publishNewSharedSubmission ($ form , $ shareType , $ shareWith , $ submitterId );
291+ $ this ->assertEquals ($ sharedUsers , $ affectedUsers );
272292 }
273293}
0 commit comments