@@ -244,14 +244,63 @@ public function test_load_template_data($user_id, $method_data, $subscriptions,
244244
245245 $ this ->template ->expects ($ expected ? self ::once () : self ::never ())
246246 ->method ('assign_vars ' )
247- ->with ([
248- 'NOTIFICATIONS_WEBPUSH_ENABLE ' => true ,
249- 'U_WEBPUSH_SUBSCRIBE ' => $ this ->controller_helper ->route ('phpbb_webpushnotifications_ucp_push_subscribe_controller ' ),
250- 'U_WEBPUSH_UNSUBSCRIBE ' => $ this ->controller_helper ->route ('phpbb_webpushnotifications_ucp_push_unsubscribe_controller ' ),
251- 'VAPID_PUBLIC_KEY ' => $ this ->config ['wpn_webpush_vapid_public ' ],
252- 'U_WEBPUSH_WORKER_URL ' => $ this ->controller_helper ->route ('phpbb_webpushnotifications_ucp_push_worker_controller ' ),
253- 'SUBSCRIPTIONS ' => $ subscriptions ,
254- 'WEBPUSH_FORM_TOKENS ' => $ this ->form_helper ->get_form_tokens (\phpbb \webpushnotifications \ucp \controller \webpush::FORM_TOKEN_UCP ),
247+ ->withConsecutive ([
248+ $ this ->callback (function ($ arg ) use ($ subscriptions ) {
249+ $ expectedValues = [
250+ 'NOTIFICATIONS_WEBPUSH_ENABLE ' => true ,
251+ 'U_WEBPUSH_SUBSCRIBE ' => $ this ->controller_helper ->route ('phpbb_webpushnotifications_ucp_push_subscribe_controller ' ),
252+ 'U_WEBPUSH_UNSUBSCRIBE ' => $ this ->controller_helper ->route ('phpbb_webpushnotifications_ucp_push_unsubscribe_controller ' ),
253+ 'VAPID_PUBLIC_KEY ' => $ this ->config ['wpn_webpush_vapid_public ' ],
254+ 'U_WEBPUSH_WORKER_URL ' => $ this ->controller_helper ->route ('phpbb_webpushnotifications_ucp_push_worker_controller ' ),
255+ 'SUBSCRIPTIONS ' => $ subscriptions ,
256+ 'WEBPUSH_FORM_TOKENS ' => $ this ->form_helper ->get_form_tokens (\phpbb \webpushnotifications \ucp \controller \webpush::FORM_TOKEN_UCP ),
257+ ];
258+
259+ // Check all required keys exist first
260+ $ missingKeys = array_diff (array_keys ($ expectedValues ), array_keys ($ arg ));
261+ if (!empty ($ missingKeys ))
262+ {
263+ $ this ->fail ("Expected key(s) ' " . implode ("', ' " , $ missingKeys ) . "' missing from argument array " );
264+ }
265+
266+ // Handle WEBPUSH_FORM_TOKENS separately
267+ if (isset ($ arg ['WEBPUSH_FORM_TOKENS ' ]))
268+ {
269+ $ tokenArg = $ arg ['WEBPUSH_FORM_TOKENS ' ];
270+ $ tokenExpected = $ expectedValues ['WEBPUSH_FORM_TOKENS ' ];
271+
272+ // Check creation_time separately, allow for 1 second discrepancies during test run
273+ $ timeDiff = abs ($ tokenArg ['creation_time ' ] - $ tokenExpected ['creation_time ' ]);
274+ if ($ timeDiff > 1 )
275+ {
276+ $ this ->fail (sprintf (
277+ "Creation time difference too large. Expected: %d, Actual: %d " ,
278+ $ tokenExpected ['creation_time ' ],
279+ $ tokenArg ['creation_time ' ]
280+ ));
281+ }
282+ // Remove creation_time after checking to allow other fields comparison
283+ unset($ tokenArg ['creation_time ' ], $ tokenExpected ['creation_time ' ]);
284+ $ arg ['WEBPUSH_FORM_TOKENS ' ] = $ tokenArg ;
285+ $ expectedValues ['WEBPUSH_FORM_TOKENS ' ] = $ tokenExpected ;
286+ }
287+
288+ // Compare values individually
289+ foreach ($ expectedValues as $ key => $ value )
290+ {
291+ if ($ arg [$ key ] !== $ value )
292+ {
293+ $ this ->fail (sprintf (
294+ "Mismatch for key '%s'. Expected: %s, Actual: %s " ,
295+ $ key ,
296+ var_export ($ value , true ),
297+ var_export ($ arg [$ key ], true )
298+ ));
299+ }
300+ }
301+
302+ return true ;
303+ })
255304 ]);
256305
257306 $ dispatcher = new \phpbb \event \dispatcher ();
@@ -390,8 +439,8 @@ public function test_validate_pwa_options($validate, $cfg_array, $expected_error
390439 $ config_name = key ($ cfg_array );
391440 $ config_definition = ['validate ' => $ validate ];
392441
393- $ pwa_icon_small = isset ( $ cfg_array ['pwa_icon_small ' ]) ? $ cfg_array [ ' pwa_icon_small ' ] : '' ;
394- $ pwa_icon_large = isset ( $ cfg_array ['pwa_icon_large ' ]) ? $ cfg_array [ ' pwa_icon_large ' ] : '' ;
442+ $ pwa_icon_small = $ cfg_array ['pwa_icon_small ' ] ?? '' ;
443+ $ pwa_icon_large = $ cfg_array ['pwa_icon_large ' ] ?? '' ;
395444
396445 [$ small_image_name , $ small_image_ext ] = $ pwa_icon_small ? explode ('. ' , $ pwa_icon_small , 2 ) : ['' , '' ];
397446 [$ large_image_name , $ large_image_ext ] = $ pwa_icon_large ? explode ('. ' , $ pwa_icon_large , 2 ) : ['' , '' ];
0 commit comments