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.' ); $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.' ); 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.' ); $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.' ); 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)); } } } 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_pre() { $this->assertEquals('
---', wptexturize('
---')); $this->assertEquals('
--', wptexturize('--'));
}
}
?>