Make WordPress Core


Ignore:
Timestamp:
08/20/2009 07:58:01 AM (15 years ago)
Author:
westi
Message:

Add some more test case for make_clickable to capture other common use-cases.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_includes_formatting.php

    r234 r235  
    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.'
     48            'There was a spoon named http://wordpress.org: said Alice.',
     49            'There was a spoon named (http://wordpress.org) said Alice.'
    4950            );
    5051        $urls_expected = array(
     
    5354            'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>, said Alice.',
    5455            'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>; said Alice.',
    55             'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>: said Alice.'
    56             );
    57 
    58         foreach ($urls_before as $key => $url) {
    59             $this->assertEquals($urls_expected[$key], make_clickable($url));
    60         }
    61     }
    62 
     56            'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>: said Alice.',
     57            'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>) said Alice.'
     58            );
     59
     60        foreach ($urls_before as $key => $url) {
     61            $this->assertEquals($urls_expected[$key], make_clickable($url));
     62        }
     63    }
     64
     65    // tests that make_clickable will not link trailing periods, commas and
     66    // (semi-)colons in URLs with protocol (i.e. http://wordpress.org)
     67    function test_strip_trailing_with_protocol_nothing_afterwards() {
     68        $urls_before = array(
     69            'http://wordpress.org/hello.html',
     70            'There was a spoon named http://wordpress.org.',
     71            'There was a spoon named http://wordpress.org,',
     72            'There was a spoon named http://wordpress.org;',
     73            'There was a spoon named http://wordpress.org:',
     74            'There was a spoon named (http://wordpress.org)'
     75            );
     76        $urls_expected = array(
     77            '<a href="http://wordpress.org/hello.html" rel="nofollow">http://wordpress.org/hello.html</a>',
     78            'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>.',
     79            'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>,',
     80            'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>;',
     81            'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>:',
     82            'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>)'
     83            );
     84
     85        foreach ($urls_before as $key => $url) {
     86            $this->assertEquals($urls_expected[$key], make_clickable($url));
     87        }
     88    }   
     89   
    6390    // tests that make_clickable will not link trailing periods, commas and
    6491    // (semi-)colons in URLs without protocol (i.e. www.wordpress.org)
     
    6996            'There was a spoon named www.wordpress.org, said Alice.',
    7097            'There was a spoon named www.wordpress.org; said Alice.',
    71             'There was a spoon named www.wordpress.org: said Alice.'
     98            'There was a spoon named www.wordpress.org: said Alice.',
     99            'There was a spoon named www.wordpress.org) said Alice.'
    72100            );
    73101        $urls_expected = array(
     
    76104            'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>, said Alice.',
    77105            'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>; said Alice.',
    78             'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>: said Alice.'
    79             );
    80 
    81         foreach ($urls_before as $key => $url) {
    82             $this->assertEquals($urls_expected[$key], make_clickable($url));
    83         }
    84     }
    85 
     106            'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>: said Alice.',
     107            'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>) said Alice.'
     108            );
     109
     110        foreach ($urls_before as $key => $url) {
     111            $this->assertEquals($urls_expected[$key], make_clickable($url));
     112        }
     113    }
     114
     115    // tests that make_clickable will not link trailing periods, commas and
     116    // (semi-)colons in URLs without protocol (i.e. www.wordpress.org)
     117    function test_strip_trailing_without_protocol_nothing_afterwards() {
     118        $urls_before = array(
     119            'www.wordpress.org',
     120            'There was a spoon named www.wordpress.org.',
     121            'There was a spoon named www.wordpress.org,',
     122            'There was a spoon named www.wordpress.org;',
     123            'There was a spoon named www.wordpress.org:',
     124            'There was a spoon named www.wordpress.org)'
     125            );
     126        $urls_expected = array(
     127            '<a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>',
     128            'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>.',
     129            'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>,',
     130            'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>;',
     131            'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>:',
     132            'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>)'
     133            );
     134
     135        foreach ($urls_before as $key => $url) {
     136            $this->assertEquals($urls_expected[$key], make_clickable($url));
     137        }
     138    }   
     139   
    86140    function test_iri() {
    87141        $this->knownWPBug(4570);
Note: See TracChangeset for help on using the changeset viewer.