Make WordPress Core

Changeset 58007


Ignore:
Timestamp:
04/15/2024 05:23:33 PM (8 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.6 branch.

Props peterwilsoncc, jorbin.
See #60865.

Location:
branches/4.6
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/4.6

  • branches/4.6/src

    • Property svn:mergeinfo deleted
  • branches/4.6/tests/phpunit/tests/http/functions.php

    r50089 r58007  
    1515    }
    1616
    17     function test_head_request() {
    18         // this url give a direct 200 response
    19         $url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
     17    /**
     18     * @covers ::wp_remote_head
     19     */
     20    public function test_head_request() {
     21        // This URL gives a direct 200 response.
     22        $url      = 'https://s.w.org/screenshots/3.9/dashboard.png';
    2023        $response = wp_remote_head( $url );
    2124
     
    2427        $headers = wp_remote_retrieve_headers( $response );
    2528
    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->assertSame( 'image/png', $headers['Content-Type'] );
     30        $this->assertSame( '153204', $headers['Content-Length'] );
     31        $this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
    2932    }
    3033
     
    3336     */
    3437    function test_returns_array() {
    35         $url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
     38        $url      = 'https://s.w.org/screenshots/3.9/dashboard.png';
    3639        $response = wp_remote_head( $url );
    3740        $this->assertInternalType( 'array', $response );
    3841    }
    3942
    40     function test_head_redirect() {
    41         // this url will 301 redirect
    42         $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
     43    /**
     44     * @covers ::wp_remote_head
     45     */
     46    public function test_head_redirect() {
     47        // This URL will 301 redirect.
     48        $url      = 'https://wp.org/screenshots/3.9/dashboard.png';
    4349        $response = wp_remote_head( $url );
    4450
     
    4753    }
    4854
    49     function test_head_404() {
    50         $url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
     55    /**
     56     * @covers ::wp_remote_head
     57     */
     58    public function test_head_404() {
     59        $url      = 'https://wordpress.org/screenshots/3.9/awefasdfawef.jpg';
    5160        $response = wp_remote_head( $url );
    5261
     
    5564    }
    5665
    57     function test_get_request() {
    58         $url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
     66    /**
     67     * @covers ::wp_remote_get
     68     * @covers ::wp_remote_retrieve_headers
     69     * @covers ::wp_remote_retrieve_response_code
     70     */
     71    public function test_get_request() {
     72        $url = 'https://s.w.org/screenshots/3.9/dashboard.png';
     73
     74        $response = wp_remote_get( $url );
     75
     76        $this->skipTestOnTimeout( $response );
     77
     78        $headers = wp_remote_retrieve_headers( $response );
     79   
     80        // Should return the same headers as a HEAD request.
     81        $this->assertSame( 'image/png', $headers['Content-Type'] );
     82        $this->assertSame( '153204', $headers['Content-Length'] );
     83        $this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
     84    }
     85
     86    /**
     87     * @covers ::wp_remote_get
     88     * @covers ::wp_remote_retrieve_headers
     89     * @covers ::wp_remote_retrieve_response_code
     90     */
     91    public function test_get_redirect() {
     92        // This will redirect to wordpress.org.
     93        $url = 'https://wp.org/screenshots/3.9/dashboard.png';
    5994
    6095        $response = wp_remote_get( $url );
     
    6499        $headers = wp_remote_retrieve_headers( $response );
    65100
    66         // should return the same headers as a head request
    67         $this->assertEquals( 'image/jpeg', $headers['content-type'] );
    68         $this->assertEquals( '40148', $headers['content-length'] );
    69         $this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) );
     101        // Should return the same headers as a HEAD request.
     102        $this->assertSame( 'image/png', $headers['Content-Type'] );
     103        $this->assertSame( '153204', $headers['Content-Length'] );
     104        $this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
    70105    }
    71106
    72     function test_get_redirect() {
    73         // this will redirect to asdftestblog1.files.wordpress.com
    74         $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
    75 
    76         $response = wp_remote_get( $url );
    77 
    78         $this->skipTestOnTimeout( $response );
    79 
    80         $headers = wp_remote_retrieve_headers( $response );
    81 
    82         // should return the same headers as a head request
    83         $this->assertEquals( 'image/jpeg', $headers['content-type'] );
    84         $this->assertEquals( '40148', $headers['content-length'] );
    85         $this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) );
    86     }
    87 
    88     function test_get_redirect_limit_exceeded() {
    89         // this will redirect to asdftestblog1.files.wordpress.com
    90         $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
     107    /**
     108     * @covers ::wp_remote_get
     109     */
     110    public function test_get_redirect_limit_exceeded() {
     111        // This will redirect to wordpress.org.
     112        $url = 'https://wp.org/screenshots/3.9/dashboard.png';
    91113
    92114        // pretend we've already redirected 5 times
  • branches/4.6/tests/phpunit/tests/image/functions.php

    r31512 r58007  
    305305        }
    306306
    307         $file = wp_crop_image( 'https://asdftestblog1.files.wordpress.com/2008/04/canola.jpg',
     307        $file = wp_crop_image( 'https://s.w.org/screenshots/3.9/dashboard.png',
    308308                              0, 0, 100, 100, 100, 100, false,
    309                               DIR_TESTDATA . '/images/' . rand_str() . '.jpg' );
     309                              DIR_TESTDATA . '/images/' . rand_str() . '.png' );
    310310        $this->assertNotInstanceOf( 'WP_Error', $file );
    311311        $this->assertFileExists( $file );
     
    329329        }
    330330
    331         $file = wp_crop_image( 'https://asdftestblog1.files.wordpress.com/2008/04/canoladoesnotexist.jpg',
     331        $file = wp_crop_image( 'https://wordpress.org/screenshots/3.9/canoladoesnotexist.jpg',
    332332                              0, 0, 100, 100, 100, 100 );
    333333        $this->assertInstanceOf( 'WP_Error', $file );
Note: See TracChangeset for help on using the changeset viewer.