Make WordPress Core


Ignore:
Timestamp:
07/14/2017 04:04:04 PM (7 years ago)
Author:
westonruter
Message:

REST API: Ensure maxwidth and maxheight params are forwarded to oEmbed provider in proxy requests.

Also correct phpdoc return tag on WP_oEmbed_Controller::get_proxy_item() and remove dead code in oEmbed controller phpunit tests.

Amends [40628].
See #40450.
Fixes #41299.

File:
1 edited

Legend:

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

    r41035 r41047  
    5050        parent::tearDown();
    5151
    52         remove_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10, 3 );
     52        remove_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10 );
    5353    }
    5454
     
    7171        unset( $preempt, $r );
    7272
     73        $parsed_url = wp_parse_url( $url );
     74        parse_str( $parsed_url['query'], $query_params );
    7375        $this->request_count += 1;
    7476
    7577        // Mock request to YouTube Embed.
    76         if ( false !== strpos( $url, self::YOUTUBE_VIDEO_ID ) ) {
     78        if ( ! empty( $query_params['url'] ) && false !== strpos( $query_params['url'], self::YOUTUBE_VIDEO_ID ) ) {
    7779            return array(
    7880                'response' => array(
     
    8587                        'provider_name'    => 'YouTube',
    8688                        'provider_url'     => 'https://www.youtube.com',
    87                         'thumbnail_width'  => 480,
    88                         'width'            => 500,
    89                         'thumbnail_height' => 360,
    90                         'html'             => '<iframe width="500" height="375" src="https://www.youtube.com/embed/' . self::YOUTUBE_VIDEO_ID . '?feature=oembed" frameborder="0" allowfullscreen></iframe>',
     89                        'thumbnail_width'  => $query_params['maxwidth'],
     90                        'width'            => $query_params['maxwidth'],
     91                        'thumbnail_height' => $query_params['maxheight'],
     92                        'height'           => $query_params['maxheight'],
     93                        'html'             => '<iframe width="' . $query_params['maxwidth'] . '" height="' . $query_params['maxheight'] . '" src="https://www.youtube.com/embed/' . self::YOUTUBE_VIDEO_ID . '?feature=oembed" frameborder="0" allowfullscreen></iframe>',
    9194                        'author_name'      => 'Yosemitebear62',
    9295                        'thumbnail_url'    => 'https://i.ytimg.com/vi/' . self::YOUTUBE_VIDEO_ID . '/hqdefault.jpg',
    9396                        'title'            => 'Yosemitebear Mountain Double Rainbow 1-8-10',
    94                         'height'           => 375,
    9597                    )
    9698                ),
     
    478480
    479481        $this->assertEquals( 400, $response->get_status() );
    480         $data = $response->get_data();
    481482    }
    482483
     
    485486        $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' );
    486487        $request->set_param( 'url', 'https://www.youtube.com/watch?v=' . self::YOUTUBE_VIDEO_ID );
     488        $request->set_param( 'maxwidth', 456 );
     489        $request->set_param( 'maxheight', 789 );
    487490        $request->set_param( '_wpnonce', wp_create_nonce( 'wp_rest' ) );
    488491        $response = $this->server->dispatch( $request );
     
    499502        $request->set_param( 'url', 'https://www.youtube.com/watch?v=' . self::YOUTUBE_VIDEO_ID );
    500503        $request->set_param( '_wpnonce', wp_create_nonce( 'wp_rest' ) );
     504        $request->set_param( 'maxwidth', 456 );
     505        $request->set_param( 'maxheight', 789 );
    501506        $response = $this->server->dispatch( $request );
    502507        $this->assertEquals( 1, $this->request_count );
     
    509514        $this->assertEquals( 'YouTube', $data->provider_name );
    510515        $this->assertEquals( 'https://i.ytimg.com/vi/' . self::YOUTUBE_VIDEO_ID . '/hqdefault.jpg', $data->thumbnail_url );
     516        $this->assertEquals( $data->width, $request['maxwidth'] );
     517        $this->assertEquals( $data->height, $request['maxheight'] );
    511518    }
    512519
Note: See TracChangeset for help on using the changeset viewer.