Make WordPress Core

Ticket #49147: 49147.4.diff

File 49147.4.diff, 1.9 KB (added by johnwatkins0, 5 years ago)
  • src/wp-includes/rest-api/class-wp-rest-server.php

    diff --git a/src/wp-includes/rest-api/class-wp-rest-server.php b/src/wp-includes/rest-api/class-wp-rest-server.php
    index efda2321b7..12de6c55f0 100644
    a b class WP_REST_Server { 
    12881288                        // For non-variable routes, generate links.
    12891289                        if ( strpos( $route, '{' ) === false ) {
    12901290                                $data['_links'] = array(
    1291                                         'self' => rest_url( $route ),
     1291                                        'self' => array(
     1292                                                array(
     1293                                                        'href' => rest_url( $route ),
     1294                                                ),
     1295                                        ),
    12921296                                );
    12931297                        }
    12941298                }
  • tests/phpunit/tests/rest-api/rest-server.php

    diff --git a/tests/phpunit/tests/rest-api/rest-server.php b/tests/phpunit/tests/rest-api/rest-server.php
    index 755f0296ea..afcd1c52b6 100644
    a b  
    77 */
    88
    99/**
    10  * @group restapi
     10 * @group restapi22
    1111 */
    1212class Tests_REST_Server extends WP_Test_REST_TestCase {
    1313        public function setUp() {
    class Tests_REST_Server extends WP_Test_REST_TestCase { 
    10201020                $this->assertContains( 'test/another', $namespaces );
    10211021        }
    10221022
     1023        /**
     1024         * Tests that the schema _links array is correctly formatted in non-variable REST routes.
     1025         *
     1026         * @ticket 49147
     1027         */
     1028        public function test_links_array_in_non_variable_routes() {
     1029                $this->set_permalink_structure( '/%postname%' );
     1030
     1031                $server = new WP_REST_Server();
     1032
     1033                $links = array(
     1034                        'self' => array(
     1035                                array( 'href' => 'http://example.org/wp-json/wp/v2/posts' ),
     1036                        ),
     1037                );
     1038
     1039                $result = $server->get_data_for_route(
     1040                        '/wp/v2/posts',
     1041                        array(
     1042                                array(
     1043                                        'methods'       => array( 'OPTIONS' => 1 ),
     1044                                        'show_in_index' => true,
     1045                                ),
     1046                        )
     1047                );
     1048
     1049                $this->assertEquals(
     1050                        $result['_links'],
     1051                        $links
     1052                );
     1053        }
     1054
    10231055        public function test_x_robot_tag_header_on_requests() {
    10241056                $request = new WP_REST_Request( 'GET', '/', array() );
    10251057