Make WordPress Core


Ignore:
Timestamp:
08/20/2021 11:43:21 PM (5 years ago)
Author:
azaozz
Message:

REST API: Remove trailing slashes when preloading requests and add unit tests for it.

Props antonvlasenko.
Fixes #51636.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api.php

    r51568 r51648  
    950950
    951951                $this->assertSame( array_keys( $preload_data ), array( '/wp/v2/types', 'OPTIONS' ) );
     952                $this->assertArrayHasKey( '/wp/v2/media', $preload_data['OPTIONS'] );
     953
     954                $GLOBALS['wp_rest_server'] = $rest_server;
     955        }
     956
     957        /**
     958         * @ticket 51636
     959         */
     960        function test_rest_preload_api_request_removes_trailing_slashes() {
     961                $rest_server               = $GLOBALS['wp_rest_server'];
     962                $GLOBALS['wp_rest_server'] = null;
     963
     964                $preload_paths = array(
     965                        '/wp/v2/types//',
     966                        array( '/wp/v2/media///', 'OPTIONS' ),
     967                        '////',
     968                );
     969
     970                $preload_data = array_reduce(
     971                        $preload_paths,
     972                        'rest_preload_api_request',
     973                        array()
     974                );
     975
     976                $this->assertSame( array_keys( $preload_data ), array( '/wp/v2/types', 'OPTIONS', '/' ) );
    952977                $this->assertArrayHasKey( '/wp/v2/media', $preload_data['OPTIONS'] );
    953978
Note: See TracChangeset for help on using the changeset viewer.