Ticket #39293: 39293.diff
File 39293.diff, 2.3 KB (added by , 6 years ago) |
---|
-
src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
1923 1923 1924 1924 case 'post-formats': 1925 1925 $supports_formats = get_theme_support( 'post-formats' ); 1926 1927 // Force to an array. Supports formats can return true even if empty in some cases. 1928 $supports_formats = is_array( $supports_formats ) ? array_values( $supports_formats[0] ) : array(); 1929 1930 $supported_formats = array_merge( array( 'standard' ), $supports_formats ); 1931 1926 1932 $schema['properties']['format'] = array( 1927 1933 'description' => __( 'The format for the object.' ), 1928 1934 'type' => 'string', 1929 'enum' => array_merge( array( 'standard' ), $supports_formats ? array_values( $supports_formats[0] ) : array() ),1935 'enum' => $supported_formats, 1930 1936 'context' => array( 'view', 'edit' ), 1931 1937 ); 1932 1938 break; -
tests/phpunit/tests/rest-api/rest-posts-controller.php
858 858 $this->assertEquals( $post2, $data[0]['id'] ); 859 859 } 860 860 861 /** 862 * Ticket #39293 863 */ 864 public function test_get_items_no_supported_post_formats() { 865 // See Ticket #39293. This sets an empty post format which resolves to `true`. 866 add_theme_support( 'post-formats' ); 867 868 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ); 869 $response = $this->server->dispatch( $request ); 870 $data = $response->get_data(); 871 872 $formats = array( 'standard' ); 873 874 $this->assertEquals( $formats, $data['schema']['properties']['format']['enum'] ); 875 876 // Set the expected state back for the rest of the tests. 877 global $_wp_theme_features; 878 unset( $_wp_theme_features['post-formats'] ); 879 add_theme_support( 'post-formats', array( 'post', 'gallery' ) ); 880 } 881 861 882 public function test_get_item() { 862 883 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 863 884 $response = $this->server->dispatch( $request );