diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index 9e726b4891..b55620db73 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -1983,17 +1983,13 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { break; case 'post-formats': - $supports_formats = get_theme_support( 'post-formats' ); - - // Force to an array. Supports formats can return true even if empty in some cases. - $supports_formats = is_array( $supports_formats ) ? array_values( $supports_formats[0] ) : array(); - - $supported_formats = array_merge( array( 'standard' ), $supports_formats ); + // Get the native post formats and remove the array keys. + $formats = array_values( get_post_format_slugs() ); $schema['properties']['format'] = array( 'description' => __( 'The format for the object.' ), 'type' => 'string', - 'enum' => $supported_formats, + 'enum' => $formats, 'context' => array( 'view', 'edit' ), ); break; diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index f7b7a74206..db94b71d5f 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -990,20 +990,12 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te $this->assertEquals( $post2, $data[0]['id'] ); } - public function test_get_items_no_supported_post_formats() { - // This causes get_theme_support( 'post-formats' ) to return `true` (not an array) - add_theme_support( 'post-formats' ); - + public function test_get_items_all_post_formats() { $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ); $response = $this->server->dispatch( $request ); $data = $response->get_data(); - // Set the expected state back for the rest of the tests. - global $_wp_theme_features; - unset( $_wp_theme_features['post-formats'] ); - add_theme_support( 'post-formats', array( 'post', 'gallery' ) ); - - $formats = array( 'standard' ); + $formats = array_values( get_post_format_slugs() ); $this->assertEquals( $formats, $data['schema']['properties']['format']['enum'] ); } @@ -1651,8 +1643,10 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te ) ); $request->set_body_params( $params ); $response = $this->server->dispatch( $request ); + $this->assertEquals( 201, $response->get_status() ); - $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); + $data = $response->get_data(); + $this->assertEquals( 'link', $data['format'] ); } public function test_create_update_post_with_featured_media() { @@ -2149,8 +2143,10 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te ) ); $request->set_body_params( $params ); $response = $this->server->dispatch( $request ); + $this->assertEquals( 200, $response->get_status() ); - $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); + $data = $response->get_data(); + $this->assertEquals( 'link', $data['format'] ); } public function test_update_post_ignore_readonly() { diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index a7f253282f..23a2fb918b 100644 --- a/tests/qunit/fixtures/wp-api-generated.js +++ b/tests/qunit/fixtures/wp-api-generated.js @@ -388,7 +388,16 @@ mockedApiResponse.Schema = { "format": { "required": false, "enum": [ - "standard" + "standard", + "aside", + "chat", + "gallery", + "link", + "image", + "quote", + "status", + "video", + "audio" ], "description": "The format for the object.", "type": "string" @@ -562,7 +571,16 @@ mockedApiResponse.Schema = { "format": { "required": false, "enum": [ - "standard" + "standard", + "aside", + "chat", + "gallery", + "link", + "image", + "quote", + "status", + "video", + "audio" ], "description": "The format for the object.", "type": "string"