@@ -31,8 +31,8 @@ public function data_provider_to_test_constructor(): array {
31
31
return array (
32
32
'valid_minimal ' => array (
33
33
'data ' => array (
34
- // Note: The 'etag' field is currently optional, so this data is still valid without it.
35
34
'url ' => home_url ( '/ ' ),
35
+ 'etag ' => md5 ( '' ),
36
36
'viewport ' => $ viewport ,
37
37
'timestamp ' => microtime ( true ),
38
38
'elements ' => array (),
@@ -127,14 +127,14 @@ static function ( $value ) {
127
127
'error ' => 'OD_URL_Metric[etag] must be at most 32 characters long. ' ,
128
128
),
129
129
'missing_etag ' => array (
130
- 'data ' => array (
130
+ 'data ' => array (
131
131
'uuid ' => wp_generate_uuid4 (),
132
132
'url ' => home_url ( '/ ' ),
133
133
'viewport ' => $ viewport ,
134
134
'timestamp ' => microtime ( true ),
135
135
'elements ' => array (),
136
136
),
137
- // Note: Add error message 'etag is a required property of OD_URL_Metric.' when 'etag' becomes mandatory.
137
+ ' error ' => 'etag is a required property of OD_URL_Metric. ' ,
138
138
),
139
139
'missing_viewport ' => array (
140
140
'data ' => array (
@@ -327,14 +327,9 @@ static function ( OD_Element $element ) {
327
327
$ this ->assertSame ( $ data ['url ' ], $ url_metric ->get_url () );
328
328
$ this ->assertSame ( $ data ['url ' ], $ url_metric ->get ( 'url ' ) );
329
329
330
- // Note: When the 'etag' field becomes required, the else statement can be removed.
331
- if ( array_key_exists ( 'etag ' , $ data ) ) {
332
- $ this ->assertSame ( $ data ['etag ' ], $ url_metric ->get_etag () );
333
- $ this ->assertSame ( $ data ['etag ' ], $ url_metric ->get ( 'etag ' ) );
334
- $ this ->assertTrue ( 1 === preg_match ( '/^[a-f0-9]{32}$/ ' , $ url_metric ->get_etag () ) );
335
- } else {
336
- $ this ->assertNull ( $ url_metric ->get_etag () );
337
- }
330
+ $ this ->assertSame ( $ data ['etag ' ], $ url_metric ->get_etag () );
331
+ $ this ->assertSame ( $ data ['etag ' ], $ url_metric ->get ( 'etag ' ) );
332
+ $ this ->assertTrue ( 1 === preg_match ( '/^[a-f0-9]{32}$/ ' , $ url_metric ->get_etag () ) );
338
333
339
334
$ this ->assertTrue ( wp_is_uuid ( $ url_metric ->get_uuid () ) );
340
335
$ this ->assertSame ( $ url_metric ->get_uuid (), $ url_metric ->get ( 'uuid ' ) );
@@ -370,6 +365,7 @@ public function data_provider_to_test_constructor_with_extended_schema(): array
370
365
371
366
$ data = array (
372
367
'url ' => home_url ( '/ ' ),
368
+ 'etag ' => md5 ( '' ),
373
369
'viewport ' => $ viewport ,
374
370
'timestamp ' => microtime ( true ),
375
371
'elements ' => array ( $ valid_element ),
@@ -390,6 +386,7 @@ static function ( array $properties ): array {
390
386
},
391
387
'data ' => array (
392
388
'url ' => home_url ( '/ ' ),
389
+ 'etag ' => md5 ( '' ),
393
390
'viewport ' => $ viewport ,
394
391
'timestamp ' => microtime ( true ),
395
392
'elements ' => array (),
@@ -424,6 +421,7 @@ static function ( array $properties ): array {
424
421
},
425
422
'data ' => array (
426
423
'url ' => home_url ( '/ ' ),
424
+ 'etag ' => md5 ( '' ),
427
425
'viewport ' => $ viewport ,
428
426
'timestamp ' => microtime ( true ),
429
427
'elements ' => array (),
@@ -455,6 +453,7 @@ static function ( array $properties ): array {
455
453
},
456
454
'data ' => array (
457
455
'url ' => home_url ( '/ ' ),
456
+ 'etag ' => md5 ( '' ),
458
457
'viewport ' => $ viewport ,
459
458
'timestamp ' => microtime ( true ),
460
459
'elements ' => array (),
@@ -478,6 +477,7 @@ static function ( array $properties ): array {
478
477
},
479
478
'data ' => array (
480
479
'url ' => home_url ( '/ ' ),
480
+ 'etag ' => md5 ( '' ),
481
481
'viewport ' => $ viewport ,
482
482
'timestamp ' => microtime ( true ),
483
483
'elements ' => array (
@@ -516,6 +516,7 @@ static function ( array $properties ): array {
516
516
},
517
517
'data ' => array (
518
518
'url ' => home_url ( '/ ' ),
519
+ 'etag ' => md5 ( '' ),
519
520
'viewport ' => $ viewport ,
520
521
'timestamp ' => microtime ( true ),
521
522
'elements ' => array ( $ valid_element ),
@@ -545,6 +546,7 @@ static function ( array $properties ): array {
545
546
},
546
547
'data ' => array (
547
548
'url ' => home_url ( '/ ' ),
549
+ 'etag ' => md5 ( '' ),
548
550
'viewport ' => $ viewport ,
549
551
'timestamp ' => microtime ( true ),
550
552
'elements ' => array (
@@ -917,8 +919,7 @@ public function test_get_json_schema_extensibility( Closure $set_up, Closure $as
917
919
*/
918
920
protected function check_schema_subset ( array $ schema , string $ path , bool $ extended = false ): void {
919
921
$ this ->assertArrayHasKey ( 'required ' , $ schema , $ path );
920
- // Skipping the check for 'root/etag' as it is currently optional.
921
- if ( ! $ extended && 'root/etag ' !== $ path ) {
922
+ if ( ! $ extended ) {
922
923
$ this ->assertTrue ( $ schema ['required ' ], $ path );
923
924
}
924
925
$ this ->assertArrayHasKey ( 'type ' , $ schema , $ path );
0 commit comments