| 281 | /** |
| 282 | * @ticket 15928 |
| 283 | */ |
| 284 | function test_wp_get_attachment_url_ssl() { |
| 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 | // Remember initial settings |
| 295 | $force_ssl_admin = force_ssl_admin(); |
| 296 | |
| 297 | // Force SSL in the admin |
| 298 | force_ssl_admin( true ); |
| 299 | |
| 300 | // Should return scheme HTTPS in admin when SSL forced |
| 301 | set_current_screen( 'dashboard' ); |
| 302 | $url = wp_get_attachment_url( $attachment_id ); |
| 303 | $this->assertEquals( $url, set_url_scheme( $url, 'https' ) ); |
| 304 | |
| 305 | // Test non-admin pages |
| 306 | set_current_screen( 'front' ); |
| 307 | |
| 308 | // Return scheme HTTP from front when not using SSL |
| 309 | $_SERVER['HTTPS'] = 'off'; |
| 310 | $attachment_url = wp_get_attachment_url( $attachment_id ); |
| 311 | $this->assertEquals( $attachment_url, set_url_scheme( $attachment_url, 'http' ) ); |
| 312 | |
| 313 | // Return scheme HTTPS from front when using SSL |
| 314 | $_SERVER['HTTPS'] = 'on'; |
| 315 | $attachment_url = wp_get_attachment_url( $attachment_id ); |
| 316 | $this->assertEquals( $attachment_url, set_url_scheme( $attachment_url, 'https' ) ); |
| 317 | |
| 318 | |
| 319 | // cleanup |
| 320 | force_ssl_admin( $force_ssl_admin ); |
| 321 | } |
| 322 | |