Changeset 909 in tests for trunk/tests/formatting/WPTexturize.php
- Timestamp:
- 07/19/2012 01:52:37 AM (13 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/formatting/WPTexturize.php
r903 r909 4 4 * @group formatting 5 5 */ 6 class TestMakeClickable extends WP_UnitTestCase { 7 function test_mailto_xss() { 8 $in = 'testzzz@"STYLE="behavior:url(\'#default#time2\')"onBegin="alert(\'refresh-XSS\')"'; 9 $this->assertEquals($in, make_clickable($in)); 10 } 11 12 function test_valid_mailto() { 13 $valid_emails = array( 14 'foo@example.com', 15 'foo.bar@example.com', 16 'Foo.Bar@a.b.c.d.example.com', 17 '0@example.com', 18 'foo@example-example.com', 19 ); 20 foreach ($valid_emails as $email) { 21 $this->assertEquals('<a href="mailto:'.$email.'">'.$email.'</a>', make_clickable($email)); 22 } 23 } 24 25 function test_invalid_mailto() { 26 $invalid_emails = array( 27 'foo', 28 'foo@', 29 'foo@@example.com', 30 '@example.com', 31 'foo @example.com', 32 'foo@example', 33 ); 34 foreach ($invalid_emails as $email) { 35 $this->assertEquals($email, make_clickable($email)); 36 } 37 } 38 39 // tests that make_clickable will not link trailing periods, commas and 40 // (semi-)colons in URLs with protocol (i.e. http://wordpress.org) 41 function test_strip_trailing_with_protocol() { 42 $urls_before = array( 43 'http://wordpress.org/hello.html', 44 'There was a spoon named http://wordpress.org. Alice!', 45 'There was a spoon named http://wordpress.org, said Alice.', 46 'There was a spoon named http://wordpress.org; said Alice.', 47 'There was a spoon named http://wordpress.org: said Alice.', 48 'There was a spoon named (http://wordpress.org) said Alice.' 49 ); 50 $urls_expected = array( 51 '<a href="http://wordpress.org/hello.html" rel="nofollow">http://wordpress.org/hello.html</a>', 52 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>. Alice!', 53 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>, said Alice.', 54 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>; said Alice.', 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)); 61 } 62 } 63 64 // tests that make_clickable will not link trailing periods, commas and 65 // (semi-)colons in URLs with protocol (i.e. http://wordpress.org) 66 function test_strip_trailing_with_protocol_nothing_afterwards() { 67 $urls_before = array( 68 'http://wordpress.org/hello.html', 69 'There was a spoon named http://wordpress.org.', 70 'There was a spoon named http://wordpress.org,', 71 'There was a spoon named http://wordpress.org;', 72 'There was a spoon named http://wordpress.org:', 73 'There was a spoon named (http://wordpress.org)', 74 'There was a spoon named (http://wordpress.org)x', 75 ); 76 $urls_expected = array( 77 '<a href="http://wordpress.org/hello.html" rel="nofollow">http://wordpress.org/hello.html</a>', 78 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>.', 79 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>,', 80 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>;', 81 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>:', 82 'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>)', 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)); 88 } 89 } 90 91 // tests that make_clickable will not link trailing periods, commas and 92 // (semi-)colons in URLs without protocol (i.e. www.wordpress.org) 93 function test_strip_trailing_without_protocol() { 94 $urls_before = array( 95 'www.wordpress.org', 96 'There was a spoon named www.wordpress.org. Alice!', 97 'There was a spoon named www.wordpress.org, said Alice.', 98 'There was a spoon named www.wordpress.org; said Alice.', 99 'There was a spoon named www.wordpress.org: said Alice.', 100 'There was a spoon named www.wordpress.org) said Alice.' 101 ); 102 $urls_expected = array( 103 '<a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>', 104 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>. Alice!', 105 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>, said Alice.', 106 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>; said Alice.', 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)); 113 } 114 } 115 116 // tests that make_clickable will not link trailing periods, commas and 117 // (semi-)colons in URLs without protocol (i.e. www.wordpress.org) 118 function test_strip_trailing_without_protocol_nothing_afterwards() { 119 $urls_before = array( 120 'www.wordpress.org', 121 'There was a spoon named www.wordpress.org.', 122 'There was a spoon named www.wordpress.org,', 123 'There was a spoon named www.wordpress.org;', 124 'There was a spoon named www.wordpress.org:', 125 'There was a spoon named www.wordpress.org)' 126 ); 127 $urls_expected = array( 128 '<a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>', 129 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>.', 130 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>,', 131 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>;', 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)); 138 } 139 } 140 141 // #4570 142 function test_iri() { 143 $urls_before = array( 144 'http://www.詹姆斯.com/', 145 'http://bg.wikipedia.org/Баба', 146 'http://example.com/?a=баба&b=дядо', 147 ); 148 $urls_expected = array( 149 '<a href="http://www.詹姆斯.com/" rel="nofollow">http://www.詹姆斯.com/</a>', 150 '<a href="http://bg.wikipedia.org/Баба" rel="nofollow">http://bg.wikipedia.org/Баба</a>', 151 '<a href="http://example.com/?a=баба&b=дядо" rel="nofollow">http://example.com/?a=баба&b=дядо</a>', 152 ); 153 foreach ($urls_before as $key => $url) { 154 $this->assertEquals($urls_expected[$key], make_clickable($url)); 155 } 156 } 157 158 // #10990 159 function test_brackets_in_urls() { 160 $urls_before = array( 161 'http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)', 162 '(http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software))', 163 'blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software) blah', 164 'blah (http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah', 165 'blah blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software) blah blah', 166 'blah blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah blah', 167 'blah blah (http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah blah', 168 'blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software).) blah blah', 169 'blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software).)moreurl blah blah', 170 'In his famous speech “You and Your research” (here: 171 http://www.cs.virginia.edu/~robins/YouAndYourResearch.html) 172 Richard Hamming wrote about people getting more done with their doors closed, but', 173 ); 174 $urls_expected = array( 175 '<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>', 176 '(<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>)', 177 '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', 178 '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', 179 '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', 180 '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', 181 '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', 182 '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', 183 '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', 184 'In his famous speech “You and Your research” (here: 185 <a href="http://www.cs.virginia.edu/~robins/YouAndYourResearch.html" rel="nofollow">http://www.cs.virginia.edu/~robins/YouAndYourResearch.html</a>) 186 Richard Hamming wrote about people getting more done with their doors closed, but', 187 ); 188 foreach ($urls_before as $key => $url) { 189 $this->assertEquals($urls_expected[$key], make_clickable($url)); 190 } 191 } 192 193 // Based on a real comments which were incorrectly linked. #11211 194 function test_real_world_examples() { 195 $urls_before = array( 196 'Example: WordPress, test (some text), I love example.com (http://example.org), it is brilliant', 197 'Example: WordPress, test (some text), I love example.com (http://example.com), it is brilliant', 198 'Some text followed by a bracketed link with a trailing elipsis (http://example.com)...', 199 '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...', 200 ); 201 $urls_expected = array( 202 'Example: WordPress, test (some text), I love example.com (<a href="http://example.org" rel="nofollow">http://example.org</a>), it is brilliant', 203 'Example: WordPress, test (some text), I love example.com (<a href="http://example.com" rel="nofollow">http://example.com</a>), it is brilliant', 204 'Some text followed by a bracketed link with a trailing elipsis (<a href="http://example.com" rel="nofollow">http://example.com</a>)...', 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 ); 207 foreach ($urls_before as $key => $url) { 208 $this->assertEquals($urls_expected[$key], make_clickable($url)); 209 } 210 } 211 212 // #14993 213 function test_twitter_hash_bang() { 214 $urls_before = array( 215 'http://twitter.com/#!/wordpress/status/25907440233', 216 'This is a really good tweet http://twitter.com/#!/wordpress/status/25907440233 !', 217 'This is a really good tweet http://twitter.com/#!/wordpress/status/25907440233!', 218 ); 219 $urls_expected = array( 220 '<a href="http://twitter.com/#!/wordpress/status/25907440233" rel="nofollow">http://twitter.com/#!/wordpress/status/25907440233</a>', 221 'This is a really good tweet <a href="http://twitter.com/#!/wordpress/status/25907440233" rel="nofollow">http://twitter.com/#!/wordpress/status/25907440233</a> !', 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 ); 224 foreach ($urls_before as $key => $url) { 225 $this->assertEquals($urls_expected[$key], make_clickable($url)); 226 } 227 } 228 229 function test_wrapped_in_angles() { 230 $before = array( 231 'URL wrapped in angle brackets <http://example.com/>', 232 'URL wrapped in angle brackets with padding < http://example.com/ >', 233 'mailto wrapped in angle brackets <foo@example.com>', 234 ); 235 $expected = array( 236 'URL wrapped in angle brackets <<a href="http://example.com/" rel="nofollow">http://example.com/</a>>', 237 'URL wrapped in angle brackets with padding < <a href="http://example.com/" rel="nofollow">http://example.com/</a> >', 238 'mailto wrapped in angle brackets <foo@example.com>', 239 ); 240 foreach ($before as $key => $url) { 241 $this->assertEquals($expected[$key], make_clickable($url)); 242 } 243 } 244 245 function test_preceded_by_punctuation() { 246 $before = array( 247 'Comma then URL,http://example.com/', 248 'Period then URL.http://example.com/', 249 'Semi-colon then URL;http://example.com/', 250 'Colon then URL:http://example.com/', 251 'Exclamation mark then URL!http://example.com/', 252 'Question mark then URL?http://example.com/', 253 ); 254 $expected = array( 255 'Comma then URL,<a href="http://example.com/" rel="nofollow">http://example.com/</a>', 256 'Period then URL.<a href="http://example.com/" rel="nofollow">http://example.com/</a>', 257 'Semi-colon then URL;<a href="http://example.com/" rel="nofollow">http://example.com/</a>', 258 'Colon then URL:<a href="http://example.com/" rel="nofollow">http://example.com/</a>', 259 'Exclamation mark then URL!<a href="http://example.com/" rel="nofollow">http://example.com/</a>', 260 'Question mark then URL?<a href="http://example.com/" rel="nofollow">http://example.com/</a>', 261 ); 262 foreach ($before as $key => $url) { 263 $this->assertEquals($expected[$key], make_clickable($url)); 264 } 265 } 266 267 function test_dont_break_attributes() { 268 $urls_before = array( 269 "<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>", 270 "(<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)", 271 "http://trunk.domain/testing#something (<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)", 272 "http://trunk.domain/testing#something 273 (<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)", 274 "<span style='text-align:center; display: block;'><object width='425' height='350'><param name='movie' value='http://www.youtube.com/v/nd_BdvG43rE&rel=1&fs=1&showsearch=0&showinfo=1&iv_load_policy=1' /> <param name='allowfullscreen' value='true' /> <param name='wmode' value='opaque' /> <embed src='http://www.youtube.com/v/nd_BdvG43rE&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>", 275 '<a href="http://example.com/example.gif" title="Image from http://example.com">Look at this image!</a>', 276 ); 277 $urls_expected = array( 278 "<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>", 279 "(<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)", 280 "<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'>)", 281 "<a href=\"http://trunk.domain/testing#something\" rel=\"nofollow\">http://trunk.domain/testing#something</a> 282 (<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)", 283 "<span style='text-align:center; display: block;'><object width='425' height='350'><param name='movie' value='http://www.youtube.com/v/nd_BdvG43rE&rel=1&fs=1&showsearch=0&showinfo=1&iv_load_policy=1' /> <param name='allowfullscreen' value='true' /> <param name='wmode' value='opaque' /> <embed src='http://www.youtube.com/v/nd_BdvG43rE&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>", 284 '<a href="http://example.com/example.gif" title="Image from http://example.com">Look at this image!</a>', 285 ); 286 foreach ($urls_before as $key => $url) { 287 $this->assertEquals($urls_expected[$key], make_clickable($url)); 288 } 289 } 290 291 /** 292 * @ticket 16892 293 */ 294 function test_click_inside_html() { 295 $urls_before = array( 296 '<span>http://example.com</span>', 297 '<p>http://example.com/</p>', 298 ); 299 $urls_expected = array( 300 '<span><a href="http://example.com" rel="nofollow">http://example.com</a></span>', 301 '<p><a href="http://example.com/" rel="nofollow">http://example.com/</a></p>', 302 ); 303 foreach ($urls_before as $key => $url) { 304 $this->assertEquals( $urls_expected[$key], make_clickable( $url ) ); 305 } 306 } 307 308 function test_no_links_within_links() { 309 $in = array( 310 'Some text with a link <a href="http://example.com">http://example.com</a>', 311 //'<a href="http://wordpress.org">This is already a link www.wordpress.org</a>', // fails in 3.3.1 too 312 ); 313 foreach ( $in as $text ) { 314 $this->assertEquals( $text, make_clickable( $text ) ); 315 } 316 } 317 318 /** 319 * ticket 16892 320 */ 321 function test_no_segfault() { 322 if ( version_compare( $GLOBALS['wp_version'], '3.1.1', '<' ) ) 323 $this->markTestSkipped(); 324 325 $in = str_repeat( 'http://example.com/2011/03/18/post-title/', 256 ); 326 $out = make_clickable( $in ); 327 if ( version_compare( $GLOBALS['wp_version'], '3.4-alpha', '>=' ) ) 328 $this->assertEquals( $in, $out ); 329 } 330 331 /** 332 * @ticket 16859 333 */ 334 function test_square_brackets() { 335 $urls_before = array( 336 'http://example.com/?foo[bar]=baz', 337 'http://example.com/?baz=bar&foo[bar]=baz', 338 ); 339 $urls_expected = array( 340 '<a href="http://example.com/?foo%5Bbar%5D=baz" rel="nofollow">http://example.com/?foo%5Bbar%5D=baz</a>', 341 '<a href="http://example.com/?baz=bar&foo%5Bbar%5D=baz" rel="nofollow">http://example.com/?baz=bar&foo%5Bbar%5D=baz</a>', 342 ); 343 foreach ($urls_before as $key => $url) { 344 $this->assertEquals( $urls_expected[$key], make_clickable( $url ) ); 345 } 346 } 347 } 348 349 /** 350 * @group formatting 351 */ 352 class TestJSEscape extends WP_UnitTestCase { 353 function test_js_escape_simple() { 354 $out = esc_js('foo bar baz();'); 355 $this->assertEquals('foo bar baz();', $out); 356 } 357 358 function test_js_escape_quotes() { 359 $out = esc_js('foo "bar" \'baz\''); 360 // does it make any sense to change " into "? Why not \"? 361 $this->assertEquals("foo "bar" \'baz\'", $out); 362 } 363 364 function test_js_escape_backslash() { 365 $bs = '\\'; 366 $out = esc_js('foo '.$bs.'t bar '.$bs.$bs.' baz'); 367 // \t becomes t - bug? 368 $this->assertEquals('foo t bar '.$bs.$bs.' baz', $out); 369 } 370 371 function test_js_escape_amp() { 372 $out = esc_js('foo & bar &baz; ''); 373 $this->assertEquals("foo & bar &baz; '", $out); 374 } 375 376 function test_js_escape_quote_entity() { 377 $out = esc_js('foo ' bar ' baz &'); 378 $this->assertEquals("foo \\' bar \\' baz &", $out); 379 } 380 381 function test_js_no_carriage_return() { 382 $out = esc_js("foo\rbar\nbaz\r"); 383 // \r is stripped 384 $this->assertequals("foobar\\nbaz", $out); 385 } 386 387 function test_js_escape_rn() { 388 $out = esc_js("foo\r\nbar\nbaz\r\n"); 389 // \r is stripped 390 $this->assertequals("foo\\nbar\\nbaz\\n", $out); 391 } 392 } 393 394 /** 395 * @group formatting 396 */ 397 class TestHtmlExcerpt extends WP_UnitTestCase { 398 function test_simple() { 399 $this->assertEquals("Baba", wp_html_excerpt("Baba told me not to come", 4)); 400 } 401 function test_html() { 402 $this->assertEquals("Baba", wp_html_excerpt("<a href='http://baba.net/'>Baba</a> told me not to come", 4)); 403 } 404 function test_entities() { 405 $this->assertEquals("Baba ", wp_html_excerpt("Baba & Dyado", 8)); 406 $this->assertEquals("Baba ", wp_html_excerpt("Baba & Dyado", 8)); 407 $this->assertEquals("Baba & D", wp_html_excerpt("Baba & Dyado", 12)); 408 $this->assertEquals("Baba & Dyado", wp_html_excerpt("Baba & Dyado", 100)); 409 } 410 } 411 412 /* // @todo These tests need to be rewritten for sanitize_sql_orderby 413 class TestSanitizeOrderby extends WP_UnitTestCase { 414 function test_empty() { 415 $cols = array('a' => 'a'); 416 $this->assertEquals( '', sanitize_sql_orderby('', $cols) ); 417 $this->assertEquals( '', sanitize_sql_orderby(' ', $cols) ); 418 $this->assertEquals( '', sanitize_sql_orderby("\t", $cols) ); 419 $this->assertEquals( '', sanitize_sql_orderby(null, $cols) ); 420 $this->assertEquals( '', sanitize_sql_orderby(0, $cols) ); 421 $this->assertEquals( '', sanitize_sql_orderby('+', $cols) ); 422 $this->assertEquals( '', sanitize_sql_orderby('-', $cols) ); 423 } 424 425 function test_unknown_column() { 426 $cols = array('name' => 'post_name', 'date' => 'post_date'); 427 $this->assertEquals( '', sanitize_sql_orderby('unknown_column', $cols) ); 428 $this->assertEquals( '', sanitize_sql_orderby('+unknown_column', $cols) ); 429 $this->assertEquals( '', sanitize_sql_orderby('-unknown_column', $cols) ); 430 $this->assertEquals( '', sanitize_sql_orderby('-unknown1,+unknown2,unknown3', $cols) ); 431 $this->assertEquals( 'post_name ASC', sanitize_sql_orderby('name,unknown_column', $cols) ); 432 $this->assertEquals( '', sanitize_sql_orderby('!@#$%^&*()_=~`\'",./', $cols) ); 433 } 434 435 function test_valid() { 436 $cols = array('name' => 'post_name', 'date' => 'post_date', 'random' => 'rand()'); 437 $this->assertEquals( 'post_name ASC', sanitize_sql_orderby('name', $cols) ); 438 $this->assertEquals( 'post_name ASC', sanitize_sql_orderby('+name', $cols) ); 439 $this->assertEquals( 'post_name DESC', sanitize_sql_orderby('-name', $cols) ); 440 $this->assertEquals( 'post_date ASC, post_name ASC', sanitize_sql_orderby('date,name', $cols) ); 441 $this->assertEquals( 'post_date ASC, post_name ASC', sanitize_sql_orderby(' date , name ', $cols) ); 442 $this->assertEquals( 'post_name DESC, post_date ASC', sanitize_sql_orderby('-name,date', $cols) ); 443 $this->assertEquals( 'post_name ASC, post_date ASC', sanitize_sql_orderby('name ,+ date', $cols) ); 444 $this->assertEquals( 'rand() ASC', sanitize_sql_orderby('random', $cols) ); 445 } 446 } 447 */ 448 449 /** 450 * @group formatting 451 */ 452 class TestWPTexturize extends WP_UnitTestCase { 6 class Tests_Formatting_WPTexturize extends WP_UnitTestCase { 453 7 function test_dashes() { 454 8 $this->assertEquals('Hey — boo?', wptexturize('Hey -- boo?')); … … 620 174 } 621 175 } 622 623 /**624 * @group formatting625 */626 class TestEscUrl extends WP_UnitTestCase {627 function test_spaces() {628 $this->assertEquals('http://example.com/MrWordPress', esc_url('http://example.com/Mr WordPress'));629 $this->assertEquals('http://example.com/Mr%20WordPress', esc_url('http://example.com/Mr%20WordPress'));630 }631 632 function test_bad_characters() {633 $this->assertEquals('http://example.com/watchthelinefeedgo', esc_url('http://example.com/watchthelinefeed%0Ago'));634 $this->assertEquals('http://example.com/watchthelinefeedgo', esc_url('http://example.com/watchthelinefeed%0ago'));635 $this->assertEquals('http://example.com/watchthecarriagereturngo', esc_url('http://example.com/watchthecarriagereturn%0Dgo'));636 $this->assertEquals('http://example.com/watchthecarriagereturngo', esc_url('http://example.com/watchthecarriagereturn%0dgo'));637 //Nesting Checks638 $this->assertEquals('http://example.com/watchthecarriagereturngo', esc_url('http://example.com/watchthecarriagereturn%0%0ddgo'));639 $this->assertEquals('http://example.com/watchthecarriagereturngo', esc_url('http://example.com/watchthecarriagereturn%0%0DDgo'));640 $this->assertEquals('http://example.com/', esc_url('http://example.com/%0%0%0DAD'));641 $this->assertEquals('http://example.com/', esc_url('http://example.com/%0%0%0ADA'));642 $this->assertEquals('http://example.com/', esc_url('http://example.com/%0%0%0DAd'));643 $this->assertEquals('http://example.com/', esc_url('http://example.com/%0%0%0ADa'));644 }645 646 function test_relative() {647 $this->assertEquals('/example.php', esc_url('/example.php'));648 $this->assertEquals('example.php', esc_url('example.php'));649 $this->assertEquals('#fragment', esc_url('#fragment'));650 $this->assertEquals('?foo=bar', esc_url('?foo=bar'));651 }652 653 function test_protocol() {654 $this->assertEquals('http://example.com', esc_url('http://example.com'));655 $this->assertEquals('', esc_url('nasty://example.com/'));656 }657 658 function test_display_extras() {659 $this->assertEquals('http://example.com/'quoted'', esc_url('http://example.com/\'quoted\''));660 $this->assertEquals('http://example.com/\'quoted\'', esc_url('http://example.com/\'quoted\'',null,'notdisplay'));661 }662 663 function test_non_ascii() {664 $this->assertEquals( 'http://example.org/баба', esc_url( 'http://example.org/баба' ) );665 $this->assertEquals( 'http://баба.org/баба', esc_url( 'http://баба.org/баба' ) );666 $this->assertEquals( 'http://müller.com/', esc_url( 'http://müller.com/' ) );667 }668 669 function test_feed() {670 $this->assertEquals( '', esc_url( 'feed:javascript:alert(1)' ) );671 $this->assertEquals( '', esc_url( 'feed:javascript:feed:alert(1)' ) );672 $this->assertEquals( '', esc_url( 'feed:feed:javascript:alert(1)' ) );673 $this->assertEquals( 'feed:feed:alert(1)', esc_url( 'feed:feed:alert(1)' ) );674 $this->assertEquals( 'feed:http://wordpress.org/feed/', esc_url( 'feed:http://wordpress.org/feed/' ) );675 }676 677 /**678 * @ticket 16859679 */680 function test_square_brackets() {681 $this->assertEquals( 'http://example.com/?foo%5Bbar%5D=baz', esc_url( 'http://example.com/?foo[bar]=baz' ) );682 $this->assertEquals( 'http://example.com/?baz=bar&foo%5Bbar%5D=baz', esc_url( 'http://example.com/?baz=bar&foo[bar]=baz' ) );683 //IPv6 addresses in urls - RFC2732684 $this->assertEquals( 'http://[::FFFF::127.0.0.1]', esc_url( 'http://[::FFFF::127.0.0.1]' ) );685 $this->assertEquals( 'http://[::127.0.0.1]', esc_url( 'http://[::127.0.0.1]' ) );686 $this->assertEquals( 'http://[::DEAD:BEEF:DEAD:BEEF:DEAD:BEEF:DEAD:BEEF]', esc_url( 'http://[::DEAD:BEEF:DEAD:BEEF:DEAD:BEEF:DEAD:BEEF]' ) );687 }688 }689 690 /**691 * @group formatting692 */693 class TestAutop extends WP_UnitTestCase {694 //From ticket http://core.trac.wordpress.org/ticket/11008695 function test_first_post() {696 $expected = '<p>Welcome to WordPress! This post contains important information. After you read it, you can make it private to hide it from visitors but still have the information handy for future reference.</p>697 <p>First things first:</p>698 <ul>699 <li><a href="%1$s" title="Subscribe to the WordPress mailing list for Release Notifications">Subscribe to the WordPress mailing list for release notifications</a></li>700 </ul>701 <p>As a subscriber, you will receive an email every time an update is available (and only then). This will make it easier to keep your site up to date, and secure from evildoers.<br />702 When a new version is released, <a href="%2$s" title="If you are already logged in, this will take you directly to the Dashboard">log in to the Dashboard</a> and follow the instructions.<br />703 Upgrading is a couple of clicks!</p>704 <p>Then you can start enjoying the WordPress experience:</p>705 <ul>706 <li>Edit your personal information at <a href="%3$s" title="Edit settings like your password, your display name and your contact information">Users › Your Profile</a></li>707 <li>Start publishing at <a href="%4$s" title="Create a new post">Posts › Add New</a> and at <a href="%5$s" title="Create a new page">Pages › Add New</a></li>708 <li>Browse and install plugins at <a href="%6$s" title="Browse and install plugins at the official WordPress repository directly from your Dashboard">Plugins › Add New</a></li>709 <li>Browse and install themes at <a href="%7$s" title="Browse and install themes at the official WordPress repository directly from your Dashboard">Appearance › Add New Themes</a></li>710 <li>Modify and prettify your website’s links at <a href="%8$s" title="For example, select a link structure like: http://example.com/1999/12/post-name">Settings › Permalinks</a></li>711 <li>Import content from another system or WordPress site at <a href="%9$s" title="WordPress comes with importers for the most common publishing systems">Tools › Import</a></li>712 <li>Find answers to your questions at the <a href="%10$s" title="The official WordPress documentation, maintained by the WordPress community">WordPress Codex</a></li>713 </ul>714 <p>To keep this post for reference, <a href="%11$s" title="Click to edit the content and settings of this post">click to edit it</a>, go to the Publish box and change its Visibility from Public to Private.</p>715 <p>Thank you for selecting WordPress. We wish you happy publishing!</p>716 <p>PS. Not yet subscribed for update notifications? <a href="%1$s" title="Subscribe to the WordPress mailing list for Release Notifications">Do it now!</a></p>717 ';718 $test_data = '719 Welcome to WordPress! This post contains important information. After you read it, you can make it private to hide it from visitors but still have the information handy for future reference.720 721 First things first:722 <ul>723 <li><a href="%1$s" title="Subscribe to the WordPress mailing list for Release Notifications">Subscribe to the WordPress mailing list for release notifications</a></li>724 </ul>725 As a subscriber, you will receive an email every time an update is available (and only then). This will make it easier to keep your site up to date, and secure from evildoers.726 When a new version is released, <a href="%2$s" title="If you are already logged in, this will take you directly to the Dashboard">log in to the Dashboard</a> and follow the instructions.727 Upgrading is a couple of clicks!728 729 Then you can start enjoying the WordPress experience:730 <ul>731 <li>Edit your personal information at <a href="%3$s" title="Edit settings like your password, your display name and your contact information">Users › Your Profile</a></li>732 <li>Start publishing at <a href="%4$s" title="Create a new post">Posts › Add New</a> and at <a href="%5$s" title="Create a new page">Pages › Add New</a></li>733 <li>Browse and install plugins at <a href="%6$s" title="Browse and install plugins at the official WordPress repository directly from your Dashboard">Plugins › Add New</a></li>734 <li>Browse and install themes at <a href="%7$s" title="Browse and install themes at the official WordPress repository directly from your Dashboard">Appearance › Add New Themes</a></li>735 <li>Modify and prettify your website’s links at <a href="%8$s" title="For example, select a link structure like: http://example.com/1999/12/post-name">Settings › Permalinks</a></li>736 <li>Import content from another system or WordPress site at <a href="%9$s" title="WordPress comes with importers for the most common publishing systems">Tools › Import</a></li>737 <li>Find answers to your questions at the <a href="%10$s" title="The official WordPress documentation, maintained by the WordPress community">WordPress Codex</a></li>738 </ul>739 To keep this post for reference, <a href="%11$s" title="Click to edit the content and settings of this post">click to edit it</a>, go to the Publish box and change its Visibility from Public to Private.740 741 Thank you for selecting WordPress. We wish you happy publishing!742 743 PS. Not yet subscribed for update notifications? <a href="%1$s" title="Subscribe to the WordPress mailing list for Release Notifications">Do it now!</a>744 ';745 746 // On windows environments, the EOL-style is \r\n747 $expected = str_replace( "\r\n", "\n", $expected);748 749 $this->assertEquals($expected, wpautop($test_data));750 }751 752 /**753 * wpautop() Should not alter the contents of "<pre>" elements754 *755 * @ticket 19855756 */757 public function test_skip_pre_elements() {758 $code = file_get_contents( DIR_TESTDATA . '/formatting/sizzle.js' );759 $code = str_replace( "\r", '', $code );760 $code = htmlentities( $code );761 762 // Not wrapped in <p> tags763 $str = "<pre>$code</pre>";764 $this->assertEquals( $str, trim( wpautop( $str ) ) );765 766 // Text before/after is wrapped in <p> tags767 $str = "Look at this code\n\n<pre>$code</pre>\n\nIsn't that cool?";768 769 // Expected text after wpautop770 $expected = '<p>Look at this code</p>' . "\n<pre>" . $code . "</pre>\n" . '<p>Isn\'t that cool?</p>';771 $this->assertEquals( $expected, trim( wpautop( $str ) ) );772 773 // Make sure HTML breaks are maintained if manually inserted774 $str = "Look at this code\n\n<pre>Line1<br />Line2<br>Line3<br/>Line4\nActual Line 2\nActual Line 3</pre>\n\nCool, huh?";775 $expected = "<p>Look at this code</p>\n<pre>Line1<br />Line2<br>Line3<br/>Line4\nActual Line 2\nActual Line 3</pre>\n<p>Cool, huh?</p>";776 $this->assertEquals( $expected, trim( wpautop( $str ) ) );777 }778 779 /**780 * wpautop() Should not add <br/> to "<input>" elements781 *782 * @ticket 16456783 */784 public function test_skip_input_elements() {785 $str = 'Username: <input type="text" id="username" name="username" /><br />Password: <input type="password" id="password1" name="password1" />';786 $this->assertEquals( "<p>$str</p>", trim( wpautop( $str ) ) );787 }788 }789 790 /**791 * @group formatting792 */793 class TestLikeEscape extends WP_UnitTestCase {794 /**795 * @ticket 10041796 */797 function test_like_escape() {798 799 $inputs = array(800 'howdy%', //Single Percent801 'howdy_', //Single Underscore802 'howdy\\', //Single slash803 'howdy\\howdy%howdy_', //The works804 );805 $expected = array(806 "howdy\\%",807 'howdy\\_',808 'howdy\\\\',809 'howdy\\\\howdy\\%howdy\\_'810 );811 812 foreach ($inputs as $key => $input) {813 $this->assertEquals($expected[$key], like_escape($input));814 }815 }816 }817 818 /**819 * @group formatting820 */821 class TestSanitizeTextField extends WP_UnitTestCase {822 // #11528823 function test_sanitize_text_field() {824 $inputs = array(825 'оРангутанг', //Ensure UTF8 text is safe the Р is D0 A0 and A0 is the non-breaking space.826 'САПР', //Ensure UTF8 text is safe the Р is D0 A0 and A0 is the non-breaking space.827 'one is < two',828 'tags <span>are</span> <em>not allowed</em> here',829 ' we should trim leading and trailing whitespace ',830 'we also trim extra internal whitespace',831 'tabs get removed too',832 'newlines are not welcome833 here',834 'We also %AB remove %ab octets',835 'We don\'t need to wory about %A836 B removing %a837 b octets even when %a B they are obscured by whitespace',838 '%AB%BC%DE', //Just octets839 'Invalid octects remain %II',840 'Nested octects %%%ABABAB %A%A%ABBB',841 );842 $expected = array(843 'оРангутанг',844 'САПР',845 'one is < two',846 'tags are not allowed here',847 'we should trim leading and trailing whitespace',848 'we also trim extra internal whitespace',849 'tabs get removed too',850 'newlines are not welcome here',851 'We also remove octets',852 'We don\'t need to wory about %A B removing %a b octets even when %a B they are obscured by whitespace',853 '', //Emtpy as we strip all the octets out854 'Invalid octects remain %II',855 'Nested octects',856 );857 858 foreach ($inputs as $key => $input) {859 $this->assertEquals($expected[$key], sanitize_text_field($input));860 }861 }862 }863 864 /**865 * @group formatting866 */867 class TestSanitizeMimeType extends WP_UnitTestCase {868 // 17855869 function test_sanitize_valid_mime_type() {870 $inputs = array(871 'application/atom+xml',872 'application/EDI-X12',873 'application/EDIFACT',874 'application/json',875 'application/javascript',876 'application/octet-stream',877 'application/ogg',878 'application/pdf',879 'application/postscript',880 'application/soap+xml',881 'application/x-woff',882 'application/xhtml+xml',883 'application/xml-dtd',884 'application/xop+xml',885 'application/zip',886 'application/x-gzip',887 'audio/basic',888 'image/jpeg',889 'text/css',890 'text/html',891 'text/plain',892 'video/mpeg',893 );894 895 foreach ( $inputs as $input ) {896 $this->assertEquals($input, sanitize_mime_type($input));897 }898 }899 }900 901 /**902 * @group formatting903 */904 class TestSanitizeFileName extends WP_UnitTestCase {905 function test_munges_extensions() {906 # r17990907 $file_name = sanitize_file_name( 'test.phtml.txt' );908 $this->assertEquals( 'test.phtml_.txt', $file_name );909 }910 911 function test_removes_special_chars() {912 $special_chars = array("?", "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "'", "\"", "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}", chr(0));913 $string = 'test';914 foreach ( $special_chars as $char )915 $string .= $char;916 $string .= 'test';917 $this->assertEquals( 'testtest', sanitize_file_name( $string ) );918 }919 920 function test_replaces_any_number_of_hyphens_with_one_hyphen() {921 $this->assertEquals("a-t-t", sanitize_file_name("a----t----t"));922 }923 924 function test_trims_trailing_hyphens() {925 $this->assertEquals("a-t-t", sanitize_file_name("a----t----t----"));926 }927 928 function test_replaces_any_amount_of_whitespace_with_one_hyphen() {929 $this->assertEquals("a-t", sanitize_file_name("a t"));930 $this->assertEquals("a-t", sanitize_file_name("a \n\n\nt"));931 }932 }933 934 /**935 * @group formatting936 */937 class TestWPSpecialchars extends WP_UnitTestCase {938 function test_wp_specialchars_basics() {939 $html = "&<hello world>";940 $this->assertEquals( $html, _wp_specialchars( $html ) );941 942 $double = "&amp;&lt;hello world&gt;";943 $this->assertEquals( $double, _wp_specialchars( $html, ENT_NOQUOTES, false, true ) );944 }945 946 function test_allowed_entity_names() {947 global $allowedentitynames;948 949 // Allowed entities should be unchanged950 foreach ( $allowedentitynames as $ent ) {951 $ent = '&' . $ent . ';';952 $this->assertEquals( $ent, _wp_specialchars( $ent ) );953 }954 }955 956 function test_not_allowed_entity_names() {957 $ents = array( 'iacut', 'aposs', 'pos', 'apo', 'apo?', 'apo.*', '.*apo.*', 'apos ', ' apos', ' apos ' );958 959 foreach ( $ents as $ent ) {960 $escaped = '&' . $ent . ';';961 $ent = '&' . $ent . ';';962 $this->assertEquals( $escaped, _wp_specialchars( $ent ) );963 }964 }965 966 function test_optionally_escapes_quotes() {967 $source = "\"'hello!'\"";968 $this->assertEquals( '"'hello!'"', _wp_specialchars($source, 'single') );969 $this->assertEquals( ""'hello!'"", _wp_specialchars($source, 'double') );970 $this->assertEquals( '"'hello!'"', _wp_specialchars($source, true) );971 $this->assertEquals( $source, _wp_specialchars($source) );972 }973 }974 975 /**976 * @group formatting977 */978 class TestEscAttr extends WP_UnitTestCase {979 function test_esc_attr_quotes() {980 $attr = '"double quotes"';981 $this->assertEquals( '"double quotes"', esc_attr( $attr ) );982 983 $attr = "'single quotes'";984 $this->assertEquals( ''single quotes'', esc_attr( $attr ) );985 986 $attr = "'mixed' " . '"quotes"';987 $this->assertEquals( ''mixed' "quotes"', esc_attr( $attr ) );988 989 // Handles double encoding?990 $attr = '"double quotes"';991 $this->assertEquals( '"double quotes"', esc_attr( esc_attr( $attr ) ) );992 993 $attr = "'single quotes'";994 $this->assertEquals( ''single quotes'', esc_attr( esc_attr( $attr ) ) );995 996 $attr = "'mixed' " . '"quotes"';997 $this->assertEquals( ''mixed' "quotes"', esc_attr( esc_attr( $attr ) ) );998 }999 1000 function test_esc_attr_amp() {1001 $out = esc_attr( 'foo & bar &baz; '' );1002 $this->assertEquals( "foo & bar &baz; '", $out );1003 }1004 }1005 1006 /**1007 * @group formatting1008 */1009 class TestEscHtml extends WP_UnitTestCase {1010 function test_esc_html_basics() {1011 // Simple string1012 $html = "The quick brown fox.";1013 $this->assertEquals( $html, esc_html( $html ) );1014 1015 // URL with &1016 $html = "http://localhost/trunk/wp-login.php?action=logout&_wpnonce=cd57d75985";1017 $escaped = "http://localhost/trunk/wp-login.php?action=logout&_wpnonce=cd57d75985";1018 $this->assertEquals( $escaped, esc_html( $html ) );1019 1020 // SQL query1021 $html = "SELECT meta_key, meta_value FROM wp_trunk_sitemeta WHERE meta_key IN ('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled') AND site_id = 1";1022 $escaped = "SELECT meta_key, meta_value FROM wp_trunk_sitemeta WHERE meta_key IN ('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled') AND site_id = 1";1023 $this->assertEquals( $escaped, esc_html( $html ) );1024 }1025 1026 function test_escapes_ampersands() {1027 $source = "penn & teller & at&t";1028 $res = "penn & teller & at&t";1029 $this->assertEquals( $res, esc_html($source) );1030 }1031 1032 function test_escapes_greater_and_less_than() {1033 $source = "this > that < that <randomhtml />";1034 $res = "this > that < that <randomhtml />";1035 $this->assertEquals( $res, esc_html($source) );1036 }1037 1038 function test_ignores_existing_entities() {1039 $source = '& £ " &';1040 $res = '& £ " &';1041 $this->assertEquals( $res, esc_html($source) );1042 }1043 }1044 1045 /**1046 * @group formatting1047 */1048 class TestSanitizeUser extends WP_UnitTestCase {1049 function test_strips_html() {1050 $input = "Captain <strong>Awesome</strong>";1051 $expected = is_multisite() ? 'captain awesome' : 'Captain Awesome';1052 $this->assertEquals($expected, sanitize_user($input));1053 }1054 /**1055 * @ticket 108231056 */1057 function test_strips_entities() {1058 $this->assertEquals("ATT", sanitize_user("AT&T"));1059 $this->assertEquals("ATT Test;", sanitize_user("AT&T Test;"));1060 $this->assertEquals("AT&T Test;", sanitize_user("AT&T Test;"));1061 }1062 function test_strips_percent_encoded_octets() {1063 $expected = is_multisite() ? 'franois' : 'Franois';1064 $this->assertEquals( $expected, sanitize_user( "Fran%c3%a7ois" ) );1065 }1066 function test_optional_strict_mode_reduces_to_safe_ascii_subset() {1067 $this->assertEquals("abc", sanitize_user("()~ab~ˆcˆ!", true));1068 }1069 }1070 1071 /**1072 * @group formatting1073 */1074 class TestIsEmail extends WP_UnitTestCase {1075 function test_returns_true_if_given_a_valid_email_address() {1076 $data = array(1077 "bob@example.com",1078 "phil@example.info",1079 "ace@204.32.222.14",1080 "kevin@many.subdomains.make.a.happy.man.edu"1081 );1082 foreach ( $data as $datum ) {1083 $this->assertEquals( $datum, is_email($datum), $datum );1084 }1085 }1086 1087 function test_returns_false_if_given_an_invalid_email_address() {1088 $data = array(1089 "khaaaaaaaaaaaaaaan!",1090 'http://bob.example.com/',1091 "sif i'd give u it, spamer!1",1092 "com.exampleNOSPAMbob",1093 "bob@your mom"1094 );1095 foreach ($data as $datum) {1096 $this->assertFalse(is_email($datum), $datum);1097 }1098 }1099 }1100 1101 /**1102 * @group formatting1103 */1104 class TestSanitizeTitle extends WP_UnitTestCase {1105 function test_strips_html() {1106 $input = "Captain <strong>Awesome</strong>";1107 $expected = "captain-awesome";1108 $this->assertEquals($expected, sanitize_title($input));1109 }1110 1111 function test_titles_sanitized_to_nothing_are_replaced_with_optional_fallback() {1112 $input = "<strong></strong>";1113 $fallback = "Captain Awesome";1114 $this->assertEquals($fallback, sanitize_title($input, $fallback));1115 }1116 }1117 1118 /**1119 * @group formatting1120 */1121 class TestSanitizeTitleWithDashes extends WP_UnitTestCase {1122 function test_strips_html() {1123 $input = "Captain <strong>Awesome</strong>";1124 $expected = "captain-awesome";1125 $this->assertEquals($expected, sanitize_title($input));1126 }1127 1128 function test_strips_unencoded_percent_signs() {1129 $this->assertEquals("fran%c3%a7ois", sanitize_title_with_dashes("fran%c3%a7%ois"));1130 }1131 1132 function test_makes_title_lowercase() {1133 $this->assertEquals("abc", sanitize_title_with_dashes("ABC"));1134 }1135 1136 function test_replaces_any_amount_of_whitespace_with_one_hyphen() {1137 $this->assertEquals("a-t", sanitize_title_with_dashes("a t"));1138 $this->assertEquals("a-t", sanitize_title_with_dashes("a \n\n\nt"));1139 }1140 1141 function test_replaces_any_number_of_hyphens_with_one_hyphen() {1142 $this->assertEquals("a-t-t", sanitize_title_with_dashes("a----t----t"));1143 }1144 1145 function test_trims_trailing_hyphens() {1146 $this->assertEquals("a-t-t", sanitize_title_with_dashes("a----t----t----"));1147 }1148 1149 function test_handles_non_entity_ampersands() {1150 $this->assertEquals("penn-teller-bull", sanitize_title_with_dashes("penn & teller bull"));1151 }1152 1153 /**1154 * @ticket 108231155 */1156 function test_strips_entities() {1157 $this->assertEquals("no-entities-here", sanitize_title_with_dashes("No Entities – Here &"));1158 $this->assertEquals("one-two", sanitize_title_with_dashes("One & Two", '', 'save'));1159 $this->assertEquals("one-two", sanitize_title_with_dashes("One { Two;", '', 'save'));1160 $this->assertEquals("one-two", sanitize_title_with_dashes("One & Two;", '', 'save'));1161 $this->assertEquals("one-two", sanitize_title_with_dashes("One Two™;", '', 'save'));1162 $this->assertEquals("one-two", sanitize_title_with_dashes("One && Two;", '', 'save'));1163 $this->assertEquals("onetwo", sanitize_title_with_dashes("One&Two", '', 'save'));1164 $this->assertEquals("onetwo-test", sanitize_title_with_dashes("One&Two Test;", '', 'save'));1165 }1166 1167 function test_replaces_nbsp() {1168 $this->assertEquals("dont-break-the-space", sanitize_title_with_dashes("don't break the space", '', 'save'));1169 }1170 1171 function test_replaces_ndash_mdash() {1172 $this->assertEquals("do-the-dash", sanitize_title_with_dashes("Do – the Dash", '', 'save'));1173 $this->assertEquals("do-the-dash", sanitize_title_with_dashes("Do the — Dash", '', 'save'));1174 }1175 1176 function test_replaces_iexcel_iquest() {1177 $this->assertEquals("just-a-slug", sanitize_title_with_dashes("Just ¡a Slug", '', 'save'));1178 $this->assertEquals("just-a-slug", sanitize_title_with_dashes("Just a Slug¿", '', 'save'));1179 }1180 1181 function test_replaces_angle_quotes() {1182 $this->assertEquals("just-a-slug", sanitize_title_with_dashes("‹Just a Slug›", '', 'save'));1183 $this->assertEquals("just-a-slug", sanitize_title_with_dashes("«Just a Slug»", '', 'save'));1184 }1185 1186 function test_replaces_curly_quotes() {1187 $this->assertEquals("hey-its-curly-joe", sanitize_title_with_dashes("Hey its “Curly Joe”", '', 'save'));1188 $this->assertEquals("hey-its-curly-joe", sanitize_title_with_dashes("Hey its ‘Curly Joe’", '', 'save'));1189 $this->assertEquals("hey-its-curly-joe", sanitize_title_with_dashes("Hey its „Curly Joe“", '', 'save'));1190 $this->assertEquals("hey-its-curly-joe", sanitize_title_with_dashes("Hey its ‚Curly Joe‛", '', 'save'));1191 $this->assertEquals("hey-its-curly-joe", sanitize_title_with_dashes("Hey its „Curly Joe‟", '', 'save'));1192 }1193 1194 function test_replaces_copy_reg_deg_trade() {1195 $this->assertEquals("just-a-slug", sanitize_title_with_dashes("Just © a Slug", '', 'save'));1196 $this->assertEquals("just-a-slug", sanitize_title_with_dashes("® Just a Slug", '', 'save'));1197 $this->assertEquals("just-a-slug", sanitize_title_with_dashes("Just a ° Slug", '', 'save'));1198 $this->assertEquals("just-a-slug", sanitize_title_with_dashes("Just ™ a Slug", '', 'save'));1199 }1200 1201 /**1202 * @ticket 198201203 */1204 function test_replaces_multiply_sign() {1205 $this->assertEquals("6x7-is-42", sanitize_title_with_dashes("6×7 is 42", '', 'save'));1206 }1207 1208 /**1209 * @ticket 207721210 */1211 function test_replaces_standalone_diacritic() {1212 $this->assertEquals("aaaa", sanitize_title_with_dashes("āáǎà", '', 'save'));1213 }1214 1215 }1216 1217 /**1218 * @group formatting1219 */1220 class TestConvertChars extends WP_UnitTestCase {1221 function test_replaces_windows1252_entities_with_unicode_ones() {1222 $input = "‚ƒ„…†‡ˆ‰Š‹Œ‘’“”•–—˜™š›œŸ";1223 $output = "‚ƒ„…†‡ˆ‰Š‹Œ‘’“”•–—˜™š›œŸ";1224 $this->assertEquals($output, convert_chars($input));1225 }1226 1227 /**1228 * @ticket 205031229 */1230 function test_replaces_latin_letter_z_with_caron() {1231 $input = "Žž";1232 $output = "Žž";1233 $this->assertEquals( $output, convert_chars( $input ) );1234 }1235 1236 function test_converts_html_br_and_hr_to_the_xhtml_self_closing_variety() {1237 $inputs = array(1238 "abc <br> lol <br />" => "abc <br /> lol <br />",1239 "<br> ho ho <hr>" => "<br /> ho ho <hr />",1240 "<hr><br>" => "<hr /><br />"1241 );1242 foreach ($inputs as $input => $expected) {1243 $this->assertEquals($expected, convert_chars($input));1244 }1245 }1246 1247 function test_escapes_lone_ampersands() {1248 $this->assertEquals("at&t", convert_chars("at&t"));1249 }1250 1251 function test_removes_category_and_title_metadata_tags() {1252 $this->assertEquals("", convert_chars("<title><div class='lol'>abc</div></title><category>a</category>"));1253 }1254 }1255 1256 /**1257 * @group formatting1258 */1259 class TestZeroise extends WP_UnitTestCase {1260 function test_pads_with_leading_zeroes() {1261 $this->assertEquals("00005", zeroise(5, 5));1262 }1263 1264 function test_does_nothing_if_input_is_already_longer() {1265 $this->assertEquals("5000000", zeroise(5000000, 2));1266 }1267 }1268 1269 /**1270 * @group formatting1271 */1272 class TestBackslashit extends WP_UnitTestCase {1273 function test_backslashes_alphas() {1274 $this->assertEquals("\\a943\\b\\c", backslashit("a943bc"));1275 }1276 1277 function test_double_backslashes_leading_numbers() {1278 $this->assertEquals("\\\\95", backslashit("95"));1279 }1280 }1281 1282 /**1283 * @group formatting1284 */1285 class TestUntrailingslashit extends WP_UnitTestCase {1286 function test_removes_trailing_slashes() {1287 $this->assertEquals("a", untrailingslashit("a/"));1288 $this->assertEquals("a", untrailingslashit("a////"));1289 }1290 }1291 1292 /**1293 * @group formatting1294 */1295 class TestTrailingslashit extends WP_UnitTestCase {1296 function test_adds_trailing_slash() {1297 $this->assertEquals("a/", trailingslashit("a"));1298 }1299 1300 function test_does_not_add_trailing_slash_if_one_exists() {1301 $this->assertEquals("a/", trailingslashit("a/"));1302 }1303 }1304 1305 /**1306 * The clean_pre() removes pararaph and line break1307 * tags within `<pre>` elements as part of wpautop().1308 *1309 * @group formatting1310 */1311 class TestCleanPre extends WP_UnitTestCase {1312 function test_removes_self_closing_br_with_space() {1313 $source = 'a b c\n<br />sldfj<br />';1314 $res = 'a b c\nsldfj';1315 1316 $this->assertEquals($res, clean_pre($source));1317 }1318 1319 function test_removes_self_closing_br_without_space() {1320 $source = 'a b c\n<br/>sldfj<br/>';1321 $res = 'a b c\nsldfj';1322 $this->assertEquals($res, clean_pre($source));1323 }1324 1325 // I don't think this can ever happen in production;1326 // <br> is changed to <br /> elsewhere. Left in because1327 // that replacement shouldn't happen (what if you want1328 // HTML 4 output?).1329 function test_removes_html_br() {1330 $source = 'a b c\n<br>sldfj<br>';1331 $res = 'a b c\nsldfj';1332 $this->assertEquals($res, clean_pre($source));1333 }1334 1335 function test_removes_p() {1336 $source = "<p>isn't this exciting!</p><p>oh indeed!</p>";1337 $res = "\nisn't this exciting!\noh indeed!";1338 $this->assertEquals($res, clean_pre($source));1339 }1340 }1341 1342 /**1343 * @group formatting1344 */1345 class TestSmilies extends WP_UnitTestCase {1346 1347 function test_convert_smilies() {1348 global $wpsmiliestrans;1349 $includes_path = includes_url("images/smilies/");1350 1351 // standard smilies, use_smilies: ON1352 update_option( 'use_smilies', 1 );1353 1354 smilies_init();1355 1356 $inputs = array(1357 'Lorem ipsum dolor sit amet mauris ;-) Praesent gravida sodales. :lol: Vivamus nec diam in faucibus eu, bibendum varius nec, imperdiet purus est, at augue at lacus malesuada elit dapibus a, :eek: mauris. Cras mauris viverra elit. Nam laoreet viverra. Pellentesque tortor. Nam libero ante, porta urna ut turpis. Nullam wisi magna, :mrgreen: tincidunt nec, sagittis non, fringilla enim. Nam consectetuer nec, ullamcorper pede eu dui odio consequat vel, vehicula tortor quis pede turpis cursus quis, egestas ipsum ultricies ut, eleifend velit. Mauris vestibulum iaculis. Sed in nunc. Vivamus elit porttitor egestas. Mauris purus :?:',1358 '<strong>Welcome to the jungle!</strong> We got fun n games! :) We got everything you want 8-) <em>Honey we know the names :)</em>',1359 "<strong;)>a little bit of this\na little bit:other: of that :D\n:D a little bit of good\nyeah with a little bit of bad8O",1360 '<strong style="here comes the sun :-D">and I say it\'s allright:D:D',1361 '<!-- Woo-hoo, I\'m a comment, baby! :x > -->',1362 ':?:P:?::-x:mrgreen:::', /*1363 'the question is, <textarea>Should smilies be converted in textareas :?:</textarea>',1364 'the question is, <code>Should smilies be converted in code or pre tags :?:</code>',1365 'the question is, <code style="color:#fff">Should smilies be converted in code or pre tags :?:</code>',1366 'the question is, <code>Should smilies be converted in invalid code or pre tags :?:</pre>',1367 '<Am I greedy?>Yes I am :)> :) The world makes me :mad:' */1368 );1369 1370 $outputs = array(1371 'Lorem ipsum dolor sit amet mauris <img src=\''.$includes_path.'icon_wink.gif\' alt=\';-)\' class=\'wp-smiley\' /> Praesent gravida sodales. <img src=\''.$includes_path.'icon_lol.gif\' alt=\':lol:\' class=\'wp-smiley\' /> Vivamus nec diam in faucibus eu, bibendum varius nec, imperdiet purus est, at augue at lacus malesuada elit dapibus a, <img src=\''.$includes_path.'icon_surprised.gif\' alt=\':eek:\' class=\'wp-smiley\' /> mauris. Cras mauris viverra elit. Nam laoreet viverra. Pellentesque tortor. Nam libero ante, porta urna ut turpis. Nullam wisi magna, <img src=\''.$includes_path.'icon_mrgreen.gif\' alt=\':mrgreen:\' class=\'wp-smiley\' /> tincidunt nec, sagittis non, fringilla enim. Nam consectetuer nec, ullamcorper pede eu dui odio consequat vel, vehicula tortor quis pede turpis cursus quis, egestas ipsum ultricies ut, eleifend velit. Mauris vestibulum iaculis. Sed in nunc. Vivamus elit porttitor egestas. Mauris purus <img src=\''.$includes_path.'icon_question.gif\' alt=\':?:\' class=\'wp-smiley\' /> ',1372 '<strong>Welcome to the jungle!</strong> We got fun n games! <img src=\''.$includes_path.'icon_smile.gif\' alt=\':)\' class=\'wp-smiley\' /> We got everything you want <img src=\''.$includes_path.'icon_cool.gif\' alt=\'8-)\' class=\'wp-smiley\' /> <em>Honey we know the names <img src=\''.$includes_path.'icon_smile.gif\' alt=\':)\' class=\'wp-smiley\' /> </em>',1373 "<strong;)>a little bit of this\na little bit:other: of that <img src='{$includes_path}icon_biggrin.gif' alt=':D' class='wp-smiley' /> <img src='{$includes_path}icon_biggrin.gif' alt=':D' class='wp-smiley' /> a little bit of good\nyeah with a little bit of bad8O",1374 '<strong style="here comes the sun :-D">and I say it\'s allright:D:D',1375 '<!-- Woo-hoo, I\'m a comment, baby! :x > -->',1376 ' <img src=\''.$includes_path.'icon_question.gif\' alt=\':?:\' class=\'wp-smiley\' /> P:?::-x:mrgreen:::', /*1377 'the question is, <textarea>Should smilies be converted in textareas :?:</textarea>',1378 'the question is, <code>Should smilies be converted in code or pre tags :?:</code>',1379 'the question is, <code style="color:#fff">Should smilies be converted in code or pre tags :?:</code>',1380 'the question is, <code>Should smilies be converted in invalid code or pre tags :?:</pre>',1381 '<Am I greedy?>Yes I am <img src=\''.$includes_path.'icon_smile.gif\' alt=\':)\' class=\'wp-smiley\' /> > <img src=\''.$includes_path.'icon_smile.gif\' alt=\':)\' class=\'wp-smiley\' /> The world makes me <img src=\'http://wp-test.php/wp-includes/images/smilies/icon_mad.gif\' alt=\':mad:\' class=\'wp-smiley\' />' */1382 );1383 1384 foreach ( $inputs as $k => $input ) {1385 $this->assertEquals( $outputs[$k], convert_smilies($input) );1386 }1387 1388 update_option( 'use_smilies', 0 );1389 1390 // standard smilies, use_smilies: OFF1391 1392 foreach ( $inputs as $input ) {1393 $this->assertEquals( $input, convert_smilies($input) );1394 }1395 1396 return;1397 1398 // custom smilies, use_smilies: ON1399 update_option( 'use_smilies', 1 );1400 $wpsmiliestrans = array(1401 ':PP' => 'icon_tongue.gif',1402 ':arrow:' => 'icon_arrow.gif',1403 ':monkey:' => 'icon_shock_the_monkey.gif',1404 ':nervou:' => 'icon_nervou.gif'1405 );1406 1407 smilies_init();1408 1409 $inputs = array('Peter Brian Gabriel (born 13 February 1950) is a British singer, musician, and songwriter who rose to fame as the lead vocalist and flautist of the progressive rock group Genesis. :monkey:',1410 'Star Wars Jedi Knight:arrow: Jedi Academy is a first and third-person shooter action game set in the Star Wars universe. It was developed by Raven Software and published, distributed and marketed by LucasArts in North America and by Activision in the rest of the world. :nervou:',1411 ':arrow:monkey:Lorem ipsum dolor sit amet enim. Etiam ullam:PP<br />corper. Suspendisse a pellentesque dui, non felis.<a>:arrow::arrow</a>'1412 );1413 1414 $outputs = array('Peter Brian Gabriel (born 13 February 1950) is a British singer, musician, and songwriter who rose to fame as the lead vocalist and flautist of the progressive rock group Genesis. <img src=\''.$includes_path.'icon_shock_the_monkey.gif\' alt=\'icon_arrow\' class=\'wp-smiley\' />',1415 'Star Wars Jedi Knight<img src=\''.$includes_path.'icon_arrow.gif\' alt=\'icon_arrow\' class=\'wp-smiley\' /> Jedi Academy is a first and third-person shooter action game set in the Star Wars universe. It was developed by Raven Software and published, distributed and marketed by LucasArts in North America and by Activision in the rest of the world. <img src=\''.$includes_path.'icon_nervou.gif\' alt=\'icon_nervou\' class=\'wp-smiley\' />',1416 '<img src=\''.$includes_path.'icon_arrow.gif\' alt=\'icon_arrow\' class=\'wp-smiley\' />monkey:Lorem ipsum dolor sit amet enim. Etiam ullam<img src=\''.$includes_path.'icon_tongue.gif\' alt=\'icon_tongue\' class=\'wp-smiley\' /><br />corper. Suspendisse a pellentesque dui, non felis.<a><img src=\''.$includes_path.'icon_arrow.gif\' alt=\'icon_arrow\' class=\'wp-smiley\' />:arrow</a>'1417 );1418 1419 foreach ( $inputs as $k => $input ) {1420 $this->assertEquals( $outputs[$k], convert_smilies($input) );1421 }1422 }1423 }1424 1425 /**1426 * @group formatting1427 */1428 class TestWPTrimWords extends WP_UnitTestCase {1429 private $long_text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce varius lacinia vehicula. Etiam sapien risus, ultricies ac posuere eu, convallis sit amet augue. Pellentesque urna massa, lacinia vel iaculis eget, bibendum in mauris. Aenean eleifend pulvinar ligula, a convallis eros gravida non. Suspendisse potenti. Pellentesque et odio tortor. In vulputate pellentesque libero, sed dapibus velit mollis viverra. Pellentesque id urna euismod dolor cursus sagittis.';1430 1431 function test_trims_to_55_by_default() {1432 $trimmed = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce varius lacinia vehicula. Etiam sapien risus, ultricies ac posuere eu, convallis sit amet augue. Pellentesque urna massa, lacinia vel iaculis eget, bibendum in mauris. Aenean eleifend pulvinar ligula, a convallis eros gravida non. Suspendisse potenti. Pellentesque et odio tortor. In vulputate pellentesque libero, sed dapibus velit…';1433 $this->assertEquals( $trimmed, wp_trim_words( $this->long_text ) );1434 }1435 1436 function test_trims_to_10() {1437 $trimmed = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce varius…';1438 $this->assertEquals( $trimmed, wp_trim_words( $this->long_text, 10 ) );1439 }1440 1441 function test_trims_to_5_and_uses_custom_more() {1442 $trimmed = 'Lorem ipsum dolor sit amet,[...] Read on!';1443 $this->assertEquals( $trimmed, wp_trim_words( $this->long_text, 5, '[...] Read on!' ) );1444 }1445 1446 function test_strips_tags_before_trimming() {1447 $text = 'This text contains a <a href="http://wordpress.org"> link </a> to WordPress.org!';1448 $trimmed = 'This text contains a link…';1449 $this->assertEquals( $trimmed, wp_trim_words( $text, 5 ) );1450 }1451 1452 // #187261453 function test_strips_script_and_style_content() {1454 $trimmed = 'This text contains. It should go.';1455 1456 $text = 'This text contains<script>alert(" Javascript");</script>. It should go.';1457 $this->assertEquals( $trimmed, wp_trim_words( $text ) );1458 1459 $text = 'This text contains<style>#css { width:expression(alert("css")) }</style>. It should go.';1460 $this->assertEquals( $trimmed, wp_trim_words( $text ) );1461 }1462 1463 function test_doesnt_trim_short_text() {1464 $text = 'This is some short text.';1465 $this->assertEquals( $text, wp_trim_words( $text ) );1466 }1467 }1468 1469 /**1470 * @group formatting1471 */1472 class TestRemoveAccents extends WP_UnitTestCase {1473 public function test_remove_accents_simple() {1474 $this->assertEquals( 'abcdefghijkl', remove_accents( 'abcdefghijkl' ) );1475 }1476 1477 /**1478 * @ticket 95911479 */1480 public function test_remove_accents_latin1_supplement() {1481 $input = 'ªºÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ';1482 $output = 'aoAAAAAAAECEEEEIIIIDNOOOOOOUUUUYTHsaaaaaaaeceeeeiiiidnoooooouuuuythy';1483 1484 $this->assertEquals( $output, remove_accents( $input ), 'remove_accents replaces Latin-1 Supplement' );1485 }1486 1487 public function test_remove_accents_latin_extended_a() {1488 $input = 'ĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſ';1489 $output = 'AaAaAaCcCcCcCcDdDdEeEeEeEeEeGgGgGgGgHhHhIiIiIiIiIiIJijJjKkkLlLlLlLlLlNnNnNnNnNOoOoOoOEoeRrRrRrSsSsSsSsTtTtTtUuUuUuUuUuUuWwYyYZzZzZzs';1490 1491 $this->assertEquals( $output, remove_accents( $input ), 'remove_accents replaces Latin Extended A' );1492 }1493 1494 public function test_remove_accents_latin_extended_b() {1495 $this->assertEquals( 'SsTt', remove_accents( 'ȘșȚț' ), 'remove_accents replaces Latin Extended B' );1496 }1497 1498 public function test_remove_accents_euro_pound_signs() {1499 $this->assertEquals( 'E', remove_accents( '€' ), 'remove_accents replaces euro sign' );1500 $this->assertEquals( '', remove_accents( '£' ), 'remove_accents replaces pound sign' );1501 }1502 1503 public function test_remove_accents_iso8859() {1504 // File is Latin1 encoded1505 $file = DIR_TESTDATA . DIRECTORY_SEPARATOR . 'formatting' . DIRECTORY_SEPARATOR . 'remove_accents.01.input.txt';1506 $input = file_get_contents( $file );1507 $input = trim( $input );1508 $output = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyyOEoeAEDHTHssaedhth";1509 1510 $this->assertEquals( $output, remove_accents( $input ), 'remove_accents from ISO-8859-1 text' );1511 }1512 1513 /**1514 * @ticket 177381515 */1516 public function test_remove_accents_vowels_diacritic() {1517 // Vowels with diacritic1518 // unmarked1519 $this->assertEquals( 'OoUu', remove_accents( 'ƠơƯư' ) );1520 // grave accent1521 $this->assertEquals( 'AaAaEeOoOoUuYy', remove_accents( 'ẦầẰằỀềỒồỜờỪừỲỳ' ) );1522 // hook1523 $this->assertEquals( 'AaAaAaEeEeIiOoOoOoUuUuYy', remove_accents( 'ẢảẨẩẲẳẺẻỂểỈỉỎỏỔổỞởỦủỬửỶỷ' ) );1524 // tilde1525 $this->assertEquals( 'AaAaEeEeOoOoUuYy', remove_accents( 'ẪẫẴẵẼẽỄễỖỗỠỡỮữỸỹ' ) );1526 // acute accent1527 $this->assertEquals( 'AaAaEeOoOoUu', remove_accents( 'ẤấẮắẾếỐốỚớỨứ' ) );1528 // dot below1529 $this->assertEquals( 'AaAaAaEeEeIiOoOoOoUuUuYy', remove_accents( 'ẠạẬậẶặẸẹỆệỊịỌọỘộỢợỤụỰựỴỵ' ) );1530 }1531 1532 /**1533 * @ticket 207721534 */1535 public function test_remove_accents_hanyu_pinyin() {1536 // Vowels with diacritic (Chinese, Hanyu Pinyin)1537 // macron1538 $this->assertEquals( 'aeiouuAEIOUU', remove_accents( 'āēīōūǖĀĒĪŌŪǕ' ) );1539 // acute accent1540 $this->assertEquals( 'aeiouuAEIOUU', remove_accents( 'áéíóúǘÁÉÍÓÚǗ' ) );1541 // caron1542 $this->assertEquals( 'aeiouuAEIOUU', remove_accents( 'ǎěǐǒǔǚǍĚǏǑǓǙ' ) );1543 // grave accent1544 $this->assertEquals( 'aeiouuAEIOUU', remove_accents( 'àèìòùǜÀÈÌÒÙǛ' ) );1545 // unmarked1546 $this->assertEquals( 'aaeiouuAEIOUU', remove_accents( 'aɑeiouüAEIOUÜ' ) );1547 }1548 }1549 1550 /**1551 * @group formatting1552 */1553 class TestStripSlashesDeep extends WP_UnitTestCase {1554 /**1555 * @ticket 180261556 */1557 function test_preserves_original_datatype() {1558 1559 $this->assertEquals( true, stripslashes_deep( true ) );1560 $this->assertEquals( false, stripslashes_deep( false ) );1561 $this->assertEquals( 4, stripslashes_deep( 4 ) );1562 $this->assertEquals( 'foo', stripslashes_deep( 'foo' ) );1563 $arr = array( 'a' => true, 'b' => false, 'c' => 4, 'd' => 'foo' );1564 $arr['e'] = $arr; // Add a sub-array1565 $this->assertEquals( $arr, stripslashes_deep( $arr ) ); // Keyed array1566 $this->assertEquals( array_values( $arr ), stripslashes_deep( array_values( $arr ) ) ); // Non-keyed1567 1568 $obj = new stdClass;1569 foreach ( $arr as $k => $v )1570 $obj->$k = $v;1571 $this->assertEquals( $obj, stripslashes_deep( $obj ) );1572 }1573 1574 function test_strips_slashes() {1575 $old = "I can\'t see, isn\'t that it?";1576 $new = "I can't see, isn't that it?";1577 $this->assertEquals( $new, stripslashes_deep( $old ) );1578 $this->assertEquals( $new, stripslashes_deep( "I can\\'t see, isn\\'t that it?" ) );1579 $this->assertEquals( array( 'a' => $new ), stripslashes_deep( array( 'a' => $old ) ) ); // Keyed array1580 $this->assertEquals( array( $new ), stripslashes_deep( array( $old ) ) ); // Non-keyed1581 1582 $obj_old = new stdClass;1583 $obj_old->a = $old;1584 $obj_new = new stdClass;1585 $obj_new->a = $new;1586 $this->assertEquals( $obj_new, stripslashes_deep( $obj_old ) );1587 }1588 1589 function test_permits_escaped_slash() {1590 $txt = "I can't see, isn\'t that it?";1591 $this->assertEquals( $txt, stripslashes_deep( "I can\'t see, isn\\\'t that it?" ) );1592 $this->assertEquals( $txt, stripslashes_deep( "I can\'t see, isn\\\\\'t that it?" ) );1593 }1594 }
Note: See TracChangeset
for help on using the changeset viewer.