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/formatting/EscUrl.php

    r35370 r42343  
    1010     */
    1111    function test_spaces() {
    12         $this->assertEquals( 'http://example.com/Mr%20WordPress',    esc_url( 'http://example.com/Mr WordPress' ) );
    13         $this->assertEquals( 'http://example.com/Mr%20WordPress',    esc_url( 'http://example.com/Mr%20WordPress' ) );
     12        $this->assertEquals( 'http://example.com/Mr%20WordPress', esc_url( 'http://example.com/Mr WordPress' ) );
     13        $this->assertEquals( 'http://example.com/Mr%20WordPress', esc_url( 'http://example.com/Mr%20WordPress' ) );
    1414        $this->assertEquals( 'http://example.com/Mr%20%20WordPress', esc_url( 'http://example.com/Mr%20%20WordPress' ) );
    15         $this->assertEquals( 'http://example.com/Mr+WordPress',      esc_url( 'http://example.com/Mr+WordPress' ) );
     15        $this->assertEquals( 'http://example.com/Mr+WordPress', esc_url( 'http://example.com/Mr+WordPress' ) );
    1616
    1717        $this->assertEquals( 'http://example.com/?foo=one%20two%20three&bar=four', esc_url( 'http://example.com/?foo=one two three&bar=four' ) );
     
    2020
    2121    function test_bad_characters() {
    22         $this->assertEquals('http://example.com/watchthelinefeedgo', esc_url('http://example.com/watchthelinefeed%0Ago'));
    23         $this->assertEquals('http://example.com/watchthelinefeedgo', esc_url('http://example.com/watchthelinefeed%0ago'));
    24         $this->assertEquals('http://example.com/watchthecarriagereturngo', esc_url('http://example.com/watchthecarriagereturn%0Dgo'));
    25         $this->assertEquals('http://example.com/watchthecarriagereturngo', esc_url('http://example.com/watchthecarriagereturn%0dgo'));
     22        $this->assertEquals( 'http://example.com/watchthelinefeedgo', esc_url( 'http://example.com/watchthelinefeed%0Ago' ) );
     23        $this->assertEquals( 'http://example.com/watchthelinefeedgo', esc_url( 'http://example.com/watchthelinefeed%0ago' ) );
     24        $this->assertEquals( 'http://example.com/watchthecarriagereturngo', esc_url( 'http://example.com/watchthecarriagereturn%0Dgo' ) );
     25        $this->assertEquals( 'http://example.com/watchthecarriagereturngo', esc_url( 'http://example.com/watchthecarriagereturn%0dgo' ) );
    2626        //Nesting Checks
    27         $this->assertEquals('http://example.com/watchthecarriagereturngo', esc_url('http://example.com/watchthecarriagereturn%0%0ddgo'));
    28         $this->assertEquals('http://example.com/watchthecarriagereturngo', esc_url('http://example.com/watchthecarriagereturn%0%0DDgo'));
    29         $this->assertEquals('http://example.com/', esc_url('http://example.com/%0%0%0DAD'));
    30         $this->assertEquals('http://example.com/', esc_url('http://example.com/%0%0%0ADA'));
    31         $this->assertEquals('http://example.com/', esc_url('http://example.com/%0%0%0DAd'));
    32         $this->assertEquals('http://example.com/', esc_url('http://example.com/%0%0%0ADa'));
     27        $this->assertEquals( 'http://example.com/watchthecarriagereturngo', esc_url( 'http://example.com/watchthecarriagereturn%0%0ddgo' ) );
     28        $this->assertEquals( 'http://example.com/watchthecarriagereturngo', esc_url( 'http://example.com/watchthecarriagereturn%0%0DDgo' ) );
     29        $this->assertEquals( 'http://example.com/', esc_url( 'http://example.com/%0%0%0DAD' ) );
     30        $this->assertEquals( 'http://example.com/', esc_url( 'http://example.com/%0%0%0ADA' ) );
     31        $this->assertEquals( 'http://example.com/', esc_url( 'http://example.com/%0%0%0DAd' ) );
     32        $this->assertEquals( 'http://example.com/', esc_url( 'http://example.com/%0%0%0ADa' ) );
    3333    }
    3434
    3535    function test_relative() {
    36         $this->assertEquals('/example.php', esc_url('/example.php'));
    37         $this->assertEquals('example.php', esc_url('example.php'));
    38         $this->assertEquals('#fragment', esc_url('#fragment'));
    39         $this->assertEquals('?foo=bar', esc_url('?foo=bar'));
     36        $this->assertEquals( '/example.php', esc_url( '/example.php' ) );
     37        $this->assertEquals( 'example.php', esc_url( 'example.php' ) );
     38        $this->assertEquals( '#fragment', esc_url( '#fragment' ) );
     39        $this->assertEquals( '?foo=bar', esc_url( '?foo=bar' ) );
    4040    }
    4141
     
    4343        $url = 'https://user:pass@host.example.com:1234/path;p=1?query=2&r[]=3#fragment';
    4444
    45         $this->assertEquals( array(
    46             'scheme'   => 'https',
    47             'host'     => 'host.example.com',
    48             'port'     => 1234,
    49             'user'     => 'user',
    50             'pass'     => 'pass',
    51             'path'     => '/path;p=1',
    52             'query'    => 'query=2&r[]=3',
    53             'fragment' => 'fragment',
    54         ), parse_url( $url ) );
     45        $this->assertEquals(
     46            array(
     47                'scheme'   => 'https',
     48                'host'     => 'host.example.com',
     49                'port'     => 1234,
     50                'user'     => 'user',
     51                'pass'     => 'pass',
     52                'path'     => '/path;p=1',
     53                'query'    => 'query=2&r[]=3',
     54                'fragment' => 'fragment',
     55            ), parse_url( $url )
     56        );
    5557        $this->assertEquals( 'https://user:pass@host.example.com:1234/path;p=1?query=2&r%5B%5D=3#fragment', esc_url_raw( $url ) );
    5658        $this->assertEquals( 'https://user:pass@host.example.com:1234/path;p=1?query=2&r%5B%5D=3#fragment', esc_url( $url ) );
     
    6668
    6769    function test_encoding() {
    68         $this->assertEquals( 'http://example.com?foo=1&bar=2',      esc_url_raw( 'http://example.com?foo=1&bar=2' ) );
    69         $this->assertEquals( 'http://example.com?foo=1&bar=2',  esc_url_raw( 'http://example.com?foo=1&bar=2' ) );
     70        $this->assertEquals( 'http://example.com?foo=1&bar=2', esc_url_raw( 'http://example.com?foo=1&bar=2' ) );
     71        $this->assertEquals( 'http://example.com?foo=1&bar=2', esc_url_raw( 'http://example.com?foo=1&bar=2' ) );
    7072        $this->assertEquals( 'http://example.com?foo=1&bar=2', esc_url_raw( 'http://example.com?foo=1&bar=2' ) );
    7173
     
    7981
    8082    function test_protocol() {
    81         $this->assertEquals('http://example.com', esc_url('http://example.com'));
    82         $this->assertEquals('', esc_url('nasty://example.com/'));
    83         $this->assertEquals( '', esc_url( 'example.com', array(
    84             'https',
    85         ) ) );
    86         $this->assertEquals( '', esc_url( 'http://example.com', array(
    87             'https',
    88         ) ) );
    89         $this->assertEquals( 'https://example.com', esc_url( 'https://example.com', array(
    90             'http', 'https',
    91         ) ) );
     83        $this->assertEquals( 'http://example.com', esc_url( 'http://example.com' ) );
     84        $this->assertEquals( '', esc_url( 'nasty://example.com/' ) );
     85        $this->assertEquals(
     86            '', esc_url(
     87                'example.com', array(
     88                    'https',
     89                )
     90            )
     91        );
     92        $this->assertEquals(
     93            '', esc_url(
     94                'http://example.com', array(
     95                    'https',
     96                )
     97            )
     98        );
     99        $this->assertEquals(
     100            'https://example.com', esc_url(
     101                'https://example.com', array(
     102                    'http',
     103                    'https',
     104                )
     105            )
     106        );
    92107
    93108        foreach ( wp_allowed_protocols() as $scheme ) {
    94109            $this->assertEquals( "{$scheme}://example.com", esc_url( "{$scheme}://example.com" ), $scheme );
    95             $this->assertEquals( "{$scheme}://example.com", esc_url( "{$scheme}://example.com", array(
    96                 $scheme,
    97             ) ), $scheme );
     110            $this->assertEquals(
     111                "{$scheme}://example.com", esc_url(
     112                    "{$scheme}://example.com", array(
     113                        $scheme,
     114                    )
     115                ), $scheme
     116            );
    98117        }
    99118
     
    102121
    103122        $this->assertTrue( ! in_array( 'foo', wp_allowed_protocols(), true ) );
    104         $this->assertEquals( 'foo://example.com', esc_url( 'foo://example.com', array(
    105             'foo',
    106         ) ) );
     123        $this->assertEquals(
     124            'foo://example.com', esc_url(
     125                'foo://example.com', array(
     126                    'foo',
     127                )
     128            )
     129        );
    107130
    108131    }
     
    112135     */
    113136    function test_protocol_case() {
    114         $this->assertEquals('http://example.com', esc_url('HTTP://example.com'));
    115         $this->assertEquals('http://example.com', esc_url('Http://example.com'));
     137        $this->assertEquals( 'http://example.com', esc_url( 'HTTP://example.com' ) );
     138        $this->assertEquals( 'http://example.com', esc_url( 'Http://example.com' ) );
    116139    }
    117140
    118141    function test_display_extras() {
    119         $this->assertEquals('http://example.com/'quoted'', esc_url('http://example.com/\'quoted\''));
    120         $this->assertEquals('http://example.com/\'quoted\'', esc_url('http://example.com/\'quoted\'',null,'notdisplay'));
     142        $this->assertEquals( 'http://example.com/'quoted'', esc_url( 'http://example.com/\'quoted\'' ) );
     143        $this->assertEquals( 'http://example.com/\'quoted\'', esc_url( 'http://example.com/\'quoted\'', null, 'notdisplay' ) );
    121144    }
    122145
     
    169192     */
    170193    function test_mailto_with_newline() {
    171         $body = <<<EOT
     194        $body       = <<<EOT
    172195Hi there,
    173196
     
    183206     */
    184207    function test_mailto_in_http_url_with_newline() {
    185         $body = <<<EOT
     208        $body       = <<<EOT
    186209Hi there,
    187210
     
    208231     */
    209232    function test_invalid_charaters() {
    210         $this->assertEmpty( esc_url_raw('"^<>{}`') );
    211     }
    212 
    213     /** 
     233        $this->assertEmpty( esc_url_raw( '"^<>{}`' ) );
     234    }
     235
     236    /**
    214237     * @ticket 34202
    215238     */
Note: See TracChangeset for help on using the changeset viewer.