Make WordPress Core


Ignore:
Timestamp:
01/19/2023 09:46:58 PM (4 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-users-controller.php

    r54891 r55102  
    28262826        }
    28272827
     2828        public function additional_field_get_callback( $object, $field_name ) {
     2829                return get_user_meta( $object['id'], $field_name, true );
     2830        }
     2831
     2832        public function additional_field_update_callback( $value, $user, $field_name ) {
     2833                if ( 'returnError' === $value ) {
     2834                        return new WP_Error( 'rest_invalid_param', 'Testing an error.', array( 'status' => 400 ) );
     2835                }
     2836                update_user_meta( $user->ID, $field_name, $value );
     2837        }
     2838
    28282839        /**
    28292840         * @ticket 39701
     
    30733084        }
    30743085
    3075         public function additional_field_get_callback( $object ) {
    3076                 return get_user_meta( $object['id'], 'my_custom_int', true );
    3077         }
    3078 
    3079         public function additional_field_update_callback( $value, $user ) {
    3080                 if ( 'returnError' === $value ) {
    3081                         return new WP_Error( 'rest_invalid_param', 'Testing an error.', array( 'status' => 400 ) );
    3082                 }
    3083                 update_user_meta( $user->ID, 'my_custom_int', $value );
    3084         }
    3085 
    30863086        protected function check_user_data( $user, $data, $context, $links ) {
    30873087                $this->assertSame( $user->ID, $data['id'] );
Note: See TracChangeset for help on using the changeset viewer.