| 281 | /** |
| 282 | * @ticket 15928 |
| 283 | */ |
| 284 | public function test_wp_get_attachment_with_https_off() { |
| 285 | $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); |
| 286 | $contents = file_get_contents( $filename ); |
| 287 | |
| 288 | $upload = wp_upload_bits( basename( $filename ), null, $contents ); |
| 289 | $this->assertTrue( empty( $upload['error'] ) ); |
| 290 | |
| 291 | // Set attachment ID |
| 292 | $attachment_id = $this->_make_attachment( $upload ); |
| 293 | |
| 294 | $is_ssl = is_ssl(); |
| 295 | $_SERVER['HTTPS'] = 'off'; |
| 296 | |
| 297 | // Test that wp_get_attachemt_url returns with http scheme |
| 298 | $url = wp_get_attachment_url( $attachment_id ); |
| 299 | $this->assertSame( set_url_scheme( $url, 'http' ), $url ); |
| 300 | |
| 301 | // Cleanup |
| 302 | $_SERVER['HTTPS'] = $is_ssl ? 'on' : 'off'; |
| 303 | } |
| 304 | |
| 305 | /** |
| 306 | * @ticket 15928 |
| 307 | */ |
| 308 | public function test_wp_get_attachment_url_with_https_on_same_host() { |
| 309 | $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); |
| 310 | $contents = file_get_contents( $filename ); |
| 311 | |
| 312 | $upload = wp_upload_bits( basename( $filename ), null, $contents ); |
| 313 | $this->assertTrue( empty( $upload['error'] ) ); |
| 314 | |
| 315 | // Set attachment ID |
| 316 | $attachment_id = $this->_make_attachment( $upload ); |
| 317 | |
| 318 | $is_ssl = is_ssl(); |
| 319 | $_SERVER['HTTPS'] = 'on'; |
| 320 | |
| 321 | $upload_dir = wp_upload_dir(); |
| 322 | $_SERVER['HTTP_HOST'] = parse_url( $upload_dir['baseurl'], PHP_URL_HOST ); |
| 323 | |
| 324 | // Test that wp_get_attachemt_url returns with https scheme |
| 325 | $url = wp_get_attachment_url( $attachment_id ); |
| 326 | $this->assertSame( set_url_scheme( $url, 'https' ), $url ); |
| 327 | |
| 328 | // Cleanup |
| 329 | $_SERVER['HTTPS'] = $is_ssl ? 'on' : 'off'; |
| 330 | } |
| 331 | |