Make WordPress Core

Ticket #40626: 40626-add-global.patch

File 40626-add-global.patch, 1.7 KB (added by pdufour, 7 years ago)
  • src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php

    diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php
    index d3f665d..131e34c 100644
    a b class WP_REST_Revisions_Controller extends WP_REST_Controller { 
    338338         * @return WP_REST_Response Response object.
    339339         */
    340340        public function prepare_item_for_response( $post, $request ) {
     341                $GLOBALS['post'] = $post;
     342
     343                setup_postdata( $post );
    341344
    342345                $schema = $this->get_item_schema();
    343346
  • tests/phpunit/tests/rest-api/rest-revisions-controller.php

    diff --git a/tests/phpunit/tests/rest-api/rest-revisions-controller.php b/tests/phpunit/tests/rest-api/rest-revisions-controller.php
    index 4557004..cdb7e2b 100644
    a b  
     1
    12<?php
    23/**
    34 * Unit tests covering WP_REST_Revisions_Controller functionality.
    class WP_Test_REST_Revisions_Controller extends WP_Test_REST_Controller_Testcase 
    335336                $this->assertEquals( rest_url( '/wp/v2/' . $parent_base . '/' . $revision->post_parent ), $links['parent'][0]['href'] );
    336337        }
    337338
     339        public function test_get_item_sets_up_postdata() {
     340                wp_set_current_user( self::$editor_id );
     341                $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
     342                $this->server->dispatch( $request );
     343
     344                $post = get_post();
     345                $parent_post_id = wp_is_post_revision ( $post->ID );
     346
     347                $this->assertEquals( $post->ID, $this->revision_id1 );
     348                $this->assertEquals( $parent_post_id, self::$post_id );
     349        }
     350
    338351}