http://example.com/
', ); $urls_expected = array( 'http://example.com', '', ); foreach ($urls_before as $key => $url) { $this->assertEquals( $urls_expected[$key], make_clickable( $url ) ); } } function test_no_links_within_links() { $in = array( 'Some text with a link http://example.com', //'This is already a link www.wordpress.org', // fails in 3.3.1 too ); foreach ( $in as $text ) { $this->assertEquals( $text, make_clickable( $text ) ); } } /** * @ticket 16892 */ function test_no_segfault() { if ( version_compare( $GLOBALS['wp_version'], '3.1.1', '<' ) ) $this->markTestSkipped(); $in = str_repeat( 'http://example.com/2011/03/18/post-title/', 256 ); $out = make_clickable( $in ); if ( version_compare( $GLOBALS['wp_version'], '3.4-alpha', '>=' ) ) $this->assertEquals( $in, $out ); } } class TestJSEscape extends WPTestCase { function test_js_escape_simple() { $out = esc_js('foo bar baz();'); $this->assertEquals('foo bar baz();', $out); } function test_js_escape_quotes() { $out = esc_js('foo "bar" \'baz\''); // does it make any sense to change " into "? Why not \"? $this->assertEquals("foo "bar" \'baz\'", $out); } function test_js_escape_backslash() { $bs = '\\'; $out = esc_js('foo '.$bs.'t bar '.$bs.$bs.' baz'); // \t becomes t - bug? $this->assertEquals('foo t bar '.$bs.$bs.' baz', $out); } function test_js_escape_amp() { $out = esc_js('foo & bar &baz; ''); $this->assertEquals("foo & bar &baz; '", $out); } function test_js_escape_quote_entity() { $out = esc_js('foo ' bar ' baz &'); $this->assertEquals("foo \\' bar \\' baz &", $out); } function test_js_no_carriage_return() { $out = esc_js("foo\rbar\nbaz\r"); // \r is stripped $this->assertequals("foobar\\nbaz", $out); } function test_js_escape_rn() { $out = esc_js("foo\r\nbar\nbaz\r\n"); // \r is stripped $this->assertequals("foo\\nbar\\nbaz\\n", $out); } } class TestHtmlExcerpt extends WPTestCase { function test_simple() { $this->assertEquals("Baba", wp_html_excerpt("Baba told me not to come", 4)); } function test_html() { $this->assertEquals("Baba", wp_html_excerpt("Baba told me not to come", 4)); } function test_entities() { $this->assertEquals("Baba ", wp_html_excerpt("Baba & Dyado", 8)); $this->assertEquals("Baba ", wp_html_excerpt("Baba & Dyado", 8)); $this->assertEquals("Baba & D", wp_html_excerpt("Baba & Dyado", 12)); $this->assertEquals("Baba & Dyado", wp_html_excerpt("Baba & Dyado", 100)); } } /* // @todo These tests need to be rewritten for sanitize_sql_orderby class TestSanitizeOrderby extends WPTestCase { function test_empty() { $cols = array('a' => 'a'); $this->assertEquals( '', sanitize_sql_orderby('', $cols) ); $this->assertEquals( '', sanitize_sql_orderby(' ', $cols) ); $this->assertEquals( '', sanitize_sql_orderby("\t", $cols) ); $this->assertEquals( '', sanitize_sql_orderby(null, $cols) ); $this->assertEquals( '', sanitize_sql_orderby(0, $cols) ); $this->assertEquals( '', sanitize_sql_orderby('+', $cols) ); $this->assertEquals( '', sanitize_sql_orderby('-', $cols) ); } function test_unknown_column() { $cols = array('name' => 'post_name', 'date' => 'post_date'); $this->assertEquals( '', sanitize_sql_orderby('unknown_column', $cols) ); $this->assertEquals( '', sanitize_sql_orderby('+unknown_column', $cols) ); $this->assertEquals( '', sanitize_sql_orderby('-unknown_column', $cols) ); $this->assertEquals( '', sanitize_sql_orderby('-unknown1,+unknown2,unknown3', $cols) ); $this->assertEquals( 'post_name ASC', sanitize_sql_orderby('name,unknown_column', $cols) ); $this->assertEquals( '', sanitize_sql_orderby('!@#$%^&*()_=~`\'",./', $cols) ); } function test_valid() { $cols = array('name' => 'post_name', 'date' => 'post_date', 'random' => 'rand()'); $this->assertEquals( 'post_name ASC', sanitize_sql_orderby('name', $cols) ); $this->assertEquals( 'post_name ASC', sanitize_sql_orderby('+name', $cols) ); $this->assertEquals( 'post_name DESC', sanitize_sql_orderby('-name', $cols) ); $this->assertEquals( 'post_date ASC, post_name ASC', sanitize_sql_orderby('date,name', $cols) ); $this->assertEquals( 'post_date ASC, post_name ASC', sanitize_sql_orderby(' date , name ', $cols) ); $this->assertEquals( 'post_name DESC, post_date ASC', sanitize_sql_orderby('-name,date', $cols) ); $this->assertEquals( 'post_name ASC, post_date ASC', sanitize_sql_orderby('name ,+ date', $cols) ); $this->assertEquals( 'rand() ASC', sanitize_sql_orderby('random', $cols) ); } } */ class TestWPTexturize extends WPTestCase { function test_dashes() { $this->assertEquals('Hey — boo?', wptexturize('Hey -- boo?')); $this->assertEquals('Hey — boo?', wptexturize('Hey -- boo?')); } function test_disable() { $this->assertEquals('---', wptexturize('
---')); $this->assertEquals('[a]a–b[code]---[/code]a–b[/a]', wptexturize('[a]a--b[code]---[/code]a--b[/a]')); $this->assertEquals('
--', wptexturize('--'));
$this->assertEquals('---', wptexturize('---'));
$this->assertEquals('href="baba" “baba”', wptexturize('href="baba" "baba"'));
$enabled_tags_inside_code = 'curl -s baba | grep sfive | cut -d "\"" -f 10 > topmp3.txt';
$this->assertEquals($enabled_tags_inside_code, wptexturize($enabled_tags_inside_code));
$double_nest = '"baba""baba""baba"';
$this->assertEquals($double_nest, wptexturize($double_nest));
$invalid_nest = '"baba"'; $this->assertEquals($invalid_nest, wptexturize($invalid_nest)); } //WP Ticket #1418 function test_bracketed_quotes_1418() { $this->assertEquals('(“test”)', wptexturize('("test")')); $this->assertEquals('(‘test’)', wptexturize("('test')")); $this->assertEquals('(’twas)', wptexturize("('twas)")); } //WP Ticket #3810 function test_bracketed_quotes_3810() { $this->assertEquals('A dog (“Hubertus”) was sent out.', wptexturize('A dog ("Hubertus") was sent out.')); } //WP Ticket #4539 function test_basic_quotes() { $this->assertEquals('test’s', wptexturize('test\'s')); $this->assertEquals('test’s', wptexturize('test\'s')); $this->assertEquals('‘quoted’', wptexturize('\'quoted\'')); $this->assertEquals('“quoted”', wptexturize('"quoted"')); $this->assertEquals('space before ‘quoted’ space after', wptexturize('space before \'quoted\' space after')); $this->assertEquals('space before “quoted” space after', wptexturize('space before "quoted" space after')); $this->assertEquals('(‘quoted’)', wptexturize('(\'quoted\')')); $this->assertEquals('{“quoted”}', wptexturize('{"quoted"}')); $this->assertEquals('‘qu(ot)ed’', wptexturize('\'qu(ot)ed\'')); $this->assertEquals('“qu{ot}ed”', wptexturize('"qu{ot}ed"')); $this->assertEquals(' ‘test’s quoted’ ', wptexturize(' \'test\'s quoted\' ')); $this->assertEquals(' “test’s quoted” ', wptexturize(' "test\'s quoted" ')); } //WP Tickets #4539, #15241 function test_full_sentences_with_unmatched_single_quotes() { $this->assertEquals( 'That means every moment you’re working on something without it being in the public it’s actually dying.', wptexturize("That means every moment you're working on something without it being in the public it's actually dying.") ); } //WP Ticket #4539 function test_quotes() { $this->knownWPBug(4539); $this->assertEquals('“Quoted String”', wptexturize('"Quoted String"')); $this->assertEquals('Here is “a test with a link”', wptexturize('Here is "a test with a link"')); $this->assertEquals('Here is “a test with a link and a period”.', wptexturize('Here is "a test with a link and a period".')); $this->assertEquals('Here is “a test with a link” and a space.', wptexturize('Here is "a test with a link" and a space.')); $this->assertEquals('Here is “a test with a link and some text quoted”', wptexturize('Here is "a test with a link and some text quoted"')); $this->assertEquals('Here is “a test with a link”, and a comma.', wptexturize('Here is "a test with a link", and a comma.')); $this->assertEquals('Here is “a test with a link”; and a semi-colon.', wptexturize('Here is "a test with a link"; and a semi-colon.')); $this->assertEquals('Here is “a test with a link”- and a dash.', wptexturize('Here is "a test with a link"- and a dash.')); $this->assertEquals('Here is “a test with a link”… and ellipses.', wptexturize('Here is "a test with a link"... and ellipses.')); $this->assertEquals('Here is “a test with a link”.', wptexturize('Here is "a test with a link".')); $this->assertEquals('Here is “a test with a link”and a work stuck to the end.', wptexturize('Here is "a test with a link"and a work stuck to the end.')); $this->assertEquals('A test with a finishing number, “like 23”.', wptexturize('A test with a finishing number, "like 23".')); $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.')); } //WP Ticket #4539 function test_quotes_before_s() { $this->knownWPBug(4539); $this->assertEquals('test’s', wptexturize("test's")); $this->assertEquals('‘test’s', wptexturize("'test's")); $this->assertEquals('‘test’s’', wptexturize("'test's'")); $this->assertEquals('‘string’', wptexturize("'string'")); $this->assertEquals('‘string’s’', wptexturize("'string's'")); } //WP Ticket #4539 function test_quotes_before_numbers() { $this->knownWPBug(4539); $this->assertEquals('Class of ’99', wptexturize("Class of '99")); $this->assertEquals('Class of ’99’s', wptexturize("Class of '99's")); $this->assertEquals('‘Class of ’99’', wptexturize("'Class of '99'")); $this->assertEquals('‘Class of ’99’s’', wptexturize("'Class of '99's'")); $this->assertEquals('‘Class of ’99’s’', wptexturize("'Class of '99’s'")); $this->assertEquals('“Class of 99”', wptexturize("\"Class of 99\"")); $this->assertEquals('“Class of ’99”', wptexturize("\"Class of '99\"")); } function test_quotes_after_numbers() { $this->assertEquals('Class of ’99', wptexturize("Class of '99")); } //WP Ticket #15241 and #4539 function test_other_html() { $this->knownWPBug(4539); $this->assertEquals('‘', wptexturize("'")); $this->assertEquals('‘Quoted Text’,', wptexturize("'Quoted Text',")); $this->assertEquals('“Quoted Text”,', wptexturize('"Quoted Text",')); } function test_x() { $this->assertEquals('14×24', wptexturize("14x24")); } function test_minutes_seconds() { $this->assertEquals('9′', wptexturize('9\'')); $this->assertEquals('9″', wptexturize("9\"")); $this->assertEquals('a 9′ b', wptexturize('a 9\' b')); $this->assertEquals('a 9″ b', wptexturize("a 9\" b")); $this->assertEquals('“a 9′ b”', wptexturize('"a 9\' b"')); $this->assertEquals('‘a 9″ b’', wptexturize("'a 9\" b'")); } //WP Ticket #15241 and #4539 function test_entity_quote_cuddling() { $this->knownWPBug(4539); $this->assertEquals(' “Testing”', wptexturize(' "Testing"')); $this->assertEquals('&“Testing”', wptexturize('&"Testing"')); } } class TestCleanUrl extends WPTestCase { function test_spaces() { $this->assertEquals('http://example.com/MrWordPress', esc_url('http://example.com/Mr WordPress')); $this->assertEquals('http://example.com/Mr%20WordPress', esc_url('http://example.com/Mr%20WordPress')); } function test_bad_characters() { $this->assertEquals('http://example.com/watchthelinefeedgo', esc_url('http://example.com/watchthelinefeed%0Ago')); $this->assertEquals('http://example.com/watchthelinefeedgo', esc_url('http://example.com/watchthelinefeed%0ago')); $this->assertEquals('http://example.com/watchthecarriagereturngo', esc_url('http://example.com/watchthecarriagereturn%0Dgo')); $this->assertEquals('http://example.com/watchthecarriagereturngo', esc_url('http://example.com/watchthecarriagereturn%0dgo')); //Nesting Checks $this->assertEquals('http://example.com/watchthecarriagereturngo', esc_url('http://example.com/watchthecarriagereturn%0%0ddgo')); $this->assertEquals('http://example.com/watchthecarriagereturngo', esc_url('http://example.com/watchthecarriagereturn%0%0DDgo')); $this->assertEquals('http://example.com/', esc_url('http://example.com/%0%0%0DAD')); $this->assertEquals('http://example.com/', esc_url('http://example.com/%0%0%0ADA')); $this->assertEquals('http://example.com/', esc_url('http://example.com/%0%0%0DAd')); $this->assertEquals('http://example.com/', esc_url('http://example.com/%0%0%0ADa')); } function test_relative() { $this->assertEquals('/example.php', esc_url('/example.php')); $this->assertEquals('example.php', esc_url('example.php')); $this->assertEquals('#fragment', esc_url('#fragment')); $this->assertEquals('?foo=bar', esc_url('?foo=bar')); } function test_protocol() { $this->assertEquals('http://example.com', esc_url('http://example.com')); $this->assertEquals('', esc_url('nasty://example.com/')); } function test_display_extras() { $this->assertEquals('http://example.com/'quoted'', esc_url('http://example.com/\'quoted\'')); $this->assertEquals('http://example.com/\'quoted\'', esc_url('http://example.com/\'quoted\'',null,'notdisplay')); } function test_non_ascii() { $this->assertEquals( 'http://example.org/баба', esc_url( 'http://example.org/баба' ) ); $this->assertEquals( 'http://баба.org/баба', esc_url( 'http://баба.org/баба' ) ); $this->assertEquals( 'http://müller.com/', esc_url( 'http://müller.com/' ) ); } function test_feed() { $this->assertEquals( '', esc_url( 'feed:javascript:alert(1)' ) ); $this->assertEquals( '', esc_url( 'feed:javascript:feed:alert(1)' ) ); $this->assertEquals( '', esc_url( 'feed:feed:javascript:alert(1)' ) ); $this->assertEquals( 'feed:feed:alert(1)', esc_url( 'feed:feed:alert(1)' ) ); $this->assertEquals( 'feed:http://wordpress.org/feed/', esc_url( 'feed:http://wordpress.org/feed/' ) ); } } class TestAutop extends WPTestCase { //From ticket http://core.trac.wordpress.org/ticket/11008 function test_first_post() { $expected = '
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.
First things first:
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.
When a new version is released, log in to the Dashboard and follow the instructions.
Upgrading is a couple of clicks!
Then you can start enjoying the WordPress experience:
To keep this post for reference, click to edit it, go to the Publish box and change its Visibility from Public to Private.
Thank you for selecting WordPress. We wish you happy publishing!
PS. Not yet subscribed for update notifications? Do it now!
'; $test_data = ' 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. First things first: 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. When a new version is released, log in to the Dashboard and follow the instructions. Upgrading is a couple of clicks! Then you can start enjoying the WordPress experience:" elements
* @link http://core.trac.wordpress.org/ticket/19855
* @return void
*/
public function test_skip_pre_elements() {
$this->knownWPBug( 19855 );
$code = file_get_contents( realpath( dirname( __FILE__ ) . '/../wp-testdata/formatting/sizzle.js' ) );
$code = str_replace( "\r", '', $code );
$code = htmlentities( $code );
// Not wrapped in tags
$str = "
$code
";
$this->assertEquals( $str, trim( wpautop( $str ) ) );
// Text before/after is wrapped in tags
$str = "Look at this code\n\n
$code
\n\nIsn't that cool?";
// Expected text after wpautop
$expected = 'Look at this code
' . "\n" . $code . "
\n" . 'Isn\'t that cool?
';
$this->assertEquals( $expected, trim( wpautop( $str ) ) );
// Make sure HTML breaks are maintained if manually inserted
$str = "Look at this code\n\nLine1
Line2
Line3
Line4\nActual Line 2\nActual Line 3
\n\nCool, huh?";
$expected = "Look at this code
\nLine1
Line2
Line3
Line4\nActual Line 2\nActual Line 3
\nCool, huh?
";
$this->assertEquals( $expected, trim( wpautop( $str ) ) );
}
/**
* wpautop() Should not add
to "" elements
* @link http://core.trac.wordpress.org/ticket/16456
* @return void
*/
public function test_skip_input_elements() {
$this->knownWPBug( 16456 );
$str = 'Username:
Password: ';
$this->assertEquals( "$str
", trim( wpautop( $str ) ) );
}
}
class TestLikeEscape extends WPTestCase {
function test_like_escape() {
$this->knownWPBug(10041);
$inputs = array(
'howdy%', //Single Percent
'howdy_', //Single Underscore
'howdy\\', //Single slash
'howdy\\howdy%howdy_', //The works
);
$expected = array(
"howdy\\%",
'howdy\\_',
'howdy\\\\',
'howdy\\\\howdy\\%howdy\\_'
);
foreach ($inputs as $key => $input) {
$this->assertEquals($expected[$key], like_escape($input));
}
}
}
class TestSanitizeTextField extends WPTestCase {
// #11528
function test_sanitize_text_field() {
$inputs = array(
'оРангутанг', //Ensure UTF8 text is safe the Р is D0 A0 and A0 is the non-breaking space.
'САПР', //Ensure UTF8 text is safe the Р is D0 A0 and A0 is the non-breaking space.
'one is < two',
'tags are not allowed here',
' we should trim leading and trailing whitespace ',
'we also trim extra internal whitespace',
'tabs get removed too',
'newlines are not welcome
here',
'We also %AB remove %ab octets',
'We don\'t need to wory about %A
B removing %a
b octets even when %a B they are obscured by whitespace',
'%AB%BC%DE', //Just octets
'Invalid octects remain %II',
'Nested octects %%%ABABAB %A%A%ABBB',
);
$expected = array(
'оРангутанг',
'САПР',
'one is < two',
'tags are not allowed here',
'we should trim leading and trailing whitespace',
'we also trim extra internal whitespace',
'tabs get removed too',
'newlines are not welcome here',
'We also remove octets',
'We don\'t need to wory about %A B removing %a b octets even when %a B they are obscured by whitespace',
'', //Emtpy as we strip all the octets out
'Invalid octects remain %II',
'Nested octects',
);
foreach ($inputs as $key => $input) {
$this->assertEquals($expected[$key], sanitize_text_field($input));
}
}
}
class TestSanitizeMimeType extends WPTestCase {
// 17855
function test_sanitize_valid_mime_type() {
$inputs = array(
'application/atom+xml',
'application/EDI-X12',
'application/EDIFACT',
'application/json',
'application/javascript',
'application/octet-stream',
'application/ogg',
'application/pdf',
'application/postscript',
'application/soap+xml',
'application/x-woff',
'application/xhtml+xml',
'application/xml-dtd',
'application/xop+xml',
'application/zip',
'application/x-gzip',
'audio/basic',
'image/jpeg',
'text/css',
'text/html',
'text/plain',
'video/mpeg',
);
foreach ( $inputs as $input ) {
$this->assertEquals($input, sanitize_mime_type($input));
}
}
}
class TestSanitizeFileName extends WPTestCase {
function test_munges_extensions() {
# r17990
$file_name = sanitize_file_name( 'test.phtml.txt' );
$this->assertEquals( 'test.phtml_.txt', $file_name );
}
function test_removes_special_chars() {
$special_chars = array("?", "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "'", "\"", "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}", chr(0));
$string = 'test';
foreach ( $special_chars as $char )
$string .= $char;
$string .= 'test';
$this->assertEquals( 'testtest', sanitize_file_name( $string ) );
}
function test_replaces_any_number_of_hyphens_with_one_hyphen() {
$this->assertEquals("a-t-t", sanitize_file_name("a----t----t"));
}
function test_trims_trailing_hyphens() {
$this->assertEquals("a-t-t", sanitize_file_name("a----t----t----"));
}
function test_replaces_any_amount_of_whitespace_with_one_hyphen() {
$this->assertEquals("a-t", sanitize_file_name("a t"));
$this->assertEquals("a-t", sanitize_file_name("a \n\n\nt"));
}
}
class TestWPSpecialchars extends WPTestCase {
function test_wp_specialchars_basics() {
$html = "&<hello world>";
$this->assertEquals( $html, _wp_specialchars( $html ) );
$double = "&<hello world>";
$this->assertEquals( $double, _wp_specialchars( $html, ENT_NOQUOTES, false, true ) );
}
function test_allowed_entity_names() {
global $allowedentitynames;
// Allowed entities should be unchanged
foreach ( $allowedentitynames as $ent ) {
$ent = '&' . $ent . ';';
$this->assertEquals( $ent, _wp_specialchars( $ent ) );
}
}
function test_not_allowed_entity_names() {
$ents = array( 'iacut', 'aposs', 'pos', 'apo', 'apo?', 'apo.*', '.*apo.*', 'apos ', ' apos', ' apos ' );
foreach ( $ents as $ent ) {
$escaped = '&' . $ent . ';';
$ent = '&' . $ent . ';';
$this->assertEquals( $escaped, _wp_specialchars( $ent ) );
}
}
function test_optionally_escapes_quotes() {
$source = "\"'hello!'\"";
$this->assertEquals( '"'hello!'"', _wp_specialchars($source, 'single') );
$this->assertEquals( ""'hello!'"", _wp_specialchars($source, 'double') );
$this->assertEquals( '"'hello!'"', _wp_specialchars($source, true) );
$this->assertEquals( $source, _wp_specialchars($source) );
}
}
class TestEscAttr extends WPTestCase {
function test_esc_attr_quotes() {
$attr = '"double quotes"';
$this->assertEquals( '"double quotes"', esc_attr( $attr ) );
$attr = "'single quotes'";
$this->assertEquals( ''single quotes'', esc_attr( $attr ) );
$attr = "'mixed' " . '"quotes"';
$this->assertEquals( ''mixed' "quotes"', esc_attr( $attr ) );
// Handles double encoding?
$attr = '"double quotes"';
$this->assertEquals( '"double quotes"', esc_attr( esc_attr( $attr ) ) );
$attr = "'single quotes'";
$this->assertEquals( ''single quotes'', esc_attr( esc_attr( $attr ) ) );
$attr = "'mixed' " . '"quotes"';
$this->assertEquals( ''mixed' "quotes"', esc_attr( esc_attr( $attr ) ) );
}
function test_esc_attr_amp() {
$out = esc_attr( 'foo & bar &baz; '' );
$this->assertEquals( "foo & bar &baz; '", $out );
}
}
class TestEscHtml extends WPTestCase {
function test_esc_html_basics() {
// Simple string
$html = "The quick brown fox.";
$this->assertEquals( $html, esc_html( $html ) );
// URL with &
$html = "http://localhost/trunk/wp-login.php?action=logout&_wpnonce=cd57d75985";
$escaped = "http://localhost/trunk/wp-login.php?action=logout&_wpnonce=cd57d75985";
$this->assertEquals( $escaped, esc_html( $html ) );
// SQL query
$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";
$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";
$this->assertEquals( $escaped, esc_html( $html ) );
}
function test_escapes_ampersands() {
$source = "penn & teller & at&t";
$res = "penn & teller & at&t";
$this->assertEquals( $res, esc_html($source) );
}
function test_escapes_greater_and_less_than() {
$source = "this > that < that ";
$res = "this > that < that <randomhtml />";
$this->assertEquals( $res, esc_html($source) );
}
function test_ignores_existing_entities() {
$source = '& £ " &';
$res = '& £ " &';
$this->assertEquals( $res, esc_html($source) );
}
}
class TestSanitizeUser extends WPTestCase {
function test_strips_html() {
$input = "Captain Awesome";
$expected = is_multisite() ? 'captain awesome' : 'Captain Awesome';
$this->assertEquals($expected, sanitize_user($input));
}
function test_strips_entities() {
$this->knownWPBug( 10823 );
$this->assertEquals("ATT", sanitize_user("AT&T"));
$this->assertEquals("ATT Test;", sanitize_user("AT&T Test;"));
$this->assertEquals("AT&T Test;", sanitize_user("AT&T Test;"));
}
function test_strips_percent_encoded_octets() {
$expected = is_multisite() ? 'franois' : 'Franois';
$this->assertEquals( $expected, sanitize_user( "Fran%c3%a7ois" ) );
}
function test_optional_strict_mode_reduces_to_safe_ascii_subset() {
$this->assertEquals("abc", sanitize_user("()~ab~ˆcˆ!", true));
}
}
class TestIsEmail extends WPTestCase {
function test_returns_true_if_given_a_valid_email_address() {
$data = array(
"bob@example.com",
"phil@example.info",
"ace@204.32.222.14",
"kevin@many.subdomains.make.a.happy.man.edu"
);
foreach ( $data as $datum ) {
$this->assertEquals( $datum, is_email($datum), $datum );
}
}
function test_returns_false_if_given_an_invalid_email_address() {
$data = array(
"khaaaaaaaaaaaaaaan!",
'http://bob.example.com/',
"sif i'd give u it, spamer!1",
"com.exampleNOSPAMbob",
"bob@your mom"
);
foreach ($data as $datum) {
$this->assertFalse(is_email($datum), $datum);
}
}
}
class TestSanitizeTitle extends WPTestCase {
function test_strips_html() {
$input = "Captain Awesome";
$expected = "captain-awesome";
$this->assertEquals($expected, sanitize_title($input));
}
function test_titles_sanitized_to_nothing_are_replaced_with_optional_fallback() {
$input = "";
$fallback = "Captain Awesome";
$this->assertEquals($fallback, sanitize_title($input, $fallback));
}
}
class TestSanitizeTitleWithDashes extends WPTestCase {
function test_strips_html() {
$input = "Captain Awesome";
$expected = "captain-awesome";
$this->assertEquals($expected, sanitize_title($input));
}
function test_strips_unencoded_percent_signs() {
$this->assertEquals("fran%c3%a7ois", sanitize_title_with_dashes("fran%c3%a7%ois"));
}
function test_makes_title_lowercase() {
$this->assertEquals("abc", sanitize_title_with_dashes("ABC"));
}
function test_replaces_any_amount_of_whitespace_with_one_hyphen() {
$this->assertEquals("a-t", sanitize_title_with_dashes("a t"));
$this->assertEquals("a-t", sanitize_title_with_dashes("a \n\n\nt"));
}
function test_replaces_any_number_of_hyphens_with_one_hyphen() {
$this->assertEquals("a-t-t", sanitize_title_with_dashes("a----t----t"));
}
function test_trims_trailing_hyphens() {
$this->assertEquals("a-t-t", sanitize_title_with_dashes("a----t----t----"));
}
function test_handles_non_entity_ampersands() {
$this->assertEquals("penn-teller-bull", sanitize_title_with_dashes("penn & teller bull"));
}
function test_strips_entities() {
$this->knownWPBug( 10823 );
$this->assertEquals("no-entities-here", sanitize_title_with_dashes("No Entities – Here &"));
$this->assertEquals("one-two", sanitize_title_with_dashes("One & Two", '', 'save'));
$this->assertEquals("one-two", sanitize_title_with_dashes("One { Two;", '', 'save'));
$this->assertEquals("one-two", sanitize_title_with_dashes("One & Two;", '', 'save'));
$this->assertEquals("one-two", sanitize_title_with_dashes("One Two™;", '', 'save'));
$this->assertEquals("one-two", sanitize_title_with_dashes("One && Two;", '', 'save'));
$this->assertEquals("onetwo", sanitize_title_with_dashes("One&Two", '', 'save'));
$this->assertEquals("onetwo-test", sanitize_title_with_dashes("One&Two Test;", '', 'save'));
}
function test_replaces_nbsp() {
$this->assertEquals("dont-break-the-space", sanitize_title_with_dashes("don't break the space", '', 'save'));
}
function test_replaces_ndash_mdash() {
$this->assertEquals("do-the-dash", sanitize_title_with_dashes("Do – the Dash", '', 'save'));
$this->assertEquals("do-the-dash", sanitize_title_with_dashes("Do the — Dash", '', 'save'));
}
function test_replaces_iexcel_iquest() {
$this->assertEquals("just-a-slug", sanitize_title_with_dashes("Just ¡a Slug", '', 'save'));
$this->assertEquals("just-a-slug", sanitize_title_with_dashes("Just a Slug¿", '', 'save'));
}
function test_replaces_angle_quotes() {
$this->assertEquals("just-a-slug", sanitize_title_with_dashes("‹Just a Slug›", '', 'save'));
$this->assertEquals("just-a-slug", sanitize_title_with_dashes("«Just a Slug»", '', 'save'));
}
function test_replaces_curly_quotes() {
$this->assertEquals("hey-its-curly-joe", sanitize_title_with_dashes("Hey its “Curly Joe”", '', 'save'));
$this->assertEquals("hey-its-curly-joe", sanitize_title_with_dashes("Hey its ‘Curly Joe’", '', 'save'));
$this->assertEquals("hey-its-curly-joe", sanitize_title_with_dashes("Hey its „Curly Joe“", '', 'save'));
$this->assertEquals("hey-its-curly-joe", sanitize_title_with_dashes("Hey its ‚Curly Joe‛", '', 'save'));
$this->assertEquals("hey-its-curly-joe", sanitize_title_with_dashes("Hey its „Curly Joe‟", '', 'save'));
}
function test_replaces_copy_reg_deg_trade() {
$this->assertEquals("just-a-slug", sanitize_title_with_dashes("Just © a Slug", '', 'save'));
$this->assertEquals("just-a-slug", sanitize_title_with_dashes("® Just a Slug", '', 'save'));
$this->assertEquals("just-a-slug", sanitize_title_with_dashes("Just a ° Slug", '', 'save'));
$this->assertEquals("just-a-slug", sanitize_title_with_dashes("Just ™ a Slug", '', 'save'));
}
function test_replaces_multiply_sign() {
$this->knownWPBug(19820);
$this->assertEquals("6x7-is-42", sanitize_title_with_dashes("6×7 is 42", '', 'save'));
}
}
class TestConvertChars extends WPTestCase {
function test_replaces_windows1252_entities_with_unicode_ones() {
$input = "
";
$output = "‚ƒ„…†‡ˆ‰Š‹Œ‘’“”•–—˜™š›œŸ";
$this->assertEquals($output, convert_chars($input));
}
function test_replaces_latin_letter_z_with_caron() {
$this->knownWPBug(20503);
$input = "";
$output = "Žž";
$this->assertEquals( $output, convert_chars( $input ) );
}
function test_converts_html_br_and_hr_to_the_xhtml_self_closing_variety() {
$inputs = array(
"abc
lol
" => "abc
lol
",
"
ho ho
" => "
ho ho
",
"
" => "
"
);
foreach ($inputs as $input => $expected) {
$this->assertEquals($expected, convert_chars($input));
}
}
function test_escapes_lone_ampersands() {
$this->assertEquals("at&t", convert_chars("at&t"));
}
function test_removes_category_and_title_metadata_tags() {
$this->assertEquals("", convert_chars("abc a "));
}
}
class TestZeroise extends WPTestCase {
function test_pads_with_leading_zeroes() {
$this->assertEquals("00005", zeroise(5, 5));
}
function test_does_nothing_if_input_is_already_longer() {
$this->assertEquals("5000000", zeroise(5000000, 2));
}
}
class TestBackslashit extends WPTestCase {
function test_backslashes_alphas() {
$this->assertEquals("\\a943\\b\\c", backslashit("a943bc"));
}
function test_double_backslashes_leading_numbers() {
$this->assertEquals("\\\\95", backslashit("95"));
}
}
class TestUntrailingslashit extends WPTestCase {
function test_removes_trailing_slashes() {
$this->assertEquals("a", untrailingslashit("a/"));
$this->assertEquals("a", untrailingslashit("a////"));
}
}
class TestTrailingslashit extends WPTestCase {
function test_adds_trailing_slash() {
$this->assertEquals("a/", trailingslashit("a"));
}
function test_does_not_add_trailing_slash_if_one_exists() {
$this->assertEquals("a/", trailingslashit("a/"));
}
}
/* The `clean_pre` function removes pararaph and line break
tags within `` elements as part of `wpautop`. */
class TestCleanPre extends WPTestCase {
function test_removes_self_closing_br_with_space() {
$source = 'a b c\n
sldfj
';
$res = 'a b c\nsldfj';
$this->assertEquals($res, clean_pre($source));
}
function test_removes_self_closing_br_without_space() {
$source = 'a b c\n
sldfj
';
$res = 'a b c\nsldfj';
$this->assertEquals($res, clean_pre($source));
}
// I don't think this can ever happen in production;
//
is changed to
elsewhere. Left in because
// that replacement shouldn't happen (what if you want
// HTML 4 output?).
function test_removes_html_br() {
$source = 'a b c\n
sldfj
';
$res = 'a b c\nsldfj';
$this->assertEquals($res, clean_pre($source));
}
function test_removes_p() {
$source = "isn't this exciting!
oh indeed!
";
$res = "\nisn't this exciting!\noh indeed!";
$this->assertEquals($res, clean_pre($source));
}
}
class TestSmilies extends WPTestCase {
function test_convert_smilies() {
global $wpsmiliestrans;
$includes_path = includes_url("images/smilies/");
// standard smilies, use_smilies: ON
update_option( 'use_smilies', 1 );
smilies_init();
$inputs = array(
'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 :?:',
'Welcome to the jungle! We got fun n games! :) We got everything you want 8-) Honey we know the names :)',
"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",
'and I say it\'s allright:D:D',
'',
':?:P:?::-x:mrgreen:::', /*
'the question is, ',
'the question is, Should smilies be converted in code or pre tags :?:',
'the question is, Should smilies be converted in code or pre tags :?:',
'the question is, Should smilies be converted in invalid code or pre tags :?:',
'Yes I am :)> :) The world makes me :mad:' */
);
$outputs = array(
'Lorem ipsum dolor sit amet mauris
Praesent gravida sodales.
Vivamus nec diam in faucibus eu, bibendum varius nec, imperdiet purus est, at augue at lacus malesuada elit dapibus a,
mauris. Cras mauris viverra elit. Nam laoreet viverra. Pellentesque tortor. Nam libero ante, porta urna ut turpis. Nullam wisi magna,
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
',
'Welcome to the jungle! We got fun n games!
We got everything you want
Honey we know the names
',
"a little bit of this\na little bit:other: of that
a little bit of good\nyeah with a little bit of bad8O",
'and I say it\'s allright:D:D',
'',
'
P:?::-x:mrgreen:::', /*
'the question is, ',
'the question is, Should smilies be converted in code or pre tags :?:',
'the question is, Should smilies be converted in code or pre tags :?:',
'the question is, Should smilies be converted in invalid code or pre tags :?: ',
'