Esempio n. 1
0
$t->is(excerpt_text("This is a beautiful morning", "This", 5, '...', true), "This is ...", 'text_excerpt() takes a fifth argument allowing excerpt on whitespace');
$t->is(excerpt_text("This is a beautiful morning", "day"), '', 'text_excerpt() does nothing if the search string is not in input');
// wrap_text()
$t->diag('wrap_text()');
$line = 'This is a very long line to be wrapped...';
$t->is(wrap_text($line), "This is a very long line to be wrapped...\n", 'wrap_text() wraps long lines with a default of 80');
$t->is(wrap_text($line, 10), "This is a\nvery long\nline to be\nwrapped...\n", 'wrap_text() takes a line length as its second argument');
$t->is(wrap_text($line, 5), "This\nis a\nvery\nlong\nline\nto be\nwrapped...\n", 'wrap_text() takes a line length as its second argument');
// simple_format_text()
$t->diag('simple_format_text()');
$t->is(simple_format_text("crazy\r\n cross\r platform linebreaks"), "<p>crazy\n<br /> cross\n<br /> platform linebreaks</p>", 'text_simple_format() replaces \\n by <br />');
$t->is(simple_format_text("A paragraph\n\nand another one!"), "<p>A paragraph</p>\n\n<p>and another one!</p>", 'text_simple_format() replaces \\n\\n by <p>');
$t->is(simple_format_text("A paragraph\n With a newline"), "<p>A paragraph\n<br /> With a newline</p>", 'text_simple_format() wrap all string with <p>');
// text_strip_links()
$t->diag('text_strip_links()');
$t->is(strip_links_text("<a href='almost'>on my mind</a>"), "on my mind", 'text_strip_links() strips all links in input');
// auto_link_text()
$t->diag('auto_link_text()');
$email_raw = '*****@*****.**';
$email_result = '<a href="mailto:' . $email_raw . '">' . $email_raw . '</a>';
$link_raw = 'http://www.google.com';
$link_result = '<a href="' . $link_raw . '">' . $link_raw . '</a>';
$link2_raw = 'www.google.com';
$link2_result = '<a href="http://' . $link2_raw . '">' . $link2_raw . '</a>';
$t->is(auto_link_text('hello ' . $email_raw, 'email_addresses'), 'hello ' . $email_result, 'auto_link_text() converts emails to links');
$t->is(auto_link_text('Go to ' . $link_raw, 'urls'), 'Go to ' . $link_result, 'auto_link_text() converts absolute URLs to links');
$t->is(auto_link_text('Go to ' . $link_raw, 'email_addresses'), 'Go to ' . $link_raw, 'auto_link_text() takes a second parameter');
$t->is(auto_link_text('Go to ' . $link_raw . ' and say hello to ' . $email_raw), 'Go to ' . $link_result . ' and say hello to ' . $email_result, 'auto_link_text() converts emails and URLs if no second argument is given');
$t->is(auto_link_text('<p>Link ' . $link_raw . '</p>'), '<p>Link ' . $link_result . '</p>', 'auto_link_text() converts URLs to links');
$t->is(auto_link_text('<p>' . $link_raw . ' Link</p>'), '<p>' . $link_result . ' Link</p>', 'auto_link_text() converts URLs to links');
$t->is(auto_link_text('Go to ' . $link2_raw, 'urls'), 'Go to ' . $link2_result, 'auto_link_text() converts URLs to links even if link does not start with http://');
$t->diag('wrap_text()');
$line = 'This is a very long line to be wrapped...';
$t->is(wrap_text($line), "This is a very long line to be wrapped...\n", 'wrap_text() wraps long lines with a default of 80');
$t->is(wrap_text($line, 10), "This is a\nvery long\nline to be\nwrapped...\n", 'wrap_text() takes a line length as its second argument');
$t->is(wrap_text($line, 5), "This\nis a\nvery\nlong\nline\nto be\nwrapped...\n", 'wrap_text() takes a line length as its second argument');
// simple_format_text()
$t->diag('simple_format_text()');
$t->is(simple_format_text("crazy\r\n cross\r platform linebreaks"), "<p>crazy\n<br /> cross\n<br /> platform linebreaks</p>", 'text_simple_format() replaces \\n by <br />');
$t->is(simple_format_text("A paragraph\n\nand another one!"), "<p>A paragraph</p><p>and another one!</p>", 'text_simple_format() replaces \\n\\n by <p>');
$t->is(simple_format_text("A paragraph\n\n\n\nand another one!"), "<p>A paragraph</p><p>and another one!</p>", 'text_simple_format() replaces \\n\\n\\n\\n by <p>');
$t->is(simple_format_text("A paragraph\n With a newline"), "<p>A paragraph\n<br /> With a newline</p>", 'text_simple_format() wrap all string with <p>');
$t->is(simple_format_text("1\n2\n3"), "<p>1\n<br />2\n<br />3</p>", 'text_simple_format() Ticket #6824');
// text_strip_links()
$t->diag('text_strip_links()');
$t->is(strip_links_text("<a href='almost'>on my mind</a>"), "on my mind", 'text_strip_links() strips all links in input');
$t->is(strip_links_text('<a href="first.html">first</a> and <a href="second.html">second</a>'), "first and second", 'text_strip_links() strips all links in input');
// auto_link_text()
$t->diag('auto_link_text()');
$email_raw = '*****@*****.**';
$email_result = '<a href="mailto:' . $email_raw . '">' . $email_raw . '</a>';
$link_raw = 'http://www.google.com';
$link_result = '<a href="' . $link_raw . '">' . $link_raw . '</a>';
$link2_raw = 'www.google.com';
$link2_result = '<a href="http://' . $link2_raw . '">' . $link2_raw . '</a>';
$t->is(auto_link_text('hello ' . $email_raw, 'email_addresses'), 'hello ' . $email_result, 'auto_link_text() converts emails to links');
$t->is(auto_link_text('Go to ' . $link_raw, 'urls'), 'Go to ' . $link_result, 'auto_link_text() converts absolute URLs to links');
$t->is(auto_link_text('Go to ' . $link_raw, 'email_addresses'), 'Go to ' . $link_raw, 'auto_link_text() takes a second parameter');
$t->is(auto_link_text('Go to ' . $link_raw . ' and say hello to ' . $email_raw), 'Go to ' . $link_result . ' and say hello to ' . $email_result, 'auto_link_text() converts emails and URLs if no second argument is given');
$t->is(auto_link_text('<p>Link ' . $link_raw . '</p>'), '<p>Link ' . $link_result . '</p>', 'auto_link_text() converts URLs to links');
$t->is(auto_link_text('<p>' . $link_raw . ' Link</p>'), '<p>' . $link_result . ' Link</p>', 'auto_link_text() converts URLs to links');
$t->is(auto_link_text('Go to ' . $link2_raw, 'urls'), 'Go to ' . $link2_result, 'auto_link_text() converts URLs to links even if link does not start with http://');