@@ -253,24 +253,50 @@ public function test_load_template_data($user_id, $method_data, $subscriptions,
253
253
'VAPID_PUBLIC_KEY ' => $ this ->config ['wpn_webpush_vapid_public ' ],
254
254
'U_WEBPUSH_WORKER_URL ' => $ this ->controller_helper ->route ('phpbb_webpushnotifications_ucp_push_worker_controller ' ),
255
255
'SUBSCRIPTIONS ' => $ subscriptions ,
256
+ 'WEBPUSH_FORM_TOKENS ' => $ this ->form_helper ->get_form_tokens (\phpbb \webpushnotifications \ucp \controller \webpush::FORM_TOKEN_UCP ),
256
257
];
257
258
258
- foreach ($ expectedValues as $ key => $ value )
259
+ // Check all required keys exist first
260
+ $ missingKeys = array_diff (array_keys ($ expectedValues ), array_keys ($ arg ));
261
+ if (!empty ($ missingKeys ))
259
262
{
260
- if (!array_key_exists ($ key , $ arg ))
261
- {
262
- $ this ->fail ("Expected key ' $ key' is missing from the argument array " );
263
- }
264
- if ($ arg [$ key ] !== $ value )
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 )
265
275
{
266
- $ this ->fail ("Mismatch for key ' $ key'. Expected: " . var_export ($ value , true ) . ", Actual: " . var_export ($ arg [$ key ], true ));
276
+ $ this ->fail (sprintf (
277
+ "Creation time difference too large. Expected: %d, Actual: %d " ,
278
+ $ tokenExpected ['creation_time ' ],
279
+ $ tokenArg ['creation_time ' ]
280
+ ));
267
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 ;
268
286
}
269
287
270
- // Check if WEBPUSH_FORM_TOKENS exists, but don't check its value
271
- if (! array_key_exists ( ' WEBPUSH_FORM_TOKENS ' , $ arg ) )
288
+ // Compare values individually
289
+ foreach ( $ expectedValues as $ key => $ value )
272
290
{
273
- $ this ->fail ("Expected key 'WEBPUSH_FORM_TOKENS' is missing from the argument array " );
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
+ }
274
300
}
275
301
276
302
return true ;
0 commit comments