Make WordPress Core

Ticket #46986: 46986.4.diff

File 46986.4.diff, 3.0 KB (added by garrett-eclipse, 4 years ago)

Update vimeo links in unit tests to use embed sample video from Vimeo as suggested by Meta.

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

     
    520520                $provider = add_query_arg( 'maxwidth', (int) $args['width'], $provider );
    521521                $provider = add_query_arg( 'maxheight', (int) $args['height'], $provider );
    522522                $provider = add_query_arg( 'url', urlencode( $url ), $provider );
    523                 $provider = add_query_arg( 'dnt', 1, $provider );
     523                if ( strpos( $provider, 'vimeo.com' ) === false ) {
     524                        $provider = add_query_arg( 'dnt', 1, $provider );
     525                }
    524526
    525527                /**
    526528                 * Filters the oEmbed URL to be fetched.
     
    527529                 *
    528530                 * @since 2.9.0
    529531                 * @since 4.9.0 The `dnt` (Do Not Track) query parameter was added to all oEmbed provider URLs.
     532                 * @since 5.6.0 The `dnt` (Do Not Track) query parameter was removed from Vimeo oEmbed URLs. (@ticket: #46986)
    530533                 *
     534                 * The `dnt` parameter can be re-enabled on Vimeo oEmbed URLs using the following:
     535                 *
     536                 *     function enable_dnt_vimeo_oembed( $provider, $url, $args ) {
     537                 *         if ( strpos( $provider, 'vimeo.com' ) !== false ) {
     538                 *             $provider = add_query_arg( 'dnt', 1, $provider );
     539                 *         }
     540                 *         return $provider;
     541                 *     }
     542                 *     add_filter( 'oembed_fetch_url', 'enable_dnt_vimeo_oembed', 10, 3 );
     543                 *
    531544                 * @param string $provider URL of the oEmbed provider.
    532545                 * @param string $url      URL of the content to be embedded.
    533546                 * @param array  $args     Optional arguments, usually passed from a shortcode.
  • tests/phpunit/tests/oembed/wpOembed.php

     
    2828                return $result ? $result : false;
    2929        }
    3030
     31        /*
     32         * @see test_add_dnt_vimeo_oembed_fetch_url()
     33         */
     34        public function _filter_add_dnt_vimeo( $provider ) {
     35                if ( strpos( $provider, 'vimeo.com' ) !== false ) {
     36                        $provider = add_query_arg( 'dnt', 1, $provider );
     37                }
     38                return $provider;
     39        }
     40
    3141        public function test_wp_filter_pre_oembed_result_prevents_http_request_for_internal_permalinks() {
    3242                $post_id   = self::factory()->post->create();
    3343                $permalink = get_permalink( $post_id );
     
    234244                $this->assertFalse( $actual );
    235245                $this->assertSame( $current_blog_id, get_current_blog_id() );
    236246        }
     247
     248        /**
     249         * @ticket 46986
     250         */
     251        public function test_vimeo_oembed_does_not_have_dnt() {
     252                $vimeo_oembed = $this->oembed->get_data( 'https://vimeo.com/76979871' );
     253
     254                $this->assertNotContains( 'dnt=1', $vimeo_oembed->html );
     255        }
     256
     257        /**
     258         * @ticket 46986
     259         */
     260        public function test_add_dnt_vimeo_oembed_fetch_url() {
     261                add_filter( 'oembed_fetch_url', array( $this, '_filter_add_dnt_vimeo' ) );
     262                $vimeo_oembed = $this->oembed->get_data( 'https://vimeo.com/76979871' );
     263                remove_filter( 'oembed_fetch_url', array( $this, '_filter_add_dnt_vimeo' ) );
     264
     265                $this->assertContains( 'dnt=1', $vimeo_oembed->html );
     266        }
    237267}