Changeset 52010 for trunk/tests/phpunit/tests/general/wpResourceHints.php
- Timestamp:
- 11/04/2021 03:22:47 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/general/wpResourceHints.php
r51568 r52010 11 11 private $old_wp_styles; 12 12 13 function set_up() {13 public function set_up() { 14 14 parent::set_up(); 15 15 $this->old_wp_scripts = isset( $GLOBALS['wp_scripts'] ) ? $GLOBALS['wp_scripts'] : null; … … 25 25 } 26 26 27 function tear_down() {27 public function tear_down() { 28 28 $GLOBALS['wp_scripts'] = $this->old_wp_scripts; 29 29 $GLOBALS['wp_styles'] = $this->old_wp_styles; … … 31 31 } 32 32 33 function test_should_have_defaults_on_frontend() {33 public function test_should_have_defaults_on_frontend() { 34 34 $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n"; 35 35 … … 39 39 } 40 40 41 function test_dns_prefetching() {41 public function test_dns_prefetching() { 42 42 $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" . 43 43 "<link rel='dns-prefetch' href='//wordpress.org' />\n" . … … 45 45 "<link rel='dns-prefetch' href='//make.wordpress.org' />\n"; 46 46 47 add_filter( 'wp_resource_hints', array( $this, ' _add_dns_prefetch_domains' ), 10, 2 );48 49 $actual = get_echo( 'wp_resource_hints' ); 50 51 remove_filter( 'wp_resource_hints', array( $this, ' _add_dns_prefetch_domains' ) );52 53 $this->assertSame( $expected, $actual ); 54 } 55 56 function _add_dns_prefetch_domains( $hints, $method ) {47 add_filter( 'wp_resource_hints', array( $this, 'add_dns_prefetch_domains' ), 10, 2 ); 48 49 $actual = get_echo( 'wp_resource_hints' ); 50 51 remove_filter( 'wp_resource_hints', array( $this, 'add_dns_prefetch_domains' ) ); 52 53 $this->assertSame( $expected, $actual ); 54 } 55 56 public function add_dns_prefetch_domains( $hints, $method ) { 57 57 if ( 'dns-prefetch' === $method ) { 58 58 $hints[] = 'http://wordpress.org'; … … 70 70 * @ticket 37652 71 71 */ 72 function test_preconnect() {72 public function test_preconnect() { 73 73 $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" . 74 74 "<link rel='preconnect' href='//wordpress.org' />\n" . … … 77 77 "<link rel='preconnect' href='http://w.org' />\n"; 78 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->assertSame( $expected, $actual ); 86 } 87 88 function _add_preconnect_domains( $hints, $method ) {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->assertSame( $expected, $actual ); 86 } 87 88 public function add_preconnect_domains( $hints, $method ) { 89 89 if ( 'preconnect' === $method ) { 90 90 $hints[] = '//wordpress.org'; … … 98 98 } 99 99 100 function test_prerender() {100 public function test_prerender() { 101 101 $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" . 102 102 "<link rel='prerender' href='https://make.wordpress.org/great-again' />\n" . … … 104 104 "<link rel='prerender' href='//core.trac.wordpress.org' />\n"; 105 105 106 add_filter( 'wp_resource_hints', array( $this, ' _add_prerender_urls' ), 10, 2 );107 108 $actual = get_echo( 'wp_resource_hints' ); 109 110 remove_filter( 'wp_resource_hints', array( $this, ' _add_prerender_urls' ) );111 112 $this->assertSame( $expected, $actual ); 113 } 114 115 function _add_prerender_urls( $hints, $method ) {106 add_filter( 'wp_resource_hints', array( $this, 'add_prerender_urls' ), 10, 2 ); 107 108 $actual = get_echo( 'wp_resource_hints' ); 109 110 remove_filter( 'wp_resource_hints', array( $this, 'add_prerender_urls' ) ); 111 112 $this->assertSame( $expected, $actual ); 113 } 114 115 public function add_prerender_urls( $hints, $method ) { 116 116 if ( 'prerender' === $method ) { 117 117 $hints[] = 'https://make.wordpress.org/great-again'; … … 124 124 } 125 125 126 function test_parse_url_dns_prefetch() {126 public function test_parse_url_dns_prefetch() { 127 127 $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" . 128 128 "<link rel='dns-prefetch' href='//make.wordpress.org' />\n"; 129 129 130 add_filter( 'wp_resource_hints', array( $this, ' _add_dns_prefetch_long_urls' ), 10, 2 );131 132 $actual = get_echo( 'wp_resource_hints' ); 133 134 remove_filter( 'wp_resource_hints', array( $this, ' _add_dns_prefetch_long_urls' ) );135 136 $this->assertSame( $expected, $actual ); 137 } 138 139 function _add_dns_prefetch_long_urls( $hints, $method ) {130 add_filter( 'wp_resource_hints', array( $this, 'add_dns_prefetch_long_urls' ), 10, 2 ); 131 132 $actual = get_echo( 'wp_resource_hints' ); 133 134 remove_filter( 'wp_resource_hints', array( $this, 'add_dns_prefetch_long_urls' ) ); 135 136 $this->assertSame( $expected, $actual ); 137 } 138 139 public function add_dns_prefetch_long_urls( $hints, $method ) { 140 140 if ( 'dns-prefetch' === $method ) { 141 141 $hints[] = 'http://make.wordpress.org/wp-includes/css/editor.css'; … … 145 145 } 146 146 147 function test_dns_prefetch_styles() {147 public function test_dns_prefetch_styles() { 148 148 $expected = "<link rel='dns-prefetch' href='//fonts.googleapis.com' />\n" . 149 149 "<link rel='dns-prefetch' href='//s.w.org' />\n"; … … 164 164 } 165 165 166 function test_dns_prefetch_scripts() {166 public function test_dns_prefetch_scripts() { 167 167 $expected = "<link rel='dns-prefetch' href='//fonts.googleapis.com' />\n" . 168 168 "<link rel='dns-prefetch' href='//s.w.org' />\n"; … … 185 185 * @ticket 37385 186 186 */ 187 function test_dns_prefetch_scripts_does_not_include_registered_only() {187 public function test_dns_prefetch_scripts_does_not_include_registered_only() { 188 188 $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n"; 189 189 $unexpected = "<link rel='dns-prefetch' href='//wordpress.org' />\n"; … … 202 202 * @ticket 37502 203 203 */ 204 function test_deregistered_scripts_are_ignored() {204 public function test_deregistered_scripts_are_ignored() { 205 205 $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n"; 206 206 … … 215 215 * @ticket 37652 216 216 */ 217 function test_malformed_urls() {217 public function test_malformed_urls() { 218 218 $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n"; 219 219 220 220 // Errant colon. 221 add_filter( 'wp_resource_hints', array( $this, ' _add_malformed_url_errant_colon' ), 10, 2 );222 $actual = get_echo( 'wp_resource_hints' ); 223 remove_filter( 'wp_resource_hints', array( $this, ' _add_malformed_url_errant_colon' ) );221 add_filter( 'wp_resource_hints', array( $this, 'add_malformed_url_errant_colon' ), 10, 2 ); 222 $actual = get_echo( 'wp_resource_hints' ); 223 remove_filter( 'wp_resource_hints', array( $this, 'add_malformed_url_errant_colon' ) ); 224 224 $this->assertSame( $expected, $actual ); 225 225 226 226 // Unsupported Scheme. 227 add_filter( 'wp_resource_hints', array( $this, ' _add_malformed_url_unsupported_scheme' ), 10, 2 );228 $actual = get_echo( 'wp_resource_hints' ); 229 remove_filter( 'wp_resource_hints', array( $this, ' _add_malformed_url_unsupported_scheme' ) );230 $this->assertSame( $expected, $actual ); 231 } 232 233 function _add_malformed_url_errant_colon( $hints, $method ) {227 add_filter( 'wp_resource_hints', array( $this, 'add_malformed_url_unsupported_scheme' ), 10, 2 ); 228 $actual = get_echo( 'wp_resource_hints' ); 229 remove_filter( 'wp_resource_hints', array( $this, 'add_malformed_url_unsupported_scheme' ) ); 230 $this->assertSame( $expected, $actual ); 231 } 232 233 public function add_malformed_url_errant_colon( $hints, $method ) { 234 234 if ( 'preconnect' === $method ) { 235 235 $hints[] = '://core.trac.wordpress.org/ticket/37652'; … … 239 239 } 240 240 241 function _add_malformed_url_unsupported_scheme( $hints, $method ) {241 public function add_malformed_url_unsupported_scheme( $hints, $method ) { 242 242 if ( 'preconnect' === $method ) { 243 243 $hints[] = 'git://develop.git.wordpress.org/'; … … 250 250 * @ticket 38121 251 251 */ 252 function test_custom_attributes() {252 public function test_custom_attributes() { 253 253 $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" . 254 254 "<link rel='preconnect' href='https://make.wordpress.org' />\n" . … … 257 257 "<link href='http://wordpress.org' rel='prerender' />\n"; 258 258 259 add_filter( 'wp_resource_hints', array( $this, ' _add_url_with_attributes' ), 10, 2 );260 261 $actual = get_echo( 'wp_resource_hints' ); 262 263 remove_filter( 'wp_resource_hints', array( $this, ' _add_url_with_attributes' ) );264 265 $this->assertSame( $expected, $actual ); 266 } 267 268 function _add_url_with_attributes( $hints, $method ) {259 add_filter( 'wp_resource_hints', array( $this, 'add_url_with_attributes' ), 10, 2 ); 260 261 $actual = get_echo( 'wp_resource_hints' ); 262 263 remove_filter( 'wp_resource_hints', array( $this, 'add_url_with_attributes' ) ); 264 265 $this->assertSame( $expected, $actual ); 266 } 267 268 public function add_url_with_attributes( $hints, $method ) { 269 269 // Ignore hints with missing href attributes. 270 270 $hints[] = array(
Note: See TracChangeset
for help on using the changeset viewer.