| 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( $url, set_url_scheme( $url, 'http' ) ); |
| 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() { |
| 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 | // Test that wp_get_attachemt_url returns with https scheme |
| 322 | $url = wp_get_attachment_url( $attachment_id ); |
| 323 | $this->assertSame( $url, set_url_scheme( $url, 'https' ) ); |
| 324 | |
| 325 | // Cleanup |
| 326 | $_SERVER['HTTPS'] = $is_ssl ? 'on' : 'off'; |
| 327 | } |
| 328 | |