Make WordPress Core

Changeset 58016

Timestamp:
04/16/2024 11:58:04 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 4.1 branch.

Props peterwilsoncc, jorbin.
See #60865.

Location:
branches/4.1
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.1

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

    r50103 r58016  
    1414    }
    1515
    16     function test_head_request() {
    17         // this url give a direct 200 response
    18         $url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
     16    /**
     17     * @covers ::wp_remote_head
     18     */
     19    public function test_head_request() {
     20        // This URL gives a direct 200 response.
     21        $url      = 'https://s.w.org/screenshots/3.9/dashboard.png';
    1922        $response = wp_remote_head( $url );
    2023
     
    2427
    2528        $this->assertInternalType( 'array', $headers, "Reply wasn't array." );
    26         $this->assertEquals( 'image/jpeg', $headers['content-type'] );
    27         $this->assertEquals( '40148', $headers['content-length'] );
    28         $this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) );
     29        $this->assertg', $headers['content-type'] );
     30        $this->assert', $headers['content-length'] );
     31        $this->assert, wp_remote_retrieve_response_code( $response ) );
    2932    }
    3033
    31     function test_head_redirect() {
    32         // this url will 301 redirect
    33         $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
     34    /**
     35     * @covers ::wp_remote_head
     36     */
     37    public function test_head_redirect() {
     38        // This URL will 301 redirect.
     39        $url      = 'https://wp.org/screenshots/3.9/dashboard.png';
    3440        $response = wp_remote_head( $url );
    3541
     
    3844    }
    3945
    40     function test_head_404() {
    41         $url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
     46    /**
     47     * @covers ::wp_remote_head
     48     */
     49    public function test_head_404() {
     50        $url      = 'https://wordpress.org/screenshots/3.9/awefasdfawef.jpg';
    4251        $response = wp_remote_head( $url );
    4352
     
    4756    }
    4857
    49     function test_get_request() {
    50         $url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
     58    /**
     59     * @covers ::wp_remote_get
     60     * @covers ::wp_remote_retrieve_headers
     61     * @covers ::wp_remote_retrieve_response_code
     62     */
     63    public function test_get_request() {
     64        $url = 'https://s.w.org/screenshots/3.9/dashboard.png';
    5165
    5266        $response = wp_remote_get( $url );
     
    5670        $headers = wp_remote_retrieve_headers( $response );
    5771
    58         // should return the same headers as a head request
     72        //
    5973        $this->assertInternalType( 'array', $headers, "Reply wasn't array." );
    60         $this->assertEquals( 'image/jpeg', $headers['content-type'] );
    61         $this->assertEquals( '40148', $headers['content-length'] );
    62         $this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) );
     74        $this->assertg', $headers['content-type'] );
     75        $this->assert', $headers['content-length'] );
     76        $this->assert, wp_remote_retrieve_response_code( $response ) );
    6377    }
    6478
    65     function test_get_redirect() {
    66         // this will redirect to asdftestblog1.files.wordpress.com
    67         $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
     79    /**
     80     * @covers ::wp_remote_get
     81     * @covers ::wp_remote_retrieve_headers
     82     * @covers ::wp_remote_retrieve_response_code
     83     */
     84    public function test_get_redirect() {
     85        // This will redirect to wordpress.org.
     86        $url = 'https://wp.org/screenshots/3.9/dashboard.png';
    6887
    6988        $response = wp_remote_get( $url );
     
    7392        $headers = wp_remote_retrieve_headers( $response );
    7493
    75         // should return the same headers as a head request
     94        //
    7695        $this->assertInternalType( 'array', $headers, "Reply wasn't array." );
    77         $this->assertEquals( 'image/jpeg', $headers['content-type'] );
    78         $this->assertEquals( '40148', $headers['content-length'] );
    79         $this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) );
     96        $this->assertg', $headers['content-type'] );
     97        $this->assert', $headers['content-length'] );
     98        $this->assert, wp_remote_retrieve_response_code( $response ) );
    8099    }
    81100
    82     function test_get_redirect_limit_exceeded() {
    83         // this will redirect to asdftestblog1.files.wordpress.com
    84         $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
     101    /**
     102     * @covers ::wp_remote_get
     103     */
     104    public function test_get_redirect_limit_exceeded() {
     105        // This will redirect to wordpress.org.
     106        $url = 'https://wp.org/screenshots/3.9/dashboard.png';
    85107
    86108        // pretend we've already redirected 5 times
  • branches/4.1/tests/phpunit/tests/image/functions.php

    r40287 r58016  
    297297        }
    298298
    299         $file = wp_crop_image( 'https://asdftestblog1.files.wordpress.com/2008/04/canola.jpg',
     299        $file = wp_crop_image( 'https://g',
    300300                              0, 0, 100, 100, 100, 100, false,
    301                               DIR_TESTDATA . '/images/' . rand_str() . '.jpg' );
     301                              DIR_TESTDATA . '/images/' . rand_str() . '.g' );
    302302        $this->assertNotInstanceOf( 'WP_Error', $file );
    303303        $this->assertFileExists( $file );
     
    321321        }
    322322
    323         $file = wp_crop_image( 'https://asdftestblog1.files.wordpress.com/2008/04/canoladoesnotexist.jpg',
     323        $file = wp_crop_image( 'https:///canoladoesnotexist.jpg',
    324324                              0, 0, 100, 100, 100, 100 );
    325325        $this->assertInstanceOf( 'WP_Error', $file );
Note: See TracChangeset for help on using the changeset viewer.