Changeset 42343 for trunk/tests/phpunit/tests/formatting/MakeClickable.php
- Timestamp:
- 11/30/2017 11:09:33 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/formatting/MakeClickable.php
r35847 r42343 7 7 function test_mailto_xss() { 8 8 $in = 'testzzz@"STYLE="behavior:url(\'#default#time2\')"onBegin="alert(\'refresh-XSS\')"'; 9 $this->assertEquals( $in, make_clickable($in));9 $this->assertEquals( $in, make_clickable( $in ) ); 10 10 } 11 11 … … 17 17 '0@example.com', 18 18 'foo@example-example.com', 19 20 foreach ( $valid_emails as $email) {21 $this->assertEquals( '<a href="mailto:'.$email.'">'.$email.'</a>', make_clickable($email));19 ); 20 foreach ( $valid_emails as $email ) { 21 $this->assertEquals( '<a href="mailto:' . $email . '">' . $email . '</a>', make_clickable( $email ) ); 22 22 } 23 23 } … … 31 31 'foo @example.com', 32 32 'foo@example', 33 34 foreach ( $invalid_emails as $email) {35 $this->assertEquals( $email, make_clickable($email));33 ); 34 foreach ( $invalid_emails as $email ) { 35 $this->assertEquals( $email, make_clickable( $email ) ); 36 36 } 37 37 } … … 40 40 // (semi-)colons in URLs with protocol (i.e. http://wordpress.org) 41 41 function test_strip_trailing_with_protocol() { 42 $urls_before = array(42 $urls_before = array( 43 43 'http://wordpress.org/hello.html', 44 44 'There was a spoon named http://wordpress.org. Alice!', … … 46 46 'There was a spoon named http://wordpress.org; said Alice.', 47 47 'There was a spoon named http://wordpress.org: said Alice.', 48 'There was a spoon named (http://wordpress.org) said Alice.' 49 48 'There was a spoon named (http://wordpress.org) said Alice.', 49 ); 50 50 $urls_expected = array( 51 51 '<a href="http://wordpress.org/hello.html" rel="nofollow">http://wordpress.org/hello.html</a>', … … 54 54 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>; said Alice.', 55 55 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>: said Alice.', 56 'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>) said Alice.' 57 58 59 foreach ( $urls_before as $key => $url) {60 $this->assertEquals( $urls_expected[$key], make_clickable($url));56 'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>) said Alice.', 57 ); 58 59 foreach ( $urls_before as $key => $url ) { 60 $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) ); 61 61 } 62 62 } … … 65 65 // (semi-)colons in URLs with protocol (i.e. http://wordpress.org) 66 66 function test_strip_trailing_with_protocol_nothing_afterwards() { 67 $urls_before = array(67 $urls_before = array( 68 68 'http://wordpress.org/hello.html', 69 69 'There was a spoon named http://wordpress.org.', … … 73 73 'There was a spoon named (http://wordpress.org)', 74 74 'There was a spoon named (http://wordpress.org)x', 75 75 ); 76 76 $urls_expected = array( 77 77 '<a href="http://wordpress.org/hello.html" rel="nofollow">http://wordpress.org/hello.html</a>', … … 82 82 'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>)', 83 83 'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>)x', 84 85 86 foreach ( $urls_before as $key => $url) {87 $this->assertEquals( $urls_expected[$key], make_clickable($url));84 ); 85 86 foreach ( $urls_before as $key => $url ) { 87 $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) ); 88 88 } 89 89 } … … 92 92 // (semi-)colons in URLs without protocol (i.e. www.wordpress.org) 93 93 function test_strip_trailing_without_protocol() { 94 $urls_before = array(94 $urls_before = array( 95 95 'www.wordpress.org', 96 96 'There was a spoon named www.wordpress.org. Alice!', … … 98 98 'There was a spoon named www.wordpress.org; said Alice.', 99 99 'There was a spoon named www.wordpress.org: said Alice.', 100 'There was a spoon named www.wordpress.org) said Alice.' 101 100 'There was a spoon named www.wordpress.org) said Alice.', 101 ); 102 102 $urls_expected = array( 103 103 '<a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>', … … 106 106 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>; said Alice.', 107 107 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>: said Alice.', 108 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>) said Alice.' 109 110 111 foreach ( $urls_before as $key => $url) {112 $this->assertEquals( $urls_expected[$key], make_clickable($url));108 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>) said Alice.', 109 ); 110 111 foreach ( $urls_before as $key => $url ) { 112 $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) ); 113 113 } 114 114 } … … 117 117 // (semi-)colons in URLs without protocol (i.e. www.wordpress.org) 118 118 function test_strip_trailing_without_protocol_nothing_afterwards() { 119 $urls_before = array(119 $urls_before = array( 120 120 'www.wordpress.org', 121 121 'There was a spoon named www.wordpress.org.', … … 123 123 'There was a spoon named www.wordpress.org;', 124 124 'There was a spoon named www.wordpress.org:', 125 'There was a spoon named www.wordpress.org)' 126 125 'There was a spoon named www.wordpress.org)', 126 ); 127 127 $urls_expected = array( 128 128 '<a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>', … … 131 131 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>;', 132 132 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>:', 133 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>)' 134 135 136 foreach ( $urls_before as $key => $url) {137 $this->assertEquals( $urls_expected[$key], make_clickable($url));133 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>)', 134 ); 135 136 foreach ( $urls_before as $key => $url ) { 137 $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) ); 138 138 } 139 139 } … … 141 141 // #4570 142 142 function test_iri() { 143 $urls_before = array(143 $urls_before = array( 144 144 'http://www.詹姆斯.com/', 145 145 'http://bg.wikipedia.org/Баба', … … 151 151 '<a href="http://example.com/?a=баба&b=дядо" rel="nofollow">http://example.com/?a=баба&b=дядо</a>', 152 152 ); 153 foreach ( $urls_before as $key => $url) {154 $this->assertEquals( $urls_expected[$key], make_clickable($url));153 foreach ( $urls_before as $key => $url ) { 154 $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) ); 155 155 } 156 156 } … … 158 158 // #10990 159 159 function test_brackets_in_urls() { 160 $urls_before = array(160 $urls_before = array( 161 161 'http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)', 162 162 '(http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software))', … … 186 186 Richard Hamming wrote about people getting more done with their doors closed, but', 187 187 ); 188 foreach ( $urls_before as $key => $url) {189 $this->assertEquals( $urls_expected[$key], make_clickable($url));188 foreach ( $urls_before as $key => $url ) { 189 $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) ); 190 190 } 191 191 } … … 193 193 // Based on a real comments which were incorrectly linked. #11211 194 194 function test_real_world_examples() { 195 $urls_before = array(195 $urls_before = array( 196 196 'Example: WordPress, test (some text), I love example.com (http://example.org), it is brilliant', 197 197 'Example: WordPress, test (some text), I love example.com (http://example.com), it is brilliant', … … 205 205 '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...', 206 206 ); 207 foreach ( $urls_before as $key => $url) {208 $this->assertEquals( $urls_expected[$key], make_clickable($url));207 foreach ( $urls_before as $key => $url ) { 208 $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) ); 209 209 } 210 210 } … … 212 212 // #14993 213 213 function test_twitter_hash_bang() { 214 $urls_before = array(214 $urls_before = array( 215 215 'http://twitter.com/#!/wordpress/status/25907440233', 216 216 'This is a really good tweet http://twitter.com/#!/wordpress/status/25907440233 !', … … 222 222 'This is a really good tweet <a href="http://twitter.com/#!/wordpress/status/25907440233" rel="nofollow">http://twitter.com/#!/wordpress/status/25907440233</a>!', 223 223 ); 224 foreach ( $urls_before as $key => $url) {225 $this->assertEquals( $urls_expected[$key], make_clickable($url));224 foreach ( $urls_before as $key => $url ) { 225 $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) ); 226 226 } 227 227 } 228 228 229 229 function test_wrapped_in_angles() { 230 $before = array(230 $before = array( 231 231 'URL wrapped in angle brackets <http://example.com/>', 232 232 'URL wrapped in angle brackets with padding < http://example.com/ >', … … 238 238 'mailto wrapped in angle brackets <foo@example.com>', 239 239 ); 240 foreach ( $before as $key => $url) {241 $this->assertEquals( $expected[$key], make_clickable($url));240 foreach ( $before as $key => $url ) { 241 $this->assertEquals( $expected[ $key ], make_clickable( $url ) ); 242 242 } 243 243 } 244 244 245 245 function test_preceded_by_punctuation() { 246 $before = array(246 $before = array( 247 247 'Comma then URL,http://example.com/', 248 248 'Period then URL.http://example.com/', … … 260 260 'Question mark then URL?<a href="http://example.com/" rel="nofollow">http://example.com/</a>', 261 261 ); 262 foreach ( $before as $key => $url) {263 $this->assertEquals( $expected[$key], make_clickable($url));262 foreach ( $before as $key => $url ) { 263 $this->assertEquals( $expected[ $key ], make_clickable( $url ) ); 264 264 } 265 265 } 266 266 267 267 function test_dont_break_attributes() { 268 $urls_before = array(268 $urls_before = array( 269 269 "<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>", 270 270 "(<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)", … … 284 284 '<a href="http://example.com/example.gif" title="Image from http://example.com">Look at this image!</a>', 285 285 ); 286 foreach ( $urls_before as $key => $url) {287 $this->assertEquals( $urls_expected[$key], make_clickable($url));286 foreach ( $urls_before as $key => $url ) { 287 $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) ); 288 288 } 289 289 } … … 325 325 ); 326 326 327 foreach ( $before as $key => $url ) 327 foreach ( $before as $key => $url ) { 328 328 $this->assertEquals( $expected[ $key ], make_clickable( $url ) ); 329 } 329 330 } 330 331 … … 333 334 */ 334 335 function test_click_inside_html() { 335 $urls_before = array(336 $urls_before = array( 336 337 '<span>http://example.com</span>', 337 338 '<p>http://example.com/</p>', … … 341 342 '<p><a href="http://example.com/" rel="nofollow">http://example.com/</a></p>', 342 343 ); 343 foreach ( $urls_before as $key => $url) {344 $this->assertEquals( $urls_expected[ $key], make_clickable( $url ) );344 foreach ( $urls_before as $key => $url ) { 345 $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) ); 345 346 } 346 347 } … … 360 361 */ 361 362 function test_no_segfault() { 362 $in = str_repeat( 'http://example.com/2011/03/18/post-title/', 256 );363 $in = str_repeat( 'http://example.com/2011/03/18/post-title/', 256 ); 363 364 $out = make_clickable( $in ); 364 365 $this->assertEquals( $in, $out );
Note: See TracChangeset
for help on using the changeset viewer.