Make WordPress Core


Ignore:
Timestamp:
04/15/2024 12:30:10 PM (3 months ago)
Author:
SergeyBiryukov
Message:

Tests: Use an image on WordPress.org CDN in external HTTP tests.

Due to some changes on the WP.com side to compress the requested images on the fly, the exact image size in the response could be different between platforms.

This commit aims to make the affected tests more reliable.

Follow-up to [139/tests], [31258], [34568], [47142], [57903], [57904], [57924].

Merges [57931] to the 5.4 branch.

Props peterwilsoncc, jorbin.
See #60865.

Location:
branches/5.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.4

  • branches/5.4/tests/phpunit/tests/http/functions.php

    r47122 r57997  
    1717    function test_head_request() {
    1818        // This URL gives a direct 200 response.
    19         $url      = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
     19        $url      = 'https://s.w.org/screenshots/3.9/dashboard.png';
    2020        $response = wp_remote_head( $url );
    2121
     
    2626        $this->assertInternalType( 'array', $response );
    2727
    28         $this->assertEquals( 'image/jpeg', $headers['content-type'] );
    29         $this->assertEquals( '40148', $headers['content-length'] );
    30         $this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) );
     28        $this->assertSame( 'image/png', $headers['Content-Type'] );
     29        $this->assertSame( '153204', $headers['Content-Length'] );
     30        $this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
    3131    }
    3232
    3333    function test_head_redirect() {
    3434        // This URL will 301 redirect.
    35         $url      = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
     35        $url      = 'https://wp.org/screenshots/3.9/dashboard.png';
    3636        $response = wp_remote_head( $url );
    3737
     
    4040    }
    4141
    42     function test_head_404() {
    43         $url      = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
     42    /**
     43     * @covers ::wp_remote_head
     44     */
     45    public function test_head_404() {
     46        $url      = 'https://wordpress.org/screenshots/3.9/awefasdfawef.jpg';
    4447        $response = wp_remote_head( $url );
    4548
     
    4851    }
    4952
    50     function test_get_request() {
    51         $url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
     53    /**
     54     * @covers ::wp_remote_get
     55     * @covers ::wp_remote_retrieve_headers
     56     * @covers ::wp_remote_retrieve_response_code
     57     */
     58    public function test_get_request() {
     59        $url = 'https://s.w.org/screenshots/3.9/dashboard.png';
    5260
    5361        $response = wp_remote_get( $url );
     
    6068
    6169        // Should return the same headers as a HEAD request.
    62         $this->assertEquals( 'image/jpeg', $headers['content-type'] );
    63         $this->assertEquals( '40148', $headers['content-length'] );
    64         $this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) );
     70        $this->assertSame( 'image/png', $headers['Content-Type'] );
     71        $this->assertSame( '153204', $headers['Content-Length'] );
     72        $this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
    6573    }
    6674
    6775    function test_get_redirect() {
    68         // This will redirect to asdftestblog1.files.wordpress.com.
    69         $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
     76        // This will redirect to wordpress.org.
     77        $url = 'https://wp.org/screenshots/3.9/dashboard.png';
    7078
    7179        $response = wp_remote_get( $url );
     
    7684
    7785        // Should return the same headers as a HEAD request.
    78         $this->assertEquals( 'image/jpeg', $headers['content-type'] );
    79         $this->assertEquals( '40148', $headers['content-length'] );
    80         $this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) );
     86        $this->assertSame( 'image/png', $headers['Content-Type'] );
     87        $this->assertSame( '153204', $headers['Content-Length'] );
     88        $this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
    8189    }
    8290
    8391    function test_get_redirect_limit_exceeded() {
    84         // This will redirect to asdftestblog1.files.wordpress.com.
    85         $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
     92        // This will redirect to wordpress.org.
     93        $url = 'https://wp.org/screenshots/3.9/dashboard.png';
    8694
    8795        // Pretend we've already redirected 5 times.
Note: See TracChangeset for help on using the changeset viewer.