Make WordPress Core


Ignore:
Timestamp:
05/06/2024 06:39:15 PM (2 years ago)
Author:
johnbillion
Message:

Build/Test Tools: Standardise the assertions for remote HTTP request tests.

This ensures that as much information as possible is shown when an HTTP request fails during an external HTTP test.

Fixes #61148

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/http/functions.php

    r57931 r58108  
    1616
    1717                $this->skipTestOnTimeout( $response );
     18                $this->assertNotWPError( $response );
    1819
    1920                $headers = wp_remote_retrieve_headers( $response );
    2021
    2122                $this->assertIsArray( $response );
    22 
     23                $this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
    2324                $this->assertSame( 'image/png', $headers['Content-Type'] );
    2425                $this->assertSame( '153204', $headers['Content-Length'] );
    25                 $this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
    2626        }
    2727
    … …  
    3535
    3636                $this->skipTestOnTimeout( $response );
     37                $this->assertNotWPError( $response );
    3738                $this->assertSame( 301, wp_remote_retrieve_response_code( $response ) );
    3839        }
    … …  
    4647
    4748                $this->skipTestOnTimeout( $response );
     49                $this->assertNotWPError( $response );
    4850                $this->assertSame( 404, wp_remote_retrieve_response_code( $response ) );
    4951        }
    … …  
    6062
    6163                $this->skipTestOnTimeout( $response );
     64                $this->assertNotWPError( $response );
    6265
    6366                $headers = wp_remote_retrieve_headers( $response );
    6467
    65                 $this->assertIsArray( $response );
    66 
    6768                // Should return the same headers as a HEAD request.
     69                $this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
    6870                $this->assertSame( 'image/png', $headers['Content-Type'] );
    6971                $this->assertSame( '153204', $headers['Content-Length'] );
    70                 $this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
    7172        }
    7273
    … …  
    8384
    8485                $this->skipTestOnTimeout( $response );
     86                $this->assertNotWPError( $response );
    8587
    8688                $headers = wp_remote_retrieve_headers( $response );
    8789
    8890                // Should return the same headers as a HEAD request.
     91                $this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
    8992                $this->assertSame( 'image/png', $headers['Content-Type'] );
    9093                $this->assertSame( '153204', $headers['Content-Length'] );
    91                 $this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
    9294        }
    9395
    … …  
    120122
    121123                $this->skipTestOnTimeout( $response );
     124                $this->assertNotWPError( $response );
    122125
    123126                $cookies = wp_remote_retrieve_cookies( $response );
    … …  
    165168
    166169                $this->skipTestOnTimeout( $response );
     170                $this->assertNotWPError( $response );
    167171
    168172                $cookies = wp_remote_retrieve_cookies( $response );
    … …  
    196200
    197201                $this->skipTestOnTimeout( $response );
     202                $this->assertNotWPError( $response );
    198203
    199204                $cookies = wp_remote_retrieve_cookies( $response );
Note: See TracChangeset for help on using the changeset viewer.