@@ -910,21 +910,25 @@ public function test_od_decompress_rest_request_body_modifies_request(): void {
910
910
}
911
911
912
912
/**
913
- * Test that the `od_max_url_metric_size ` filter can be used to modify the maximum size of URL Metrics.
913
+ * Test that the `od_maximum_url_metric_size ` filter can be used to modify the maximum size of URL Metrics.
914
914
*
915
- * @dataProvider data_provider_max_url_metrics_size_filter
915
+ * @dataProvider data_provider_maximum_url_metrics_size_filter
916
916
*
917
917
* @covers ::od_register_endpoint
918
918
* @covers ::od_handle_rest_request
919
- * @covers ::od_get_max_url_metric_size
919
+ * @covers ::od_get_maximum_url_metric_size
920
920
*
921
- * @param Closure $set_up Set up function.
922
- * @param array<string, mixed> $params Params.
923
- * @param int $expected_status Expected status.
924
- * @param string|null $expected_code Expected code.
921
+ * @param Closure $set_up Set up function.
922
+ * @param array<string, mixed> $params Params.
923
+ * @param int $expected_status Expected status.
924
+ * @param string|null $expected_code Expected code.
925
+ * @param bool $expected_incorrect_usage Expected incorrect usage.
925
926
*/
926
- public function test_max_url_metrics_size_filter ( Closure $ set_up , array $ params , int $ expected_status , ?string $ expected_code ): void {
927
+ public function test_maximum_url_metrics_size_filter ( Closure $ set_up , array $ params , int $ expected_status , ?string $ expected_code, bool $ expected_incorrect_usage ): void {
927
928
$ set_up ();
929
+ if ( $ expected_incorrect_usage ) {
930
+ $ this ->setExpectedIncorrectUsage ( 'Filter: 'od_maximum_url_metric_size' ' );
931
+ }
928
932
$ request = $ this ->create_request ( $ params );
929
933
unset( $ params ['hmac ' ], $ params ['slug ' ], $ params ['current_etag ' ], $ params ['cache_purge_post_id ' ] );
930
934
$ request ->set_header ( 'Content-Type ' , 'application/json ' );
@@ -938,25 +942,25 @@ public function test_max_url_metrics_size_filter( Closure $set_up, array $params
938
942
}
939
943
940
944
/**
941
- * Data provider for test_max_url_metrics_size_filter .
945
+ * Data provider for test_maximum_url_metrics_size_filter .
942
946
*
943
947
* @return array<string, mixed> Test data.
944
948
*/
945
- public function data_provider_max_url_metrics_size_filter (): array {
949
+ public function data_provider_maximum_url_metrics_size_filter (): array {
946
950
$ valid_params = $ this ->get_valid_params ();
947
951
$ valid_element = $ valid_params ['elements ' ][0 ];
948
952
949
953
return array (
950
- 'url_metrics_should_be_accepted_because_of_increased_max_url_metrics_size ' => array (
951
- 'set_up ' => static function (): void {
954
+ 'url_metrics_should_be_accepted_because_of_increased_maximum_url_metrics_size ' => array (
955
+ 'set_up ' => static function (): void {
952
956
add_filter (
953
- 'od_max_url_metric_size ' ,
957
+ 'od_maximum_url_metric_size ' ,
954
958
static function (): int {
955
959
return MB_IN_BYTES * 2 ;
956
960
}
957
961
);
958
962
},
959
- 'params ' => array_merge (
963
+ 'params ' => array_merge (
960
964
$ valid_params ,
961
965
array (
962
966
// Fill the JSON with more than 1MB of data.
@@ -970,19 +974,20 @@ static function (): int {
970
974
),
971
975
)
972
976
),
973
- 'expected_status ' => 200 ,
974
- 'expected_code ' => null ,
977
+ 'expected_status ' => 200 ,
978
+ 'expected_code ' => null ,
979
+ 'expected_incorrect_usage ' => false ,
975
980
),
976
- 'url_metrics_should_be_rejected_because_of_decreased_max_url_metrics_size ' => array (
977
- 'set_up ' => static function (): void {
981
+ 'url_metrics_should_be_rejected_because_of_decreased_maximum_url_metrics_size ' => array (
982
+ 'set_up ' => static function (): void {
978
983
add_filter (
979
- 'od_max_url_metric_size ' ,
984
+ 'od_maximum_url_metric_size ' ,
980
985
static function (): int {
981
986
return MB_IN_BYTES / 2 ;
982
987
}
983
988
);
984
989
},
985
- 'params ' => array_merge (
990
+ 'params ' => array_merge (
986
991
$ valid_params ,
987
992
array (
988
993
// Fill the JSON with more than 1MB of data.
@@ -996,10 +1001,37 @@ static function (): int {
996
1001
),
997
1002
)
998
1003
),
999
- 'expected_status ' => 413 ,
1000
- 'expected_code ' => 'rest_content_too_large ' ,
1004
+ 'expected_status ' => 413 ,
1005
+ 'expected_code ' => 'rest_content_too_large ' ,
1006
+ 'expected_incorrect_usage ' => false ,
1007
+ ),
1008
+ 'negative_maximum_url_metric_size_is_treated_as_1mb ' => array (
1009
+ 'set_up ' => static function (): void {
1010
+ add_filter (
1011
+ 'od_maximum_url_metric_size ' ,
1012
+ static function (): int {
1013
+ return -1 ;
1014
+ }
1015
+ );
1016
+ },
1017
+ 'params ' => array_merge (
1018
+ $ valid_params ,
1019
+ array (
1020
+ // Fill the JSON with more than 1MB of data.
1021
+ 'elements ' => array (
1022
+ array_merge (
1023
+ $ valid_element ,
1024
+ array (
1025
+ 'xpath ' => sprintf ( '/HTML/BODY/DIV[@id= \'%s \']/*[1][self::DIV] ' , str_repeat ( 'A ' , MB_IN_BYTES / 2 ) ),
1026
+ )
1027
+ ),
1028
+ ),
1029
+ )
1030
+ ),
1031
+ 'expected_status ' => 200 ,
1032
+ 'expected_code ' => null ,
1033
+ 'expected_incorrect_usage ' => true ,
1001
1034
),
1002
-
1003
1035
);
1004
1036
}
1005
1037
0 commit comments