| | 95 | function test_preconnect() { |
| | 96 | $expected = "<link rel='dns-prefetch' href='//s.w.org'>\n" . |
| | 97 | "<link rel='preconnect' href='//core.trac.wordpress.org'>\n"; |
| | 98 | |
| | 99 | add_filter( 'wp_resource_hints', array( $this, '_add_preconnect_urls' ), 10, 2 ); |
| | 100 | |
| | 101 | $actual = get_echo( 'wp_resource_hints' ); |
| | 102 | |
| | 103 | remove_filter( 'wp_resource_hints', array( $this, '_add_preconnect_urls' ) ); |
| | 104 | |
| | 105 | $this->assertEquals( $expected, $actual ); |
| | 106 | } |
| | 107 | |
| | 108 | function _add_preconnect_urls( $hints, $method ) { |
| | 109 | if ( 'preconnect' === $method ) { |
| | 110 | $hints[] = '//core.trac.wordpress.org/ticket/37652'; |
| | 111 | } |
| | 112 | |
| | 113 | return $hints; |
| | 114 | } |
| | 115 | |
| | 200 | |
| | 201 | function test_misformed_urls() { |
| | 202 | $expected = "<link rel='dns-prefetch' href='//s.w.org'>\n"; |
| | 203 | |
| | 204 | // Errant colon. |
| | 205 | add_filter( 'wp_resource_hints', array( $this, '_add_misformed_url_errant_colon' ), 10, 2 ); |
| | 206 | $actual = get_echo( 'wp_resource_hints' ); |
| | 207 | remove_filter( 'wp_resource_hints', array( $this, '_add_misformed_url_errant_colon' ) ); |
| | 208 | $this->assertEquals( $expected, $actual ); |
| | 209 | |
| | 210 | // Unsupported Scheme. |
| | 211 | add_filter( 'wp_resource_hints', array( $this, '_add_misformed_url_unsupported_scheme' ), 10, 2 ); |
| | 212 | $actual = get_echo( 'wp_resource_hints' ); |
| | 213 | remove_filter( 'wp_resource_hints', array( $this, '_add_misformed_url_unsupported_scheme' ) ); |
| | 214 | $this->assertEquals( $expected, $actual ); |
| | 215 | } |
| | 216 | |
| | 217 | function _add_misformed_url_errant_colon( $hints, $method ) { |
| | 218 | if ( 'preconnect' === $method ) { |
| | 219 | $hints[] = '://core.trac.wordpress.org/ticket/37652'; |
| | 220 | } |
| | 221 | |
| | 222 | return $hints; |
| | 223 | } |
| | 224 | |
| | 225 | function _add_misformed_url_unsupported_scheme( $hints, $method ) { |
| | 226 | if ( 'preconnect' === $method ) { |
| | 227 | $hints[] = 'git://develop.git.wordpress.org/'; |
| | 228 | } |
| | 229 | |
| | 230 | return $hints; |
| | 231 | } |