Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 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/http.php

    r42228 r42343  
    7676        // 0: The URL, 1: The expected resulting structure
    7777        return array(
    78             array( self::FULL_TEST_URL, array(
     78            array(
     79                self::FULL_TEST_URL,
     80                array(
     81                    'scheme'   => 'http',
     82                    'host'     => 'host.name',
     83                    'port'     => 9090,
     84                    'user'     => 'username',
     85                    'pass'     => 'password',
     86                    'path'     => '/path',
     87                    'query'    => 'arg1=value1&arg2=value2',
     88                    'fragment' => 'anchor',
     89                ),
     90            ),
     91            array(
     92                'http://example.com/',
     93                array(
     94                    'scheme' => 'http',
     95                    'host'   => 'example.com',
     96                    'path'   => '/',
     97                ),
     98            ),
     99
     100            // < PHP 5.4.7: Schemeless URL
     101            array(
     102                '//example.com/path/',
     103                array(
     104                    'host' => 'example.com',
     105                    'path' => '/path/',
     106                ),
     107            ),
     108            array(
     109                '//example.com/',
     110                array(
     111                    'host' => 'example.com',
     112                    'path' => '/',
     113                ),
     114            ),
     115            array(
     116                'http://example.com//path/',
     117                array(
     118                    'scheme' => 'http',
     119                    'host'   => 'example.com',
     120                    'path'   => '//path/',
     121                ),
     122            ),
     123
     124            // < PHP 5.4.7: Scheme separator in the URL.
     125            array(
     126                'http://example.com/http://example.net/',
     127                array(
     128                    'scheme' => 'http',
     129                    'host'   => 'example.com',
     130                    'path'   => '/http://example.net/',
     131                ),
     132            ),
     133            array( '/path/http://example.net/', array( 'path' => '/path/http://example.net/' ) ),
     134
     135            // < PHP 5.4.7: IPv6 literals in schemeless URLs are handled incorrectly.
     136            array(
     137                '//[::FFFF::127.0.0.1]/',
     138                array(
     139                    'host' => '[::FFFF::127.0.0.1]',
     140                    'path' => '/',
     141                ),
     142            ),
     143
     144            // PHP's parse_url() calls this an invalid url, we handle it as a path
     145            array( '/://example.com/', array( 'path' => '/://example.com/' ) ),
     146
     147            // Schemeless URL containing colons cause parse errors in PHP 7+.
     148            array(
     149                '//fonts.googleapis.com/css?family=Open+Sans:400&subset=latin',
     150                array(
     151                    'host'  => 'fonts.googleapis.com',
     152                    'path'  => '/css',
     153                    'query' => 'family=Open+Sans:400&subset=latin',
     154                ),
     155            ),
     156            array(
     157                '//fonts.googleapis.com/css?family=Open+Sans:400',
     158                array(
     159                    'host'  => 'fonts.googleapis.com',
     160                    'path'  => '/css',
     161                    'query' => 'family=Open+Sans:400',
     162                ),
     163            ),
     164
     165            array( 'filenamefound', array( 'path' => 'filenamefound' ) ),
     166
     167            // Empty string or non-string passed in.
     168            array( '', array( 'path' => '' ) ),
     169            array( 123, array( 'path' => '123' ) ),
     170        );
     171        /*
     172         * Untestable edge cases in various PHP:
     173         * - ///example.com - Fails in PHP >= 5.4.7, assumed path in <5.4.7
     174         * - ://example.com - assumed path in PHP >= 5.4.7, fails in <5.4.7
     175         */
     176    }
     177
     178    /**
     179     * @ticket 36356
     180     */
     181    function test_wp_parse_url_with_default_component() {
     182        $actual = wp_parse_url( self::FULL_TEST_URL, -1 );
     183        $this->assertEquals(
     184            array(
    79185                'scheme'   => 'http',
    80186                'host'     => 'host.name',
     
    85191                'query'    => 'arg1=value1&arg2=value2',
    86192                'fragment' => 'anchor',
    87             ) ),
    88             array( 'http://example.com/', array( 'scheme' => 'http', 'host' => 'example.com', 'path' => '/' ) ),
    89 
    90             // < PHP 5.4.7: Schemeless URL
    91             array( '//example.com/path/', array( 'host' => 'example.com', 'path' => '/path/' ) ),
    92             array( '//example.com/', array( 'host' => 'example.com', 'path' => '/' ) ),
    93             array( 'http://example.com//path/', array( 'scheme' => 'http', 'host' => 'example.com', 'path' => '//path/' ) ),
    94 
    95             // < PHP 5.4.7: Scheme separator in the URL.
    96             array( 'http://example.com/http://example.net/', array( 'scheme' => 'http', 'host' => 'example.com', 'path' => '/http://example.net/' ) ),
    97             array( '/path/http://example.net/', array( 'path' => '/path/http://example.net/' ) ),
    98 
    99             // < PHP 5.4.7: IPv6 literals in schemeless URLs are handled incorrectly.
    100             array( '//[::FFFF::127.0.0.1]/', array( 'host' => '[::FFFF::127.0.0.1]', 'path' => '/' ) ),
    101 
    102             // PHP's parse_url() calls this an invalid url, we handle it as a path
    103             array( '/://example.com/', array( 'path' => '/://example.com/' ) ),
    104 
    105             // Schemeless URL containing colons cause parse errors in PHP 7+.
    106             array(
    107                 '//fonts.googleapis.com/css?family=Open+Sans:400&subset=latin',
    108                 array(
    109                     'host'  => 'fonts.googleapis.com',
    110                     'path'  => '/css',
    111                     'query' => 'family=Open+Sans:400&subset=latin',
    112                 ),
    113             ),
    114             array(
    115                 '//fonts.googleapis.com/css?family=Open+Sans:400',
    116                 array(
    117                     'host'  => 'fonts.googleapis.com',
    118                     'path'  => '/css',
    119                     'query' => 'family=Open+Sans:400',
    120                 ),
    121             ),
    122 
    123             array( 'filenamefound', array( 'path' => 'filenamefound' ) ),
    124 
    125             // Empty string or non-string passed in.
    126             array( '', array( 'path' => '' ) ),
    127             array( 123, array( 'path' => '123' ) ),
    128         );
    129         /*
    130          * Untestable edge cases in various PHP:
    131          * - ///example.com - Fails in PHP >= 5.4.7, assumed path in <5.4.7
    132          * - ://example.com - assumed path in PHP >= 5.4.7, fails in <5.4.7
    133          */
    134     }
    135 
    136     /**
    137      * @ticket 36356
    138      */
    139     function test_wp_parse_url_with_default_component() {
    140         $actual = wp_parse_url( self::FULL_TEST_URL, -1 );
    141         $this->assertEquals( array(
    142             'scheme'   => 'http',
    143             'host'     => 'host.name',
    144             'port'     => 9090,
    145             'user'     => 'username',
    146             'pass'     => 'password',
    147             'path'     => '/path',
    148             'query'    => 'arg1=value1&arg2=value2',
    149             'fragment' => 'anchor',
    150         ), $actual );
     193            ), $actual
     194        );
    151195    }
    152196
     
    218262        global $wp_header_to_desc;
    219263
    220         $ref = new ReflectionClass( 'WP_Http' );
     264        $ref       = new ReflectionClass( 'WP_Http' );
    221265        $constants = $ref->getConstants();
    222266
     
    241285        );
    242286
    243         $cookie_jar = $http->normalize_cookies( array(
    244             'x'   => 'foo',
    245             'y'   => 2,
    246             'z'   => 0.45,
    247             'foo' => array( 'bar' ),
    248         ) );
     287        $cookie_jar = $http->normalize_cookies(
     288            array(
     289                'x'   => 'foo',
     290                'y'   => 2,
     291                'z'   => 0.45,
     292                'foo' => array( 'bar' ),
     293            )
     294        );
    249295
    250296        $this->assertInstanceOf( 'Requests_Cookie_Jar', $cookie_jar );
    251297
    252         foreach( array_keys( $cookies ) as $cookie ) {
     298        foreach ( array_keys( $cookies ) as $cookie ) {
    253299            if ( 'foo' === $cookie ) {
    254300                $this->assertFalse( isset( $cookie_jar[ $cookie ] ) );
     
    273319        // 0: A URL, 1: PHP URL constant, 2: The expected result.
    274320        return array(
    275             array( 'http://example.com/', -1, array( 'scheme' => 'http', 'host' => 'example.com', 'path' => '/' ) ),
    276             array( 'http://example.com/', -1, array( 'scheme' => 'http', 'host' => 'example.com', 'path' => '/' ) ),
     321            array(
     322                'http://example.com/',
     323                -1,
     324                array(
     325                    'scheme' => 'http',
     326                    'host'   => 'example.com',
     327                    'path'   => '/',
     328                ),
     329            ),
     330            array(
     331                'http://example.com/',
     332                -1,
     333                array(
     334                    'scheme' => 'http',
     335                    'host'   => 'example.com',
     336                    'path'   => '/',
     337                ),
     338            ),
    277339            array( 'http://example.com/', PHP_URL_HOST, 'example.com' ),
    278340            array( 'http://example.com/', PHP_URL_USER, null ),
Note: See TracChangeset for help on using the changeset viewer.