Make WordPress Core

Ticket #39805: 39805.2.diff

File 39805.2.diff, 3.2 KB (added by kadamwhite, 9 years ago)

Add unit tests to previous patch

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

    diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
    index 25e9c9a..583f732 100644
    class WP_REST_Posts_Controller extends WP_REST_Controller { 
    19411941                                        $schema['properties']['featured_media'] = array(
    19421942                                                'description' => __( 'The ID of the featured media for the object.' ),
    19431943                                                'type'        => 'integer',
    1944                                                 'context'     => array( 'view', 'edit' ),
     1944                                                'context'     => array( 'view', 'edit', 'embed' ),
    19451945                                        );
    19461946                                        break;
    19471947
  • tests/phpunit/tests/rest-api/rest-posts-controller.php

    diff --git tests/phpunit/tests/rest-api/rest-posts-controller.php tests/phpunit/tests/rest-api/rest-posts-controller.php
    index ca16356..8bf6482 100644
    class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 
    26592659                $this->assertArrayHasKey( 'categories', $properties );
    26602660        }
    26612661
     2662        /**
     2663         * @ticket 39805
     2664         */
     2665        public function test_get_post_view_context_properties() {
     2666                $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
     2667                $request->set_param( 'context', 'view' );
     2668                $response = $this->server->dispatch( $request );
     2669                $data = $response->get_data();
     2670
     2671                foreach( array(
     2672                        'author',
     2673                        'categories',
     2674                        'comment_status',
     2675                        'content',
     2676                        'date',
     2677                        'date_gmt',
     2678                        'excerpt',
     2679                        'featured_media',
     2680                        'format',
     2681                        'guid',
     2682                        'id',
     2683                        'link',
     2684                        'meta',
     2685                        'modified',
     2686                        'modified_gmt',
     2687                        'ping_status',
     2688                        'slug',
     2689                        'sticky',
     2690                        'tags',
     2691                        'template',
     2692                        'title',
     2693                        'type',
     2694                ) as $key ) {
     2695                        $this->assertArrayHasKey( $key, $data );
     2696                }
     2697        }
     2698
     2699        public function test_get_post_edit_context_properties() {
     2700                wp_set_current_user( self::$editor_id );
     2701
     2702                $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
     2703                $request->set_param( 'context', 'edit' );
     2704                $response = $this->server->dispatch( $request );
     2705                $data = $response->get_data();
     2706
     2707                foreach( array(
     2708                        'author',
     2709                        'categories',
     2710                        'comment_status',
     2711                        'content',
     2712                        'date',
     2713                        'date_gmt',
     2714                        'excerpt',
     2715                        'featured_media',
     2716                        'format',
     2717                        'guid',
     2718                        'id',
     2719                        'link',
     2720                        'meta',
     2721                        'modified',
     2722                        'modified_gmt',
     2723                        'password',
     2724                        'ping_status',
     2725                        'slug',
     2726                        'status',
     2727                        'sticky',
     2728                        'tags',
     2729                        'template',
     2730                        'title',
     2731                        'type',
     2732                ) as $key ) {
     2733                        $this->assertArrayHasKey( $key, $data );
     2734                }
     2735        }
     2736
     2737        public function test_get_post_embed_context_properties() {
     2738                $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
     2739                $request->set_param( 'context', 'embed' );
     2740                $response = $this->server->dispatch( $request );
     2741                $data = $response->get_data();
     2742
     2743                foreach( array(
     2744                        'author',
     2745                        'date',
     2746                        'excerpt',
     2747                        'featured_media',
     2748                        'id',
     2749                        'link',
     2750                        'slug',
     2751                        'title',
     2752                        'type',
     2753                ) as $key ) {
     2754                        $this->assertArrayHasKey( $key, $data );
     2755                }
     2756        }
     2757
    26622758        public function test_status_array_enum_args() {
    26632759                $request = new WP_REST_Request( 'GET', '/wp/v2' );
    26642760                $response = $this->server->dispatch( $request );