Make WordPress Core

Ticket #39232: 39232.2.diff

File 39232.2.diff, 3.3 KB (added by jnylen0, 10 years ago)

Modify the existing "unsupported post format" tests instead of removing them.

  • src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    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 5b6cafd..30651d0 100644
    a b class WP_REST_Posts_Controller extends WP_REST_Controller {  
    19891989                                        break;
    19901990
    19911991                                case 'post-formats':
    1992                                         $supports_formats = get_theme_support( 'post-formats' );
    1993 
    1994                                         // Force to an array. Supports formats can return true even if empty in some cases.
    1995                                         $supports_formats = is_array( $supports_formats ) ? array_values( $supports_formats[0] ) : array();
    1996 
    1997                                         $supported_formats = array_merge( array( 'standard' ), $supports_formats );
     1992                                        // Get the native post formats and remove the array keys.
     1993                                        $formats = array_values( get_post_format_slugs() );
    19981994
    19991995                                        $schema['properties']['format'] = array(
    20001996                                                'description' => __( 'The format for the object.' ),
    20011997                                                'type'        => 'string',
    2002                                                 'enum'        => $supported_formats,
     1998                                                'enum'        => $formats,
    20031999                                                'context'     => array( 'view', 'edit' ),
    20042000                                        );
    20052001                                        break;
  • tests/phpunit/tests/rest-api/rest-posts-controller.php

    diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php
    index b5c18a0..503010f 100644
    a b class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te  
    914914                $this->assertEquals( $post2, $data[0]['id'] );
    915915        }
    916916
    917         public function test_get_items_no_supported_post_formats() {
    918                 // This causes get_theme_support( 'post-formats' ) to return `true` (not an array)
    919                 add_theme_support( 'post-formats' );
    920 
     917        public function test_get_items_all_post_formats() {
    921918                $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );
    922919                $response = $this->server->dispatch( $request );
    923920                $data = $response->get_data();
    924921
    925                 // Set the expected state back for the rest of the tests.
    926                 global $_wp_theme_features;
    927                 unset( $_wp_theme_features['post-formats'] );
    928                 add_theme_support( 'post-formats', array( 'post', 'gallery' ) );
    929 
    930                 $formats = array( 'standard' );
     922                $formats = array_values( get_post_format_slugs() );
    931923
    932924                $this->assertEquals( $formats, $data['schema']['properties']['format']['enum'] );
    933925        }
    class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te  
    15751567                ) );
    15761568                $request->set_body_params( $params );
    15771569                $response = $this->server->dispatch( $request );
     1570                $this->assertEquals( 201, $response->get_status() );
    15781571
    1579                 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     1572                $data = $response->get_data();
     1573                $this->assertEquals( 'link', $data['format'] );
    15801574        }
    15811575
    15821576        public function test_create_update_post_with_featured_media() {
    class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te  
    20732067                ) );
    20742068                $request->set_body_params( $params );
    20752069                $response = $this->server->dispatch( $request );
     2070                $this->assertEquals( 200, $response->get_status() );
    20762071
    2077                 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     2072                $data = $response->get_data();
     2073                $this->assertEquals( 'link', $data['format'] );
    20782074        }
    20792075
    20802076        public function test_update_post_ignore_readonly() {