Make WordPress Core


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

    r35847 r42343  
    77    function test_mailto_xss() {
    88        $in = 'testzzz@"STYLE="behavior:url(\'#default#time2\')"onBegin="alert(\'refresh-XSS\')"';
    9         $this->assertEquals($in, make_clickable($in));
     9        $this->assertEquals( $in, make_clickable( $in ) );
    1010    }
    1111
     
    1717            '0@example.com',
    1818            'foo@example-example.com',
    19             );
    20         foreach ($valid_emails as $email) {
    21             $this->assertEquals('<a href="mailto:'.$email.'">'.$email.'</a>', make_clickable($email));
     19        );
     20        foreach ( $valid_emails as $email ) {
     21            $this->assertEquals( '<a href="mailto:' . $email . '">' . $email . '</a>', make_clickable( $email ) );
    2222        }
    2323    }
     
    3131            'foo @example.com',
    3232            'foo@example',
    33             );
    34         foreach ($invalid_emails as $email) {
    35             $this->assertEquals($email, make_clickable($email));
     33        );
     34        foreach ( $invalid_emails as $email ) {
     35            $this->assertEquals( $email, make_clickable( $email ) );
    3636        }
    3737    }
     
    4040    // (semi-)colons in URLs with protocol (i.e. http://wordpress.org)
    4141    function test_strip_trailing_with_protocol() {
    42         $urls_before = array(
     42        $urls_before   = array(
    4343            'http://wordpress.org/hello.html',
    4444            'There was a spoon named http://wordpress.org. Alice!',
     
    4646            'There was a spoon named http://wordpress.org; said Alice.',
    4747            'There was a spoon named http://wordpress.org: said Alice.',
    48             'There was a spoon named (http://wordpress.org) said Alice.'
    49             );
     48            'There was a spoon named (http://wordpress.org) said Alice.',
     49        );
    5050        $urls_expected = array(
    5151            '<a href="http://wordpress.org/hello.html" rel="nofollow">http://wordpress.org/hello.html</a>',
     
    5454            'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>; said Alice.',
    5555            'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>: said Alice.',
    56             'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>) said Alice.'
    57             );
    58 
    59         foreach ($urls_before as $key => $url) {
    60             $this->assertEquals($urls_expected[$key], make_clickable($url));
     56            'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>) said Alice.',
     57        );
     58
     59        foreach ( $urls_before as $key => $url ) {
     60            $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) );
    6161        }
    6262    }
     
    6565    // (semi-)colons in URLs with protocol (i.e. http://wordpress.org)
    6666    function test_strip_trailing_with_protocol_nothing_afterwards() {
    67         $urls_before = array(
     67        $urls_before   = array(
    6868            'http://wordpress.org/hello.html',
    6969            'There was a spoon named http://wordpress.org.',
     
    7373            'There was a spoon named (http://wordpress.org)',
    7474            'There was a spoon named (http://wordpress.org)x',
    75             );
     75        );
    7676        $urls_expected = array(
    7777            '<a href="http://wordpress.org/hello.html" rel="nofollow">http://wordpress.org/hello.html</a>',
     
    8282            'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>)',
    8383            'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>)x',
    84             );
    85 
    86         foreach ($urls_before as $key => $url) {
    87             $this->assertEquals($urls_expected[$key], make_clickable($url));
     84        );
     85
     86        foreach ( $urls_before as $key => $url ) {
     87            $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) );
    8888        }
    8989    }
     
    9292    // (semi-)colons in URLs without protocol (i.e. www.wordpress.org)
    9393    function test_strip_trailing_without_protocol() {
    94         $urls_before = array(
     94        $urls_before   = array(
    9595            'www.wordpress.org',
    9696            'There was a spoon named www.wordpress.org. Alice!',
     
    9898            'There was a spoon named www.wordpress.org; said Alice.',
    9999            'There was a spoon named www.wordpress.org: said Alice.',
    100             'There was a spoon named www.wordpress.org) said Alice.'
    101             );
     100            'There was a spoon named www.wordpress.org) said Alice.',
     101        );
    102102        $urls_expected = array(
    103103            '<a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>',
     
    106106            'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>; said Alice.',
    107107            'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>: said Alice.',
    108             'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>) said Alice.'
    109             );
    110 
    111         foreach ($urls_before as $key => $url) {
    112             $this->assertEquals($urls_expected[$key], make_clickable($url));
     108            'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>) said Alice.',
     109        );
     110
     111        foreach ( $urls_before as $key => $url ) {
     112            $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) );
    113113        }
    114114    }
     
    117117    // (semi-)colons in URLs without protocol (i.e. www.wordpress.org)
    118118    function test_strip_trailing_without_protocol_nothing_afterwards() {
    119         $urls_before = array(
     119        $urls_before   = array(
    120120            'www.wordpress.org',
    121121            'There was a spoon named www.wordpress.org.',
     
    123123            'There was a spoon named www.wordpress.org;',
    124124            'There was a spoon named www.wordpress.org:',
    125             'There was a spoon named www.wordpress.org)'
    126             );
     125            'There was a spoon named www.wordpress.org)',
     126        );
    127127        $urls_expected = array(
    128128            '<a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>',
     
    131131            'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>;',
    132132            'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>:',
    133             'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>)'
    134             );
    135 
    136         foreach ($urls_before as $key => $url) {
    137             $this->assertEquals($urls_expected[$key], make_clickable($url));
     133            'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>)',
     134        );
     135
     136        foreach ( $urls_before as $key => $url ) {
     137            $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) );
    138138        }
    139139    }
     
    141141    // #4570
    142142    function test_iri() {
    143         $urls_before = array(
     143        $urls_before   = array(
    144144            'http://www.詹姆斯.com/',
    145145            'http://bg.wikipedia.org/Баба',
     
    151151            '<a href="http://example.com/?a=баба&#038;b=дядо" rel="nofollow">http://example.com/?a=баба&#038;b=дядо</a>',
    152152        );
    153         foreach ($urls_before as $key => $url) {
    154             $this->assertEquals($urls_expected[$key], make_clickable($url));
     153        foreach ( $urls_before as $key => $url ) {
     154            $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) );
    155155        }
    156156    }
     
    158158    // #10990
    159159    function test_brackets_in_urls() {
    160         $urls_before = array(
     160        $urls_before   = array(
    161161            'http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)',
    162162            '(http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software))',
     
    186186            Richard Hamming wrote about people getting more done with their doors closed, but',
    187187        );
    188         foreach ($urls_before as $key => $url) {
    189             $this->assertEquals($urls_expected[$key], make_clickable($url));
     188        foreach ( $urls_before as $key => $url ) {
     189            $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) );
    190190        }
    191191    }
     
    193193    // Based on a real comments which were incorrectly linked. #11211
    194194    function test_real_world_examples() {
    195         $urls_before = array(
     195        $urls_before   = array(
    196196            'Example: WordPress, test (some text), I love example.com (http://example.org), it is brilliant',
    197197            'Example: WordPress, test (some text), I love example.com (http://example.com), it is brilliant',
     
    205205            'In his famous speech “You and Your research” (here: <a href="http://www.cs.virginia.edu/~robins/YouAndYourResearch.html" rel="nofollow">http://www.cs.virginia.edu/~robins/YouAndYourResearch.html</a>) Richard Hamming wrote about people getting more done with their doors closed...',
    206206        );
    207         foreach ($urls_before as $key => $url) {
    208             $this->assertEquals($urls_expected[$key], make_clickable($url));
     207        foreach ( $urls_before as $key => $url ) {
     208            $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) );
    209209        }
    210210    }
     
    212212    // #14993
    213213    function test_twitter_hash_bang() {
    214         $urls_before = array(
     214        $urls_before   = array(
    215215            'http://twitter.com/#!/wordpress/status/25907440233',
    216216            'This is a really good tweet http://twitter.com/#!/wordpress/status/25907440233 !',
     
    222222            'This is a really good tweet <a href="http://twitter.com/#!/wordpress/status/25907440233" rel="nofollow">http://twitter.com/#!/wordpress/status/25907440233</a>!',
    223223        );
    224         foreach ($urls_before as $key => $url) {
    225             $this->assertEquals($urls_expected[$key], make_clickable($url));
     224        foreach ( $urls_before as $key => $url ) {
     225            $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) );
    226226        }
    227227    }
    228228
    229229    function test_wrapped_in_angles() {
    230         $before = array(
     230        $before   = array(
    231231            'URL wrapped in angle brackets <http://example.com/>',
    232232            'URL wrapped in angle brackets with padding < http://example.com/ >',
     
    238238            'mailto wrapped in angle brackets <foo@example.com>',
    239239        );
    240         foreach ($before as $key => $url) {
    241             $this->assertEquals($expected[$key], make_clickable($url));
     240        foreach ( $before as $key => $url ) {
     241            $this->assertEquals( $expected[ $key ], make_clickable( $url ) );
    242242        }
    243243    }
    244244
    245245    function test_preceded_by_punctuation() {
    246         $before = array(
     246        $before   = array(
    247247            'Comma then URL,http://example.com/',
    248248            'Period then URL.http://example.com/',
     
    260260            'Question mark then URL?<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
    261261        );
    262         foreach ($before as $key => $url) {
    263             $this->assertEquals($expected[$key], make_clickable($url));
     262        foreach ( $before as $key => $url ) {
     263            $this->assertEquals( $expected[ $key ], make_clickable( $url ) );
    264264        }
    265265    }
    266266
    267267    function test_dont_break_attributes() {
    268         $urls_before = array(
     268        $urls_before   = array(
    269269            "<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>",
    270270            "(<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
     
    284284            '<a href="http://example.com/example.gif" title="Image from http://example.com">Look at this image!</a>',
    285285        );
    286         foreach ($urls_before as $key => $url) {
    287             $this->assertEquals($urls_expected[$key], make_clickable($url));
     286        foreach ( $urls_before as $key => $url ) {
     287            $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) );
    288288        }
    289289    }
     
    325325        );
    326326
    327         foreach ( $before as $key => $url )
     327        foreach ( $before as $key => $url ) {
    328328            $this->assertEquals( $expected[ $key ], make_clickable( $url ) );
     329        }
    329330    }
    330331
     
    333334     */
    334335    function test_click_inside_html() {
    335         $urls_before = array(
     336        $urls_before   = array(
    336337            '<span>http://example.com</span>',
    337338            '<p>http://example.com/</p>',
     
    341342            '<p><a href="http://example.com/" rel="nofollow">http://example.com/</a></p>',
    342343        );
    343         foreach ($urls_before as $key => $url) {
    344             $this->assertEquals( $urls_expected[$key], make_clickable( $url ) );
     344        foreach ( $urls_before as $key => $url ) {
     345            $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) );
    345346        }
    346347    }
     
    360361     */
    361362    function test_no_segfault() {
    362         $in = str_repeat( 'http://example.com/2011/03/18/post-title/', 256 );
     363        $in  = str_repeat( 'http://example.com/2011/03/18/post-title/', 256 );
    363364        $out = make_clickable( $in );
    364365        $this->assertEquals( $in, $out );
Note: See TracChangeset for help on using the changeset viewer.