Make WordPress Core

Ticket #15928: 15928.7.patch

File 15928.7.patch, 2.1 KB (added by joemcgill, 10 years ago)

Same as 15928.diff

  • src/wp-includes/post.php

    diff --git src/wp-includes/post.php src/wp-includes/post.php
    index f97318e..4d201b3 100644
    function wp_get_attachment_url( $post_id = 0 ) { 
    49444944                $url = get_the_guid( $post->ID );
    49454945        }
    49464946
     4947        // Match the current scheme.
     4948        $url = set_url_scheme( $url );
     4949
    49474950        /**
    49484951         * Filter the attachment URL.
    49494952         *
  • tests/phpunit/tests/post/attachments.php

    diff --git tests/phpunit/tests/post/attachments.php tests/phpunit/tests/post/attachments.php
    index d079654..7c4fb06 100644
    class Tests_Post_Attachments extends WP_UnitTestCase { 
    278278                $this->assertEquals( $attachment->post_parent, $post_id );
    279279        }
    280280
     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
    281329}
     330