Make WordPress Core

Ticket #41299: 41299.0.diff

File 41299.0.diff, 4.8 KB (added by westonruter, 8 years ago)

https://github.com/xwp/wordpress-develop/pull/239

  • src/wp-includes/class-wp-oembed-controller.php

    diff --git src/wp-includes/class-wp-oembed-controller.php src/wp-includes/class-wp-oembed-controller.php
    index d825c415d2..63cc1842ed 100644
    final class WP_oEmbed_Controller { 
    153153         *
    154154         * @see WP_oEmbed::get_html()
    155155         * @param WP_REST_Request $request Full data about the request.
    156          * @return WP_Error|array oEmbed response data or WP_Error on failure.
     156         * @return object|WP_Error oEmbed response data or WP_Error on failure.
    157157         */
    158158        public function get_proxy_item( $request ) {
    159159                $args = $request->get_params();
    160160
    161161                // Serve oEmbed data from cache if set.
     162                unset( $args['_wpnonce'] );
    162163                $cache_key = 'oembed_' . md5( serialize( $args ) );
    163164                $data = get_transient( $cache_key );
    164165                if ( ! empty( $data ) ) {
    final class WP_oEmbed_Controller { 
    168169                $url = $request['url'];
    169170                unset( $args['url'] );
    170171
     172                // Copy maxwidth/maxheight to width/height since WP_oEmbed::fetch() uses these arg names.
     173                if ( isset( $args['maxwidth'] ) ) {
     174                        $args['width'] = $args['maxwidth'];
     175                }
     176                if ( isset( $args['maxheight'] ) ) {
     177                        $args['height'] = $args['maxheight'];
     178                }
     179
    171180                $data = _wp_oembed_get_object()->get_data( $url, $args );
    172181
    173182                if ( false === $data ) {
  • tests/phpunit/tests/oembed/controller.php

    diff --git tests/phpunit/tests/oembed/controller.php tests/phpunit/tests/oembed/controller.php
    index a23c799e41..dc4bc8a4ce 100644
    class Test_oEmbed_Controller extends WP_UnitTestCase { 
    4444        public function tearDown() {
    4545                parent::tearDown();
    4646
    47                 remove_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10, 3 );
     47                remove_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10 );
    4848        }
    4949
    5050        /**
    class Test_oEmbed_Controller extends WP_UnitTestCase { 
    6565        public function mock_embed_request( $preempt, $r, $url ) {
    6666                unset( $preempt, $r );
    6767
     68                $parsed_url = wp_parse_url( $url );
     69                parse_str( $parsed_url['query'], $query_params );
    6870                $this->request_count += 1;
    6971
    7072                // Mock request to YouTube Embed.
    71                 if ( false !== strpos( $url, self::YOUTUBE_VIDEO_ID ) ) {
     73                if ( ! empty( $query_params['url'] ) && false !== strpos( $query_params['url'], self::YOUTUBE_VIDEO_ID ) ) {
    7274                        return array(
    7375                                'response' => array(
    7476                                        'code' => 200,
    class Test_oEmbed_Controller extends WP_UnitTestCase { 
    7981                                                'type'             => 'video',
    8082                                                'provider_name'    => 'YouTube',
    8183                                                'provider_url'     => 'https://www.youtube.com',
    82                                                 'thumbnail_width'  => 480,
    83                                                 'width'            => 500,
    84                                                 'thumbnail_height' => 360,
    85                                                 'html'             => '<iframe width="500" height="375" src="https://www.youtube.com/embed/' . self::YOUTUBE_VIDEO_ID . '?feature=oembed" frameborder="0" allowfullscreen></iframe>',
     84                                                'thumbnail_width'  => $query_params['maxwidth'],
     85                                                'width'            => $query_params['maxwidth'],
     86                                                'thumbnail_height' => $query_params['maxheight'],
     87                                                'height'           => $query_params['maxheight'],
     88                                                '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>',
    8689                                                'author_name'      => 'Yosemitebear62',
    8790                                                'thumbnail_url'    => 'https://i.ytimg.com/vi/' . self::YOUTUBE_VIDEO_ID . '/hqdefault.jpg',
    8891                                                'title'            => 'Yosemitebear Mountain Double Rainbow 1-8-10',
    89                                                 'height'           => 375,
    9092                                        )
    9193                                ),
    9294                        );
    class Test_oEmbed_Controller extends WP_UnitTestCase { 
    472474                $response = $this->server->dispatch( $request );
    473475
    474476                $this->assertEquals( 400, $response->get_status() );
    475                 $data = $response->get_data();
    476477        }
    477478
    478479        public function test_proxy_with_valid_oembed_provider() {
    class Test_oEmbed_Controller extends WP_UnitTestCase { 
    480481
    481482                $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' );
    482483                $request->set_param( 'url', 'https://www.youtube.com/watch?v=' . self::YOUTUBE_VIDEO_ID );
     484                $request->set_param( 'maxwidth', 456 );
     485                $request->set_param( 'maxheight', 789 );
    483486                $response = $this->server->dispatch( $request );
    484487                $this->assertEquals( 200, $response->get_status() );
    485488                $this->assertEquals( 1, $this->request_count );
    class Test_oEmbed_Controller extends WP_UnitTestCase { 
    495498                $this->assertTrue( is_object( $data ) );
    496499                $this->assertEquals( 'YouTube', $data->provider_name );
    497500                $this->assertEquals( 'https://i.ytimg.com/vi/' . self::YOUTUBE_VIDEO_ID . '/hqdefault.jpg', $data->thumbnail_url );
     501                $this->assertEquals( $data->width, $request['maxwidth'] );
     502                $this->assertEquals( $data->height, $request['maxheight'] );
    498503        }
    499504
    500505        public function test_proxy_with_invalid_oembed_provider_no_discovery() {