Make WordPress Core

Ticket #49147: 49147.7.diff

File 49147.7.diff, 1.5 KB (added by TimothyBlynJacobs, 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..87e46d5807 100644
    a b class Tests_REST_Server extends WP_Test_REST_TestCase { 
    10201020                $this->assertContains( 'test/another', $namespaces );
    10211021        }
    10221022
     1023        /**
     1024         * @ticket 49147
     1025         */
     1026        public function test_get_data_for_non_variable_route_includes_links() {
     1027                $expected = array(
     1028                        'self' => array(
     1029                                array( 'href' => rest_url('wp/v2/posts') ),
     1030                        ),
     1031                );
     1032
     1033                $actual = rest_get_server()->get_data_for_route(
     1034                        '/wp/v2/posts',
     1035                        array(
     1036                                array(
     1037                                        'methods'       => array( 'OPTIONS' => 1 ),
     1038                                        'show_in_index' => true,
     1039                                ),
     1040                        )
     1041                );
     1042
     1043                $this->assertEquals( $expected, $actual['_links'] );
     1044        }
     1045
    10231046        public function test_x_robot_tag_header_on_requests() {
    10241047                $request = new WP_REST_Request( 'GET', '/', array() );
    10251048