Skip to content

Commit 83e969b

Browse files
REST API: Update test to ensure non-empty properties array remains unchanged in schema
1 parent ac942d5 commit 83e969b

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

tests/phpunit/tests/rest-api/rest-schema-validation.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,16 +2122,22 @@ public function test_empty_properties_array_sanitized_to_object() {
21222122
* @ticket 63186
21232123
*/
21242124
public function test_non_empty_properties_array_remains_unchanged() {
2125-
$schema = array(
2126-
'type' => 'object',
2127-
'properties' => array(
2128-
'field' => array( 'type' => 'string' ),
2125+
$data = array(
2126+
'schema' => array(
2127+
'type' => 'object',
2128+
'properties' => array(
2129+
'field' => array( 'type' => 'string' ),
2130+
),
21292131
),
21302132
);
21312133

2132-
$sanitized_schema = apply_filters( 'rest_pre_echo_response', $schema );
2133-
$this->assertNotEmpty( $sanitized_schema['properties'] );
2134-
$this->assertIsArray( $sanitized_schema['properties'], 'Non-empty properties should remain as an array.' );
2135-
$this->assertArrayHasKey( 'field', $sanitized_schema['properties'] );
2134+
$request = new WP_REST_Request( 'OPTIONS', '/test' );
2135+
$server = rest_get_server();
2136+
2137+
$sanitized_data = apply_filters( 'rest_pre_echo_response', $data, $server, $request );
2138+
2139+
$this->assertNotEmpty( $sanitized_data['schema']['properties'] );
2140+
$this->assertIsArray( $sanitized_data['schema']['properties'], 'Non-empty properties should remain as an array.' );
2141+
$this->assertArrayHasKey( 'field', $sanitized_data['schema']['properties'] );
21362142
}
21372143
}

0 commit comments

Comments
 (0)