Changeset 909 in tests
- Timestamp:
- 07/19/2012 01:52:37 AM (12 years ago)
- Location:
- trunk/tests
- Files:
-
- 3 added
- 1 deleted
- 13 edited
- 44 copied
- 9 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/actions.php
r904 r909 6 6 * @group hooks 7 7 */ 8 class WPTestActions extends WP_UnitTestCase {8 class Tests_Actions extends WP_UnitTestCase { 9 9 10 10 function test_simple_action() { -
trunk/tests/admin/includesMisc.php
r904 r909 4 4 * @group admin 5 5 */ 6 class Test ShortenUrlextends WP_UnitTestCase {6 class Tests_Admin_includesMisc extends WP_UnitTestCase { 7 7 function test_shorten_url() { 8 8 $tests = array( -
trunk/tests/admin/includesScreen.php
r904 r909 4 4 * @group admin 5 5 */ 6 class WPTestScreen extends WP_UnitTestCase {6 class Tests_Admin_includesScreen extends WP_UnitTestCase { 7 7 var $core_screens = array( 8 8 'index.php' => array( 'base' => 'dashboard', 'id' => 'dashboard' ), -
trunk/tests/admin/includesTemplate.php
r904 r909 3 3 * @group admin 4 4 */ 5 class WPTestCheckedSelectedextends WP_UnitTestCase {5 class Tests_Admin_includesTemplate extends WP_UnitTestCase { 6 6 function test_equal() { 7 7 $this->assertEquals(' selected=\'selected\'', selected('foo','foo',false)); -
trunk/tests/admin/includesTheme.php
r904 r909 3 3 * @group themes 4 4 */ 5 class Test PageTemplatesextends WP_UnitTestCase {5 class Tests_Admin_includesTheme extends WP_UnitTestCase { 6 6 function setUp() { 7 7 parent::setUp(); -
trunk/tests/ajax/EditComment.php
r904 r909 15 15 * @runTestsInSeparateProcesses 16 16 */ 17 class Tests_Ajax_EditComment sextends WP_Ajax_UnitTestCase {17 class Tests_Ajax_EditComment extends WP_Ajax_UnitTestCase { 18 18 19 19 /** -
trunk/tests/auth.php
r904 r909 4 4 * @group pluggable 5 5 */ 6 class Test AuthFunctionsextends WP_UnitTestCase {6 class Tests_Auth extends WP_UnitTestCase { 7 7 var $user_id; 8 8 … … 43 43 } 44 44 } 45 46 /**47 * @group pluggable48 * @group mail49 * @ticket UT4750 */51 class TestMailFunctions extends WP_UnitTestCase {52 function setUp() {53 parent::setUp();54 }55 56 function test_wp_mail_custom_boundaries() {57 $to = 'user@example.com';58 $subject = 'Test email with custom boundaries';59 $headers = '' . "\n";60 $headers .= 'MIME-Version: 1.0' . "\n";61 $headers .= 'Content-Type: multipart/mixed; boundary="----=_Part_4892_25692638.1192452070893"' . "\n";62 $headers .= "\n";63 $body = "\n";64 $body .= '------=_Part_4892_25692638.1192452070893' . "\n";65 $body .= 'Content-Type: text/plain; charset=ISO-8859-1' . "\n";66 $body .= 'Content-Transfer-Encoding: 7bit' . "\n";67 $body .= 'Content-Disposition: inline' . "\n";68 $body .= "\n";69 $body .= 'Here is a message with an attachment of a binary file.' . "\n";70 $body .= "\n";71 $body .= '------=_Part_4892_25692638.1192452070893' . "\n";72 $body .= 'Content-Type: image/x-icon; name=favicon.ico' . "\n";73 $body .= 'Content-Transfer-Encoding: base64' . "\n";74 $body .= 'Content-Disposition: attachment; filename=favicon.ico' . "\n";75 $body .= "\n";76 $body .= 'AAABAAEAEBAAAAAAAABoBQAAFgAAACgAAAAQAAAAIAAAAAEACAAAAAAAAAAAAAAAAAAAAAAAAAAA' . "\n";77 $body .= 'AAAAAAAAAAAAAACAAACAAAAAgIAAgAAAAIAAgACAgAAAwMDAAICAgAAAAP8AAP8AAAD//wD/AAAA' . "\n";78 $body .= '/wD/AP//AAD///8A//3/AP39/wD6/f8A+P3/AP/8/wD9/P8A+vz/AP/7/wD/+v8A/vr/APz6/wD4' . "\n";79 $body .= '+v8A+/n/APP5/wD/+P8A+vj/AO/4/wDm+P8A2fj/AP/3/wD/9v8A9vb/AP/1/wD69f8A9PT/AO30' . "\n";80 $body .= '/wD/8/8A//L/APnx/wD28P8A///+APj//gD2//4A9P/+AOP//gD//f4A6f/9AP///AD2//wA8//8' . "\n";81 $body .= 'APf9/AD///sA/v/7AOD/+wD/+vsA9/X7APr/+gDv/voA///5AP/9+QD/+/kA+e35AP//+ADm//gA' . "\n";82 $body .= '4f/4AP/9+AD0+/gA///3APv/9wDz//cA8f/3AO3/9wD/8fcA//32AP369gDr+vYA8f/1AOv/9QD/' . "\n";83 $body .= '+/UA///0APP/9ADq//QA///zAP/18wD///IA/fzyAP//8QD///AA9//wAPjw8AD//+8A8//vAP//' . "\n";84 $body .= '7gD9/+4A9v/uAP/u7gD//+0A9v/tAP7/6wD/+eoA///pAP//6AD2/+gA//nnAP/45wD38eYA/fbl' . "\n";85 $body .= 'AP/25AD29uQA7N/hAPzm4AD/690AEhjdAAAa3AAaJdsA//LXAC8g1gANH9YA+dnTAP/n0gDh5dIA' . "\n";86 $body .= 'DyjSABkk0gAdH9EABxDRAP/l0AAAJs4AGRTOAPPczQAAKs0AIi7MAA4UywD56soA8tPKANTSygD/' . "\n";87 $body .= '18kA6NLHAAAjxwDj28QA/s7CAP/1wQDw3r8A/9e8APrSrwDCtqoAzamjANmPiQDQj4YA35mBAOme' . "\n";88 $body .= 'fgDHj3wA1qR6AO+sbwDpmm8A2IVlAKmEYgCvaFoAvHNXAEq2VgA5s1UAPbhQAFWtTwBStU0ARbNN' . "\n";89 $body .= 'AEGxTQA7tEwAObZIAEq5RwDKdEYAULhDANtuQgBEtTwA1ls3ALhgMQCxNzEA2FsvAEC3LQB0MCkA' . "\n";90 $body .= 'iyYoANZTJwDLWyYAtjMlALE6JACZNSMAuW4iANlgIgDoWCEAylwgAMUuIAD3Vh8A52gdALRCHQCx' . "\n";91 $body .= 'WhwAsEkcALU4HACMOBwA0V4bAMYyGgCPJRoA218ZAJM7FwC/PxYA0msVAM9jFQD2XBUAqioVAIAf' . "\n";92 $body .= 'FQDhYRQAujMTAMUxEwCgLBMAnxIPAMsqDgCkFgsA6GMHALE2BAC9JQAAliIAAFYTAAAAAAAAAAAA' . "\n";93 $body .= 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' . "\n";94 $body .= 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/' . "\n";95 $body .= '//8AsbGxsbGxsbGxsbGxsbGxd7IrMg8PDw8PDw8PUBQeJXjQYE9PcKPM2NfP2sWhcg+BzTE7dLjb' . "\n";96 $body .= 'mG03YWaV4JYye8MPbsLZlEouKRRCg9SXMoW/U53enGRAFzCRtNO7mTiAyliw30gRTg9VbJCKfYs0' . "\n";97 $body .= 'j9VmuscfLTFbIy8SOhA0Inq5Y77GNBMYIxQUJzM2Vxx2wEmfyCYWMRldXCg5MU0aicRUms58SUVe' . "\n";98 $body .= 'RkwjPBRSNIfBMkSgvWkyPxVHFIaMSx1/0S9nkq7WdWo1a43Jt2UqgtJERGJ5m6K8y92znpNWIYS1' . "\n";99 $body .= 'UQ89Mmg5cXNaX0EkGyyI3KSsp6mvpaqosaatq7axsQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' . "\n";100 $body .= 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=' . "\n";101 $body .= '------=_Part_4892_25692638.1192452070893--' . "\n";102 $body .= "\n";103 104 unset($GLOBALS['phpmailer']->mock_sent);105 $_SERVER['SERVER_NAME'] = 'example.com';106 wp_mail($to, $subject, $body, $headers);107 108 // We need some better assertions here but these catch the failure for now.109 $this->assertEquals($body, $GLOBALS['phpmailer']->mock_sent[0]['body']);110 $this->assertTrue(strpos($GLOBALS['phpmailer']->mock_sent[0]['header'], 'boundary="----=_Part_4892_25692638.1192452070893"') > 0);111 $this->assertTrue(strpos($GLOBALS['phpmailer']->mock_sent[0]['header'], 'charset=""') > 0);112 unset( $_SERVER['SERVER_NAME'] );113 }114 115 /**116 * @ticket 15448117 */118 function test_wp_mail_plain_and_html() {119 120 $to = 'user@example.com';121 $subject = 'Test email with plain text and html versions';122 $messages = array( 'text/plain' => 'Here is some plain text.',123 'text/html' =>'<html><head></head><body>Here is the HTML ;-)<body></html>' );124 125 unset($GLOBALS['phpmailer']->mock_sent);126 $_SERVER['SERVER_NAME'] = 'example.com';127 wp_mail( $to, $subject, $messages );128 129 preg_match( '/boundary="(.*)"/', $GLOBALS['phpmailer']->mock_sent[0]['header'], $matches);130 $boundry = $matches[1];131 $body = '--' . $boundry . '132 Content-Type: text/plain; charset = "UTF-8"133 Content-Transfer-Encoding: 8bit134 135 Here is some plain text.136 137 138 --' . $boundry . '139 Content-Type: text/html; charset = "UTF-8"140 Content-Transfer-Encoding: 8bit141 142 <html><head></head><body>Here is the HTML ;-)<body></html>143 144 145 146 --' . $boundry . '--147 ';148 // We need some better assertions here but these test the behaviour for now.149 $this->assertEquals($body, $GLOBALS['phpmailer']->mock_sent[0]['body']);150 unset( $_SERVER['SERVER_NAME'] );151 }152 153 /**154 * @ticket 17305155 */156 function test_wp_mail_rfc2822_addresses() {157 158 $to = "Name <address@tld.com>";159 $from = "Another Name <another_address@different-tld.com>";160 $cc = "The Carbon Guy <cc@cc.com>";161 $bcc = "The Blind Carbon Guy <bcc@bcc.com>";162 $subject = "RFC2822 Testing";163 $message = "My RFC822 Test Message";164 $headers[] = "From: {$from}";165 $headers[] = "CC: {$cc}";166 $headers[] = "BCC: {$bcc}";167 168 unset($GLOBALS['phpmailer']->mock_sent);169 $_SERVER['SERVER_NAME'] = 'example.com';170 wp_mail( $to, $subject, $message, $headers );171 172 // WordPress 3.2 and later correctly split the address into the two parts and send them seperately to PHPMailer173 // Earlier versions of PHPMailer were not touchy about the formatting of these arguments.174 if ( version_compare( $GLOBALS['wp_version'], '3.1.9', '>' ) ) {175 $this->assertEquals('address@tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]);176 $this->assertEquals('Name', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][1]);177 $this->assertEquals('cc@cc.com', $GLOBALS['phpmailer']->mock_sent[0]['cc'][0][0]);178 $this->assertEquals('The Carbon Guy', $GLOBALS['phpmailer']->mock_sent[0]['cc'][0][1]);179 $this->assertEquals('bcc@bcc.com', $GLOBALS['phpmailer']->mock_sent[0]['bcc'][0][0]);180 $this->assertEquals('The Blind Carbon Guy', $GLOBALS['phpmailer']->mock_sent[0]['bcc'][0][1]);181 } else {182 $this->assertEquals($to, $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]);183 $this->assertEquals($cc, $GLOBALS['phpmailer']->mock_sent[0]['cc'][0][0]);184 $this->assertEquals($bcc, $GLOBALS['phpmailer']->mock_sent[0]['bcc'][0][0]);185 }186 187 $this->assertEquals($message . "\n", $GLOBALS['phpmailer']->mock_sent[0]['body']);188 unset( $_SERVER['SERVER_NAME'] );189 }190 191 /**192 * @ticket 17305193 */194 function test_wp_mail_multiple_rfc2822_to_addresses() {195 196 $to = "Name <address@tld.com>, Another Name <another_address@different-tld.com>";197 $subject = "RFC2822 Testing";198 $message = "My RFC822 Test Message";199 200 unset($GLOBALS['phpmailer']->mock_sent);201 $_SERVER['SERVER_NAME'] = 'example.com';202 wp_mail( $to, $subject, $message );203 204 // WordPress 3.2 and later correctly split the address into the two parts and send them seperately to PHPMailer205 // Earlier versions of PHPMailer were not touchy about the formatting of these arguments.206 if ( version_compare( $GLOBALS['wp_version'], '3.1.9', '>' ) ) {207 $this->assertEquals('address@tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]);208 $this->assertEquals('Name', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][1]);209 $this->assertEquals('another_address@different-tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][1][0]);210 $this->assertEquals('Another Name', $GLOBALS['phpmailer']->mock_sent[0]['to'][1][1]);211 } else {212 $this->assertEquals('Name <address@tld.com>', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]);213 $this->assertEquals('Another Name <another_address@different-tld.com>', $GLOBALS['phpmailer']->mock_sent[0]['to'][1][0]);214 }215 216 $this->assertEquals($message . "\n", $GLOBALS['phpmailer']->mock_sent[0]['body']);217 unset( $_SERVER['SERVER_NAME'] );218 }219 220 function test_wp_mail_multiple_to_addresses() {221 $to = "address@tld.com, another_address@different-tld.com";222 $subject = "RFC2822 Testing";223 $message = "My RFC822 Test Message";224 225 unset($GLOBALS['phpmailer']->mock_sent);226 $_SERVER['SERVER_NAME'] = 'example.com';227 wp_mail( $to, $subject, $message );228 229 $this->assertEquals('address@tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]);230 $this->assertEquals('another_address@different-tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][1][0]);231 $this->assertEquals($message . "\n", $GLOBALS['phpmailer']->mock_sent[0]['body']);232 unset( $_SERVER['SERVER_NAME'] );233 }234 235 /**236 * @ticket 18463237 */238 function test_wp_mail_to_address_no_name() {239 240 $to = "<address@tld.com>";241 $subject = "RFC2822 Testing";242 $message = "My RFC822 Test Message";243 244 unset($GLOBALS['phpmailer']->mock_sent);245 $_SERVER['SERVER_NAME'] = 'example.com';246 wp_mail( $to, $subject, $message );247 248 // Old PHPMailer blindly accepts the address, the new one santizes it249 if ( version_compare( $GLOBALS['wp_version'], '3.1.9', '>' ) )250 $this->assertEquals('address@tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]);251 else252 $this->assertEquals('<address@tld.com>', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]);253 $this->assertEquals($message . "\n", $GLOBALS['phpmailer']->mock_sent[0]['body']);254 unset( $_SERVER['SERVER_NAME'] );255 }256 }257 258 /**259 * @group pluggable260 */261 class TestRedirectFunctions extends WP_UnitTestCase {262 function test_wp_sanitize_redirect() {263 $this->assertEquals('http://example.com/watchthelinefeedgo', wp_sanitize_redirect('http://example.com/watchthelinefeed%0Ago'));264 $this->assertEquals('http://example.com/watchthelinefeedgo', wp_sanitize_redirect('http://example.com/watchthelinefeed%0ago'));265 $this->assertEquals('http://example.com/watchthecarriagereturngo', wp_sanitize_redirect('http://example.com/watchthecarriagereturn%0Dgo'));266 $this->assertEquals('http://example.com/watchthecarriagereturngo', wp_sanitize_redirect('http://example.com/watchthecarriagereturn%0dgo'));267 //Nesting checks268 $this->assertEquals('http://example.com/watchthecarriagereturngo', wp_sanitize_redirect('http://example.com/watchthecarriagereturn%0%0ddgo'));269 $this->assertEquals('http://example.com/watchthecarriagereturngo', wp_sanitize_redirect('http://example.com/watchthecarriagereturn%0%0DDgo'));270 }271 } -
trunk/tests/cache.php
r904 r909 4 4 * @group cache 5 5 */ 6 class Test ObjectCache extends WP_UnitTestCase {6 class Tests_Cache extends WP_UnitTestCase { 7 7 var $cache = NULL; 8 8 -
trunk/tests/db.php
r904 r909 6 6 * @group wpdb 7 7 */ 8 class Test WPDB extends WP_UnitTestCase {8 class Tests_DB extends WP_UnitTestCase { 9 9 10 10 /** -
trunk/tests/dependencies/scripts.php
r904 r909 4 4 * @group scripts 5 5 */ 6 class Test WP_Scripts extends WP_UnitTestCase {6 class Tests_Dependencies_Scripts extends WP_UnitTestCase { 7 7 var $old_wp_scripts; 8 8 … … 13 13 $GLOBALS['wp_scripts'] = new WP_Scripts(); 14 14 $GLOBALS['wp_scripts']->default_version = get_bloginfo( 'version' ); 15 16 15 } 17 16 -
trunk/tests/dependencies/styles.php
r904 r909 4 4 * @group scripts 5 5 */ 6 class Test WP_Styles extends WP_UnitTestCase {6 class Tests_Dependencies_Styles extends WP_UnitTestCase { 7 7 var $old_wp_styles; 8 8 -
trunk/tests/file.php
r904 r909 1 1 <?php 2 2 3 /** 4 * @group file 5 */ 3 6 class Tests_File extends WP_UnitTestCase { 4 7 … … 7 10 8 11 $this->badchars = '"\'[]*&?$'; 12 } 13 14 /** 15 * @group plugins 16 * @group themes 17 */ 18 function test_get_file_data() { 19 $theme_headers = array( 20 'Name' => 'Theme Name', 21 'ThemeURI' => 'Theme URI', 22 'Description' => 'Description', 23 'Version' => 'Version', 24 'Author' => 'Author', 25 'AuthorURI' => 'Author URI', 26 ); 27 28 $actual = get_file_data( DIR_TESTDATA . '/themedir1/default/style.css', $theme_headers ); 29 30 $expected = array( 31 'Name' => 'WordPress Default', 32 'ThemeURI' => 'http://wordpress.org/', 33 'Description' => 'The default WordPress theme based on the famous <a href="http://binarybonsai.com/kubrick/">Kubrick</a>.', 34 'Version' => '1.6', 35 'Author' => 'Michael Heilemann', 36 'AuthorURI' => 'http://binarybonsai.com/', 37 ); 38 39 foreach ( $actual as $header => $value ) 40 $this->assertEquals( $expected[ $header ], $value, $header ); 41 } 42 43 /** 44 * @group plugins 45 * @group themes 46 */ 47 function test_get_file_data_cr_line_endings() { 48 $headers = array( 'SomeHeader' => 'Some Header', 'Description' => 'Description', 'Author' => 'Author' ); 49 $actual = get_file_data( DIR_TESTDATA . '/formatting/cr-line-endings-file-header.php', $headers ); 50 $expected = array( 51 'SomeHeader' => 'Some header value!', 52 'Description' => 'This file is using CR line endings for a testcase.', 53 'Author' => 'A Very Old Mac', 54 ); 55 56 foreach ( $actual as $header => $value ) 57 $this->assertEquals( $expected[ $header ], $value, $header ); 9 58 } 10 59 -
trunk/tests/filters.php
r904 r909 6 6 * @group hooks 7 7 */ 8 class WPTestFilters extends WP_UnitTestCase {8 class Tests_Filters extends WP_UnitTestCase { 9 9 10 10 function test_simple_filter() { -
trunk/tests/formatting/Autop.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 { 453 function test_dashes() { 454 $this->assertEquals('Hey — boo?', wptexturize('Hey -- boo?')); 455 $this->assertEquals('<a href="http://xx--xx">Hey — boo?</a>', wptexturize('<a href="http://xx--xx">Hey -- boo?</a>')); 456 } 457 458 function test_disable() { 459 $this->assertEquals('<pre>---</pre>', wptexturize('<pre>---</pre>')); 460 $this->assertEquals('[a]a–b[code]---[/code]a–b[/a]', wptexturize('[a]a--b[code]---[/code]a--b[/a]')); 461 $this->assertEquals('<pre><code></code>--</pre>', wptexturize('<pre><code></code>--</pre>')); 462 463 $this->assertEquals('<code>---</code>', wptexturize('<code>---</code>')); 464 465 $this->assertEquals('<code>href="baba"</code> “baba”', wptexturize('<code>href="baba"</code> "baba"')); 466 467 $enabled_tags_inside_code = '<code>curl -s <a href="http://x/">baba</a> | grep sfive | cut -d "\"" -f 10 > topmp3.txt</code>'; 468 $this->assertEquals($enabled_tags_inside_code, wptexturize($enabled_tags_inside_code)); 469 470 $double_nest = '<pre>"baba"<code>"baba"<pre></pre></code>"baba"</pre>'; 471 $this->assertEquals($double_nest, wptexturize($double_nest)); 472 473 $invalid_nest = '<pre></code>"baba"</pre>'; 474 $this->assertEquals($invalid_nest, wptexturize($invalid_nest)); 475 476 } 477 478 //WP Ticket #1418 479 function test_bracketed_quotes_1418() { 480 $this->assertEquals('(“test”)', wptexturize('("test")')); 481 $this->assertEquals('(‘test’)', wptexturize("('test')")); 482 $this->assertEquals('(’twas)', wptexturize("('twas)")); 483 } 484 485 //WP Ticket #3810 486 function test_bracketed_quotes_3810() { 487 $this->assertEquals('A dog (“Hubertus”) was sent out.', wptexturize('A dog ("Hubertus") was sent out.')); 488 } 489 490 //WP Ticket #4539 491 function test_basic_quotes() { 492 $this->assertEquals('test’s', wptexturize('test\'s')); 493 $this->assertEquals('test’s', wptexturize('test\'s')); 494 495 $this->assertEquals('‘quoted’', wptexturize('\'quoted\'')); 496 $this->assertEquals('“quoted”', wptexturize('"quoted"')); 497 498 $this->assertEquals('space before ‘quoted’ space after', wptexturize('space before \'quoted\' space after')); 499 $this->assertEquals('space before “quoted” space after', wptexturize('space before "quoted" space after')); 500 501 $this->assertEquals('(‘quoted’)', wptexturize('(\'quoted\')')); 502 $this->assertEquals('{“quoted”}', wptexturize('{"quoted"}')); 503 504 $this->assertEquals('‘qu(ot)ed’', wptexturize('\'qu(ot)ed\'')); 505 $this->assertEquals('“qu{ot}ed”', wptexturize('"qu{ot}ed"')); 506 507 $this->assertEquals(' ‘test’s quoted’ ', wptexturize(' \'test\'s quoted\' ')); 508 $this->assertEquals(' “test’s quoted” ', wptexturize(' "test\'s quoted" ')); 509 } 510 511 /** 512 * @ticket 4539 513 * @ticket 15241 514 */ 515 function test_full_sentences_with_unmatched_single_quotes() { 516 $this->assertEquals( 517 'That means every moment you’re working on something without it being in the public it’s actually dying.', 518 wptexturize("That means every moment you're working on something without it being in the public it's actually dying.") 519 ); 520 } 521 522 /** 523 * @ticket 4539 524 */ 525 function test_quotes() { 526 $this->assertEquals('“Quoted String”', wptexturize('"Quoted String"')); 527 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"')); 528 $this->assertEquals('Here is “<a href="http://example.com">a test with a link and a period</a>”.', wptexturize('Here is "<a href="http://example.com">a test with a link and a period</a>".')); 529 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>” and a space.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>" and a space.')); 530 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a> and some text quoted”', wptexturize('Here is "<a href="http://example.com">a test with a link</a> and some text quoted"')); 531 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”, and a comma.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>", and a comma.')); 532 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”; and a semi-colon.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"; and a semi-colon.')); 533 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”- and a dash.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"- and a dash.')); 534 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”… and ellipses.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"... and ellipses.')); 535 $this->assertEquals('Here is “a test <a href="http://example.com">with a link</a>”.', wptexturize('Here is "a test <a href="http://example.com">with a link</a>".')); 536 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”and a work stuck to the end.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"and a work stuck to the end.')); 537 $this->assertEquals('A test with a finishing number, “like 23”.', wptexturize('A test with a finishing number, "like 23".')); 538 $this->assertEquals('A test with a number, “like 62”, is nice to have.', wptexturize('A test with a number, "like 62", is nice to have.')); 539 } 540 541 /** 542 * @ticket 4539 543 */ 544 function test_quotes_before_s() { 545 $this->assertEquals('test’s', wptexturize("test's")); 546 $this->assertEquals('‘test’s', wptexturize("'test's")); 547 $this->assertEquals('‘test’s’', wptexturize("'test's'")); 548 $this->assertEquals('‘string’', wptexturize("'string'")); 549 $this->assertEquals('‘string’s’', wptexturize("'string's'")); 550 } 551 552 /** 553 * @ticket 4539 554 */ 555 function test_quotes_before_numbers() { 556 $this->assertEquals('Class of ’99', wptexturize("Class of '99")); 557 $this->assertEquals('Class of ’99’s', wptexturize("Class of '99's")); 558 $this->assertEquals('‘Class of ’99’', wptexturize("'Class of '99'")); 559 $this->assertEquals('‘Class of ’99’s’', wptexturize("'Class of '99's'")); 560 $this->assertEquals('‘Class of ’99’s’', wptexturize("'Class of '99’s'")); 561 $this->assertEquals('“Class of 99”', wptexturize("\"Class of 99\"")); 562 $this->assertEquals('“Class of ’99”', wptexturize("\"Class of '99\"")); 563 } 564 565 function test_quotes_after_numbers() { 566 $this->assertEquals('Class of ’99', wptexturize("Class of '99")); 567 } 568 569 /** 570 * @ticket 4539 571 * @ticket 15241 572 */ 573 function test_other_html() { 574 $this->assertEquals('‘<strong>', wptexturize("'<strong>")); 575 $this->assertEquals('‘<strong>Quoted Text</strong>’,', wptexturize("'<strong>Quoted Text</strong>',")); 576 $this->assertEquals('“<strong>Quoted Text</strong>”,', wptexturize('"<strong>Quoted Text</strong>",')); 577 } 578 579 function test_x() { 580 $this->assertEquals('14×24', wptexturize("14x24")); 581 } 582 583 function test_minutes_seconds() { 584 $this->assertEquals('9′', wptexturize('9\'')); 585 $this->assertEquals('9″', wptexturize("9\"")); 586 587 $this->assertEquals('a 9′ b', wptexturize('a 9\' b')); 588 $this->assertEquals('a 9″ b', wptexturize("a 9\" b")); 589 590 $this->assertEquals('“a 9′ b”', wptexturize('"a 9\' b"')); 591 $this->assertEquals('‘a 9″ b’', wptexturize("'a 9\" b'")); 592 } 593 594 /** 595 * @ticket 8775 596 */ 597 function test_wptexturize_quotes_around_numbers() { 598 $this->assertEquals('“12345”', wptexturize('"12345"')); 599 $this->assertEquals('‘12345’', wptexturize('\'12345\'')); 600 $this->assertEquals('“a 9′ plus a ‘9’, maybe a 9′ ‘9’ ”', wptexturize('"a 9\' plus a \'9\', maybe a 9\' \'9\' "')); 601 $this->assertEquals('<p>‘99<br />‘123’<br />’tis<br />‘s’</p>', wptexturize('<p>\'99<br />\'123\'<br />\'tis<br />\'s\'</p>')); 602 } 603 604 /** 605 * @ticket 8912 606 */ 607 function test_wptexturize_html_comments() { 608 $this->assertEquals('<!--[if !IE]>--><!--<![endif]-->', wptexturize('<!--[if !IE]>--><!--<![endif]-->')); 609 $this->assertEquals('<!--[if !IE]>"a 9\' plus a \'9\', maybe a 9\' \'9\' "<![endif]-->', wptexturize('<!--[if !IE]>"a 9\' plus a \'9\', maybe a 9\' \'9\' "<![endif]-->')); 610 $this->assertEquals('<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>', wptexturize('<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>')); 611 } 612 613 /** 614 * @ticket 4539 615 * @ticket 15241 616 */ 617 function test_entity_quote_cuddling() { 618 $this->assertEquals(' “Testing”', wptexturize(' "Testing"')); 619 $this->assertEquals('&“Testing”', wptexturize('&"Testing"')); 620 } 621 } 622 623 /** 624 * @group formatting 625 */ 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 Checks 638 $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 16859 679 */ 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 - RFC2732 684 $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 formatting 692 */ 693 class TestAutop extends WP_UnitTestCase { 6 class Tests_Formatting_Autop extends WP_UnitTestCase { 694 7 //From ticket http://core.trac.wordpress.org/ticket/11008 695 8 function test_first_post() { … … 787 100 } 788 101 } 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 } -
trunk/tests/formatting/CleanPre.php
r903 r909 1 1 <?php 2 3 /**4 * @group formatting5 */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 and40 // (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 and65 // (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 and92 // (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 and117 // (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 // #4570142 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 // #10990159 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. #11211194 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 // #14993213 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#something273 (<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 16892293 */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 too312 );313 foreach ( $in as $text ) {314 $this->assertEquals( $text, make_clickable( $text ) );315 }316 }317 318 /**319 * ticket 16892320 */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 16859333 */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 formatting351 */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 stripped384 $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 stripped390 $this->assertequals("foo\\nbar\\nbaz\\n", $out);391 }392 }393 394 /**395 * @group formatting396 */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_orderby413 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 formatting451 */452 class TestWPTexturize extends WP_UnitTestCase {453 function test_dashes() {454 $this->assertEquals('Hey — boo?', wptexturize('Hey -- boo?'));455 $this->assertEquals('<a href="http://xx--xx">Hey — boo?</a>', wptexturize('<a href="http://xx--xx">Hey -- boo?</a>'));456 }457 458 function test_disable() {459 $this->assertEquals('<pre>---</pre>', wptexturize('<pre>---</pre>'));460 $this->assertEquals('[a]a–b[code]---[/code]a–b[/a]', wptexturize('[a]a--b[code]---[/code]a--b[/a]'));461 $this->assertEquals('<pre><code></code>--</pre>', wptexturize('<pre><code></code>--</pre>'));462 463 $this->assertEquals('<code>---</code>', wptexturize('<code>---</code>'));464 465 $this->assertEquals('<code>href="baba"</code> “baba”', wptexturize('<code>href="baba"</code> "baba"'));466 467 $enabled_tags_inside_code = '<code>curl -s <a href="http://x/">baba</a> | grep sfive | cut -d "\"" -f 10 > topmp3.txt</code>';468 $this->assertEquals($enabled_tags_inside_code, wptexturize($enabled_tags_inside_code));469 470 $double_nest = '<pre>"baba"<code>"baba"<pre></pre></code>"baba"</pre>';471 $this->assertEquals($double_nest, wptexturize($double_nest));472 473 $invalid_nest = '<pre></code>"baba"</pre>';474 $this->assertEquals($invalid_nest, wptexturize($invalid_nest));475 476 }477 478 //WP Ticket #1418479 function test_bracketed_quotes_1418() {480 $this->assertEquals('(“test”)', wptexturize('("test")'));481 $this->assertEquals('(‘test’)', wptexturize("('test')"));482 $this->assertEquals('(’twas)', wptexturize("('twas)"));483 }484 485 //WP Ticket #3810486 function test_bracketed_quotes_3810() {487 $this->assertEquals('A dog (“Hubertus”) was sent out.', wptexturize('A dog ("Hubertus") was sent out.'));488 }489 490 //WP Ticket #4539491 function test_basic_quotes() {492 $this->assertEquals('test’s', wptexturize('test\'s'));493 $this->assertEquals('test’s', wptexturize('test\'s'));494 495 $this->assertEquals('‘quoted’', wptexturize('\'quoted\''));496 $this->assertEquals('“quoted”', wptexturize('"quoted"'));497 498 $this->assertEquals('space before ‘quoted’ space after', wptexturize('space before \'quoted\' space after'));499 $this->assertEquals('space before “quoted” space after', wptexturize('space before "quoted" space after'));500 501 $this->assertEquals('(‘quoted’)', wptexturize('(\'quoted\')'));502 $this->assertEquals('{“quoted”}', wptexturize('{"quoted"}'));503 504 $this->assertEquals('‘qu(ot)ed’', wptexturize('\'qu(ot)ed\''));505 $this->assertEquals('“qu{ot}ed”', wptexturize('"qu{ot}ed"'));506 507 $this->assertEquals(' ‘test’s quoted’ ', wptexturize(' \'test\'s quoted\' '));508 $this->assertEquals(' “test’s quoted” ', wptexturize(' "test\'s quoted" '));509 }510 511 /**512 * @ticket 4539513 * @ticket 15241514 */515 function test_full_sentences_with_unmatched_single_quotes() {516 $this->assertEquals(517 'That means every moment you’re working on something without it being in the public it’s actually dying.',518 wptexturize("That means every moment you're working on something without it being in the public it's actually dying.")519 );520 }521 522 /**523 * @ticket 4539524 */525 function test_quotes() {526 $this->assertEquals('“Quoted String”', wptexturize('"Quoted String"'));527 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"'));528 $this->assertEquals('Here is “<a href="http://example.com">a test with a link and a period</a>”.', wptexturize('Here is "<a href="http://example.com">a test with a link and a period</a>".'));529 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>” and a space.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>" and a space.'));530 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a> and some text quoted”', wptexturize('Here is "<a href="http://example.com">a test with a link</a> and some text quoted"'));531 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”, and a comma.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>", and a comma.'));532 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”; and a semi-colon.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"; and a semi-colon.'));533 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”- and a dash.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"- and a dash.'));534 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”… and ellipses.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"... and ellipses.'));535 $this->assertEquals('Here is “a test <a href="http://example.com">with a link</a>”.', wptexturize('Here is "a test <a href="http://example.com">with a link</a>".'));536 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”and a work stuck to the end.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"and a work stuck to the end.'));537 $this->assertEquals('A test with a finishing number, “like 23”.', wptexturize('A test with a finishing number, "like 23".'));538 $this->assertEquals('A test with a number, “like 62”, is nice to have.', wptexturize('A test with a number, "like 62", is nice to have.'));539 }540 541 /**542 * @ticket 4539543 */544 function test_quotes_before_s() {545 $this->assertEquals('test’s', wptexturize("test's"));546 $this->assertEquals('‘test’s', wptexturize("'test's"));547 $this->assertEquals('‘test’s’', wptexturize("'test's'"));548 $this->assertEquals('‘string’', wptexturize("'string'"));549 $this->assertEquals('‘string’s’', wptexturize("'string's'"));550 }551 552 /**553 * @ticket 4539554 */555 function test_quotes_before_numbers() {556 $this->assertEquals('Class of ’99', wptexturize("Class of '99"));557 $this->assertEquals('Class of ’99’s', wptexturize("Class of '99's"));558 $this->assertEquals('‘Class of ’99’', wptexturize("'Class of '99'"));559 $this->assertEquals('‘Class of ’99’s’', wptexturize("'Class of '99's'"));560 $this->assertEquals('‘Class of ’99’s’', wptexturize("'Class of '99’s'"));561 $this->assertEquals('“Class of 99”', wptexturize("\"Class of 99\""));562 $this->assertEquals('“Class of ’99”', wptexturize("\"Class of '99\""));563 }564 565 function test_quotes_after_numbers() {566 $this->assertEquals('Class of ’99', wptexturize("Class of '99"));567 }568 569 /**570 * @ticket 4539571 * @ticket 15241572 */573 function test_other_html() {574 $this->assertEquals('‘<strong>', wptexturize("'<strong>"));575 $this->assertEquals('‘<strong>Quoted Text</strong>’,', wptexturize("'<strong>Quoted Text</strong>',"));576 $this->assertEquals('“<strong>Quoted Text</strong>”,', wptexturize('"<strong>Quoted Text</strong>",'));577 }578 579 function test_x() {580 $this->assertEquals('14×24', wptexturize("14x24"));581 }582 583 function test_minutes_seconds() {584 $this->assertEquals('9′', wptexturize('9\''));585 $this->assertEquals('9″', wptexturize("9\""));586 587 $this->assertEquals('a 9′ b', wptexturize('a 9\' b'));588 $this->assertEquals('a 9″ b', wptexturize("a 9\" b"));589 590 $this->assertEquals('“a 9′ b”', wptexturize('"a 9\' b"'));591 $this->assertEquals('‘a 9″ b’', wptexturize("'a 9\" b'"));592 }593 594 /**595 * @ticket 8775596 */597 function test_wptexturize_quotes_around_numbers() {598 $this->assertEquals('“12345”', wptexturize('"12345"'));599 $this->assertEquals('‘12345’', wptexturize('\'12345\''));600 $this->assertEquals('“a 9′ plus a ‘9’, maybe a 9′ ‘9’ ”', wptexturize('"a 9\' plus a \'9\', maybe a 9\' \'9\' "'));601 $this->assertEquals('<p>‘99<br />‘123’<br />’tis<br />‘s’</p>', wptexturize('<p>\'99<br />\'123\'<br />\'tis<br />\'s\'</p>'));602 }603 604 /**605 * @ticket 8912606 */607 function test_wptexturize_html_comments() {608 $this->assertEquals('<!--[if !IE]>--><!--<![endif]-->', wptexturize('<!--[if !IE]>--><!--<![endif]-->'));609 $this->assertEquals('<!--[if !IE]>"a 9\' plus a \'9\', maybe a 9\' \'9\' "<![endif]-->', wptexturize('<!--[if !IE]>"a 9\' plus a \'9\', maybe a 9\' \'9\' "<![endif]-->'));610 $this->assertEquals('<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>', wptexturize('<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>'));611 }612 613 /**614 * @ticket 4539615 * @ticket 15241616 */617 function test_entity_quote_cuddling() {618 $this->assertEquals(' “Testing”', wptexturize(' "Testing"'));619 $this->assertEquals('&“Testing”', wptexturize('&"Testing"'));620 }621 }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 2 1305 3 /** … … 1309 7 * @group formatting 1310 8 */ 1311 class Test CleanPre extends WP_UnitTestCase {9 class Tests_Formatting_CleanPre extends WP_UnitTestCase { 1312 10 function test_removes_self_closing_br_with_space() { 1313 11 $source = 'a b c\n<br />sldfj<br />'; … … 1339 37 } 1340 38 } 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 } -
trunk/tests/formatting/ConvertChars.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 { 453 function test_dashes() { 454 $this->assertEquals('Hey — boo?', wptexturize('Hey -- boo?')); 455 $this->assertEquals('<a href="http://xx--xx">Hey — boo?</a>', wptexturize('<a href="http://xx--xx">Hey -- boo?</a>')); 456 } 457 458 function test_disable() { 459 $this->assertEquals('<pre>---</pre>', wptexturize('<pre>---</pre>')); 460 $this->assertEquals('[a]a–b[code]---[/code]a–b[/a]', wptexturize('[a]a--b[code]---[/code]a--b[/a]')); 461 $this->assertEquals('<pre><code></code>--</pre>', wptexturize('<pre><code></code>--</pre>')); 462 463 $this->assertEquals('<code>---</code>', wptexturize('<code>---</code>')); 464 465 $this->assertEquals('<code>href="baba"</code> “baba”', wptexturize('<code>href="baba"</code> "baba"')); 466 467 $enabled_tags_inside_code = '<code>curl -s <a href="http://x/">baba</a> | grep sfive | cut -d "\"" -f 10 > topmp3.txt</code>'; 468 $this->assertEquals($enabled_tags_inside_code, wptexturize($enabled_tags_inside_code)); 469 470 $double_nest = '<pre>"baba"<code>"baba"<pre></pre></code>"baba"</pre>'; 471 $this->assertEquals($double_nest, wptexturize($double_nest)); 472 473 $invalid_nest = '<pre></code>"baba"</pre>'; 474 $this->assertEquals($invalid_nest, wptexturize($invalid_nest)); 475 476 } 477 478 //WP Ticket #1418 479 function test_bracketed_quotes_1418() { 480 $this->assertEquals('(“test”)', wptexturize('("test")')); 481 $this->assertEquals('(‘test’)', wptexturize("('test')")); 482 $this->assertEquals('(’twas)', wptexturize("('twas)")); 483 } 484 485 //WP Ticket #3810 486 function test_bracketed_quotes_3810() { 487 $this->assertEquals('A dog (“Hubertus”) was sent out.', wptexturize('A dog ("Hubertus") was sent out.')); 488 } 489 490 //WP Ticket #4539 491 function test_basic_quotes() { 492 $this->assertEquals('test’s', wptexturize('test\'s')); 493 $this->assertEquals('test’s', wptexturize('test\'s')); 494 495 $this->assertEquals('‘quoted’', wptexturize('\'quoted\'')); 496 $this->assertEquals('“quoted”', wptexturize('"quoted"')); 497 498 $this->assertEquals('space before ‘quoted’ space after', wptexturize('space before \'quoted\' space after')); 499 $this->assertEquals('space before “quoted” space after', wptexturize('space before "quoted" space after')); 500 501 $this->assertEquals('(‘quoted’)', wptexturize('(\'quoted\')')); 502 $this->assertEquals('{“quoted”}', wptexturize('{"quoted"}')); 503 504 $this->assertEquals('‘qu(ot)ed’', wptexturize('\'qu(ot)ed\'')); 505 $this->assertEquals('“qu{ot}ed”', wptexturize('"qu{ot}ed"')); 506 507 $this->assertEquals(' ‘test’s quoted’ ', wptexturize(' \'test\'s quoted\' ')); 508 $this->assertEquals(' “test’s quoted” ', wptexturize(' "test\'s quoted" ')); 509 } 510 511 /** 512 * @ticket 4539 513 * @ticket 15241 514 */ 515 function test_full_sentences_with_unmatched_single_quotes() { 516 $this->assertEquals( 517 'That means every moment you’re working on something without it being in the public it’s actually dying.', 518 wptexturize("That means every moment you're working on something without it being in the public it's actually dying.") 519 ); 520 } 521 522 /** 523 * @ticket 4539 524 */ 525 function test_quotes() { 526 $this->assertEquals('“Quoted String”', wptexturize('"Quoted String"')); 527 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"')); 528 $this->assertEquals('Here is “<a href="http://example.com">a test with a link and a period</a>”.', wptexturize('Here is "<a href="http://example.com">a test with a link and a period</a>".')); 529 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>” and a space.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>" and a space.')); 530 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a> and some text quoted”', wptexturize('Here is "<a href="http://example.com">a test with a link</a> and some text quoted"')); 531 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”, and a comma.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>", and a comma.')); 532 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”; and a semi-colon.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"; and a semi-colon.')); 533 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”- and a dash.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"- and a dash.')); 534 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”… and ellipses.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"... and ellipses.')); 535 $this->assertEquals('Here is “a test <a href="http://example.com">with a link</a>”.', wptexturize('Here is "a test <a href="http://example.com">with a link</a>".')); 536 $this->assertEquals('Here is “<a href="http://example.com">a test with a link</a>”and a work stuck to the end.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"and a work stuck to the end.')); 537 $this->assertEquals('A test with a finishing number, “like 23”.', wptexturize('A test with a finishing number, "like 23".')); 538 $this->assertEquals('A test with a number, “like 62”, is nice to have.', wptexturize('A test with a number, "like 62", is nice to have.')); 539 } 540 541 /** 542 * @ticket 4539 543 */ 544 function test_quotes_before_s() { 545 $this->assertEquals('test’s', wptexturize("test's")); 546 $this->assertEquals('‘test’s', wptexturize("'test's")); 547 $this->assertEquals('‘test’s’', wptexturize("'test's'")); 548 $this->assertEquals('‘string’', wptexturize("'string'")); 549 $this->assertEquals('‘string’s’', wptexturize("'string's'")); 550 } 551 552 /** 553 * @ticket 4539 554 */ 555 function test_quotes_before_numbers() { 556 $this->assertEquals('Class of ’99', wptexturize("Class of '99")); 557 $this->assertEquals('Class of ’99’s', wptexturize("Class of '99's")); 558 $this->assertEquals('‘Class of ’99’', wptexturize("'Class of '99'")); 559 $this->assertEquals('‘Class of ’99’s’', wptexturize("'Class of '99's'")); 560 $this->assertEquals('‘Class of ’99’s’', wptexturize("'Class of '99’s'")); 561 $this->assertEquals('“Class of 99”', wptexturize("\"Class of 99\"")); 562 $this->assertEquals('“Class of ’99”', wptexturize("\"Class of '99\"")); 563 } 564 565 function test_quotes_after_numbers() { 566 $this->assertEquals('Class of ’99', wptexturize("Class of '99")); 567 } 568 569 /** 570 * @ticket 4539 571 * @ticket 15241 572 */ 573 function test_other_html() { 574 $this->assertEquals('‘<strong>', wptexturize("'<strong>")); 575 $this->assertEquals('‘<strong>Quoted Text</strong>’,', wptexturize("'<strong>Quoted Text</strong>',")); 576 $this->assertEquals('“<strong>Quoted Text</strong>”,', wptexturize('"<strong>Quoted Text</strong>",')); 577 } 578 579 function test_x() { 580 $this->assertEquals('14×24', wptexturize("14x24")); 581 } 582 583 function test_minutes_seconds() { 584 $this->assertEquals('9′', wptexturize('9\'')); 585 $this->assertEquals('9″', wptexturize("9\"")); 586 587 $this->assertEquals('a 9′ b', wptexturize('a 9\' b')); 588 $this->assertEquals('a 9″ b', wptexturize("a 9\" b")); 589 590 $this->assertEquals('“a 9′ b”', wptexturize('"a 9\' b"')); 591 $this->assertEquals('‘a 9″ b’', wptexturize("'a 9\" b'")); 592 } 593 594 /** 595 * @ticket 8775 596 */ 597 function test_wptexturize_quotes_around_numbers() { 598 $this->assertEquals('“12345”', wptexturize('"12345"')); 599 $this->assertEquals('‘12345’', wptexturize('\'12345\'')); 600 $this->assertEquals('“a 9′ plus a ‘9’, maybe a 9′ ‘9’ ”', wptexturize('"a 9\' plus a \'9\', maybe a 9\' \'9\' "')); 601 $this->assertEquals('<p>‘99<br />‘123’<br />’tis<br />‘s’</p>', wptexturize('<p>\'99<br />\'123\'<br />\'tis<br />\'s\'</p>')); 602 } 603 604 /** 605 * @ticket 8912 606 */ 607 function test_wptexturize_html_comments() { 608 $this->assertEquals('<!--[if !IE]>--><!--<![endif]-->', wptexturize('<!--[if !IE]>--><!--<![endif]-->')); 609 $this->assertEquals('<!--[if !IE]>"a 9\' plus a \'9\', maybe a 9\' \'9\' "<![endif]-->', wptexturize('<!--[if !IE]>"a 9\' plus a \'9\', maybe a 9\' \'9\' "<![endif]-->')); 610 $this->assertEquals('<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>', wptexturize('<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>')); 611 } 612 613 /** 614 * @ticket 4539 615 * @ticket 15241 616 */ 617 function test_entity_quote_cuddling() { 618 $this->assertEquals(' “Testing”', wptexturize(' "Testing"')); 619 $this->assertEquals('&“Testing”', wptexturize('&"Testing"')); 620 } 621 } 622 623 /** 624 * @group formatting 625 */ 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 Checks 638 $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 16859 679 */ 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 - RFC2732 684 $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 formatting 692 */ 693 class TestAutop extends WP_UnitTestCase { 694 //From ticket http://core.trac.wordpress.org/ticket/11008 695 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\n 747 $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>" elements 754 * 755 * @ticket 19855 756 */ 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> tags 763 $str = "<pre>$code</pre>"; 764 $this->assertEquals( $str, trim( wpautop( $str ) ) ); 765 766 // Text before/after is wrapped in <p> tags 767 $str = "Look at this code\n\n<pre>$code</pre>\n\nIsn't that cool?"; 768 769 // Expected text after wpautop 770 $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 inserted 774 $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>" elements 781 * 782 * @ticket 16456 783 */ 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 formatting 792 */ 793 class TestLikeEscape extends WP_UnitTestCase { 794 /** 795 * @ticket 10041 796 */ 797 function test_like_escape() { 798 799 $inputs = array( 800 'howdy%', //Single Percent 801 'howdy_', //Single Underscore 802 'howdy\\', //Single slash 803 'howdy\\howdy%howdy_', //The works 804 ); 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 formatting 820 */ 821 class TestSanitizeTextField extends WP_UnitTestCase { 822 // #11528 823 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 welcome 833 here', 834 'We also %AB remove %ab octets', 835 'We don\'t need to wory about %A 836 B removing %a 837 b octets even when %a B they are obscured by whitespace', 838 '%AB%BC%DE', //Just octets 839 '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 out 854 '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 formatting 866 */ 867 class TestSanitizeMimeType extends WP_UnitTestCase { 868 // 17855 869 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 formatting 903 */ 904 class TestSanitizeFileName extends WP_UnitTestCase { 905 function test_munges_extensions() { 906 # r17990 907 $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 formatting 936 */ 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 unchanged 950 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 formatting 977 */ 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 formatting 1008 */ 1009 class TestEscHtml extends WP_UnitTestCase { 1010 function test_esc_html_basics() { 1011 // Simple string 1012 $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 query 1021 $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 formatting 1047 */ 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 10823 1056 */ 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 formatting 1073 */ 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 formatting 1103 */ 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 formatting 1120 */ 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 10823 1155 */ 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 19820 1203 */ 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 20772 1210 */ 1211 function test_replaces_standalone_diacritic() { 1212 $this->assertEquals("aaaa", sanitize_title_with_dashes("āáǎà", '', 'save')); 1213 } 1214 1215 } 1216 1217 /** 1218 * @group formatting 1219 */ 1220 class TestConvertChars extends WP_UnitTestCase { 6 class Tests_Formatting_ConvertChars extends WP_UnitTestCase { 1221 7 function test_replaces_windows1252_entities_with_unicode_ones() { 1222 8 $input = "‚ƒ„…†‡ˆ‰Š‹Œ‘’“”•–—˜™š›œŸ"; … … 1253 39 } 1254 40 } 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;