Make WordPress Core

Changeset 56444


Ignore:
Timestamp:
08/24/2023 02:33:28 PM (3 years ago)
Author:
jorbin
Message:

Build/Tests: Tests_Formatting_MakeClickable should use data providors

Removes the foreach loops from the tests by moving the in-test data sets into data providers and combines the URL data sets into one data provider to test with one test method. By using a data providor, all the tests run rather than stopping at the first failure in this group.

Fixes #57660.
Props hellofromTonya.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/formatting/makeClickable.php

    r55495 r56444  
    1212        }
    1313
    14         public function test_valid_mailto() {
    15                 $valid_emails = array(
    16                         'foo@example.com',
    17                         'foo.bar@example.com',
    18                         'Foo.Bar@a.b.c.d.example.com',
    19                         '0@example.com',
    20                         'foo@example-example.com',
     14        /**
     15         * @dataProvider data_valid_mailto
     16         *
     17         * @param string $email Email to test.
     18         */
     19        public function test_valid_mailto( $email ) {
     20                $this->assertSame( '<a href="mailto:' . $email . '">' . $email . '</a>', make_clickable( $email ) );
     21        }
     22
     23        /**
     24         * Data provider.
     25         *
     26         * @return array
     27         */
     28        public function data_valid_mailto() {
     29                return array(
     30                        array( 'foo@example.com' ),
     31                        array( 'foo.bar@example.com' ),
     32                        array( 'Foo.Bar@a.b.c.d.example.com' ),
     33                        array( '0@example.com' ),
     34                        array( 'foo@example-example.com' ),
    2135                );
    22                 foreach ( $valid_emails as $email ) {
    23                         $this->assertSame( '<a href="mailto:' . $email . '">' . $email . '</a>', make_clickable( $email ) );
    24                 }
    25         }
    26 
    27         public function test_invalid_mailto() {
    28                 $invalid_emails = array(
    29                         'foo',
    30                         'foo@',
    31                         'foo@@example.com',
    32                         '@example.com',
    33                         'foo @example.com',
    34                         'foo@example',
     36        }
     37
     38        /**
     39         * @dataProvider data_invalid_mailto
     40         *
     41         * @param string $email Email to test.
     42         */
     43        public function test_invalid_mailto( $email ) {
     44                $this->assertSame( $email, make_clickable( $email ) );
     45        }
     46
     47        /**
     48         * Data provider.
     49         *
     50         * @return array
     51         */
     52        public function data_invalid_mailto() {
     53                return array(
     54                        array( 'foo' ),
     55                        array( 'foo@' ),
     56                        array( 'foo@@example.com' ),
     57                        array( '@example.com' ),
     58                        array( 'foo @example.com' ),
     59                        array( 'foo@example' ),
    3560                );
    36                 foreach ( $invalid_emails as $email ) {
    37                         $this->assertSame( $email, make_clickable( $email ) );
    38                 }
    39         }
    40 
    41         /**
    42          * Tests that make_clickable() will not link trailing periods, commas,
    43          * and (semi-)colons in URLs with protocol (i.e. http://wordpress.org).
    44          */
    45         public function test_strip_trailing_with_protocol() {
    46                 $urls_before   = array(
    47                         'http://wordpress.org/hello.html',
    48                         'There was a spoon named http://wordpress.org. Alice!',
    49                         'There was a spoon named http://wordpress.org, said Alice.',
    50                         'There was a spoon named http://wordpress.org; said Alice.',
    51                         'There was a spoon named http://wordpress.org: said Alice.',
    52                         'There was a spoon named (http://wordpress.org) said Alice.',
     61        }
     62
     63        /**
     64         * @ticket 4570
     65         * @ticket 10990
     66         * @ticket 11211
     67         * @ticket 14993
     68         * @ticket 16892
     69         *
     70         * @dataProvider data_urls
     71         *
     72         * @param string $text     Content to test.
     73         * @param string $expected Expected results.
     74         */
     75        public function test_urls( $text, $expected ) {
     76                $this->assertSame( $expected, make_clickable( $text ) );
     77        }
     78
     79        /**
     80         * Data provider.
     81         *
     82         * @return array
     83         */
     84        public function data_urls() {
     85                return array(
     86                        // Does not link trailing periods, commas, and (semi-)colons in URLs with protocol (i.e. http://wordpress.org).
     87                        'URL only'                                   => array(
     88                                'text'     => 'http://wordpress.org/hello.html',
     89                                'expected' => '<a href="http://wordpress.org/hello.html" rel="nofollow">http://wordpress.org/hello.html</a>',
     90                        ),
     91                        'URL. with more content after'               => array(
     92                                'text'     => 'There was a spoon named http://wordpress.org. Alice!',
     93                                'expected' => 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>. Alice!',
     94                        ),
     95                        'URL, with more content after'               => array(
     96                                'text'     => 'There was a spoon named http://wordpress.org, said Alice.',
     97                                'expected' => 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>, said Alice.',
     98                        ),
     99                        'URL; with more content after'               => array(
     100                                'text'     => 'There was a spoon named http://wordpress.org; said Alice.',
     101                                'expected' => 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>; said Alice.',
     102                        ),
     103                        'URL: with more content after'               => array(
     104                                'text'     => 'There was a spoon named http://wordpress.org: said Alice.',
     105                                'expected' => 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>: said Alice.',
     106                        ),
     107                        'URL) with more content after'               => array(
     108                                'text'     => 'There was a spoon named (http://wordpress.org) said Alice.',
     109                                'expected' => 'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>) said Alice.',
     110                        ),
     111
     112                        // Does not link trailing periods, commas, and (semi-)colons in URLs with protocol (i.e. http://wordpress.org) with nothing afterwards.
     113                        'URL.'                                       => array(
     114                                'text'     => 'There was a spoon named http://wordpress.org.',
     115                                'expected' => 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>.',
     116                        ),
     117                        'URL,'                                       => array(
     118                                'text'     => 'There was a spoon named http://wordpress.org,',
     119                                'expected' => 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>,',
     120                        ),
     121                        'URL;'                                       => array(
     122                                'text'     => 'There was a spoon named http://wordpress.org;',
     123                                'expected' => 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>;',
     124                        ),
     125                        'URL:'                                       => array(
     126                                'text'     => 'There was a spoon named http://wordpress.org:',
     127                                'expected' => 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>:',
     128                        ),
     129                        'URL)'                                       => array(
     130                                'text'     => 'There was a spoon named (http://wordpress.org)',
     131                                'expected' => 'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>)',
     132                        ),
     133                        'URL)x'                                      => array(
     134                                'text'     => 'There was a spoon named (http://wordpress.org)x',
     135                                'expected' => 'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>)x',
     136                        ),
     137
     138                        // Strip trailing without protocol: will not link trailing periods, commas, and (semi-)colons in URLs without protocol (i.e. www.wordpress.org).
     139                        'No protocol www.URL. with content after'    => array(
     140                                'text'     => 'There was a spoon named www.wordpress.org. Alice!',
     141                                'expected' => 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>. Alice!',
     142                        ),
     143                        'No protocol www.URL, with content after'    => array(
     144                                'text'     => 'There was a spoon named www.wordpress.org, said Alice.',
     145                                'expected' => 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>, said Alice.',
     146                        ),
     147                        'No protocol www.URL; with content after'    => array(
     148                                'text'     => 'There was a spoon named www.wordpress.org; said Alice.',
     149                                'expected' => 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>; said Alice.',
     150                        ),
     151                        'No protocol www.URL: with content after'    => array(
     152                                'text'     => 'There was a spoon named www.wordpress.org: said Alice.',
     153                                'expected' => 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>: said Alice.',
     154                        ),
     155                        'No protocol www.URL) with content after'    => array(
     156                                'text'     => 'There was a spoon named www.wordpress.org) said Alice.',
     157                                'expected' => 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>) said Alice.',
     158                        ),
     159
     160                        // Should not link trailing periods, commas, and (semi-)colons in URLs without protocol (i.e. www.wordpress.org).
     161                        'No protocol www.URL'                        => array(
     162                                'text'     => 'www.wordpress.org',
     163                                'expected' => '<a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>',
     164                        ),
     165                        'No protocol www.URL.'                       => array(
     166                                'text'     => 'There was a spoon named www.wordpress.org.',
     167                                'expected' => 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>.',
     168                        ),
     169                        'No protocol www.URL,'                       => array(
     170                                'text'     => 'There was a spoon named www.wordpress.org,',
     171                                'expected' => 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>,',
     172                        ),
     173                        'No protocol www.URL;'                       => array(
     174                                'text'     => 'There was a spoon named www.wordpress.org;',
     175                                'expected' => 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>;',
     176                        ),
     177                        'No protocol www.URL:'                       => array(
     178                                'text'     => 'There was a spoon named www.wordpress.org:',
     179                                'expected' => 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>:',
     180                        ),
     181                        'No protocol www.URL)'                       => array(
     182                                'text'     => 'There was a spoon named www.wordpress.org)',
     183                                'expected' => 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>)',
     184                        ),
     185
     186                        // @ticket 4570
     187                        // Test IRI.
     188                        'IRI in domain'                              => array(
     189                                'text'     => 'http://www.詹姆斯.com/',
     190                                'expected' => '<a href="http://www.詹姆斯.com/" rel="nofollow">http://www.詹姆斯.com/</a>',
     191                        ),
     192                        'IRI in path'                                => array(
     193                                'text'     => 'http://bg.wikipedia.org/Баба',
     194                                'expected' => '<a href="http://bg.wikipedia.org/Баба" rel="nofollow">http://bg.wikipedia.org/Баба</a>',
     195                        ),
     196                        'IRI in query string'                        => array(
     197                                'text'     => 'http://example.com/?a=баба&b=дядо',
     198                                'expected' => '<a href="http://example.com/?a=баба&#038;b=дядо" rel="nofollow">http://example.com/?a=баба&#038;b=дядо</a>',
     199                        ),
     200
     201                        // @ticket 10990
     202                        // Test URLS with brackets (within the URL).
     203                        'URL with brackets in path'                  => array(
     204                                'text'     => 'http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)',
     205                                'expected' => '<a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>',
     206                        ),
     207                        '(URL with brackets in path)'                => array(
     208                                'text'     => '(http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software))',
     209                                'expected' => '(<a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>)',
     210                        ),
     211                        'URL with brackets in path: word before and after' => array(
     212                                'text'     => 'blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software) blah',
     213                                'expected' => 'blah <a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a> blah',
     214                        ),
     215                        'URL with brackets in path: trailing ) blah' => array(
     216                                'text'     => 'blah (http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah',
     217                                'expected' => 'blah (<a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>) blah',
     218                        ),
     219                        'URL with brackets in path: within content'  => array(
     220                                'text'     => 'blah blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software) blah blah',
     221                                'expected' => 'blah blah blah <a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a> blah blah',
     222                        ),
     223                        'URL with brackets in path: trailing ) within content' => array(
     224                                'text'     => 'blah blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah blah',
     225                                'expected' => 'blah blah blah <a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>) blah blah',
     226                        ),
     227                        '(URL with brackets in path) within content' => array(
     228                                'text'     => 'blah blah (http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah blah',
     229                                'expected' => 'blah blah (<a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>) blah blah',
     230                        ),
     231                        'URL with brackets in path: trailing .)'     => array(
     232                                'text'     => 'blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software).) blah blah',
     233                                'expected' => 'blah blah <a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>.) blah blah',
     234                        ),
     235                        'URL with brackets in path: trailing .)moreurl' => array(
     236                                'text'     => 'blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software).)moreurl blah blah',
     237                                'expected' => 'blah blah <a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>.)moreurl blah blah',
     238                        ),
     239                        'multiline content with URL with brackets in path' => array(
     240                                'text'     => 'In his famous speech “You and Your research” (here:
     241                                                           http://www.cs.virginia.edu/~robins/YouAndYourResearch.html)
     242                                                           Richard Hamming wrote about people getting more done with their doors closed, but',
     243                                'expected' => 'In his famous speech “You and Your research” (here:
     244                                                           <a href="http://www.cs.virginia.edu/~robins/YouAndYourResearch.html" rel="nofollow">http://www.cs.virginia.edu/~robins/YouAndYourResearch.html</a>)
     245                                                           Richard Hamming wrote about people getting more done with their doors closed, but',
     246                        ),
     247
     248                        // @ticket 11211
     249                        // Test with real comments which were incorrectly linked.
     250                        'real world: example.com text (.org URL)'    => array(
     251                                'text'     => 'Example: WordPress, test (some text), I love example.com (http://example.org), it is brilliant',
     252                                'expected' => 'Example: WordPress, test (some text), I love example.com (<a href="http://example.org">http://example.org</a>), it is brilliant',
     253                        ),
     254                        'real world: example.com text (.com URL)'    => array(
     255                                'text'     => 'Example: WordPress, test (some text), I love example.com (http://example.com), it is brilliant',
     256                                'expected' => 'Example: WordPress, test (some text), I love example.com (<a href="http://example.com" rel="nofollow">http://example.com</a>), it is brilliant',
     257                        ),
     258                        'real world: (URL)...'                       => array(
     259                                'text'     => 'Some text followed by a bracketed link with a trailing elipsis (http://example.com)...',
     260                                'expected' => 'Some text followed by a bracketed link with a trailing elipsis (<a href="http://example.com" rel="nofollow">http://example.com</a>)...',
     261                        ),
     262                        'real world: (here: URL)'                    => array(
     263                                'text'     => 'In his famous speech “You and Your research” (here: http://www.cs.virginia.edu/~robins/YouAndYourResearch.html) Richard Hamming wrote about people getting more done with their doors closed...',
     264                                'expected' => '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...',
     265                        ),
     266
     267                        // @ticket 14993
     268                        // Test Twitter hash bang URL.
     269                        'Twitter hash bang URL'                      => array(
     270                                'text'     => 'http://twitter.com/#!/wordpress/status/25907440233',
     271                                'expected' => '<a href="http://twitter.com/#!/wordpress/status/25907440233" rel="nofollow">http://twitter.com/#!/wordpress/status/25907440233</a>',
     272                        ),
     273                        'Twitter hash bang URL in sentence'          => array(
     274                                'text'     => 'This is a really good tweet http://twitter.com/#!/wordpress/status/25907440233 !',
     275                                'expected' => 'This is a really good tweet <a href="http://twitter.com/#!/wordpress/status/25907440233" rel="nofollow">http://twitter.com/#!/wordpress/status/25907440233</a> !',
     276                        ),
     277                        'Twitter hash bang in sentence with trailing !' => array(
     278                                'text'     => 'This is a really good tweet http://twitter.com/#!/wordpress/status/25907440233!',
     279                                'expected' => 'This is a really good tweet <a href="http://twitter.com/#!/wordpress/status/25907440233" rel="nofollow">http://twitter.com/#!/wordpress/status/25907440233</a>!',
     280                        ),
     281
     282                        // Test URLs wrapped in angled brackets, i.e. < >.
     283                        '<URL>'                                      => array(
     284                                'text'     => 'URL wrapped in angle brackets <http://example.com/>',
     285                                'expected' => 'URL wrapped in angle brackets <<a href="http://example.com/" rel="nofollow">http://example.com/</a>>',
     286                        ),
     287                        '< URL >'                                    => array(
     288                                'text'     => 'URL wrapped in angle brackets with padding < http://example.com/ >',
     289                                'expected' => 'URL wrapped in angle brackets with padding < <a href="http://example.com/" rel="nofollow">http://example.com/</a> >',
     290                        ),
     291                        '<email>'                                    => array(
     292                                'text'     => 'mailto wrapped in angle brackets <foo@example.com>',
     293                                'expected' => 'mailto wrapped in angle brackets <foo@example.com>',
     294                        ),
     295
     296                        // Test URLs preceded by punctuation.
     297                        ',URL'                                       => array(
     298                                'text'     => 'Comma then URL,http://example.com/',
     299                                'expected' => 'Comma then URL,<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
     300                        ),
     301                        '.URL'                                       => array(
     302                                'text'     => 'Period then URL.http://example.com/',
     303                                'expected' => 'Period then URL.<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
     304                        ),
     305                        ';URL'                                       => array(
     306                                'text'     => 'Semi-colon then URL;http://example.com/',
     307                                'expected' => 'Semi-colon then URL;<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
     308                        ),
     309                        ':URL'                                       => array(
     310                                'text'     => 'Colon then URL:http://example.com/',
     311                                'expected' => 'Colon then URL:<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
     312                        ),
     313                        '!URL'                                       => array(
     314                                'text'     => 'Exclamation mark then URL!http://example.com/',
     315                                'expected' => 'Exclamation mark then URL!<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
     316                        ),
     317                        '?URL'                                       => array(
     318                                'text'     => 'Question mark then URL?http://example.com/',
     319                                'expected' => 'Question mark then URL?<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
     320                        ),
     321
     322                        // Test it doesn't break tag attributes.
     323                        '<img src=URL with attributes>'              => array(
     324                                'text'     => "<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>",
     325                                'expected' => "<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>",
     326                        ),
     327                        '(<img src=URL with attributes>)'            => array(
     328                                'text'     => "(<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
     329                                'expected' => "(<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
     330                        ),
     331                        'URL (<img src=URL with attributes>)'        => array(
     332                                'text'     => "http://trunk.domain/testing#something (<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
     333                                'expected' => "<a href=\"http://trunk.domain/testing#something\" rel=\"nofollow\">http://trunk.domain/testing#something</a> (<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
     334                        ),
     335                        'multiline URL (<img src=URL with attributes>)' => array(
     336                                'text'     => "http://trunk.domain/testing#something
     337                                                  (<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
     338                                'expected' => "<a href=\"http://trunk.domain/testing#something\" rel=\"nofollow\">http://trunk.domain/testing#something</a>
     339                                                  (<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
     340                        ),
     341                        '<param value=URL><embed src=URL>'           => array(
     342                                'text'     => "<span style='text-align:center; display: block;'><object width='425' height='350'><param name='movie' value='https://www.youtube.com/watch?v=72xdCU__XCk&rel=1&fs=1&showsearch=0&showinfo=1&iv_load_policy=1' /> <param name='allowfullscreen' value='true' /> <param name='wmode' value='opaque' /> <embed src='https://www.youtube.com/watch?v=72xdCU__XCk&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>",
     343                                'expected' => "<span style='text-align:center; display: block;'><object width='425' height='350'><param name='movie' value='https://www.youtube.com/watch?v=72xdCU__XCk&rel=1&fs=1&showsearch=0&showinfo=1&iv_load_policy=1' /> <param name='allowfullscreen' value='true' /> <param name='wmode' value='opaque' /> <embed src='https://www.youtube.com/watch?v=72xdCU__XCk&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>",
     344                        ),
     345                        '<a src=URL title=URL></a>'                  => array(
     346                                'text'     => '<a href="http://example.com/example.gif" title="Image from http://example.com">Look at this image!</a>',
     347                                'expected' => '<a href="http://example.com/example.gif" title="Image from http://example.com">Look at this image!</a>',
     348                        ),
     349
     350                        // Test doesn't add links within <pre> or <code> elements.
     351                        'Does not add link within <pre>'             => array(
     352                                'text'     => '<pre>http://wordpress.org</pre>',
     353                                'expected' => '<pre>http://wordpress.org</pre>',
     354                        ),
     355                        'Does not add link within <code>'            => array(
     356                                'text'     => '<code>http://wordpress.org</code>',
     357                                'expected' => '<code>http://wordpress.org</code>',
     358                        ),
     359                        'Does not add link within <pre with attributes>' => array(
     360                                'text'     => '<pre class="foobar" id="foo">http://wordpress.org</pre>',
     361                                'expected' => '<pre class="foobar" id="foo">http://wordpress.org</pre>',
     362                        ),
     363                        'Does not add link within <code with attributes>' => array(
     364                                'text'     => '<code class="foobar" id="foo">http://wordpress.org</code>',
     365                                'expected' => '<code class="foobar" id="foo">http://wordpress.org</code>',
     366                        ),
     367                        'Adds link within <precustomtag>'            => array(
     368                                'text'     => '<precustomtag>http://wordpress.org</precustomtag>',
     369                                'expected' => '<precustomtag><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a></precustomtag>',
     370                        ),
     371                        'Adds link within <codecustomtag>'           => array(
     372                                'text'     => '<codecustomtag>http://wordpress.org</codecustomtag>',
     373                                'expected' => '<codecustomtag><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a></codecustomtag>',
     374                        ),
     375                        'Adds link to URL before <pre>, but does not add link within <pre>' => array(
     376                                'text'     => 'URL before pre http://wordpress.org<pre>http://wordpress.org</pre>',
     377                                'expected' => 'URL before pre <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a><pre>http://wordpress.org</pre>',
     378                        ),
     379                        'Adds link to URL before <code>, but does not add link within <code>' => array(
     380                                'text'     => 'URL before code http://wordpress.org<code>http://wordpress.org</code>',
     381                                'expected' => 'URL before code <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a><code>http://wordpress.org</code>',
     382                        ),
     383                        'Does not add link to <PRE>, but does add link to URL after <PRE>' => array(
     384                                'text'     => 'URL after pre <PRE>http://wordpress.org</PRE>http://wordpress.org',
     385                                'expected' => 'URL after pre <PRE>http://wordpress.org</PRE><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>',
     386                        ),
     387                        'Does not add link within <code>, but does add link to URL after <code>' => array(
     388                                'text'     => 'URL after code <code>http://wordpress.org</code>http://wordpress.org',
     389                                'expected' => 'URL after code <code>http://wordpress.org</code><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>',
     390                        ),
     391                        'Adds link to before and after URLs, but does not add link within <pre>' => array(
     392                                'text'     => 'URL before and after pre http://wordpress.org<pre>http://wordpress.org</pre>http://wordpress.org',
     393                                'expected' => 'URL before and after pre <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a><pre>http://wordpress.org</pre><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>',
     394                        ),
     395                        'Adds link to before and after URLs, but does not add link within <code>' => array(
     396                                'text'     => 'URL before and after code http://wordpress.org<code>http://wordpress.org</code>http://wordpress.org',
     397                                'expected' => 'URL before and after code <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a><code>http://wordpress.org</code><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>',
     398                        ),
     399                        'Does not add links within nested <pre>URL <code>URL</code> </pre>' => array(
     400                                'text'     => 'code inside pre <pre>http://wordpress.org <code>http://wordpress.org</code> http://wordpress.org</pre>',
     401                                'expected' => 'code inside pre <pre>http://wordpress.org <code>http://wordpress.org</code> http://wordpress.org</pre>',
     402                        ),
     403
     404                        // @ticket 16892
     405                        // Test adds link inside of HTML elements.
     406                        '<span>URL</span>'                           => array(
     407                                'text'     => '<span>http://example.com</span>',
     408                                'expected' => '<span><a href="http://example.com" rel="nofollow">http://example.com</a></span>',
     409                        ),
     410                        '<p>URL</p>'                                 => array(
     411                                'text'     => '<p>http://example.com/</p>',
     412                                'expected' => '<p><a href="http://example.com/" rel="nofollow">http://example.com/</a></p>',
     413                        ),
     414
     415                        // Test does not add links within the <a> element.
     416                        '<a>URL</a>'                                 => array(
     417                                'text'     => 'Some text with a link <a href="http://example.com">http://example.com</a>',
     418                                'expected' => 'Some text with a link <a href="http://example.com">http://example.com</a>',
     419                        ),
     420                        /*
     421                        Fails in 3.3.1 too.
     422                        '<a>text www.URL</a>'                        => array(
     423                                'text'     => '<a href="http://wordpress.org">This is already a link www.wordpress.org</a>',
     424                                'expected' => '<a href="http://wordpress.org">This is already a link www.wordpress.org</a>',
     425                        ),
     426                        */
    53427                );
    54                 $urls_expected = array(
    55                         '<a href="http://wordpress.org/hello.html" rel="nofollow">http://wordpress.org/hello.html</a>',
    56                         'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>. Alice!',
    57                         'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>, said Alice.',
    58                         'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>; said Alice.',
    59                         'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>: said Alice.',
    60                         'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>) said Alice.',
    61                 );
    62 
    63                 foreach ( $urls_before as $key => $url ) {
    64                         $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
    65                 }
    66         }
    67 
    68         /**
    69          * Tests that make_clickable() will not link trailing periods, commas,
    70          * and (semi-)colons in URLs with protocol (i.e. http://wordpress.org).
    71          */
    72         public function test_strip_trailing_with_protocol_nothing_afterwards() {
    73                 $urls_before   = array(
    74                         'http://wordpress.org/hello.html',
    75                         'There was a spoon named http://wordpress.org.',
    76                         'There was a spoon named http://wordpress.org,',
    77                         'There was a spoon named http://wordpress.org;',
    78                         'There was a spoon named http://wordpress.org:',
    79                         'There was a spoon named (http://wordpress.org)',
    80                         'There was a spoon named (http://wordpress.org)x',
    81                 );
    82                 $urls_expected = array(
    83                         '<a href="http://wordpress.org/hello.html" rel="nofollow">http://wordpress.org/hello.html</a>',
    84                         'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>.',
    85                         'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>,',
    86                         'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>;',
    87                         'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>:',
    88                         'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>)',
    89                         'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>)x',
    90                 );
    91 
    92                 foreach ( $urls_before as $key => $url ) {
    93                         $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
    94                 }
    95         }
    96 
    97         /**
    98          * Tests that make_clickable() will not link trailing periods, commas,
    99          * and (semi-)colons in URLs without protocol (i.e. www.wordpress.org).
    100          */
    101         public function test_strip_trailing_without_protocol() {
    102                 $urls_before   = array(
    103                         'www.wordpress.org',
    104                         'There was a spoon named www.wordpress.org. Alice!',
    105                         'There was a spoon named www.wordpress.org, said Alice.',
    106                         'There was a spoon named www.wordpress.org; said Alice.',
    107                         'There was a spoon named www.wordpress.org: said Alice.',
    108                         'There was a spoon named www.wordpress.org) said Alice.',
    109                 );
    110                 $urls_expected = array(
    111                         '<a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>',
    112                         'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>. Alice!',
    113                         'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>, said Alice.',
    114                         'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>; said Alice.',
    115                         'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>: said Alice.',
    116                         'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>) said Alice.',
    117                 );
    118 
    119                 foreach ( $urls_before as $key => $url ) {
    120                         $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
    121                 }
    122         }
    123 
    124         /**
    125          * Tests that make_clickable() will not link trailing periods, commas,
    126          * and (semi-)colons in URLs without protocol (i.e. www.wordpress.org).
    127          */
    128         public function test_strip_trailing_without_protocol_nothing_afterwards() {
    129                 $urls_before   = array(
    130                         'www.wordpress.org',
    131                         'There was a spoon named www.wordpress.org.',
    132                         'There was a spoon named www.wordpress.org,',
    133                         'There was a spoon named www.wordpress.org;',
    134                         'There was a spoon named www.wordpress.org:',
    135                         'There was a spoon named www.wordpress.org)',
    136                 );
    137                 $urls_expected = array(
    138                         '<a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>',
    139                         'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>.',
    140                         'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>,',
    141                         'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>;',
    142                         'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>:',
    143                         'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>)',
    144                 );
    145 
    146                 foreach ( $urls_before as $key => $url ) {
    147                         $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
    148                 }
    149         }
    150 
    151         /**
    152          * @ticket 4570
    153          */
    154         public function test_iri() {
    155                 $urls_before   = array(
    156                         'http://www.詹姆斯.com/',
    157                         'http://bg.wikipedia.org/Баба',
    158                         'http://example.com/?a=баба&b=дядо',
    159                 );
    160                 $urls_expected = array(
    161                         '<a href="http://www.詹姆斯.com/" rel="nofollow">http://www.詹姆斯.com/</a>',
    162                         '<a href="http://bg.wikipedia.org/Баба" rel="nofollow">http://bg.wikipedia.org/Баба</a>',
    163                         '<a href="http://example.com/?a=баба&#038;b=дядо" rel="nofollow">http://example.com/?a=баба&#038;b=дядо</a>',
    164                 );
    165                 foreach ( $urls_before as $key => $url ) {
    166                         $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
    167                 }
    168         }
    169 
    170         /**
    171          * @ticket 10990
    172          */
    173         public function test_brackets_in_urls() {
    174                 $urls_before   = array(
    175                         'http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)',
    176                         '(http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software))',
    177                         'blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software) blah',
    178                         'blah (http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah',
    179                         'blah blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software) blah blah',
    180                         'blah blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah blah',
    181                         'blah blah (http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah blah',
    182                         'blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software).) blah blah',
    183                         'blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software).)moreurl blah blah',
    184                         'In his famous speech “You and Your research” (here:
    185                         http://www.cs.virginia.edu/~robins/YouAndYourResearch.html)
    186                         Richard Hamming wrote about people getting more done with their doors closed, but',
    187                 );
    188                 $urls_expected = array(
    189                         '<a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>',
    190                         '(<a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>)',
    191                         'blah <a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a> blah',
    192                         'blah (<a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>) blah',
    193                         'blah blah blah <a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a> blah blah',
    194                         'blah blah blah <a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>) blah blah',
    195                         'blah blah (<a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>) blah blah',
    196                         'blah blah <a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>.) blah blah',
    197                         'blah blah <a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>.)moreurl blah blah',
    198                         'In his famous speech “You and Your research” (here:
    199                         <a href="http://www.cs.virginia.edu/~robins/YouAndYourResearch.html" rel="nofollow">http://www.cs.virginia.edu/~robins/YouAndYourResearch.html</a>)
    200                         Richard Hamming wrote about people getting more done with their doors closed, but',
    201                 );
    202                 foreach ( $urls_before as $key => $url ) {
    203                         $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
    204                 }
    205         }
    206 
    207         /**
    208          * Based on real comments which were incorrectly linked.
    209          *
    210          * @ticket 11211
    211          */
    212         public function test_real_world_examples() {
    213                 $urls_before   = array(
    214                         'Example: WordPress, test (some text), I love example.com (http://example.org), it is brilliant',
    215                         'Example: WordPress, test (some text), I love example.com (http://example.com), it is brilliant',
    216                         'Some text followed by a bracketed link with a trailing elipsis (http://example.com)...',
    217                         'In his famous speech “You and Your research” (here: http://www.cs.virginia.edu/~robins/YouAndYourResearch.html) Richard Hamming wrote about people getting more done with their doors closed...',
    218                 );
    219                 $urls_expected = array(
    220                         'Example: WordPress, test (some text), I love example.com (<a href="http://example.org">http://example.org</a>), it is brilliant',
    221                         'Example: WordPress, test (some text), I love example.com (<a href="http://example.com" rel="nofollow">http://example.com</a>), it is brilliant',
    222                         'Some text followed by a bracketed link with a trailing elipsis (<a href="http://example.com" rel="nofollow">http://example.com</a>)...',
    223                         '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...',
    224                 );
    225                 foreach ( $urls_before as $key => $url ) {
    226                         $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
    227                 }
    228         }
    229 
    230         /**
    231          * @ticket 14993
    232          */
    233         public function test_twitter_hash_bang() {
    234                 $urls_before   = array(
    235                         'http://twitter.com/#!/wordpress/status/25907440233',
    236                         'This is a really good tweet http://twitter.com/#!/wordpress/status/25907440233 !',
    237                         'This is a really good tweet http://twitter.com/#!/wordpress/status/25907440233!',
    238                 );
    239                 $urls_expected = array(
    240                         '<a href="http://twitter.com/#!/wordpress/status/25907440233" rel="nofollow">http://twitter.com/#!/wordpress/status/25907440233</a>',
    241                         'This is a really good tweet <a href="http://twitter.com/#!/wordpress/status/25907440233" rel="nofollow">http://twitter.com/#!/wordpress/status/25907440233</a> !',
    242                         'This is a really good tweet <a href="http://twitter.com/#!/wordpress/status/25907440233" rel="nofollow">http://twitter.com/#!/wordpress/status/25907440233</a>!',
    243                 );
    244                 foreach ( $urls_before as $key => $url ) {
    245                         $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
    246                 }
    247         }
    248 
    249         public function test_wrapped_in_angles() {
    250                 $before   = array(
    251                         'URL wrapped in angle brackets <http://example.com/>',
    252                         'URL wrapped in angle brackets with padding < http://example.com/ >',
    253                         'mailto wrapped in angle brackets <foo@example.com>',
    254                 );
    255                 $expected = array(
    256                         'URL wrapped in angle brackets <<a href="http://example.com/" rel="nofollow">http://example.com/</a>>',
    257                         'URL wrapped in angle brackets with padding < <a href="http://example.com/" rel="nofollow">http://example.com/</a> >',
    258                         'mailto wrapped in angle brackets <foo@example.com>',
    259                 );
    260                 foreach ( $before as $key => $url ) {
    261                         $this->assertSame( $expected[ $key ], make_clickable( $url ) );
    262                 }
    263         }
    264 
    265         public function test_preceded_by_punctuation() {
    266                 $before   = array(
    267                         'Comma then URL,http://example.com/',
    268                         'Period then URL.http://example.com/',
    269                         'Semi-colon then URL;http://example.com/',
    270                         'Colon then URL:http://example.com/',
    271                         'Exclamation mark then URL!http://example.com/',
    272                         'Question mark then URL?http://example.com/',
    273                 );
    274                 $expected = array(
    275                         'Comma then URL,<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
    276                         'Period then URL.<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
    277                         'Semi-colon then URL;<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
    278                         'Colon then URL:<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
    279                         'Exclamation mark then URL!<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
    280                         'Question mark then URL?<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
    281                 );
    282                 foreach ( $before as $key => $url ) {
    283                         $this->assertSame( $expected[ $key ], make_clickable( $url ) );
    284                 }
    285         }
    286 
    287         public function test_dont_break_attributes() {
    288                 $urls_before   = array(
    289                         "<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>",
    290                         "(<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
    291                         "http://trunk.domain/testing#something (<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
    292                         "http://trunk.domain/testing#something
    293                         (<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
    294                         "<span style='text-align:center; display: block;'><object width='425' height='350'><param name='movie' value='https://www.youtube.com/watch?v=72xdCU__XCk&rel=1&fs=1&showsearch=0&showinfo=1&iv_load_policy=1' /> <param name='allowfullscreen' value='true' /> <param name='wmode' value='opaque' /> <embed src='https://www.youtube.com/watch?v=72xdCU__XCk&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>",
    295                         '<a href="http://example.com/example.gif" title="Image from http://example.com">Look at this image!</a>',
    296                 );
    297                 $urls_expected = array(
    298                         "<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>",
    299                         "(<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
    300                         "<a href=\"http://trunk.domain/testing#something\" rel=\"nofollow\">http://trunk.domain/testing#something</a> (<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
    301                         "<a href=\"http://trunk.domain/testing#something\" rel=\"nofollow\">http://trunk.domain/testing#something</a>
    302                         (<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
    303                         "<span style='text-align:center; display: block;'><object width='425' height='350'><param name='movie' value='https://www.youtube.com/watch?v=72xdCU__XCk&rel=1&fs=1&showsearch=0&showinfo=1&iv_load_policy=1' /> <param name='allowfullscreen' value='true' /> <param name='wmode' value='opaque' /> <embed src='https://www.youtube.com/watch?v=72xdCU__XCk&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>",
    304                         '<a href="http://example.com/example.gif" title="Image from http://example.com">Look at this image!</a>',
    305                 );
    306                 foreach ( $urls_before as $key => $url ) {
    307                         $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
    308                 }
    309         }
    310 
    311         /**
    312          * @ticket 23756
    313          */
    314         public function test_no_links_inside_pre_or_code() {
    315                 $before = array(
    316                         '<pre>http://wordpress.org</pre>',
    317                         '<code>http://wordpress.org</code>',
    318                         '<pre class="foobar" id="foo">http://wordpress.org</pre>',
    319                         '<code class="foobar" id="foo">http://wordpress.org</code>',
    320                         '<precustomtag>http://wordpress.org</precustomtag>',
    321                         '<codecustomtag>http://wordpress.org</codecustomtag>',
    322                         'URL before pre http://wordpress.org<pre>http://wordpress.org</pre>',
    323                         'URL before code http://wordpress.org<code>http://wordpress.org</code>',
    324                         'URL after pre <PRE>http://wordpress.org</PRE>http://wordpress.org',
    325                         'URL after code <code>http://wordpress.org</code>http://wordpress.org',
    326                         'URL before and after pre http://wordpress.org<pre>http://wordpress.org</pre>http://wordpress.org',
    327                         'URL before and after code http://wordpress.org<code>http://wordpress.org</code>http://wordpress.org',
    328                         'code inside pre <pre>http://wordpress.org <code>http://wordpress.org</code> http://wordpress.org</pre>',
    329                 );
    330 
    331                 $expected = array(
    332                         '<pre>http://wordpress.org</pre>',
    333                         '<code>http://wordpress.org</code>',
    334                         '<pre class="foobar" id="foo">http://wordpress.org</pre>',
    335                         '<code class="foobar" id="foo">http://wordpress.org</code>',
    336                         '<precustomtag><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a></precustomtag>',
    337                         '<codecustomtag><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a></codecustomtag>',
    338                         'URL before pre <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a><pre>http://wordpress.org</pre>',
    339                         'URL before code <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a><code>http://wordpress.org</code>',
    340                         'URL after pre <PRE>http://wordpress.org</PRE><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>',
    341                         'URL after code <code>http://wordpress.org</code><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>',
    342                         'URL before and after pre <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a><pre>http://wordpress.org</pre><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>',
    343                         'URL before and after code <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a><code>http://wordpress.org</code><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>',
    344                         'code inside pre <pre>http://wordpress.org <code>http://wordpress.org</code> http://wordpress.org</pre>',
    345                 );
    346 
    347                 foreach ( $before as $key => $url ) {
    348                         $this->assertSame( $expected[ $key ], make_clickable( $url ) );
    349                 }
    350         }
    351 
    352         /**
    353          * @ticket 16892
    354          */
    355         public function test_click_inside_html() {
    356                 $urls_before   = array(
    357                         '<span>http://example.com</span>',
    358                         '<p>http://example.com/</p>',
    359                 );
    360                 $urls_expected = array(
    361                         '<span><a href="http://example.com" rel="nofollow">http://example.com</a></span>',
    362                         '<p><a href="http://example.com/" rel="nofollow">http://example.com/</a></p>',
    363                 );
    364                 foreach ( $urls_before as $key => $url ) {
    365                         $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
    366                 }
    367         }
    368 
    369         public function test_no_links_within_links() {
    370                 $in = array(
    371                         'Some text with a link <a href="http://example.com">http://example.com</a>',
    372                         // '<a href="http://wordpress.org">This is already a link www.wordpress.org</a>', // Fails in 3.3.1 too.
    373                 );
    374                 foreach ( $in as $text ) {
    375                         $this->assertSame( $text, make_clickable( $text ) );
    376                 }
    377428        }
    378429
Note: See TracChangeset for help on using the changeset viewer.