@@ -260,23 +260,41 @@ public function test_add_url_metric( int $viewport_width, string $exception ): v
260
260
public function data_provider_test_is_complete (): array {
261
261
// Note: Test cases for empty URL Metrics and for exact sample size are already covered in the test_add_url_metric() method.
262
262
return array (
263
- 'old_url_metric ' => array (
263
+ 'old_url_metric ' => array (
264
264
'url_metric ' => $ this ->get_sample_url_metric (
265
265
array (
266
266
'timestamp ' => microtime ( true ) - ( HOUR_IN_SECONDS + 1 ),
267
267
'etag ' => md5 ( '' ),
268
268
)
269
269
),
270
+ 'freshness_ttl ' => HOUR_IN_SECONDS ,
270
271
'expected_is_group_complete ' => false ,
271
272
),
272
- 'etag_mismatch ' => array (
273
+ 'etag_mismatch ' => array (
273
274
'url_metric ' => $ this ->get_sample_url_metric ( array ( 'etag ' => md5 ( 'different_etag ' ) ) ),
275
+ 'freshness_ttl ' => HOUR_IN_SECONDS ,
274
276
'expected_is_group_complete ' => false ,
275
277
),
276
- 'etag_match ' => array (
278
+ 'etag_match ' => array (
277
279
'url_metric ' => $ this ->get_sample_url_metric ( array ( 'etag ' => md5 ( '' ) ) ),
280
+ 'freshness_ttl ' => HOUR_IN_SECONDS ,
278
281
'expected_is_group_complete ' => true ,
279
282
),
283
+ 'negative_ttl_with_old_url_metric ' => array (
284
+ 'url_metric ' => $ this ->get_sample_url_metric (
285
+ array (
286
+ 'timestamp ' => microtime ( true ) - ( WEEK_IN_SECONDS * 4 ),
287
+ 'etag ' => md5 ( '' ),
288
+ )
289
+ ),
290
+ 'freshness_ttl ' => -HOUR_IN_SECONDS ,
291
+ 'expected_is_group_complete ' => true ,
292
+ ),
293
+ 'negative_ttl_with_etag_mismatch ' => array (
294
+ 'url_metric ' => $ this ->get_sample_url_metric ( array ( 'etag ' => md5 ( 'different_etag ' ) ) ),
295
+ 'freshness_ttl ' => -HOUR_IN_SECONDS ,
296
+ 'expected_is_group_complete ' => false ,
297
+ ),
280
298
);
281
299
}
282
300
@@ -287,8 +305,8 @@ public function data_provider_test_is_complete(): array {
287
305
*
288
306
* @dataProvider data_provider_test_is_complete
289
307
*/
290
- public function test_is_complete ( OD_URL_Metric $ url_metric , bool $ expected_is_group_complete ): void {
291
- $ collection = new OD_URL_Metric_Group_Collection ( array (), md5 ( '' ), array ( 768 ), 1 , HOUR_IN_SECONDS );
308
+ public function test_is_complete ( OD_URL_Metric $ url_metric , int $ freshness_ttl , bool $ expected_is_group_complete ): void {
309
+ $ collection = new OD_URL_Metric_Group_Collection ( array (), md5 ( '' ), array ( 768 ), 1 , $ freshness_ttl );
292
310
$ group = $ collection ->get_first_group ();
293
311
294
312
$ group ->add_url_metric ( $ url_metric );
0 commit comments