| | 281 | /** |
| | 282 | * @ticket 15928 |
| | 283 | */ |
| | 284 | public function test_wp_get_attachment_url_on_dashboard_with_force_ssl_admin() { |
| | 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->assertSame( $url, set_url_scheme( $url, 'https' ) ); |
| | 304 | |
| | 305 | force_ssl_admin( $force_ssl_admin ); |
| | 306 | } |
| | 307 | |
| | 308 | /** |
| | 309 | * @ticket 15928 |
| | 310 | */ |
| | 311 | public function test_wp_get_attachment_url_on_front_end_with_https_off() { |
| | 312 | $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); |
| | 313 | $contents = file_get_contents( $filename ); |
| | 314 | |
| | 315 | $upload = wp_upload_bits( basename( $filename ), null, $contents ); |
| | 316 | $this->assertTrue( empty( $upload['error'] ) ); |
| | 317 | |
| | 318 | // Set attachment ID |
| | 319 | $attachment_id = $this->_make_attachment( $upload ); |
| | 320 | |
| | 321 | $is_ssl = is_ssl(); |
| | 322 | $_SERVER['HTTPS'] = 'off'; |
| | 323 | |
| | 324 | // Test non-admin pages |
| | 325 | set_current_screen( 'front' ); |
| | 326 | $url = wp_get_attachment_url( $attachment_id ); |
| | 327 | $this->assertSame( $url, set_url_scheme( $url, 'http' ) ); |
| | 328 | |
| | 329 | $_SERVER['HTTPS'] = $is_ssl ? 'on' : 'off'; |
| | 330 | } |
| | 331 | |
| | 332 | /** |
| | 333 | * @ticket 15928 |
| | 334 | */ |
| | 335 | public function test_wp_get_attachment_url_on_front_end_with_https_on() { |
| | 336 | $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); |
| | 337 | $contents = file_get_contents( $filename ); |
| | 338 | |
| | 339 | $upload = wp_upload_bits( basename( $filename ), null, $contents ); |
| | 340 | $this->assertTrue( empty( $upload['error'] ) ); |
| | 341 | |
| | 342 | // Set attachment ID |
| | 343 | $attachment_id = $this->_make_attachment( $upload ); |
| | 344 | |
| | 345 | $is_ssl = is_ssl(); |
| | 346 | $_SERVER['HTTPS'] = 'on'; |
| | 347 | |
| | 348 | // Test non-admin pages |
| | 349 | set_current_screen( 'front' ); |
| | 350 | $url = wp_get_attachment_url( $attachment_id ); |
| | 351 | $this->assertSame( $url, set_url_scheme( $url, 'https' ) ); |
| | 352 | |
| | 353 | $_SERVER['HTTPS'] = $is_ssl ? 'on' : 'off'; |
| | 354 | } |