http://wordpress.org', - '
http://wordpress.org',
- 'http://wordpress.org', - '
http://wordpress.org',
- 'http://wordpress.org', - 'URL before code http://wordpress.org
http://wordpress.org',
- 'URL after pre http://wordpress.orghttp://wordpress.org', - 'URL after code
http://wordpress.orghttp://wordpress.org',
- 'URL before and after pre http://wordpress.orghttp://wordpress.orghttp://wordpress.org', - 'URL before and after code http://wordpress.org
http://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', - 'URL before code http://wordpress.org
http://wordpress.org',
- 'URL after pre http://wordpress.orghttp://wordpress.org', - 'URL after code
http://wordpress.orghttp://wordpress.org',
- 'URL before and after pre http://wordpress.orghttp://wordpress.orghttp://wordpress.org', - 'URL before and after code http://wordpress.org
http://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', - '', - ); - 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. < >. + '