assertEquals($in, make_clickable($in)); } function test_valid_mailto() { $valid_emails = array( 'foo@example.com', 'foo.bar@example.com', 'Foo.Bar@a.b.c.d.example.com', '0@example.com', 'foo@example-example.com', ); foreach ($valid_emails as $email) { $this->assertEquals(''.$email.'', make_clickable($email)); } } function test_invalid_mailto() { $invalid_emails = array( 'foo', 'foo@', 'foo@@example.com', '@example.com', 'foo @example.com', 'foo@example', ); foreach ($invalid_emails as $email) { $this->assertEquals($email, make_clickable($email)); } } // tests that make_clickable will not link trailing periods, commas and // (semi-)colons in URLs with protocol (i.e. http://wordpress.org) function test_strip_trailing_with_protocol() { $urls_before = array( 'http://wordpress.org/hello.html', 'There was a spoon named http://wordpress.org. Alice!', 'There was a spoon named http://wordpress.org, said Alice.', 'There was a spoon named http://wordpress.org; said Alice.', 'There was a spoon named http://wordpress.org: said Alice.', 'There was a spoon named (http://wordpress.org) said Alice.' ); $urls_expected = array( 'http://wordpress.org/hello.html', 'There was a spoon named http://wordpress.org. Alice!', 'There was a spoon named http://wordpress.org, said Alice.', 'There was a spoon named http://wordpress.org; said Alice.', 'There was a spoon named http://wordpress.org: said Alice.', 'There was a spoon named (http://wordpress.org) said Alice.' ); foreach ($urls_before as $key => $url) { $this->assertEquals($urls_expected[$key], make_clickable($url)); } } // tests that make_clickable will not link trailing periods, commas and // (semi-)colons in URLs with protocol (i.e. http://wordpress.org) function test_strip_trailing_with_protocol_nothing_afterwards() { $urls_before = array( 'http://wordpress.org/hello.html', 'There was a spoon named http://wordpress.org.', 'There was a spoon named http://wordpress.org,', 'There was a spoon named http://wordpress.org;', 'There was a spoon named http://wordpress.org:', 'There was a spoon named (http://wordpress.org)', 'There was a spoon named (http://wordpress.org)x', ); $urls_expected = array( 'http://wordpress.org/hello.html', 'There was a spoon named http://wordpress.org.', 'There was a spoon named http://wordpress.org,', 'There was a spoon named http://wordpress.org;', 'There was a spoon named http://wordpress.org:', 'There was a spoon named (http://wordpress.org)', 'There was a spoon named (http://wordpress.org)x', ); foreach ($urls_before as $key => $url) { $this->assertEquals($urls_expected[$key], make_clickable($url)); } } // tests that make_clickable will not link trailing periods, commas and // (semi-)colons in URLs without protocol (i.e. www.wordpress.org) function test_strip_trailing_without_protocol() { $urls_before = array( 'www.wordpress.org', 'There was a spoon named www.wordpress.org. Alice!', 'There was a spoon named www.wordpress.org, said Alice.', 'There was a spoon named www.wordpress.org; said Alice.', 'There was a spoon named www.wordpress.org: said Alice.', 'There was a spoon named www.wordpress.org) said Alice.' ); $urls_expected = array( 'http://www.wordpress.org', 'There was a spoon named http://www.wordpress.org. Alice!', 'There was a spoon named http://www.wordpress.org, said Alice.', 'There was a spoon named http://www.wordpress.org; said Alice.', 'There was a spoon named http://www.wordpress.org: said Alice.', 'There was a spoon named http://www.wordpress.org) said Alice.' ); foreach ($urls_before as $key => $url) { $this->assertEquals($urls_expected[$key], make_clickable($url)); } } // tests that make_clickable will not link trailing periods, commas and // (semi-)colons in URLs without protocol (i.e. www.wordpress.org) function test_strip_trailing_without_protocol_nothing_afterwards() { $urls_before = array( 'www.wordpress.org', 'There was a spoon named www.wordpress.org.', 'There was a spoon named www.wordpress.org,', 'There was a spoon named www.wordpress.org;', 'There was a spoon named www.wordpress.org:', 'There was a spoon named www.wordpress.org)' ); $urls_expected = array( 'http://www.wordpress.org', 'There was a spoon named http://www.wordpress.org.', 'There was a spoon named http://www.wordpress.org,', 'There was a spoon named http://www.wordpress.org;', 'There was a spoon named http://www.wordpress.org:', 'There was a spoon named http://www.wordpress.org)' ); foreach ($urls_before as $key => $url) { $this->assertEquals($urls_expected[$key], make_clickable($url)); } } // #4570 function test_iri() { $urls_before = array( 'http://www.詹姆斯.com/', 'http://bg.wikipedia.org/Баба', 'http://example.com/?a=баба&b=дядо', ); $urls_expected = array( 'http://www.詹姆斯.com/', 'http://bg.wikipedia.org/Баба', 'http://example.com/?a=баба&b=дядо', ); foreach ($urls_before as $key => $url) { $this->assertEquals($urls_expected[$key], make_clickable($url)); } } // #10990 function test_brackets_in_urls() { $urls_before = array( 'http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)', '(http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software))', 'blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software) blah', 'blah (http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah', 'blah blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software) blah blah', 'blah blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah blah', 'blah blah (http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah blah', 'blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software).) blah blah', 'blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software).)moreurl blah blah', ); $urls_expected = array( 'http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)', '(http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software))', 'blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software) blah', 'blah (http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah', 'blah blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software) blah blah', 'blah blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah blah', 'blah blah (http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah blah', 'blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software).) blah blah', 'blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software).)moreurl blah blah', ); foreach ($urls_before as $key => $url) { $this->assertEquals($urls_expected[$key], make_clickable($url)); } } // Based on a real comments which were incorrectly linked. #11211 function test_real_world_examples() { $urls_before = array( 'Example: WordPress, test (some text), I love example.com (http://example.org), it is brilliant', 'Example: WordPress, test (some text), I love example.com (http://example.com), it is brilliant', 'Some text followed by a bracketed link with a trailing elipsis (http://example.com)...', 'In his famous speech “You and Your research” (here: http://www.cs.virginia.edu/~robins/YouAndYourResearch.html) Richard Hamming wrote about people getting more done with their doors closed...', ); $urls_expected = array( 'Example: WordPress, test (some text), I love example.com (http://example.org), it is brilliant', 'Example: WordPress, test (some text), I love example.com (http://example.com), it is brilliant', 'Some text followed by a bracketed link with a trailing elipsis (http://example.com)...', 'In his famous speech “You and Your research” (here: http://www.cs.virginia.edu/~robins/YouAndYourResearch.html) Richard Hamming wrote about people getting more done with their doors closed...', ); foreach ($urls_before as $key => $url) { $this->assertEquals($urls_expected[$key], make_clickable($url)); } } // #14993 function test_twitter_hash_bang() { $urls_before = array( 'http://twitter.com/#!/wordpress/status/25907440233', 'This is a really good tweet http://twitter.com/#!/wordpress/status/25907440233 !', 'This is a really good tweet http://twitter.com/#!/wordpress/status/25907440233!', ); $urls_expected = array( 'http://twitter.com/#!/wordpress/status/25907440233', 'This is a really good tweet http://twitter.com/#!/wordpress/status/25907440233 !', 'This is a really good tweet http://twitter.com/#!/wordpress/status/25907440233!', ); foreach ($urls_before as $key => $url) { $this->assertEquals($urls_expected[$key], make_clickable($url)); } } function test_wrapped_in_angles() { $before = array( 'URL wrapped in angle brackets ', 'URL wrapped in angle brackets with padding < http://example.com/ >', 'mailto wrapped in angle brackets ', ); $expected = array( 'URL wrapped in angle brackets <http://example.com/>', 'URL wrapped in angle brackets with padding < http://example.com/ >', 'mailto wrapped in angle brackets ', ); foreach ($before as $key => $url) { $this->assertEquals($expected[$key], make_clickable($url)); } } function test_preceded_by_punctuation() { $before = array( 'Comma then URL,http://example.com/', 'Period then URL.http://example.com/', 'Semi-colon then URL;http://example.com/', 'Colon then URL:http://example.com/', 'Exclamation mark then URL!http://example.com/', 'Question mark then URL?http://example.com/', ); $expected = array( 'Comma then URL,http://example.com/', 'Period then URL.http://example.com/', 'Semi-colon then URL;http://example.com/', 'Colon then URL:http://example.com/', 'Exclamation mark then URL!http://example.com/', 'Question mark then URL?http://example.com/', ); foreach ($before as $key => $url) { $this->assertEquals($expected[$key], make_clickable($url)); } } function test_dont_break_attributes() { $urls_before = array( ":)", "(:))", "http://trunk.domain/testing#something (:))", "http://trunk.domain/testing#something (:))", " ", 'Look at this image!', ); $urls_expected = array( ":)", "(:))", "http://trunk.domain/testing#something (:))", "http://trunk.domain/testing#something (:))", " ", 'Look at this image!', ); foreach ($urls_before as $key => $url) { $this->assertEquals($urls_expected[$key], make_clickable($url)); } } function test_click_inside_html() { $this->knownWPBug( 16892 ); $urls_before = array( 'http://example.com', '

http://example.com/

', ); $urls_expected = array( 'http://example.com', '

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: 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! '; // On windows environments, the EOL-style is \r\n $expected = str_replace( "\r\n", "\n", $expected); $this->assertEquals($expected, wpautop($test_data)); } /** * wpautop() Should not alter the contents of "
" 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\n
Line1
Line2
Line3
Line4\nActual Line 2\nActual Line 3
\n\nCool, huh?"; $expected = "

Look at this code

\n
Line1
Line2
Line3
Line4\nActual Line 2\nActual Line 3
\n

Cool, 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 = "&amp;&lt;hello world&gt;"; $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("<div class='lol'>abc</div>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. \':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 :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:\'' */ ); foreach ( $inputs as $k => $input ) { $this->assertEquals( $outputs[$k], convert_smilies($input) ); } update_option( 'use_smilies', 0 ); // standard smilies, use_smilies: OFF foreach ( $inputs as $input ) { $this->assertEquals( $input, convert_smilies($input) ); } return; // custom smilies, use_smilies: ON update_option( 'use_smilies', 1 ); $wpsmiliestrans = array( ':PP' => 'icon_tongue.gif', ':arrow:' => 'icon_arrow.gif', ':monkey:' => 'icon_shock_the_monkey.gif', ':nervou:' => 'icon_nervou.gif' ); smilies_init(); $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:', '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:', ':arrow:monkey:Lorem ipsum dolor sit amet enim. Etiam ullam:PP
corper. Suspendisse a pellentesque dui, non felis.:arrow::arrow' ); $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. \'icon_arrow\'', 'Star Wars Jedi Knight\'icon_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. \'icon_nervou\'', '\'icon_arrow\'monkey:Lorem ipsum dolor sit amet enim. Etiam ullam\'icon_tongue\'
corper. Suspendisse a pellentesque dui, non felis.\'icon_arrow\':arrow' ); foreach ( $inputs as $k => $input ) { $this->assertEquals( $outputs[$k], convert_smilies($input) ); } } } class TestWPTrimWords extends WPTestCase { 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.'; function test_trims_to_55_by_default() { $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…'; $this->assertEquals( $trimmed, wp_trim_words( $this->long_text ) ); } function test_trims_to_10() { $trimmed = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce varius…'; $this->assertEquals( $trimmed, wp_trim_words( $this->long_text, 10 ) ); } function test_trims_to_5_and_uses_custom_more() { $trimmed = 'Lorem ipsum dolor sit amet,[...] Read on!'; $this->assertEquals( $trimmed, wp_trim_words( $this->long_text, 5, '[...] Read on!' ) ); } function test_strips_tags_before_trimming() { $text = 'This text contains a link to WordPress.org!'; $trimmed = 'This text contains a link…'; $this->assertEquals( $trimmed, wp_trim_words( $text, 5 ) ); } // #18726 function test_strips_script_and_style_content() { $trimmed = 'This text contains. It should go.'; $text = 'This text contains. It should go.'; $this->assertEquals( $trimmed, wp_trim_words( $text ) ); $text = 'This text contains. It should go.'; $this->assertEquals( $trimmed, wp_trim_words( $text ) ); } function test_doesnt_trim_short_text() { $text = 'This is some short text.'; $this->assertEquals( $text, wp_trim_words( $text ) ); } } class TestRemoveAccents extends WPTestCase { public function test_remove_accents_simple() { $this->assertEquals( 'abcdefghijkl', remove_accents( 'abcdefghijkl' ) ); } public function test_remove_accents_latin1_supplement() { $this->knownWPBug(9591); $input = 'ªºÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ'; $output = 'aoAAAAAAAECEEEEIIIIDNOOOOOOUUUUYTHsaaaaaaaeceeeeiiiidnoooooouuuuythy'; $this->assertEquals( $output, remove_accents( $input ), 'remove_accents replaces Latin-1 Supplement' ); } public function test_remove_accents_latin_extended_a() { $input = 'ĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſ'; $output = 'AaAaAaCcCcCcCcDdDdEeEeEeEeEeGgGgGgGgHhHhIiIiIiIiIiIJijJjKkkLlLlLlLlLlNnNnNnNnNOoOoOoOEoeRrRrRrSsSsSsSsTtTtTtUuUuUuUuUuUuWwYyYZzZzZzs'; $this->assertEquals( $output, remove_accents( $input ), 'remove_accents replaces Latin Extended A' ); } public function test_remove_accents_latin_extended_b() { $this->assertEquals( 'SsTt', remove_accents( 'ȘșȚț' ), 'remove_accents replaces Latin Extended B' ); } public function test_remove_accents_euro_pound_signs() { $this->assertEquals( 'E', remove_accents( '€' ), 'remove_accents replaces euro sign' ); $this->assertEquals( '', remove_accents( '£' ), 'remove_accents replaces pound sign' ); } public function test_remove_accents_iso8859() { // File is Latin1 encoded $file = DIR_TESTDATA . DIRECTORY_SEPARATOR . 'formatting' . DIRECTORY_SEPARATOR . 'remove_accents.01.input.txt'; $input = file_get_contents( $file ); $input = trim( $input ); $output = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyyOEoeAEDHTHssaedhth"; $this->assertEquals( $output, remove_accents( $input ), 'remove_accents from ISO-8859-1 text' ); } public function test_remove_accents_vowels_diacritic() { $this->knownWPBug(17738); // Vowels with diacritic // unmarked $this->assertEquals( 'OoUu', remove_accents( 'ƠơƯư' ) ); // grave accent $this->assertEquals( 'AaAaEeOoOoUuYy', remove_accents( 'ẦầẰằỀềỒồỜờỪừỲỳ' ) ); // hook $this->assertEquals( 'AaAaAaEeEeIiOoOoOoUuUuYy', remove_accents( 'ẢảẨẩẲẳẺẻỂểỈỉỎỏỔổỞởỦủỬửỶỷ' ) ); // tilde $this->assertEquals( 'AaAaEeEeOoOoUuYy', remove_accents( 'ẪẫẴẵẼẽỄễỖỗỠỡỮữỸỹ' ) ); // acute accent $this->assertEquals( 'AaAaEeOoOoUu', remove_accents( 'ẤấẮắẾếỐốỚớỨứ' ) ); // dot below $this->assertEquals( 'AaAaAaEeEeIiOoOoOoUuUuYy', remove_accents( 'ẠạẬậẶặẸẹỆệỊịỌọỘộỢợỤụỰựỴỵ' ) ); } } class TestStripSlashesDeep extends WPTestCase { function test_preserves_original_datatype() { $this->knownWPBug(18026); $this->assertEquals( true, stripslashes_deep( true ) ); $this->assertEquals( false, stripslashes_deep( false ) ); $this->assertEquals( 4, stripslashes_deep( 4 ) ); $this->assertEquals( 'foo', stripslashes_deep( 'foo' ) ); $arr = array( 'a' => true, 'b' => false, 'c' => 4, 'd' => 'foo' ); $arr['e'] = $arr; // Add a sub-array $this->assertEquals( $arr, stripslashes_deep( $arr ) ); // Keyed array $this->assertEquals( array_values( $arr ), stripslashes_deep( array_values( $arr ) ) ); // Non-keyed $obj = new stdClass; foreach ( $arr as $k => $v ) $obj->$k = $v; $this->assertEquals( $obj, stripslashes_deep( $obj ) ); } function test_strips_slashes() { $old = "I can\'t see, isn\'t that it?"; $new = "I can't see, isn't that it?"; $this->assertEquals( $new, stripslashes_deep( $old ) ); $this->assertEquals( $new, stripslashes_deep( "I can\\'t see, isn\\'t that it?" ) ); $this->assertEquals( array( 'a' => $new ), stripslashes_deep( array( 'a' => $old ) ) ); // Keyed array $this->assertEquals( array( $new ), stripslashes_deep( array( $old ) ) ); // Non-keyed $obj_old = new stdClass; $obj_old->a = $old; $obj_new = new stdClass; $obj_new->a = $new; $this->assertEquals( $obj_new, stripslashes_deep( $obj_old ) ); } function test_permits_escaped_slash() { $txt = "I can't see, isn\'t that it?"; $this->assertEquals( $txt, stripslashes_deep( "I can\'t see, isn\\\'t that it?" ) ); $this->assertEquals( $txt, stripslashes_deep( "I can\'t see, isn\\\\\'t that it?" ) ); } } ?>