mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
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:
parent
a9bd7719db
commit
e4e15d1d8b
@ -1678,6 +1678,16 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$wp_rest_additional_fields = array();
|
||||
}
|
||||
|
||||
public function additional_field_get_callback( $object, $field_name ) {
|
||||
return 123;
|
||||
}
|
||||
|
||||
public function additional_field_update_callback( $value, $attachment ) {
|
||||
if ( 'returnError' === $value ) {
|
||||
return new WP_Error( 'rest_invalid_param', 'Testing an error.', array( 'status' => 400 ) );
|
||||
}
|
||||
}
|
||||
|
||||
public function test_search_item_by_filename() {
|
||||
$id1 = self::factory()->attachment->create_object(
|
||||
self::$test_file,
|
||||
@ -1706,16 +1716,6 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$this->assertSame( 'image/png', $data[0]['mime_type'] );
|
||||
}
|
||||
|
||||
public function additional_field_get_callback( $object, $request ) {
|
||||
return 123;
|
||||
}
|
||||
|
||||
public function additional_field_update_callback( $value, $attachment ) {
|
||||
if ( 'returnError' === $value ) {
|
||||
return new WP_Error( 'rest_invalid_param', 'Testing an error.', array( 'status' => 400 ) );
|
||||
}
|
||||
}
|
||||
|
||||
public function test_links_exist() {
|
||||
|
||||
wp_set_current_user( self::$editor_id );
|
||||
|
||||
@ -514,12 +514,12 @@ class WP_Test_REST_Autosaves_Controller extends WP_Test_REST_Post_Type_Controlle
|
||||
$wp_rest_additional_fields = array();
|
||||
}
|
||||
|
||||
public function additional_field_get_callback( $object ) {
|
||||
return get_post_meta( $object['id'], 'my_custom_int', true );
|
||||
public function additional_field_get_callback( $object, $field_name ) {
|
||||
return get_post_meta( $object['id'], $field_name, true );
|
||||
}
|
||||
|
||||
public function additional_field_update_callback( $value, $post ) {
|
||||
update_post_meta( $post->ID, 'my_custom_int', $value );
|
||||
public function additional_field_update_callback( $value, $post, $field_name ) {
|
||||
update_post_meta( $post->ID, $field_name, $value );
|
||||
}
|
||||
|
||||
protected function check_get_autosave_response( $response, $autosave ) {
|
||||
|
||||
@ -1180,7 +1180,7 @@ class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas
|
||||
$wp_rest_additional_fields = array();
|
||||
}
|
||||
|
||||
public function additional_field_get_callback( $object, $request ) {
|
||||
public function additional_field_get_callback( $object, $field_name ) {
|
||||
return 123;
|
||||
}
|
||||
|
||||
|
||||
@ -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 ) {
|
||||
|
||||
@ -4586,15 +4586,15 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te
|
||||
$wp_rest_additional_fields = array();
|
||||
}
|
||||
|
||||
public function additional_field_get_callback( $object ) {
|
||||
return get_post_meta( $object['id'], 'my_custom_int', true );
|
||||
public function additional_field_get_callback( $object, $field_name ) {
|
||||
return get_post_meta( $object['id'], $field_name, true );
|
||||
}
|
||||
|
||||
public function additional_field_update_callback( $value, $post ) {
|
||||
public function additional_field_update_callback( $value, $post, $field_name ) {
|
||||
if ( 'returnError' === $value ) {
|
||||
return new WP_Error( 'rest_invalid_param', 'Testing an error.', array( 'status' => 400 ) );
|
||||
}
|
||||
update_post_meta( $post->ID, 'my_custom_int', $value );
|
||||
update_post_meta( $post->ID, $field_name, $value );
|
||||
}
|
||||
|
||||
public function test_publish_action_ldo_registered() {
|
||||
|
||||
@ -402,12 +402,12 @@ class WP_Test_REST_Revisions_Controller extends WP_Test_REST_Controller_Testcase
|
||||
$wp_rest_additional_fields = array();
|
||||
}
|
||||
|
||||
public function additional_field_get_callback( $object ) {
|
||||
return get_post_meta( $object['id'], 'my_custom_int', true );
|
||||
public function additional_field_get_callback( $object, $field_name ) {
|
||||
return get_post_meta( $object['id'], $field_name, true );
|
||||
}
|
||||
|
||||
public function additional_field_update_callback( $value, $post ) {
|
||||
update_post_meta( $post->ID, 'my_custom_int', $value );
|
||||
public function additional_field_update_callback( $value, $post, $field_name ) {
|
||||
update_post_meta( $post->ID, $field_name, $value );
|
||||
}
|
||||
|
||||
protected function check_get_revision_response( $response, $revision ) {
|
||||
|
||||
@ -1324,6 +1324,16 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$wp_rest_additional_fields = array();
|
||||
}
|
||||
|
||||
public function additional_field_get_callback( $object, $field_name ) {
|
||||
return 123;
|
||||
}
|
||||
|
||||
public function additional_field_update_callback( $value, $tag ) {
|
||||
if ( 'returnError' === $value ) {
|
||||
return new WP_Error( 'rest_invalid_param', 'Testing an error.', array( 'status' => 400 ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 38504
|
||||
*/
|
||||
@ -1396,16 +1406,6 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$this->assertArrayNotHasKey( $view_field, $data );
|
||||
}
|
||||
|
||||
public function additional_field_get_callback( $object, $request ) {
|
||||
return 123;
|
||||
}
|
||||
|
||||
public function additional_field_update_callback( $value, $tag ) {
|
||||
if ( 'returnError' === $value ) {
|
||||
return new WP_Error( 'rest_invalid_param', 'Testing an error.', array( 'status' => 400 ) );
|
||||
}
|
||||
}
|
||||
|
||||
protected function check_get_taxonomy_terms_response( $response ) {
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$data = $response->get_data();
|
||||
|
||||
@ -2825,6 +2825,17 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$wp_rest_additional_fields = array();
|
||||
}
|
||||
|
||||
public function additional_field_get_callback( $object, $field_name ) {
|
||||
return get_user_meta( $object['id'], $field_name, true );
|
||||
}
|
||||
|
||||
public function additional_field_update_callback( $value, $user, $field_name ) {
|
||||
if ( 'returnError' === $value ) {
|
||||
return new WP_Error( 'rest_invalid_param', 'Testing an error.', array( 'status' => 400 ) );
|
||||
}
|
||||
update_user_meta( $user->ID, $field_name, $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 39701
|
||||
* @group ms-required
|
||||
@ -3072,17 +3083,6 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
);
|
||||
}
|
||||
|
||||
public function additional_field_get_callback( $object ) {
|
||||
return get_user_meta( $object['id'], 'my_custom_int', true );
|
||||
}
|
||||
|
||||
public function additional_field_update_callback( $value, $user ) {
|
||||
if ( 'returnError' === $value ) {
|
||||
return new WP_Error( 'rest_invalid_param', 'Testing an error.', array( 'status' => 400 ) );
|
||||
}
|
||||
update_user_meta( $user->ID, 'my_custom_int', $value );
|
||||
}
|
||||
|
||||
protected function check_user_data( $user, $data, $context, $links ) {
|
||||
$this->assertSame( $user->ID, $data['id'] );
|
||||
$this->assertSame( $user->display_name, $data['name'] );
|
||||
|
||||
Loading…
Reference in New Issue
Block a user