Make WordPress Core


Ignore:
Timestamp:
10/29/2018 12:23:11 AM (8 years ago)
Author:
danielbachhuber
Message:

Block Editor: Preload wp/v2/media with OPTIONS for caps check.

Also introduces a block_editor_preload_paths filter for plugins and themes to preload additional data.

Props imath, mattheu.
Fixes #45194.

File:
1 edited

Legend:

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

    r43766 r43833  
    630630                $this->assertTrue( is_array( rest_preload_api_request( 0, '/' ) ) );
    631631        }
     632
     633        function test_rest_preload_api_request_with_method() {
     634                $rest_server = $GLOBALS['wp_rest_server'];
     635                $GLOBALS['wp_rest_server'] = null;
     636
     637                $preload_paths = array(
     638                        '/wp/v2/types',
     639                        array( '/wp/v2/media', 'OPTIONS' ),
     640                );
     641
     642                $preload_data = array_reduce(
     643                        $preload_paths,
     644                        'rest_preload_api_request',
     645                        array()
     646                );
     647
     648                $this->assertSame( array_keys( $preload_data ), array( '/wp/v2/types', 'OPTIONS' ) );
     649                $this->assertTrue( isset( $preload_data['OPTIONS']['/wp/v2/media'] ) );
     650
     651                $GLOBALS['wp_rest_server'] = $rest_server;
     652        }
    632653}
Note: See TracChangeset for help on using the changeset viewer.