Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r41289 r42343  
    1414    // You can use your own version of data/WPHTTP-testcase-redirection-script.php here.
    1515    var $redirection_script = 'http://api.wordpress.org/core/tests/1.0/redirection.php';
    16     var $fileStreamUrl = 'http://s.w.org/screenshots/3.9/dashboard.png';
     16    var $fileStreamUrl      = 'http://s.w.org/screenshots/3.9/dashboard.png';
    1717
    1818    protected $http_request_args;
     
    2222     */
    2323    function skipTestOnTimeout( $response ) {
    24         if( ! is_wp_error( $response ) ){
     24        if ( ! is_wp_error( $response ) ) {
    2525            return;
    2626        }
    27         if ( 'connect() timed out!' === $response->get_error_message() ){
     27        if ( 'connect() timed out!' === $response->get_error_message() ) {
    2828            $this->markTestSkipped( 'HTTP timeout' );
    2929        }
    3030
    31         if ( 0 === strpos( $response->get_error_message(), 'Operation timed out after' ) ){
     31        if ( 0 === strpos( $response->get_error_message(), 'Operation timed out after' ) ) {
    3232            $this->markTestSkipped( 'HTTP timeout' );
    3333        }
     
    4141    function setUp() {
    4242
    43         if ( is_callable( array('WP_Http', '_getTransport') ) ) {
    44             $this->markTestSkipped('The WP_Http tests require a class-http.php file of r17550 or later.');
     43        if ( is_callable( array( 'WP_Http', '_getTransport' ) ) ) {
     44            $this->markTestSkipped( 'The WP_Http tests require a class-http.php file of r17550 or later.' );
    4545            return;
    4646        }
    4747
    48         $class = "WP_Http_" . ucfirst( $this->transport );
    49         if ( !call_user_func( array($class, 'test') ) ) {
    50             $this->markTestSkipped( sprintf('The transport %s is not supported on this system', $this->transport) );
     48        $class = 'WP_Http_' . ucfirst( $this->transport );
     49        if ( ! call_user_func( array( $class, 'test' ) ) ) {
     50            $this->markTestSkipped( sprintf( 'The transport %s is not supported on this system', $this->transport ) );
    5151        }
    5252
     
    5454        foreach ( array( 'curl', 'streams', 'fsockopen' ) as $t ) {
    5555            remove_filter( "use_{$t}_transport", '__return_false' ); // Just strip them all
    56             if ( $t != $this->transport )
     56            if ( $t != $this->transport ) {
    5757                add_filter( "use_{$t}_transport", '__return_false' ); // and add it back if need be..
     58            }
    5859        }
    5960    }
     
    7374    function test_redirect_on_301() {
    7475        // 5 : 5 & 301
    75         $res = wp_remote_request($this->redirection_script . '?code=301&rt=' . 5, array('redirection' => 5) );
    76         $this->assertNotWPError( $res );
    77         $this->assertEquals(200, (int)$res['response']['code'] );
     76        $res = wp_remote_request( $this->redirection_script . '?code=301&rt=' . 5, array( 'redirection' => 5 ) );
     77        $this->assertNotWPError( $res );
     78        $this->assertEquals( 200, (int) $res['response']['code'] );
    7879    }
    7980
    8081    function test_redirect_on_302() {
    8182        // 5 : 5 & 302
    82         $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 5) );
    83         $this->assertNotWPError( $res );
    84         $this->assertEquals(200, (int)$res['response']['code'] );
     83        $res = wp_remote_request( $this->redirection_script . '?code=302&rt=' . 5, array( 'redirection' => 5 ) );
     84        $this->assertNotWPError( $res );
     85        $this->assertEquals( 200, (int) $res['response']['code'] );
    8586    }
    8687
     
    9091    function test_redirect_on_301_no_redirect() {
    9192        // 5 > 0 & 301
    92         $res = wp_remote_request($this->redirection_script . '?code=301&rt=' . 5, array('redirection' => 0) );
    93         $this->assertNotWPError( $res );
    94         $this->assertEquals(301, (int)$res['response']['code'] );
     93        $res = wp_remote_request( $this->redirection_script . '?code=301&rt=' . 5, array( 'redirection' => 0 ) );
     94        $this->assertNotWPError( $res );
     95        $this->assertEquals( 301, (int) $res['response']['code'] );
    9596    }
    9697
     
    100101    function test_redirect_on_302_no_redirect() {
    101102        // 5 > 0 & 302
    102         $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 0) );
    103         $this->assertNotWPError( $res );
    104         $this->assertEquals(302, (int)$res['response']['code'] );
     103        $res = wp_remote_request( $this->redirection_script . '?code=302&rt=' . 5, array( 'redirection' => 0 ) );
     104        $this->assertNotWPError( $res );
     105        $this->assertEquals( 302, (int) $res['response']['code'] );
    105106    }
    106107
    107108    function test_redirections_equal() {
    108109        // 5 - 5
    109         $res = wp_remote_request($this->redirection_script . '?rt=' . 5, array('redirection' => 5) );
    110         $this->assertNotWPError( $res );
    111         $this->assertEquals(200, (int)$res['response']['code'] );
     110        $res = wp_remote_request( $this->redirection_script . '?rt=' . 5, array( 'redirection' => 5 ) );
     111        $this->assertNotWPError( $res );
     112        $this->assertEquals( 200, (int) $res['response']['code'] );
    112113    }
    113114
    114115    function test_no_head_redirections() {
    115116        // No redirections on HEAD request:
    116         $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 1, array('method' => 'HEAD') );
    117         $this->assertNotWPError( $res );
    118         $this->assertEquals( 302, (int)$res['response']['code'] );
     117        $res = wp_remote_request( $this->redirection_script . '?code=302&rt=' . 1, array( 'method' => 'HEAD' ) );
     118        $this->assertNotWPError( $res );
     119        $this->assertEquals( 302, (int) $res['response']['code'] );
    119120    }
    120121
     
    124125    function test_redirect_on_head() {
    125126        // Redirections on HEAD request when Requested
    126         $res = wp_remote_request($this->redirection_script . '?rt=' . 5, array('redirection' => 5, 'method' => 'HEAD') );
    127         $this->assertNotWPError( $res );
    128         $this->assertEquals( 200, (int)$res['response']['code'] );
     127        $res = wp_remote_request(
     128            $this->redirection_script . '?rt=' . 5, array(
     129                'redirection' => 5,
     130                'method'      => 'HEAD',
     131            )
     132        );
     133        $this->assertNotWPError( $res );
     134        $this->assertEquals( 200, (int) $res['response']['code'] );
    129135    }
    130136
    131137    function test_redirections_greater() {
    132138        // 10 > 5
    133         $res = wp_remote_request($this->redirection_script . '?rt=' . 10, array('redirection' => 5) );
     139        $res = wp_remote_request( $this->redirection_script . '?rt=' . 10, array( 'redirection' => 5 ) );
    134140        $this->assertWPError( $res );
    135141    }
     
    137143    function test_redirections_greater_edgecase() {
    138144        // 6 > 5 (close edgecase)
    139         $res = wp_remote_request($this->redirection_script . '?rt=' . 6, array('redirection' => 5) );
     145        $res = wp_remote_request( $this->redirection_script . '?rt=' . 6, array( 'redirection' => 5 ) );
    140146        $this->assertWPError( $res );
    141147    }
     
    143149    function test_redirections_less_edgecase() {
    144150        // 4 < 5 (close edgecase)
    145         $res = wp_remote_request($this->redirection_script . '?rt=' . 4, array('redirection' => 5) );
     151        $res = wp_remote_request( $this->redirection_script . '?rt=' . 4, array( 'redirection' => 5 ) );
    146152        $this->assertNotWPError( $res );
    147153    }
     
    152158    function test_redirections_zero_redirections_specified() {
    153159        // 0 redirections asked for, Should return the document?
    154         $res = wp_remote_request($this->redirection_script . '?code=302&rt=' . 5, array('redirection' => 0) );
    155         $this->assertNotWPError( $res );
    156         $this->assertEquals( 302, (int)$res['response']['code'] );
     160        $res = wp_remote_request( $this->redirection_script . '?code=302&rt=' . 5, array( 'redirection' => 0 ) );
     161        $this->assertNotWPError( $res );
     162        $this->assertEquals( 302, (int) $res['response']['code'] );
    157163    }
    158164
     
    166172        $res = wp_remote_request( $this->redirection_script . '?201-location=true' );
    167173        $this->assertNotWPError( $res );
    168         $this->assertEquals( 'PASS', $res['body']);
     174        $this->assertEquals( 'PASS', $res['body'] );
    169175    }
    170176
     
    178184
    179185        // Test 301 - POST to POST
    180         $res = wp_remote_request( $url, array( 'method' => 'PUT', 'timeout' => 30 ) );
     186        $res = wp_remote_request(
     187            $url, array(
     188                'method'  => 'PUT',
     189                'timeout' => 30,
     190            )
     191        );
    181192        $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
    182         $this->assertTrue( !empty( $res['headers']['location'] ) );
     193        $this->assertTrue( ! empty( $res['headers']['location'] ) );
    183194    }
    184195
     
    188199    function test_send_headers() {
    189200        // Test that the headers sent are recieved by the server
    190         $headers = array('test1' => 'test', 'test2' => 0, 'test3' => '');
    191         $res = wp_remote_request( $this->redirection_script . '?header-check', array('headers' => $headers) );
     201        $headers = array(
     202            'test1' => 'test',
     203            'test2' => 0,
     204            'test3' => '',
     205        );
     206        $res     = wp_remote_request( $this->redirection_script . '?header-check', array( 'headers' => $headers ) );
    192207
    193208        $this->assertNotWPError( $res );
    194209
    195210        $headers = array();
    196         foreach ( explode("\n", $res['body']) as $key => $value ) {
    197             if ( empty($value) )
     211        foreach ( explode( "\n", $res['body'] ) as $key => $value ) {
     212            if ( empty( $value ) ) {
    198213                continue;
    199             $parts = explode(':', $value,2);
    200             unset($headers[$key]);
     214            }
     215            $parts = explode( ':', $value, 2 );
     216            unset( $headers[ $key ] );
    201217            $headers[ $parts[0] ] = $parts[1];
    202218        }
    203219
    204         $this->assertTrue( isset($headers['test1']) && 'test' == $headers['test1'] );
    205         $this->assertTrue( isset($headers['test2']) && '0' === $headers['test2'] );
     220        $this->assertTrue( isset( $headers['test1'] ) && 'test' == $headers['test1'] );
     221        $this->assertTrue( isset( $headers['test2'] ) && '0' === $headers['test2'] );
    206222        // cURL/HTTP Extension Note: Will never pass, cURL does not pass headers with an empty value.
    207223        // Should it be that empty headers with empty values are NOT sent?
     
    210226
    211227    function test_file_stream() {
    212         $url = $this->fileStreamUrl;
     228        $url  = $this->fileStreamUrl;
    213229        $size = 153204;
    214         $res = wp_remote_request( $url, array( 'stream' => true, 'timeout' => 30 ) ); //Auto generate the filename.
     230        $res  = wp_remote_request(
     231            $url, array(
     232                'stream'  => true,
     233                'timeout' => 30,
     234            )
     235        ); //Auto generate the filename.
    215236
    216237        // Cleanup before we assert, as it'll return early.
     
    233254     */
    234255    function test_file_stream_limited_size() {
    235         $url = $this->fileStreamUrl;
     256        $url  = $this->fileStreamUrl;
    236257        $size = 10000;
    237         $res = wp_remote_request( $url, array( 'stream' => true, 'timeout' => 30, 'limit_response_size' => $size ) ); //Auto generate the filename.
     258        $res  = wp_remote_request(
     259            $url, array(
     260                'stream'              => true,
     261                'timeout'             => 30,
     262                'limit_response_size' => $size,
     263            )
     264        ); //Auto generate the filename.
    238265
    239266        // Cleanup before we assert, as it'll return early.
     
    256283     */
    257284    function test_request_limited_size() {
    258         $url = $this->fileStreamUrl;
     285        $url  = $this->fileStreamUrl;
    259286        $size = 10000;
    260287
    261         $res = wp_remote_request( $url, array( 'timeout' => 30, 'limit_response_size' => $size ) );
     288        $res = wp_remote_request(
     289            $url, array(
     290                'timeout'             => 30,
     291                'limit_response_size' => $size,
     292            )
     293        );
    262294
    263295        $this->skipTestOnTimeout( $res );
     
    312344     */
    313345    function test_ip_url_with_host_header() {
    314         $ip = gethostbyname( 'api.wordpress.org' );
    315         $url = 'http://' . $ip . '/core/tests/1.0/redirection.php?print-pass=1';
     346        $ip   = gethostbyname( 'api.wordpress.org' );
     347        $url  = 'http://' . $ip . '/core/tests/1.0/redirection.php?print-pass=1';
    316348        $args = array(
    317             'headers' => array(
     349            'headers'     => array(
    318350                'Host' => 'api.wordpress.org',
    319351            ),
    320             'timeout' => 30,
     352            'timeout'     => 30,
    321353            'redirection' => 0,
    322354        );
     
    333365     */
    334366    function test_https_url_without_ssl_verification() {
    335         $url = 'https://wordpress.org/';
     367        $url  = 'https://wordpress.org/';
    336368        $args = array(
    337369            'sslverify' => false,
     
    384416     */
    385417    function test_ssl() {
    386         if ( ! wp_http_supports( array( 'ssl' ) ) )
     418        if ( ! wp_http_supports( array( 'ssl' ) ) ) {
    387419            $this->fail( 'This installation of PHP does not support SSL' );
     420        }
    388421
    389422        $res = wp_remote_get( 'https://wordpress.org/' );
     
    398431
    399432        $path = parse_url( $url, PHP_URL_PATH );
    400         $url = str_replace( $path, '/' . $path, $url );
     433        $url  = str_replace( $path, '/' . $path, $url );
    401434
    402435        $res = wp_remote_request( $url );
Note: See TracChangeset for help on using the changeset viewer.