Make WordPress Core

Ticket #37652: 37652.diff

File 37652.diff, 2.1 KB (added by swissspidy, 9 years ago)
  • src/wp-includes/general-template.php

    diff --git src/wp-includes/general-template.php src/wp-includes/general-template.php
    index 4e049d5..e0b0b90 100644
    function wp_resource_hints() { 
    28412841
    28422842                                if ( 'dns-prefetch' === $relation_type ) {
    28432843                                        $url = '//' . $parsed['host'];
     2844                                } else if ( 'preconnect' === $relation_type && empty( $parsed['scheme'] ) ) {
     2845                                        $url = '//' . $parsed['host'];
    28442846                                } else if ( ! empty( $parsed['scheme'] ) ) {
    28452847                                        $url = $parsed['scheme'] . '://' . $parsed['host'];
    28462848                                } else {
  • tests/phpunit/tests/general/resourceHints.php

    diff --git tests/phpunit/tests/general/resourceHints.php tests/phpunit/tests/general/resourceHints.php
    index f6da557..e141942 100644
    class Tests_WP_Resource_Hints extends WP_UnitTestCase { 
    6666                return $hints;
    6767        }
    6868
     69        /**
     70         * @ticket 37652
     71         */
     72        function test_preconnect() {
     73                $expected = "<link rel='dns-prefetch' href='//s.w.org'>\n" .
     74                            "<link rel='preconnect' href='//wordpress.org'>\n" .
     75                            "<link rel='preconnect' href='https://make.wordpress.org'>\n" .
     76                            "<link rel='preconnect' href='http://google.com'>\n" .
     77                            "<link rel='preconnect' href='http://w.org'>\n";
     78
     79                add_filter( 'wp_resource_hints', array( $this, '_add_preconnect_domains' ), 10, 2 );
     80
     81                $actual = get_echo( 'wp_resource_hints' );
     82
     83                remove_filter( 'wp_resource_hints', array( $this, '_add_preconnect_domains' ) );
     84
     85                $this->assertEquals( $expected, $actual );
     86        }
     87
     88        function _add_preconnect_domains( $hints, $method ) {
     89                if ( 'preconnect' === $method ) {
     90                        $hints[] = '//wordpress.org';
     91                        $hints[] = 'https://make.wordpress.org';
     92                        $hints[] = 'htps://example.com'; // Invalid URLs should be skipped.
     93                        $hints[] = 'http://google.com';
     94                        $hints[] = 'w.org';
     95                }
     96
     97                return $hints;
     98        }
     99
    69100        function test_prerender() {
    70101                $expected = "<link rel='dns-prefetch' href='//s.w.org'>\n" .
    71102                                        "<link rel='prerender' href='https://make.wordpress.org/great-again'>\n" .