Make WordPress Core

Ticket #41299: 41299.1.diff

File 41299.1.diff, 5.1 KB (added by westonruter, 8 years ago)

Refresh patch after committing fix for #41048

  • 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 e6dae0670d..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();
    final class WP_oEmbed_Controller { 
    169169                $url = $request['url'];
    170170                unset( $args['url'] );
    171171
     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
    172180                $data = _wp_oembed_get_object()->get_data( $url, $args );
    173181
    174182                if ( false === $data ) {
  • tests/phpunit/tests/oembed/controller.php

    diff --git tests/phpunit/tests/oembed/controller.php tests/phpunit/tests/oembed/controller.php
    index ef6b42edd0..529811ceb8 100644
    class Test_oEmbed_Controller extends WP_UnitTestCase { 
    4949        public function tearDown() {
    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
    5555        /**
    class Test_oEmbed_Controller extends WP_UnitTestCase { 
    7070        public function mock_embed_request( $preempt, $r, $url ) {
    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(
    7981                                        'code' => 200,
    class Test_oEmbed_Controller extends WP_UnitTestCase { 
    8486                                                'type'             => 'video',
    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                                ),
    9799                        );
    class Test_oEmbed_Controller extends WP_UnitTestCase { 
    477479                $response = $this->server->dispatch( $request );
    478480
    479481                $this->assertEquals( 400, $response->get_status() );
    480                 $data = $response->get_data();
    481482        }
    482483
    483484        public function test_proxy_with_valid_oembed_provider() {
    484485                wp_set_current_user( self::$editor );
    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 );
    489492                $this->assertEquals( 200, $response->get_status() );
    class Test_oEmbed_Controller extends WP_UnitTestCase { 
    498501                $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' );
    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 );
    503508
    class Test_oEmbed_Controller extends WP_UnitTestCase { 
    508513                $this->assertTrue( is_object( $data ) );
    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
    513520        public function test_proxy_with_invalid_oembed_provider_no_discovery() {