Skip to content

Commit d4af322

Browse files
REST API: Add test to ensure regular response data with empty properties field is not affected
1 parent 9c3d61d commit d4af322

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,4 +2140,25 @@ public function test_non_empty_properties_array_remains_unchanged() {
21402140
$this->assertIsArray( $sanitized_data['schema']['properties'], 'Non-empty properties should remain as an array.' );
21412141
$this->assertArrayHasKey( 'field', $sanitized_data['schema']['properties'] );
21422142
}
2143+
2144+
/**
2145+
* Test that regular response data with empty properties field is not affected.
2146+
*
2147+
* @ticket 63186
2148+
*/
2149+
public function test_regular_response_properties_not_affected() {
2150+
$data = array(
2151+
'id' => 123,
2152+
'title' => 'Test Post',
2153+
'properties' => array(),
2154+
);
2155+
2156+
$request = new WP_REST_Request( 'GET', '/test' );
2157+
$server = rest_get_server();
2158+
2159+
$result = apply_filters( 'rest_pre_echo_response', $data, $server, $request );
2160+
2161+
$this->assertIsArray( $result['properties'], 'Regular response data should not be affected.' );
2162+
$this->assertEmpty( $result['properties'] );
2163+
}
21432164
}

0 commit comments

Comments
 (0)