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)' ); $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)' ); 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)); } } function test_iri() { $this->knownWPBug(4570); $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)); } } 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', ); $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', ); foreach ($urls_before as $key => $url) { $this->assertEquals($urls_expected[$key], make_clickable($url)); } } // Based on a real comments which were incorrectly linked. function test_real_world_examples() { $this->knownWPBug(11211); $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)...' ); $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)...' ); foreach ($urls_before as $key => $url) { $this->assertEquals($urls_expected[$key], make_clickable($url)); } } } class TestJSEscape extends WPTestCase { function test_js_escape_simple() { $out = js_escape('foo bar baz();'); $this->assertEquals('foo bar baz();', $out); } function test_js_escape_quotes() { $out = js_escape('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 = js_escape('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 = js_escape('foo & bar &baz;'); $this->assertEquals("foo & bar &baz;", $out); } function test_js_escape_quote_entity() { $out = js_escape('foo ' bar ' baz &'); $this->assertEquals("foo \\' bar \\' baz &", $out); } function test_js_no_carriage_return() { $out = js_escape("foo\rbar\nbaz\r"); // \r is stripped $this->assertequals("foobar\\nbaz", $out); } function test_js_escape_rn() { $out = js_escape("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)); } } class TestSanitizeOrderby extends WPTestCase { function test_empty() { if ( !is_callable('sanitize_orderby') ) $this->markTestSkipped(); $cols = array('a' => 'a'); $this->assertEquals( '', sanitize_orderby('', $cols) ); $this->assertEquals( '', sanitize_orderby(' ', $cols) ); $this->assertEquals( '', sanitize_orderby("\t", $cols) ); $this->assertEquals( '', sanitize_orderby(null, $cols) ); $this->assertEquals( '', sanitize_orderby(0, $cols) ); $this->assertEquals( '', sanitize_orderby('+', $cols) ); $this->assertEquals( '', sanitize_orderby('-', $cols) ); } function test_unknown_column() { if ( !is_callable('sanitize_orderby') ) $this->markTestSkipped(); $cols = array('name' => 'post_name', 'date' => 'post_date'); $this->assertEquals( '', sanitize_orderby('unknown_column', $cols) ); $this->assertEquals( '', sanitize_orderby('+unknown_column', $cols) ); $this->assertEquals( '', sanitize_orderby('-unknown_column', $cols) ); $this->assertEquals( '', sanitize_orderby('-unknown1,+unknown2,unknown3', $cols) ); $this->assertEquals( 'post_name ASC', sanitize_orderby('name,unknown_column', $cols) ); $this->assertEquals( '', sanitize_orderby('!@#$%^&*()_=~`\'",./', $cols) ); } function test_valid() { if ( !is_callable('sanitize_orderby') ) $this->markTestSkipped(); $cols = array('name' => 'post_name', 'date' => 'post_date', 'random' => 'rand()'); $this->assertEquals( 'post_name ASC', sanitize_orderby('name', $cols) ); $this->assertEquals( 'post_name ASC', sanitize_orderby('+name', $cols) ); $this->assertEquals( 'post_name DESC', sanitize_orderby('-name', $cols) ); $this->assertEquals( 'post_date ASC, post_name ASC', sanitize_orderby('date,name', $cols) ); $this->assertEquals( 'post_date ASC, post_name ASC', sanitize_orderby(' date , name ', $cols) ); $this->assertEquals( 'post_name DESC, post_date ASC', sanitize_orderby('-name,date', $cols) ); $this->assertEquals( 'post_name ASC, post_date ASC', sanitize_orderby('name ,+ date', $cols) ); $this->assertEquals( 'rand() ASC', sanitize_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.')); } 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"')); } //WP Ticket #1258 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’', wptexturize("'Class of '99'")); } } class TestCleanUrl extends WPTestCase { function test_spaces() { $this->assertEquals('http://example.com/Mr WordPress', clean_url('http://example.com/Mr WordPress')); $this->assertEquals('http://example.com/Mr%20WordPress', clean_url('http://example.com/Mr%20WordPress')); } function test_bad_characters() { $this->assertEquals('http://example.com/watchthelinefeedgo', clean_url('http://example.com/watchthelinefeed%0Ago')); $this->assertEquals('http://example.com/watchthelinefeedgo', clean_url('http://example.com/watchthelinefeed%0ago')); $this->assertEquals('http://example.com/watchthecarriagereturngo', clean_url('http://example.com/watchthecarriagereturn%0Dgo')); $this->assertEquals('http://example.com/watchthecarriagereturngo', clean_url('http://example.com/watchthecarriagereturn%0dgo')); //Nesting Checks $this->assertEquals('http://example.com/watchthecarriagereturngo', clean_url('http://example.com/watchthecarriagereturn%0%0ddgo')); $this->assertEquals('http://example.com/watchthecarriagereturngo', clean_url('http://example.com/watchthecarriagereturn%0%0DDgo')); $this->assertEquals('http://example.com/', clean_url('http://example.com/%0%0%0DAD')); $this->assertEquals('http://example.com/', clean_url('http://example.com/%0%0%0ADA')); $this->assertEquals('http://example.com/', clean_url('http://example.com/%0%0%0DAd')); $this->assertEquals('http://example.com/', clean_url('http://example.com/%0%0%0ADa')); } function test_relative() { $this->assertEquals('/example.php', clean_url('/example.php')); $this->assertEquals('example.php', clean_url('example.php')); } function test_protocol() { $this->assertEquals('http://example.com', clean_url('http://example.com')); $this->assertEquals('', clean_url('nasty://example.com/')); } function test_display_extras() { $this->assertEquals('http://example.com/'quoted'', clean_url('http://example.com/\'quoted\'')); $this->assertEquals('http://example.com/\'quoted\'', clean_url('http://example.com/\'quoted\'',null,'notdisplay')); } } ?>