File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
tests/phpunit/tests/rest-api Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -2093,4 +2093,39 @@ public function data_combining_operation_error_message() {
20932093 ),
20942094 );
20952095 }
2096+
2097+ /**
2098+ * Test that an empty properties array is sanitized to an empty object.
2099+ *
2100+ * @ticket 63186
2101+ */
2102+ public function test_empty_properties_array_sanitized_to_object () {
2103+ $ schema = array (
2104+ 'type ' => 'object ' ,
2105+ 'properties ' => array (),
2106+ );
2107+
2108+ $ sanitized_schema = apply_filters ( 'rest_pre_echo_response ' , $ schema );
2109+ $ this ->assertIsObject ( $ sanitized_schema ['properties ' ], 'Empty properties array should be converted to an object. ' );
2110+ $ this ->assertEmpty ( (array ) $ sanitized_schema ['properties ' ] );
2111+ }
2112+
2113+ /**
2114+ * Test that a non-empty properties array remains unchanged.
2115+ *
2116+ * @ticket 63186
2117+ */
2118+ public function test_non_empty_properties_array_remains_unchanged () {
2119+ $ schema = array (
2120+ 'type ' => 'object ' ,
2121+ 'properties ' => array (
2122+ 'field ' => array ( 'type ' => 'string ' ),
2123+ ),
2124+ );
2125+
2126+ $ sanitized_schema = apply_filters ( 'rest_pre_echo_response ' , $ schema );
2127+ $ this ->assertNotEmpty ( $ sanitized_schema ['properties ' ] );
2128+ $ this ->assertIsArray ( $ sanitized_schema ['properties ' ], 'Non-empty properties should remain as an array. ' );
2129+ $ this ->assertArrayHasKey ( 'field ' , $ sanitized_schema ['properties ' ] );
2130+ }
20962131}
You can’t perform that action at this time.
0 commit comments