@@ -167,7 +167,7 @@ public function test_find_users_for_notification_idea_not_found()
167167
168168 public function test_get_avatar_with_author ()
169169 {
170- $ this ->setNotificationData (['idea_author ' => 5 ]);
170+ $ this ->setNotificationData (['updater_id ' => 5 ]);
171171
172172 $ this ->user_loader ->expects ($ this ->once ())
173173 ->method ('get_avatar ' )
@@ -179,36 +179,57 @@ public function test_get_avatar_with_author()
179179
180180 public function test_get_avatar_without_author ()
181181 {
182- $ this ->setNotificationData (['idea_author ' => 0 ]);
182+ $ this ->setNotificationData (['updater_id ' => 0 ]);
183183 $ this ->assertEquals ('' , $ this ->notification_type ->get_avatar ());
184184 }
185185
186186 public function test_users_to_query ()
187187 {
188- $ this ->setNotificationData (['idea_author ' => 0 ]);
188+ $ this ->setNotificationData (['updater_id ' => 0 ]);
189189 $ this ->assertEquals ([0 ], $ this ->notification_type ->users_to_query ());
190190 }
191191
192192 public function test_get_title ()
193193 {
194- $ this ->setNotificationData (['idea_title ' => 'Test Idea ' ]);
194+ $ this ->setNotificationData ([
195+ 'updater_id ' => 123 ,
196+ 'status ' => ext::$ statuses ['IN_PROGRESS ' ]
197+ ]);
195198
196199 $ this ->language ->expects ($ this ->once ())
197200 ->method ('is_set ' )
198201 ->with ('IDEA_STATUS_CHANGE ' )
199202 ->willReturn (true );
200203
201- $ this ->language ->expects ($ this ->once ( ))
204+ $ this ->language ->expects ($ this ->exactly ( 2 ))
202205 ->method ('lang ' )
203- ->with ('IDEA_STATUS_CHANGE ' , 'Test Idea ' )
204- ->willReturn ('Status changed for: Test Idea ' );
206+ ->willReturnCallback (function ($ key , ...$ args ) {
207+ if ($ key === 'IN_PROGRESS ' )
208+ {
209+ return 'In Progress ' ;
210+ }
211+ if ($ key === 'IDEA_STATUS_CHANGE ' && $ args [0 ] === 'TestUser ' && $ args [1 ] === 'In Progress ' )
212+ {
213+ return 'TestUser changed status to In Progress ' ;
214+ }
215+ return '' ;
216+ });
205217
206- $ this ->assertEquals ('Status changed for: Test Idea ' , $ this ->notification_type ->get_title ());
218+ $ this ->user_loader ->expects ($ this ->once ())
219+ ->method ('get_username ' )
220+ ->with (123 , 'no_profile ' )
221+ ->willReturn ('TestUser ' );
222+
223+ $ result = $ this ->notification_type ->get_title ();
224+ $ this ->assertEquals ('TestUser changed status to In Progress ' , $ result );
207225 }
208226
209227 public function test_get_title_loads_language ()
210228 {
211- $ this ->setNotificationData (['idea_title ' => 'Test Idea ' ]);
229+ $ this ->setNotificationData ([
230+ 'updater_id ' => 456 ,
231+ 'status ' => ext::$ statuses ['IMPLEMENTED ' ]
232+ ]);
212233
213234 $ this ->language ->expects ($ this ->once ())
214235 ->method ('is_set ' )
@@ -219,24 +240,39 @@ public function test_get_title_loads_language()
219240 ->method ('add_lang ' )
220241 ->with ('common ' , 'phpbb/ideas ' );
221242
222- $ this ->language ->expects ($ this ->once ( ))
243+ $ this ->language ->expects ($ this ->exactly ( 2 ))
223244 ->method ('lang ' )
224- ->with ('IDEA_STATUS_CHANGE ' , 'Test Idea ' )
225- ->willReturn ('Status changed for: Test Idea ' );
245+ ->willReturnCallback (function ($ key , ...$ args ) {
246+ if ($ key === 'IMPLEMENTED ' )
247+ {
248+ return 'Implemented ' ;
249+ }
250+ if ($ key === 'IDEA_STATUS_CHANGE ' && $ args [0 ] === 'AdminUser ' && $ args [1 ] === 'Implemented ' )
251+ {
252+ return 'AdminUser changed status to Implemented ' ;
253+ }
254+ return '' ;
255+ });
256+
257+ $ this ->user_loader ->expects ($ this ->once ())
258+ ->method ('get_username ' )
259+ ->with (456 , 'no_profile ' )
260+ ->willReturn ('AdminUser ' );
226261
227- $ this ->assertEquals ('Status changed for: Test Idea ' , $ this ->notification_type ->get_title ());
262+ $ result = $ this ->notification_type ->get_title ();
263+ $ this ->assertEquals ('AdminUser changed status to Implemented ' , $ result );
228264 }
229265
230266 public function test_get_reference ()
231267 {
232- $ this ->setNotificationData (['status ' => 2 ]);
268+ $ this ->setNotificationData (['idea_title ' => ' Test Idea ' ]);
233269
234270 $ this ->language ->expects ($ this ->once ())
235271 ->method ('lang ' )
236- ->with ('IN_PROGRESS ' )
237- ->willReturn ('In Progress ' );
272+ ->with ('NOTIFICATION_REFERENCE ' , ' Test Idea ' )
273+ ->willReturn ('“Test Idea” ' );
238274
239- $ this ->assertEquals ('In Progress ' , $ this ->notification_type ->get_reference ());
275+ $ this ->assertEquals ('“Test Idea” ' , $ this ->notification_type ->get_reference ());
240276 }
241277
242278 public function test_get_url ()
@@ -261,7 +297,8 @@ public function test_get_email_template_variables()
261297 $ this ->setNotificationData ([
262298 'idea_title ' => 'Test & Idea ' ,
263299 'status ' => 3 ,
264- 'idea_id ' => 10
300+ 'idea_id ' => 10 ,
301+ 'updater_id ' => 123 ,
265302 ]);
266303
267304 $ this ->helper ->expects ($ this ->once ())
@@ -274,11 +311,17 @@ public function test_get_email_template_variables()
274311 ->with ('IMPLEMENTED ' )
275312 ->willReturn ('Implemented ' );
276313
314+ $ this ->user_loader ->expects ($ this ->once ())
315+ ->method ('get_username ' )
316+ ->with (123 , 'username ' )
317+ ->willReturn ('TestUser ' );
318+
277319 $ result = $ this ->notification_type ->get_email_template_variables ();
278320
279321 $ expected = [
280322 'IDEA_TITLE ' => 'Test & Idea ' ,
281323 'STATUS ' => 'Implemented ' ,
324+ 'UPDATED_BY ' => 'TestUser ' ,
282325 'U_VIEW_IDEA ' => '/ideas/10 ' ,
283326 ];
284327
@@ -289,32 +332,28 @@ public function test_create_insert_array()
289332 {
290333 $ type_data = [
291334 'idea_id ' => 7 ,
292- 'status ' => 4
335+ 'status ' => 4 ,
336+ 'user_id ' => 3
293337 ];
294338 $ idea_data = [
295- 'idea_title ' => 'Sample Idea ' ,
296- 'idea_author ' => 3
339+ 'idea_title ' => 'Sample Idea '
297340 ];
298341
299342 $ this ->idea_factory ->expects ($ this ->once ())
300343 ->method ('get_idea ' )
301344 ->with (7 )
302345 ->willReturn ($ idea_data );
303346
304- // Use reflection to access set_data calls
305- $ reflection = new \ReflectionClass ($ this ->notification_type );
306- $ set_data_method = $ reflection ->getMethod ('set_data ' );
307- $ set_data_method ->setAccessible (true );
308-
309347 $ this ->notification_type ->create_insert_array ($ type_data );
310348
311349 // Verify data was set by checking get_data
350+ $ reflection = new \ReflectionClass ($ this ->notification_type );
312351 $ get_data_method = $ reflection ->getMethod ('get_data ' );
313352 $ get_data_method ->setAccessible (true );
314353
315354 $ this ->assertEquals (7 , $ get_data_method ->invoke ($ this ->notification_type , 'idea_id ' ));
316355 $ this ->assertEquals (4 , $ get_data_method ->invoke ($ this ->notification_type , 'status ' ));
356+ $ this ->assertEquals (3 , $ get_data_method ->invoke ($ this ->notification_type , 'updater_id ' ));
317357 $ this ->assertEquals ('Sample Idea ' , $ get_data_method ->invoke ($ this ->notification_type , 'idea_title ' ));
318- $ this ->assertEquals (3 , $ get_data_method ->invoke ($ this ->notification_type , 'idea_author ' ));
319358 }
320359}
0 commit comments