<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[56444] trunk/tests/phpunit/tests/formatting/makeClickable.php: Build/Tests: Tests_Formatting_MakeClickable should use data providors</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/56444">56444</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/56444","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>jorbin</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2023-08-24 14:33:28 +0000 (Thu, 24 Aug 2023)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="https://core.trac.wordpress.org/ticket/57660">#57660</a>.
Props hellofromTonya.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestsformattingmakeClickablephp">trunk/tests/phpunit/tests/formatting/makeClickable.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunktestsphpunittestsformattingmakeClickablephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/formatting/makeClickable.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/formatting/makeClickable.php 2023-08-24 14:21:36 UTC (rev 56443)
+++ trunk/tests/phpunit/tests/formatting/makeClickable.php 2023-08-24 14:33:28 UTC (rev 56444)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -11,369 +11,420 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( $in, make_clickable( $in ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 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( '<a href="mailto:' . $email . '">' . $email . '</a>', 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 ) );
- }
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Tests that make_clickable() will not link trailing periods, commas,
- * and (semi-)colons in URLs with protocol (i.e. http://wordpress.org).
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @dataProvider data_valid_mailto
+ *
+ * @param string $email Email to test.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 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.',
- );
- $urls_expected = array(
- '<a href="http://wordpress.org/hello.html" rel="nofollow">http://wordpress.org/hello.html</a>',
- 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>. Alice!',
- 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>, said Alice.',
- 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>; said Alice.',
- 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>: said Alice.',
- 'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>) said Alice.',
- );
-
- foreach ( $urls_before as $key => $url ) {
- $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_valid_mailto( $email ) {
+ $this->assertSame( '<a href="mailto:' . $email . '">' . $email . '</a>', make_clickable( $email ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Tests that make_clickable() will not link trailing periods, commas,
- * and (semi-)colons in URLs with protocol (i.e. http://wordpress.org).
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Data provider.
+ *
+ * @return array
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 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',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 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' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $urls_expected = array(
- '<a href="http://wordpress.org/hello.html" rel="nofollow">http://wordpress.org/hello.html</a>',
- 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>.',
- 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>,',
- 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>;',
- 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>:',
- 'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>)',
- 'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>)x',
- );
-
- foreach ( $urls_before as $key => $url ) {
- $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
- }
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Tests that make_clickable() will not link trailing periods, commas,
- * and (semi-)colons in URLs without protocol (i.e. www.wordpress.org).
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @dataProvider data_invalid_mailto
+ *
+ * @param string $email Email to test.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 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.',
- );
- $urls_expected = array(
- '<a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>',
- 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>. Alice!',
- 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>, said Alice.',
- 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>; said Alice.',
- 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>: said Alice.',
- 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>) said Alice.',
- );
-
- foreach ( $urls_before as $key => $url ) {
- $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_invalid_mailto( $email ) {
+ $this->assertSame( $email, make_clickable( $email ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Tests that make_clickable() will not link trailing periods, commas,
- * and (semi-)colons in URLs without protocol (i.e. www.wordpress.org).
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Data provider.
+ *
+ * @return array
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 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)',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 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' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $urls_expected = array(
- '<a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>',
- 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>.',
- 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>,',
- 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>;',
- 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>:',
- 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>)',
- );
-
- foreach ( $urls_before as $key => $url ) {
- $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
- }
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 4570
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- */
- public function test_iri() {
- $urls_before = array(
- 'http://www.詹姆斯.com/',
- 'http://bg.wikipedia.org/Баба',
- 'http://example.com/?a=баба&b=дядо',
- );
- $urls_expected = array(
- '<a href="http://www.詹姆斯.com/" rel="nofollow">http://www.詹姆斯.com/</a>',
- '<a href="http://bg.wikipedia.org/Баба" rel="nofollow">http://bg.wikipedia.org/Баба</a>',
- '<a href="http://example.com/?a=баба&b=дядо" rel="nofollow">http://example.com/?a=баба&b=дядо</a>',
- );
- foreach ( $urls_before as $key => $url ) {
- $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
- }
- }
-
- /**
</del><span class="cx" style="display: block; padding: 0 10px"> * @ticket 10990
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @ticket 11211
+ * @ticket 14993
+ * @ticket 16892
+ *
+ * @dataProvider data_urls
+ *
+ * @param string $text Content to test.
+ * @param string $expected Expected results.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 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(
- '<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>',
- '(<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 <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 (<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 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',
- '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',
- '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',
- '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',
- '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',
- '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, but',
- );
- foreach ( $urls_before as $key => $url ) {
- $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_urls( $text, $expected ) {
+ $this->assertSame( $expected, make_clickable( $text ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Based on real comments which were incorrectly linked.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Data provider.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @ticket 11211
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return array
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 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 (<a href="http://example.org">http://example.org</a>), it is brilliant',
- 'Example: WordPress, test (some text), I love example.com (<a href="http://example.com" rel="nofollow">http://example.com</a>), it is brilliant',
- 'Some text followed by a bracketed link with a trailing elipsis (<a href="http://example.com" rel="nofollow">http://example.com</a>)...',
- '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...',
- );
- foreach ( $urls_before as $key => $url ) {
- $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
- }
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 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' => '<a href="http://wordpress.org/hello.html" rel="nofollow">http://wordpress.org/hello.html</a>',
+ ),
+ 'URL. with more content after' => array(
+ 'text' => 'There was a spoon named http://wordpress.org. Alice!',
+ 'expected' => 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>. Alice!',
+ ),
+ 'URL, with more content after' => array(
+ 'text' => 'There was a spoon named http://wordpress.org, said Alice.',
+ 'expected' => 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>, 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 <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>; 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 <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>: 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 (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>) said Alice.',
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /**
- * @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(
- '<a href="http://twitter.com/#!/wordpress/status/25907440233" rel="nofollow">http://twitter.com/#!/wordpress/status/25907440233</a>',
- 'This is a really good tweet <a href="http://twitter.com/#!/wordpress/status/25907440233" rel="nofollow">http://twitter.com/#!/wordpress/status/25907440233</a> !',
- 'This is a really good tweet <a href="http://twitter.com/#!/wordpress/status/25907440233" rel="nofollow">http://twitter.com/#!/wordpress/status/25907440233</a>!',
- );
- foreach ( $urls_before as $key => $url ) {
- $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
- }
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // 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 <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>.',
+ ),
+ 'URL,' => array(
+ 'text' => 'There was a spoon named http://wordpress.org,',
+ 'expected' => 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>,',
+ ),
+ 'URL;' => array(
+ 'text' => 'There was a spoon named http://wordpress.org;',
+ 'expected' => 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>;',
+ ),
+ 'URL:' => array(
+ 'text' => 'There was a spoon named http://wordpress.org:',
+ 'expected' => 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>:',
+ ),
+ 'URL)' => array(
+ 'text' => 'There was a spoon named (http://wordpress.org)',
+ 'expected' => 'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>)',
+ ),
+ 'URL)x' => array(
+ 'text' => 'There was a spoon named (http://wordpress.org)x',
+ 'expected' => 'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>)x',
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_wrapped_in_angles() {
- $before = array(
- 'URL wrapped in angle brackets <http://example.com/>',
- 'URL wrapped in angle brackets with padding < http://example.com/ >',
- 'mailto wrapped in angle brackets <foo@example.com>',
- );
- $expected = array(
- 'URL wrapped in angle brackets <<a href="http://example.com/" rel="nofollow">http://example.com/</a>>',
- 'URL wrapped in angle brackets with padding < <a href="http://example.com/" rel="nofollow">http://example.com/</a> >',
- 'mailto wrapped in angle brackets <foo@example.com>',
- );
- foreach ( $before as $key => $url ) {
- $this->assertSame( $expected[ $key ], make_clickable( $url ) );
- }
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // 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 <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>. 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 <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>, 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 <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>; 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 <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>: 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 <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>) said Alice.',
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 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,<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
- 'Period then URL.<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
- 'Semi-colon then URL;<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
- 'Colon then URL:<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
- 'Exclamation mark then URL!<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
- 'Question mark then URL?<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
- );
- foreach ( $before as $key => $url ) {
- $this->assertSame( $expected[ $key ], make_clickable( $url ) );
- }
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // 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' => '<a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>',
+ ),
+ 'No protocol www.URL.' => array(
+ 'text' => 'There was a spoon named www.wordpress.org.',
+ 'expected' => 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>.',
+ ),
+ 'No protocol www.URL,' => array(
+ 'text' => 'There was a spoon named www.wordpress.org,',
+ 'expected' => 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>,',
+ ),
+ 'No protocol www.URL;' => array(
+ 'text' => 'There was a spoon named www.wordpress.org;',
+ 'expected' => 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>;',
+ ),
+ 'No protocol www.URL:' => array(
+ 'text' => 'There was a spoon named www.wordpress.org:',
+ 'expected' => 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>:',
+ ),
+ 'No protocol www.URL)' => array(
+ 'text' => 'There was a spoon named www.wordpress.org)',
+ 'expected' => 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>)',
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_dont_break_attributes() {
- $urls_before = array(
- "<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>",
- "(<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
- "http://trunk.domain/testing#something (<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
- "http://trunk.domain/testing#something
- (<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
- "<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>",
- '<a href="http://example.com/example.gif" title="Image from http://example.com">Look at this image!</a>',
- );
- $urls_expected = array(
- "<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>",
- "(<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
- "<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'>)",
- "<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'>)",
- "<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>",
- '<a href="http://example.com/example.gif" title="Image from http://example.com">Look at this image!</a>',
- );
- foreach ( $urls_before as $key => $url ) {
- $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
- }
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // @ticket 4570
+ // Test IRI.
+ 'IRI in domain' => array(
+ 'text' => 'http://www.詹姆斯.com/',
+ 'expected' => '<a href="http://www.詹姆斯.com/" rel="nofollow">http://www.詹姆斯.com/</a>',
+ ),
+ 'IRI in path' => array(
+ 'text' => 'http://bg.wikipedia.org/Баба',
+ 'expected' => '<a href="http://bg.wikipedia.org/Баба" rel="nofollow">http://bg.wikipedia.org/Баба</a>',
+ ),
+ 'IRI in query string' => array(
+ 'text' => 'http://example.com/?a=баба&b=дядо',
+ 'expected' => '<a href="http://example.com/?a=баба&b=дядо" rel="nofollow">http://example.com/?a=баба&b=дядо</a>',
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /**
- * @ticket 23756
- */
- public function test_no_links_inside_pre_or_code() {
- $before = array(
- '<pre>http://wordpress.org</pre>',
- '<code>http://wordpress.org</code>',
- '<pre class="foobar" id="foo">http://wordpress.org</pre>',
- '<code class="foobar" id="foo">http://wordpress.org</code>',
- '<precustomtag>http://wordpress.org</precustomtag>',
- '<codecustomtag>http://wordpress.org</codecustomtag>',
- 'URL before pre http://wordpress.org<pre>http://wordpress.org</pre>',
- 'URL before code http://wordpress.org<code>http://wordpress.org</code>',
- 'URL after pre <PRE>http://wordpress.org</PRE>http://wordpress.org',
- 'URL after code <code>http://wordpress.org</code>http://wordpress.org',
- 'URL before and after pre http://wordpress.org<pre>http://wordpress.org</pre>http://wordpress.org',
- 'URL before and after code http://wordpress.org<code>http://wordpress.org</code>http://wordpress.org',
- 'code inside pre <pre>http://wordpress.org <code>http://wordpress.org</code> http://wordpress.org</pre>',
- );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // @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' => '<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>',
+ ),
+ '(URL with brackets in path)' => array(
+ 'text' => '(http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software))',
+ '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>)',
+ ),
+ '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 <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',
+ ),
+ 'URL with brackets in path: trailing ) blah' => array(
+ 'text' => 'blah (http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah',
+ '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',
+ ),
+ '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 <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',
+ ),
+ '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 <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',
+ ),
+ '(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 (<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',
+ ),
+ '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 <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',
+ ),
+ '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 <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',
+ ),
+ '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:
+ <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, but',
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $expected = array(
- '<pre>http://wordpress.org</pre>',
- '<code>http://wordpress.org</code>',
- '<pre class="foobar" id="foo">http://wordpress.org</pre>',
- '<code class="foobar" id="foo">http://wordpress.org</code>',
- '<precustomtag><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a></precustomtag>',
- '<codecustomtag><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a></codecustomtag>',
- 'URL before pre <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a><pre>http://wordpress.org</pre>',
- 'URL before code <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a><code>http://wordpress.org</code>',
- 'URL after pre <PRE>http://wordpress.org</PRE><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>',
- 'URL after code <code>http://wordpress.org</code><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>',
- '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>',
- '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>',
- 'code inside pre <pre>http://wordpress.org <code>http://wordpress.org</code> http://wordpress.org</pre>',
- );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // @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 (<a href="http://example.org">http://example.org</a>), 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 (<a href="http://example.com" rel="nofollow">http://example.com</a>), 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 (<a href="http://example.com" rel="nofollow">http://example.com</a>)...',
+ ),
+ '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: <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...',
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( $before as $key => $url ) {
- $this->assertSame( $expected[ $key ], make_clickable( $url ) );
- }
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // @ticket 14993
+ // Test Twitter hash bang URL.
+ 'Twitter hash bang URL' => array(
+ 'text' => 'http://twitter.com/#!/wordpress/status/25907440233',
+ 'expected' => '<a href="http://twitter.com/#!/wordpress/status/25907440233" rel="nofollow">http://twitter.com/#!/wordpress/status/25907440233</a>',
+ ),
+ '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 <a href="http://twitter.com/#!/wordpress/status/25907440233" rel="nofollow">http://twitter.com/#!/wordpress/status/25907440233</a> !',
+ ),
+ '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 <a href="http://twitter.com/#!/wordpress/status/25907440233" rel="nofollow">http://twitter.com/#!/wordpress/status/25907440233</a>!',
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /**
- * @ticket 16892
- */
- public function test_click_inside_html() {
- $urls_before = array(
- '<span>http://example.com</span>',
- '<p>http://example.com/</p>',
- );
- $urls_expected = array(
- '<span><a href="http://example.com" rel="nofollow">http://example.com</a></span>',
- '<p><a href="http://example.com/" rel="nofollow">http://example.com/</a></p>',
- );
- foreach ( $urls_before as $key => $url ) {
- $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
- }
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Test URLs wrapped in angled brackets, i.e. < >.
+ '<URL>' => array(
+ 'text' => 'URL wrapped in angle brackets <http://example.com/>',
+ 'expected' => 'URL wrapped in angle brackets <<a href="http://example.com/" rel="nofollow">http://example.com/</a>>',
+ ),
+ '< URL >' => array(
+ 'text' => 'URL wrapped in angle brackets with padding < http://example.com/ >',
+ 'expected' => 'URL wrapped in angle brackets with padding < <a href="http://example.com/" rel="nofollow">http://example.com/</a> >',
+ ),
+ '<email>' => array(
+ 'text' => 'mailto wrapped in angle brackets <foo@example.com>',
+ 'expected' => 'mailto wrapped in angle brackets <foo@example.com>',
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_no_links_within_links() {
- $in = array(
- 'Some text with a link <a href="http://example.com">http://example.com</a>',
- // '<a href="http://wordpress.org">This is already a link www.wordpress.org</a>', // Fails in 3.3.1 too.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Test URLs preceded by punctuation.
+ ',URL' => array(
+ 'text' => 'Comma then URL,http://example.com/',
+ 'expected' => 'Comma then URL,<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
+ ),
+ '.URL' => array(
+ 'text' => 'Period then URL.http://example.com/',
+ 'expected' => 'Period then URL.<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
+ ),
+ ';URL' => array(
+ 'text' => 'Semi-colon then URL;http://example.com/',
+ 'expected' => 'Semi-colon then URL;<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
+ ),
+ ':URL' => array(
+ 'text' => 'Colon then URL:http://example.com/',
+ 'expected' => 'Colon then URL:<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
+ ),
+ '!URL' => array(
+ 'text' => 'Exclamation mark then URL!http://example.com/',
+ 'expected' => 'Exclamation mark then URL!<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
+ ),
+ '?URL' => array(
+ 'text' => 'Question mark then URL?http://example.com/',
+ 'expected' => 'Question mark then URL?<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
+ ),
+
+ // Test it doesn't break tag attributes.
+ '<img src=URL with attributes>' => array(
+ 'text' => "<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>",
+ 'expected' => "<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>",
+ ),
+ '(<img src=URL with attributes>)' => array(
+ 'text' => "(<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
+ 'expected' => "(<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
+ ),
+ 'URL (<img src=URL with attributes>)' => array(
+ 'text' => "http://trunk.domain/testing#something (<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
+ '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'>)",
+ ),
+ 'multiline URL (<img src=URL with attributes>)' => array(
+ 'text' => "http://trunk.domain/testing#something
+ (<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
+ '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'>)",
+ ),
+ '<param value=URL><embed src=URL>' => array(
+ '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>",
+ '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>",
+ ),
+ '<a src=URL title=URL></a>' => array(
+ 'text' => '<a href="http://example.com/example.gif" title="Image from http://example.com">Look at this image!</a>',
+ 'expected' => '<a href="http://example.com/example.gif" title="Image from http://example.com">Look at this image!</a>',
+ ),
+
+ // Test doesn't add links within <pre> or <code> elements.
+ 'Does not add link within <pre>' => array(
+ 'text' => '<pre>http://wordpress.org</pre>',
+ 'expected' => '<pre>http://wordpress.org</pre>',
+ ),
+ 'Does not add link within <code>' => array(
+ 'text' => '<code>http://wordpress.org</code>',
+ 'expected' => '<code>http://wordpress.org</code>',
+ ),
+ 'Does not add link within <pre with attributes>' => array(
+ 'text' => '<pre class="foobar" id="foo">http://wordpress.org</pre>',
+ 'expected' => '<pre class="foobar" id="foo">http://wordpress.org</pre>',
+ ),
+ 'Does not add link within <code with attributes>' => array(
+ 'text' => '<code class="foobar" id="foo">http://wordpress.org</code>',
+ 'expected' => '<code class="foobar" id="foo">http://wordpress.org</code>',
+ ),
+ 'Adds link within <precustomtag>' => array(
+ 'text' => '<precustomtag>http://wordpress.org</precustomtag>',
+ 'expected' => '<precustomtag><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a></precustomtag>',
+ ),
+ 'Adds link within <codecustomtag>' => array(
+ 'text' => '<codecustomtag>http://wordpress.org</codecustomtag>',
+ 'expected' => '<codecustomtag><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a></codecustomtag>',
+ ),
+ 'Adds link to URL before <pre>, but does not add link within <pre>' => array(
+ 'text' => 'URL before pre http://wordpress.org<pre>http://wordpress.org</pre>',
+ 'expected' => 'URL before pre <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a><pre>http://wordpress.org</pre>',
+ ),
+ 'Adds link to URL before <code>, but does not add link within <code>' => array(
+ 'text' => 'URL before code http://wordpress.org<code>http://wordpress.org</code>',
+ 'expected' => 'URL before code <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a><code>http://wordpress.org</code>',
+ ),
+ 'Does not add link to <PRE>, but does add link to URL after <PRE>' => array(
+ 'text' => 'URL after pre <PRE>http://wordpress.org</PRE>http://wordpress.org',
+ 'expected' => 'URL after pre <PRE>http://wordpress.org</PRE><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>',
+ ),
+ 'Does not add link within <code>, but does add link to URL after <code>' => array(
+ 'text' => 'URL after code <code>http://wordpress.org</code>http://wordpress.org',
+ 'expected' => 'URL after code <code>http://wordpress.org</code><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>',
+ ),
+ 'Adds link to before and after URLs, but does not add link within <pre>' => array(
+ 'text' => 'URL before and after pre http://wordpress.org<pre>http://wordpress.org</pre>http://wordpress.org',
+ '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>',
+ ),
+ 'Adds link to before and after URLs, but does not add link within <code>' => array(
+ 'text' => 'URL before and after code http://wordpress.org<code>http://wordpress.org</code>http://wordpress.org',
+ '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>',
+ ),
+ 'Does not add links within nested <pre>URL <code>URL</code> </pre>' => array(
+ 'text' => 'code inside pre <pre>http://wordpress.org <code>http://wordpress.org</code> http://wordpress.org</pre>',
+ 'expected' => 'code inside pre <pre>http://wordpress.org <code>http://wordpress.org</code> http://wordpress.org</pre>',
+ ),
+
+ // @ticket 16892
+ // Test adds link inside of HTML elements.
+ '<span>URL</span>' => array(
+ 'text' => '<span>http://example.com</span>',
+ 'expected' => '<span><a href="http://example.com" rel="nofollow">http://example.com</a></span>',
+ ),
+ '<p>URL</p>' => array(
+ 'text' => '<p>http://example.com/</p>',
+ 'expected' => '<p><a href="http://example.com/" rel="nofollow">http://example.com/</a></p>',
+ ),
+
+ // Test does not add links within the <a> element.
+ '<a>URL</a>' => array(
+ 'text' => 'Some text with a link <a href="http://example.com">http://example.com</a>',
+ 'expected' => 'Some text with a link <a href="http://example.com">http://example.com</a>',
+ ),
+ /*
+ Fails in 3.3.1 too.
+ '<a>text www.URL</a>' => array(
+ 'text' => '<a href="http://wordpress.org">This is already a link www.wordpress.org</a>',
+ 'expected' => '<a href="http://wordpress.org">This is already a link www.wordpress.org</a>',
+ ),
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( $in as $text ) {
- $this->assertSame( $text, make_clickable( $text ) );
- }
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span></span></pre>
</div>
</div>
</body>
</html>