Make WordPress Core


Ignore:
Timestamp:
01/19/2023 09:46:58 PM (3 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r54855 r55102  
    45874587    }
    45884588
    4589     public function additional_field_get_callback( $object ) {
    4590         return get_post_meta( $object['id'], 'my_custom_int', true );
    4591     }
    4592 
    4593     public function additional_field_update_callback( $value, $post ) {
     4589    public function additional_field_get_callback( $object, $field_name ) {
     4590        return get_post_meta( $object['id'], $field_name, true );
     4591    }
     4592
     4593    public function additional_field_update_callback( $value, $post, $field_name ) {
    45944594        if ( 'returnError' === $value ) {
    45954595            return new WP_Error( 'rest_invalid_param', 'Testing an error.', array( 'status' => 400 ) );
    45964596        }
    4597         update_post_meta( $post->ID, 'my_custom_int', $value );
     4597        update_post_meta( $post->ID, $field_name, $value );
    45984598    }
    45994599
Note: See TracChangeset for help on using the changeset viewer.