Make WordPress Core

Ticket #20418: 20418-unit-tests.diff

File 20418-unit-tests.diff, 4.6 KB (added by ryan, 13 years ago)
  • wp-testcase/test_includes_formatting.php

     
    217217                }
    218218        }
    219219
     220        function test_wrapped_in_angles() {
     221                $before = array(
     222                        'URL wrapped in angle brackets <http://example.com/>',
     223                        'URL wrapped in angle brackets with padding < http://example.com/ >',
     224                        'mailto wrapped in angle brackets <foo@example.com>',
     225                );
     226                $expected = array(
     227                        'URL wrapped in angle brackets <<a href="http://example.com/" rel="nofollow">http://example.com/</a>>',
     228                        'URL wrapped in angle brackets with padding < <a href="http://example.com/" rel="nofollow">http://example.com/</a> >',
     229                        'mailto wrapped in angle brackets <foo@example.com>',
     230                );
     231                foreach ($before as $key => $url) {
     232                        $this->assertEquals($expected[$key], make_clickable($url));
     233                }
     234        }
     235
    220236        function test_preceded_by_punctuation() {
    221237                $before = array(
    222238                        'Comma then URL,http://example.com/',
     
    225241                        'Colon then URL:http://example.com/',
    226242                        'Exclamation mark then URL!http://example.com/',
    227243                        'Question mark then URL?http://example.com/',
    228                         'URL wrapped in angle brackets <http://example.com/>',
    229244                );
    230245                $expected = array(
    231246                        'Comma then URL,<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
     
    234249                        'Colon then URL:<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
    235250                        'Exclamation mark then URL!<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
    236251                        'Question mark then URL?<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
    237                         'URL wrapped in angle brackets <<a href="http://example.com/" rel="nofollow">http://example.com/</a>>',
    238252                );
    239253                foreach ($before as $key => $url) {
    240254                        $this->assertEquals($expected[$key], make_clickable($url));
     
    249263                        "http://trunk.domain/testing#something
    250264                        (<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
    251265                        "<span style='text-align:center; display: block;'><object width='425' height='350'><param name='movie' value='http://www.youtube.com/v/nd_BdvG43rE&rel=1&fs=1&showsearch=0&showinfo=1&iv_load_policy=1' /> <param name='allowfullscreen' value='true' /> <param name='wmode' value='opaque' /> <embed src='http://www.youtube.com/v/nd_BdvG43rE&rel=1&fs=1&showsearch=0&showinfo=1&iv_load_policy=1' type='application/x-shockwave-flash' allowfullscreen='true' width='425' height='350' wmode='opaque'></embed> </object></span>",
     266                        '<a href="http://example.com/example.gif" title="Image from http://example.com">Look at this image!</a>',
    252267                );
    253268                $urls_expected = array(
    254269                        "<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>",
     
    257272                        "<a href=\"http://trunk.domain/testing#something\" rel=\"nofollow\">http://trunk.domain/testing#something</a>
    258273                        (<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
    259274                        "<span style='text-align:center; display: block;'><object width='425' height='350'><param name='movie' value='http://www.youtube.com/v/nd_BdvG43rE&rel=1&fs=1&showsearch=0&showinfo=1&iv_load_policy=1' /> <param name='allowfullscreen' value='true' /> <param name='wmode' value='opaque' /> <embed src='http://www.youtube.com/v/nd_BdvG43rE&rel=1&fs=1&showsearch=0&showinfo=1&iv_load_policy=1' type='application/x-shockwave-flash' allowfullscreen='true' width='425' height='350' wmode='opaque'></embed> </object></span>",
     275                        '<a href="http://example.com/example.gif" title="Image from http://example.com">Look at this image!</a>',
    260276                );
    261277                foreach ($urls_before as $key => $url) {
    262278                        $this->assertEquals($urls_expected[$key], make_clickable($url));
     
    277293                        $this->assertEquals( $urls_expected[$key], make_clickable( $url ) );
    278294                }
    279295        }
     296
     297        function test_no_links_within_links() {
     298                $in = array(
     299                        'Some text with a link <a href="http://example.com">http://example.com</a>',
     300                        //'<a href="http://wordpress.org">This is already a link www.wordpress.org</a>', // fails in 3.3.1 too
     301                );
     302                foreach ( $in as $text ) {
     303                        $this->assertEquals( $text, make_clickable( $text ) );
     304                }
     305        }
     306
     307        /**
     308         * @ticket 16892
     309         */
     310        function test_no_segfault() {
     311                if ( version_compare( $GLOBALS['wp_version'], '3.1.1', '<' ) )
     312                        $this->markTestSkipped();
     313
     314                $in = str_repeat( 'http://example.com/2011/03/18/post-title/', 256 );
     315                $out = make_clickable( $in );
     316                if ( version_compare( $GLOBALS['wp_version'], '3.4-alpha', '>=' ) )
     317                        $this->assertEquals( $in, $out );
     318        }
    280319}
    281320
    282321class TestJSEscape extends WPTestCase {