Tests: Correct additional_field_get_callback() parameters in some REST API tests.

The second parameter passed to `get_callback` in `WP_REST_Controller::add_additional_fields_to_object()` is the field name, not the request details.

Includes moving the `get_callback` and `update_callback` helper functions next to the tests they are used in.

Follow-up to [38832], [43768].

See #56793.

git-svn-id: https://develop.svn.wordpress.org/trunk@55102 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2023-01-19 21:46:58 +00:00
parent a9bd7719db
commit e4e15d1d8b
8 changed files with 48 additions and 48 deletions

View File

@@ -3298,15 +3298,15 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
$wp_rest_additional_fields = array();
}
public function additional_field_get_callback( $object ) {
return get_comment_meta( $object['id'], 'my_custom_int', true );
public function additional_field_get_callback( $object, $field_name ) {
return get_comment_meta( $object['id'], $field_name, true );
}
public function additional_field_update_callback( $value, $comment ) {
public function additional_field_update_callback( $value, $comment, $field_name ) {
if ( 'returnError' === $value ) {
return new WP_Error( 'rest_invalid_param', 'Testing an error.', array( 'status' => 400 ) );
}
update_comment_meta( $comment->comment_ID, 'my_custom_int', $value );
update_comment_meta( $comment->comment_ID, $field_name, $value );
}
protected function check_comment_data( $data, $context, $links ) {