Make WordPress Core


Ignore:
Timestamp:
10/29/2015 10:50:13 PM (9 years ago)
Author:
pento
Message:

Embeds: Who put this REST API infrastructure in my WordPress?

Well, while it's here, we probably should make use of it. The oEmbed endpoint now uses the REST API infrastructure, instead of providing its own.

Props swissspidy.

Fixes #34207.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/oembed/headers.php

    r35242 r35436  
    88 */
    99class Tests_oEmbed_HTTP_Headers extends WP_UnitTestCase {
    10     function test_request_json_response_headers() {
     10    function test_rest_pre_serve_request_headers() {
    1111        if ( ! function_exists( 'xdebug_get_headers' ) ) {
    1212            $this->markTestSkipped( 'xdebug is required for this test' );
    1313        }
    1414
    15         $post = self::factory()->post->create_and_get( array(
     15        $post = $this->factory()->post->create_and_get( array(
    1616            'post_title'  => 'Hello World',
    1717        ) );
    1818
    19         $request = array(
    20             'url'      => get_permalink( $post->ID ),
    21             'format'   => 'json',
    22             'maxwidth' => 600,
    23             'callback' => '',
    24         );
     19        $request = new WP_REST_Request( 'GET', '/oembed/1.0/embed' );
     20        $request->set_param( 'url', get_permalink( $post->ID ) );
     21        $request->set_param( 'format', 'xml' );
    2522
    26         $legacy_controller = new WP_oEmbed_Controller();
    27         $legacy_controller->dispatch( $request );
     23        $server   = new WP_REST_Server();
     24        $response = $server->dispatch( $request );
     25        $output   = get_echo( '_oembed_rest_pre_serve_request', array( true, $response, $request, $server ) );
    2826
    29         $headers = xdebug_get_headers();
    30 
    31         $this->assertTrue( in_array( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ), $headers ) );
    32         $this->assertTrue( in_array( 'X-Content-Type-Options: nosniff', $headers ) );
    33 
    34         $request['callback'] = 'foobar';
    35 
    36         $legacy_controller->dispatch( $request );
    37 
    38         $headers = xdebug_get_headers();
    39 
    40         $this->assertTrue( in_array( 'Content-Type: application/javascript; charset=' . get_option( 'blog_charset' ), $headers ) );
    41         $this->assertTrue( in_array( 'X-Content-Type-Options: nosniff', $headers ) );
    42     }
    43 
    44     function test_request_xml_response_headers() {
    45         if ( ! function_exists( 'xdebug_get_headers' ) ) {
    46             $this->markTestSkipped( 'xdebug is required for this test' );
    47         }
    48 
    49         $post = self::factory()->post->create_and_get( array(
    50             'post_title'  => 'Hello World',
    51         ) );
    52 
    53         $request = array(
    54             'url'      => get_permalink( $post->ID ),
    55             'format'   => 'xml',
    56             'maxwidth' => 600,
    57         );
    58 
    59         $legacy_controller = new WP_oEmbed_Controller();
    60         $legacy_controller->dispatch( $request );
     27        $this->assertNotEmpty( $output );
    6128
    6229        $headers = xdebug_get_headers();
Note: See TracChangeset for help on using the changeset viewer.