From c63e32fe8a5fecf844bc4fe3f1a6a5bb2390d265 Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Thu, 24 Aug 2023 14:33:28 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@56444 602fd350-edb4-49c9-b593-d223f7449a82 --- .../tests/formatting/makeClickable.php | 725 ++++++++++-------- 1 file changed, 388 insertions(+), 337 deletions(-) diff --git a/tests/phpunit/tests/formatting/makeClickable.php b/tests/phpunit/tests/formatting/makeClickable.php index 0c6236c859..6586896059 100644 --- a/tests/phpunit/tests/formatting/makeClickable.php +++ b/tests/phpunit/tests/formatting/makeClickable.php @@ -11,369 +11,420 @@ class Tests_Formatting_MakeClickable extends WP_UnitTestCase { $this->assertSame( $in, make_clickable( $in ) ); } - public function test_valid_mailto() { - $valid_emails = array( - 'foo@example.com', - 'foo.bar@example.com', - 'Foo.Bar@a.b.c.d.example.com', - '0@example.com', - 'foo@example-example.com', - ); - foreach ( $valid_emails as $email ) { - $this->assertSame( '' . $email . '', make_clickable( $email ) ); - } - } - - public function test_invalid_mailto() { - $invalid_emails = array( - 'foo', - 'foo@', - 'foo@@example.com', - '@example.com', - 'foo @example.com', - 'foo@example', - ); - foreach ( $invalid_emails as $email ) { - $this->assertSame( $email, make_clickable( $email ) ); - } + /** + * @dataProvider data_valid_mailto + * + * @param string $email Email to test. + */ + public function test_valid_mailto( $email ) { + $this->assertSame( '' . $email . '', make_clickable( $email ) ); } /** - * Tests that make_clickable() will not link trailing periods, commas, - * and (semi-)colons in URLs with protocol (i.e. http://wordpress.org). + * Data provider. + * + * @return array */ - public function test_strip_trailing_with_protocol() { - $urls_before = array( - 'http://wordpress.org/hello.html', - 'There was a spoon named http://wordpress.org. Alice!', - 'There was a spoon named http://wordpress.org, said Alice.', - 'There was a spoon named http://wordpress.org; said Alice.', - 'There was a spoon named http://wordpress.org: said Alice.', - 'There was a spoon named (http://wordpress.org) said Alice.', + public function data_valid_mailto() { + return array( + array( 'foo@example.com' ), + array( 'foo.bar@example.com' ), + array( 'Foo.Bar@a.b.c.d.example.com' ), + array( '0@example.com' ), + array( 'foo@example-example.com' ), ); - $urls_expected = array( - 'http://wordpress.org/hello.html', - 'There was a spoon named http://wordpress.org. Alice!', - 'There was a spoon named http://wordpress.org, said Alice.', - 'There was a spoon named http://wordpress.org; said Alice.', - 'There was a spoon named http://wordpress.org: said Alice.', - 'There was a spoon named (http://wordpress.org) said Alice.', - ); - - foreach ( $urls_before as $key => $url ) { - $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) ); - } } /** - * Tests that make_clickable() will not link trailing periods, commas, - * and (semi-)colons in URLs with protocol (i.e. http://wordpress.org). + * @dataProvider data_invalid_mailto + * + * @param string $email Email to test. */ - public function test_strip_trailing_with_protocol_nothing_afterwards() { - $urls_before = array( - 'http://wordpress.org/hello.html', - 'There was a spoon named http://wordpress.org.', - 'There was a spoon named http://wordpress.org,', - 'There was a spoon named http://wordpress.org;', - 'There was a spoon named http://wordpress.org:', - 'There was a spoon named (http://wordpress.org)', - 'There was a spoon named (http://wordpress.org)x', - ); - $urls_expected = array( - 'http://wordpress.org/hello.html', - 'There was a spoon named http://wordpress.org.', - 'There was a spoon named http://wordpress.org,', - 'There was a spoon named http://wordpress.org;', - 'There was a spoon named http://wordpress.org:', - 'There was a spoon named (http://wordpress.org)', - 'There was a spoon named (http://wordpress.org)x', - ); - - foreach ( $urls_before as $key => $url ) { - $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) ); - } + public function test_invalid_mailto( $email ) { + $this->assertSame( $email, make_clickable( $email ) ); } /** - * Tests that make_clickable() will not link trailing periods, commas, - * and (semi-)colons in URLs without protocol (i.e. www.wordpress.org). + * Data provider. + * + * @return array */ - public function test_strip_trailing_without_protocol() { - $urls_before = array( - 'www.wordpress.org', - 'There was a spoon named www.wordpress.org. Alice!', - 'There was a spoon named www.wordpress.org, said Alice.', - 'There was a spoon named www.wordpress.org; said Alice.', - 'There was a spoon named www.wordpress.org: said Alice.', - 'There was a spoon named www.wordpress.org) said Alice.', + public function data_invalid_mailto() { + return array( + array( 'foo' ), + array( 'foo@' ), + array( 'foo@@example.com' ), + array( '@example.com' ), + array( 'foo @example.com' ), + array( 'foo@example' ), ); - $urls_expected = array( - 'http://www.wordpress.org', - 'There was a spoon named http://www.wordpress.org. Alice!', - 'There was a spoon named http://www.wordpress.org, said Alice.', - 'There was a spoon named http://www.wordpress.org; said Alice.', - 'There was a spoon named http://www.wordpress.org: said Alice.', - 'There was a spoon named http://www.wordpress.org) said Alice.', - ); - - foreach ( $urls_before as $key => $url ) { - $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) ); - } - } - - /** - * Tests that make_clickable() will not link trailing periods, commas, - * and (semi-)colons in URLs without protocol (i.e. www.wordpress.org). - */ - public function test_strip_trailing_without_protocol_nothing_afterwards() { - $urls_before = array( - 'www.wordpress.org', - 'There was a spoon named www.wordpress.org.', - 'There was a spoon named www.wordpress.org,', - 'There was a spoon named www.wordpress.org;', - 'There was a spoon named www.wordpress.org:', - 'There was a spoon named www.wordpress.org)', - ); - $urls_expected = array( - 'http://www.wordpress.org', - 'There was a spoon named http://www.wordpress.org.', - 'There was a spoon named http://www.wordpress.org,', - 'There was a spoon named http://www.wordpress.org;', - 'There was a spoon named http://www.wordpress.org:', - 'There was a spoon named http://www.wordpress.org)', - ); - - foreach ( $urls_before as $key => $url ) { - $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) ); - } } /** * @ticket 4570 - */ - public function test_iri() { - $urls_before = array( - 'http://www.詹姆斯.com/', - 'http://bg.wikipedia.org/Баба', - 'http://example.com/?a=баба&b=дядо', - ); - $urls_expected = array( - 'http://www.詹姆斯.com/', - 'http://bg.wikipedia.org/Баба', - 'http://example.com/?a=баба&b=дядо', - ); - foreach ( $urls_before as $key => $url ) { - $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) ); - } - } - - /** * @ticket 10990 - */ - public function test_brackets_in_urls() { - $urls_before = array( - 'http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)', - '(http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software))', - 'blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software) blah', - 'blah (http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah', - 'blah blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software) blah blah', - 'blah blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah blah', - 'blah blah (http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah blah', - 'blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software).) blah blah', - 'blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software).)moreurl blah blah', - '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, but', - ); - $urls_expected = array( - 'http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)', - '(http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software))', - 'blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software) blah', - 'blah (http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah', - 'blah blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software) blah blah', - 'blah blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah blah', - 'blah blah (http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah blah', - 'blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software).) blah blah', - 'blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software).)moreurl blah blah', - '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, but', - ); - foreach ( $urls_before as $key => $url ) { - $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) ); - } - } - - /** - * Based on real comments which were incorrectly linked. - * * @ticket 11211 - */ - public function test_real_world_examples() { - $urls_before = array( - 'Example: WordPress, test (some text), I love example.com (http://example.org), it is brilliant', - 'Example: WordPress, test (some text), I love example.com (http://example.com), it is brilliant', - 'Some text followed by a bracketed link with a trailing elipsis (http://example.com)...', - '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...', - ); - $urls_expected = array( - 'Example: WordPress, test (some text), I love example.com (http://example.org), it is brilliant', - 'Example: WordPress, test (some text), I love example.com (http://example.com), it is brilliant', - 'Some text followed by a bracketed link with a trailing elipsis (http://example.com)...', - '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...', - ); - foreach ( $urls_before as $key => $url ) { - $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) ); - } - } - - /** * @ticket 14993 - */ - public function test_twitter_hash_bang() { - $urls_before = array( - 'http://twitter.com/#!/wordpress/status/25907440233', - 'This is a really good tweet http://twitter.com/#!/wordpress/status/25907440233 !', - 'This is a really good tweet http://twitter.com/#!/wordpress/status/25907440233!', - ); - $urls_expected = array( - 'http://twitter.com/#!/wordpress/status/25907440233', - 'This is a really good tweet http://twitter.com/#!/wordpress/status/25907440233 !', - 'This is a really good tweet http://twitter.com/#!/wordpress/status/25907440233!', - ); - foreach ( $urls_before as $key => $url ) { - $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) ); - } - } - - public function test_wrapped_in_angles() { - $before = array( - 'URL wrapped in angle brackets ', - 'URL wrapped in angle brackets with padding < http://example.com/ >', - 'mailto wrapped in angle brackets ', - ); - $expected = array( - 'URL wrapped in angle brackets <http://example.com/>', - 'URL wrapped in angle brackets with padding < http://example.com/ >', - 'mailto wrapped in angle brackets ', - ); - foreach ( $before as $key => $url ) { - $this->assertSame( $expected[ $key ], make_clickable( $url ) ); - } - } - - public function test_preceded_by_punctuation() { - $before = array( - 'Comma then URL,http://example.com/', - 'Period then URL.http://example.com/', - 'Semi-colon then URL;http://example.com/', - 'Colon then URL:http://example.com/', - 'Exclamation mark then URL!http://example.com/', - 'Question mark then URL?http://example.com/', - ); - $expected = array( - 'Comma then URL,http://example.com/', - 'Period then URL.http://example.com/', - 'Semi-colon then URL;http://example.com/', - 'Colon then URL:http://example.com/', - 'Exclamation mark then URL!http://example.com/', - 'Question mark then URL?http://example.com/', - ); - foreach ( $before as $key => $url ) { - $this->assertSame( $expected[ $key ], make_clickable( $url ) ); - } - } - - public function test_dont_break_attributes() { - $urls_before = array( - ":)", - "(:))", - "http://trunk.domain/testing#something (:))", - "http://trunk.domain/testing#something - (:))", - " ", - 'Look at this image!', - ); - $urls_expected = array( - ":)", - "(:))", - "http://trunk.domain/testing#something (:))", - "http://trunk.domain/testing#something - (:))", - " ", - 'Look at this image!', - ); - foreach ( $urls_before as $key => $url ) { - $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) ); - } - } - - /** - * @ticket 23756 - */ - public function test_no_links_inside_pre_or_code() { - $before = array( - '
http://wordpress.org
', - 'http://wordpress.org', - '
http://wordpress.org
', - 'http://wordpress.org', - 'http://wordpress.org', - 'http://wordpress.org', - 'URL before pre http://wordpress.org
http://wordpress.org
', - 'URL before code http://wordpress.orghttp://wordpress.org', - 'URL after pre
http://wordpress.org
http://wordpress.org', - 'URL after code http://wordpress.orghttp://wordpress.org', - 'URL before and after pre http://wordpress.org
http://wordpress.org
http://wordpress.org', - 'URL before and after code http://wordpress.orghttp://wordpress.orghttp://wordpress.org', - 'code inside pre
http://wordpress.org http://wordpress.org http://wordpress.org
', - ); - - $expected = array( - '
http://wordpress.org
', - 'http://wordpress.org', - '
http://wordpress.org
', - 'http://wordpress.org', - 'http://wordpress.org', - 'http://wordpress.org', - 'URL before pre http://wordpress.org
http://wordpress.org
', - 'URL before code http://wordpress.orghttp://wordpress.org', - 'URL after pre
http://wordpress.org
http://wordpress.org', - 'URL after code http://wordpress.orghttp://wordpress.org', - 'URL before and after pre http://wordpress.org
http://wordpress.org
http://wordpress.org', - 'URL before and after code http://wordpress.orghttp://wordpress.orghttp://wordpress.org', - 'code inside pre
http://wordpress.org http://wordpress.org http://wordpress.org
', - ); - - foreach ( $before as $key => $url ) { - $this->assertSame( $expected[ $key ], make_clickable( $url ) ); - } - } - - /** * @ticket 16892 + * + * @dataProvider data_urls + * + * @param string $text Content to test. + * @param string $expected Expected results. */ - public function test_click_inside_html() { - $urls_before = array( - 'http://example.com', - '

http://example.com/

', - ); - $urls_expected = array( - 'http://example.com', - '

http://example.com/

', - ); - foreach ( $urls_before as $key => $url ) { - $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) ); - } + public function test_urls( $text, $expected ) { + $this->assertSame( $expected, make_clickable( $text ) ); } - public function test_no_links_within_links() { - $in = array( - 'Some text with a link http://example.com', - // 'This is already a link www.wordpress.org', // Fails in 3.3.1 too. + /** + * Data provider. + * + * @return array + */ + public function data_urls() { + return array( + // Does not link trailing periods, commas, and (semi-)colons in URLs with protocol (i.e. http://wordpress.org). + 'URL only' => array( + 'text' => 'http://wordpress.org/hello.html', + 'expected' => 'http://wordpress.org/hello.html', + ), + 'URL. with more content after' => array( + 'text' => 'There was a spoon named http://wordpress.org. Alice!', + 'expected' => 'There was a spoon named http://wordpress.org. Alice!', + ), + 'URL, with more content after' => array( + 'text' => 'There was a spoon named http://wordpress.org, said Alice.', + 'expected' => 'There was a spoon named http://wordpress.org, said Alice.', + ), + 'URL; with more content after' => array( + 'text' => 'There was a spoon named http://wordpress.org; said Alice.', + 'expected' => 'There was a spoon named http://wordpress.org; said Alice.', + ), + 'URL: with more content after' => array( + 'text' => 'There was a spoon named http://wordpress.org: said Alice.', + 'expected' => 'There was a spoon named http://wordpress.org: said Alice.', + ), + 'URL) with more content after' => array( + 'text' => 'There was a spoon named (http://wordpress.org) said Alice.', + 'expected' => 'There was a spoon named (http://wordpress.org) said Alice.', + ), + + // Does not link trailing periods, commas, and (semi-)colons in URLs with protocol (i.e. http://wordpress.org) with nothing afterwards. + 'URL.' => array( + 'text' => 'There was a spoon named http://wordpress.org.', + 'expected' => 'There was a spoon named http://wordpress.org.', + ), + 'URL,' => array( + 'text' => 'There was a spoon named http://wordpress.org,', + 'expected' => 'There was a spoon named http://wordpress.org,', + ), + 'URL;' => array( + 'text' => 'There was a spoon named http://wordpress.org;', + 'expected' => 'There was a spoon named http://wordpress.org;', + ), + 'URL:' => array( + 'text' => 'There was a spoon named http://wordpress.org:', + 'expected' => 'There was a spoon named http://wordpress.org:', + ), + 'URL)' => array( + 'text' => 'There was a spoon named (http://wordpress.org)', + 'expected' => 'There was a spoon named (http://wordpress.org)', + ), + 'URL)x' => array( + 'text' => 'There was a spoon named (http://wordpress.org)x', + 'expected' => 'There was a spoon named (http://wordpress.org)x', + ), + + // Strip trailing without protocol: will not link trailing periods, commas, and (semi-)colons in URLs without protocol (i.e. www.wordpress.org). + 'No protocol www.URL. with content after' => array( + 'text' => 'There was a spoon named www.wordpress.org. Alice!', + 'expected' => 'There was a spoon named http://www.wordpress.org. Alice!', + ), + 'No protocol www.URL, with content after' => array( + 'text' => 'There was a spoon named www.wordpress.org, said Alice.', + 'expected' => 'There was a spoon named http://www.wordpress.org, said Alice.', + ), + 'No protocol www.URL; with content after' => array( + 'text' => 'There was a spoon named www.wordpress.org; said Alice.', + 'expected' => 'There was a spoon named http://www.wordpress.org; said Alice.', + ), + 'No protocol www.URL: with content after' => array( + 'text' => 'There was a spoon named www.wordpress.org: said Alice.', + 'expected' => 'There was a spoon named http://www.wordpress.org: said Alice.', + ), + 'No protocol www.URL) with content after' => array( + 'text' => 'There was a spoon named www.wordpress.org) said Alice.', + 'expected' => 'There was a spoon named http://www.wordpress.org) said Alice.', + ), + + // Should not link trailing periods, commas, and (semi-)colons in URLs without protocol (i.e. www.wordpress.org). + 'No protocol www.URL' => array( + 'text' => 'www.wordpress.org', + 'expected' => 'http://www.wordpress.org', + ), + 'No protocol www.URL.' => array( + 'text' => 'There was a spoon named www.wordpress.org.', + 'expected' => 'There was a spoon named http://www.wordpress.org.', + ), + 'No protocol www.URL,' => array( + 'text' => 'There was a spoon named www.wordpress.org,', + 'expected' => 'There was a spoon named http://www.wordpress.org,', + ), + 'No protocol www.URL;' => array( + 'text' => 'There was a spoon named www.wordpress.org;', + 'expected' => 'There was a spoon named http://www.wordpress.org;', + ), + 'No protocol www.URL:' => array( + 'text' => 'There was a spoon named www.wordpress.org:', + 'expected' => 'There was a spoon named http://www.wordpress.org:', + ), + 'No protocol www.URL)' => array( + 'text' => 'There was a spoon named www.wordpress.org)', + 'expected' => 'There was a spoon named http://www.wordpress.org)', + ), + + // @ticket 4570 + // Test IRI. + 'IRI in domain' => array( + 'text' => 'http://www.詹姆斯.com/', + 'expected' => 'http://www.詹姆斯.com/', + ), + 'IRI in path' => array( + 'text' => 'http://bg.wikipedia.org/Баба', + 'expected' => 'http://bg.wikipedia.org/Баба', + ), + 'IRI in query string' => array( + 'text' => 'http://example.com/?a=баба&b=дядо', + 'expected' => 'http://example.com/?a=баба&b=дядо', + ), + + // @ticket 10990 + // Test URLS with brackets (within the URL). + 'URL with brackets in path' => array( + 'text' => 'http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)', + 'expected' => 'http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)', + ), + '(URL with brackets in path)' => array( + 'text' => '(http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software))', + 'expected' => '(http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software))', + ), + 'URL with brackets in path: word before and after' => array( + 'text' => 'blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software) blah', + 'expected' => 'blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software) blah', + ), + 'URL with brackets in path: trailing ) blah' => array( + 'text' => 'blah (http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah', + 'expected' => 'blah (http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah', + ), + 'URL with brackets in path: within content' => array( + 'text' => 'blah blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software) blah blah', + 'expected' => 'blah blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software) blah blah', + ), + 'URL with brackets in path: trailing ) within content' => array( + 'text' => 'blah blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah blah', + 'expected' => 'blah blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah blah', + ), + '(URL with brackets in path) within content' => array( + 'text' => 'blah blah (http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah blah', + 'expected' => 'blah blah (http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah blah', + ), + 'URL with brackets in path: trailing .)' => array( + 'text' => 'blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software).) blah blah', + 'expected' => 'blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software).) blah blah', + ), + 'URL with brackets in path: trailing .)moreurl' => array( + 'text' => 'blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software).)moreurl blah blah', + 'expected' => 'blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software).)moreurl blah blah', + ), + 'multiline content with URL with brackets in path' => array( + '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, but', + 'expected' => '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, but', + ), + + // @ticket 11211 + // Test with real comments which were incorrectly linked. + 'real world: example.com text (.org URL)' => array( + 'text' => 'Example: WordPress, test (some text), I love example.com (http://example.org), it is brilliant', + 'expected' => 'Example: WordPress, test (some text), I love example.com (http://example.org), it is brilliant', + ), + 'real world: example.com text (.com URL)' => array( + 'text' => 'Example: WordPress, test (some text), I love example.com (http://example.com), it is brilliant', + 'expected' => 'Example: WordPress, test (some text), I love example.com (http://example.com), it is brilliant', + ), + 'real world: (URL)...' => array( + 'text' => 'Some text followed by a bracketed link with a trailing elipsis (http://example.com)...', + 'expected' => 'Some text followed by a bracketed link with a trailing elipsis (http://example.com)...', + ), + 'real world: (here: URL)' => array( + '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...', + 'expected' => '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...', + ), + + // @ticket 14993 + // Test Twitter hash bang URL. + 'Twitter hash bang URL' => array( + 'text' => 'http://twitter.com/#!/wordpress/status/25907440233', + 'expected' => 'http://twitter.com/#!/wordpress/status/25907440233', + ), + 'Twitter hash bang URL in sentence' => array( + 'text' => 'This is a really good tweet http://twitter.com/#!/wordpress/status/25907440233 !', + 'expected' => 'This is a really good tweet http://twitter.com/#!/wordpress/status/25907440233 !', + ), + 'Twitter hash bang in sentence with trailing !' => array( + 'text' => 'This is a really good tweet http://twitter.com/#!/wordpress/status/25907440233!', + 'expected' => 'This is a really good tweet http://twitter.com/#!/wordpress/status/25907440233!', + ), + + // Test URLs wrapped in angled brackets, i.e. < >. + '' => array( + 'text' => 'URL wrapped in angle brackets ', + 'expected' => 'URL wrapped in angle brackets <http://example.com/>', + ), + '< URL >' => array( + 'text' => 'URL wrapped in angle brackets with padding < http://example.com/ >', + 'expected' => 'URL wrapped in angle brackets with padding < http://example.com/ >', + ), + '' => array( + 'text' => 'mailto wrapped in angle brackets ', + 'expected' => 'mailto wrapped in angle brackets ', + ), + + // Test URLs preceded by punctuation. + ',URL' => array( + 'text' => 'Comma then URL,http://example.com/', + 'expected' => 'Comma then URL,http://example.com/', + ), + '.URL' => array( + 'text' => 'Period then URL.http://example.com/', + 'expected' => 'Period then URL.http://example.com/', + ), + ';URL' => array( + 'text' => 'Semi-colon then URL;http://example.com/', + 'expected' => 'Semi-colon then URL;http://example.com/', + ), + ':URL' => array( + 'text' => 'Colon then URL:http://example.com/', + 'expected' => 'Colon then URL:http://example.com/', + ), + '!URL' => array( + 'text' => 'Exclamation mark then URL!http://example.com/', + 'expected' => 'Exclamation mark then URL!http://example.com/', + ), + '?URL' => array( + 'text' => 'Question mark then URL?http://example.com/', + 'expected' => 'Question mark then URL?http://example.com/', + ), + + // Test it doesn't break tag attributes. + '' => array( + 'text' => ":)", + 'expected' => ":)", + ), + '()' => array( + 'text' => "(:))", + 'expected' => "(:))", + ), + 'URL ()' => array( + 'text' => "http://trunk.domain/testing#something (:))", + 'expected' => "http://trunk.domain/testing#something (:))", + ), + 'multiline URL ()' => array( + 'text' => "http://trunk.domain/testing#something + (:))", + 'expected' => "http://trunk.domain/testing#something + (:))", + ), + '' => array( + 'text' => " ", + 'expected' => " ", + ), + '' => array( + 'text' => 'Look at this image!', + 'expected' => 'Look at this image!', + ), + + // Test doesn't add links within
 or  elements.
+			'Does not add link within 
'             => array(
+				'text'     => '
http://wordpress.org
', + 'expected' => '
http://wordpress.org
', + ), + 'Does not add link within ' => array( + 'text' => 'http://wordpress.org', + 'expected' => 'http://wordpress.org', + ), + 'Does not add link within
' => array(
+				'text'     => '
http://wordpress.org
', + 'expected' => '
http://wordpress.org
', + ), + 'Does not add link within ' => array( + 'text' => 'http://wordpress.org', + 'expected' => 'http://wordpress.org', + ), + 'Adds link within ' => array( + 'text' => 'http://wordpress.org', + 'expected' => 'http://wordpress.org', + ), + 'Adds link within ' => array( + 'text' => 'http://wordpress.org', + 'expected' => 'http://wordpress.org', + ), + 'Adds link to URL before
, but does not add link within 
' => array(
+				'text'     => 'URL before pre http://wordpress.org
http://wordpress.org
', + 'expected' => 'URL before pre http://wordpress.org
http://wordpress.org
', + ), + 'Adds link to URL before , but does not add link within ' => array( + 'text' => 'URL before code http://wordpress.orghttp://wordpress.org', + 'expected' => 'URL before code http://wordpress.orghttp://wordpress.org', + ), + 'Does not add link to
, but does add link to URL after 
' => array(
+				'text'     => 'URL after pre 
http://wordpress.org
http://wordpress.org', + 'expected' => 'URL after pre
http://wordpress.org
http://wordpress.org', + ), + 'Does not add link within , but does add link to URL after ' => array( + 'text' => 'URL after code http://wordpress.orghttp://wordpress.org', + 'expected' => 'URL after code http://wordpress.orghttp://wordpress.org', + ), + 'Adds link to before and after URLs, but does not add link within
' => array(
+				'text'     => 'URL before and after pre http://wordpress.org
http://wordpress.org
http://wordpress.org', + 'expected' => 'URL before and after pre http://wordpress.org
http://wordpress.org
http://wordpress.org', + ), + 'Adds link to before and after URLs, but does not add link within ' => array( + 'text' => 'URL before and after code http://wordpress.orghttp://wordpress.orghttp://wordpress.org', + 'expected' => 'URL before and after code http://wordpress.orghttp://wordpress.orghttp://wordpress.org', + ), + 'Does not add links within nested
URL URL 
' => array( + 'text' => 'code inside pre
http://wordpress.org http://wordpress.org http://wordpress.org
', + 'expected' => 'code inside pre
http://wordpress.org http://wordpress.org http://wordpress.org
', + ), + + // @ticket 16892 + // Test adds link inside of HTML elements. + 'URL' => array( + 'text' => 'http://example.com', + 'expected' => 'http://example.com', + ), + '

URL

' => array( + 'text' => '

http://example.com/

', + 'expected' => '

http://example.com/

', + ), + + // Test does not add links within the element. + 'URL' => array( + 'text' => 'Some text with a link http://example.com', + 'expected' => 'Some text with a link http://example.com', + ), + /* + Fails in 3.3.1 too. + 'text www.URL' => array( + 'text' => 'This is already a link www.wordpress.org', + 'expected' => 'This is already a link www.wordpress.org', + ), + */ ); - foreach ( $in as $text ) { - $this->assertSame( $text, make_clickable( $text ) ); - } } /**