mirror of
https://github.com/moodle/moodle.git
synced 2025-02-15 13:24:56 +01:00
MDL-20826 convert_urls_into_links() - add some test to reveal (side?) problems
and allow comparing of alternatives. Merged from 19_STABLE
This commit is contained in:
parent
2b4d40c9ac
commit
db4f638aa9
@ -88,16 +88,6 @@ class web_test extends UnitTestCase {
|
||||
$this->assertEqual(fix_non_standard_entities('£ä'), '£ä');
|
||||
}
|
||||
|
||||
function test_convert_urls_into_links() {
|
||||
$string = "visit http://www.moodle.org";
|
||||
convert_urls_into_links($string);
|
||||
$this->assertEqual($string, 'visit <a href="http://www.moodle.org">http://www.moodle.org</a>');
|
||||
|
||||
$string = "visit www.moodle.org";
|
||||
convert_urls_into_links($string);
|
||||
$this->assertEqual($string, 'visit <a href="http://www.moodle.org">www.moodle.org</a>');
|
||||
}
|
||||
|
||||
function test_prepare_url() {
|
||||
global $CFG, $PAGE;
|
||||
$fullexternalurl = 'http://www.externalsite.com/somepage.php';
|
||||
@ -143,6 +133,40 @@ class web_test extends UnitTestCase {
|
||||
$this->assertTrue($url1->compare($url2, URL_MATCH_PARAMS));
|
||||
$this->assertTrue($url1->compare($url2, URL_MATCH_EXACT));
|
||||
}
|
||||
|
||||
function test_convert_urls_into_links() {
|
||||
$texts = array (
|
||||
'URL: http://moodle.org/s/i=1&j=2' => 'URL: <a href="http://moodle.org/s/i=1&j=2" target="_blank">http://moodle.org/s/i=1&j=2</a>',
|
||||
'URL: www.moodle.org/s/i=1&j=2' => 'URL: <a href="http://www.moodle.org/s/i=1&j=2" target="_blank">www.moodle.org/s/i=1&j=2</a>',
|
||||
'URL: https://moodle.org/s/i=1&j=2' => 'URL: <a href="https://moodle.org/s/i=1&j=2" target="_blank">https://moodle.org/s/i=1&j=2</a>',
|
||||
'URL: http://moodle.org:8080/s/i=1' => 'URL: <a href="http://moodle.org:8080/s/i=1" target="_blank">http://moodle.org:8080/s/i=1</a>',
|
||||
'http://moodle.org - URL' => '<a href="http://moodle.org" target="_blank">http://moodle.org</a> - URL',
|
||||
'www.moodle.org - URL' => '<a href="http://www.moodle.org" target="_blank">www.moodle.org</a> - URL',
|
||||
'(http://moodle.org) - URL' => '(<a href="http://moodle.org" target="_blank">http://moodle.org</a>) - URL',
|
||||
'(www.moodle.org) - URL' => '(<a href="http://www.moodle.org" target="_blank">www.moodle.org</a>) - URL',
|
||||
'[http://moodle.org] - URL' => '[<a href="http://moodle.org" target="_blank">http://moodle.org</a>] - URL',
|
||||
'[www.moodle.org] - URL' => '[<a href="http://www.moodle.org" target="_blank">www.moodle.org</a>] - URL',
|
||||
'[http://moodle.org/main#anchor] - URL' => '[<a href="http://moodle.org/main#anchor" target="_blank">http://moodle.org/main#anchor</a>] - URL',
|
||||
'[www.moodle.org/main#anchor] - URL' => '[<a href="http://www.moodle.org/main#anchor" target="_blank">www.moodle.org/main#anchor</a>] - URL',
|
||||
'URL: http://cc.org/url_(withpar)_go/?i=2' => 'URL: <a href="http://cc.org/url_(withpar)_go/?i=2" target="_blank">http://cc.org/url_(withpar)_go/?i=2</a>',
|
||||
'URL: www.cc.org/url_(withpar)_go/?i=2' => 'URL: <a href="http://www.cc.org/url_(withpar)_go/?i=2" target="_blank">www.cc.org/url_(withpar)_go/?i=2</a>',
|
||||
'URL: http://cc.org/url_(with)_(par)_go/?i=2' => 'URL: <a href="http://cc.org/url_(with)_(par)_go/?i=2" target="_blank">http://cc.org/url_(with)_(par)_go/?i=2</a>',
|
||||
'URL: www.cc.org/url_(with)_(par)_go/?i=2' => 'URL: <a href="http://www.cc.org/url_(with)_(par)_go/?i=2" target="_blank">www.cc.org/url_(with)_(par)_go/?i=2</a>',
|
||||
'URL: <a href="http://moodle.org">http://moodle.org</a>' => 'URL: <a href="http://moodle.org">http://moodle.org</a>',
|
||||
'URL: <a href="http://moodle.org">www.moodle.org</a>' => 'URL: <a href="http://moodle.org">www.moodle.org</a>',
|
||||
'URL: <a href="http://moodle.org"> http://moodle.org</a>' => 'URL: <a href="http://moodle.org"> http://moodle.org</a>',
|
||||
'URL: <a href="http://moodle.org"> www.moodle.org</a>' => 'URL: <a href="http://moodle.org"> www.moodle.org</a>',
|
||||
'URL: http://moodle.org/s/i=1&j=2.' => 'URL: <a href="http://moodle.org/s/i=1&j=2" target="_blank">http://moodle.org/s/i=1&j=2</a>.',
|
||||
'URL: www.moodle.org/s/i=1&j=2.' => 'URL: <a href="http://www.moodle.org/s/i=1&j=2" target="_blank">www.moodle.org/s/i=1&j=2</a>.',
|
||||
'URL: http://moodle.org)<br />' => 'URL: <a href="http://moodle.org" target="_blank">http://moodle.org</a>)<br />',
|
||||
'URL: <p>text www.moodle.org</p> text' => 'URL: <p>text <a href="http://www.moodle.org" target="_blank">www.moodle.org</a></p> text'
|
||||
);
|
||||
foreach ($texts as $text => $correctresult) {
|
||||
$failedmsg = "Testing text: \"$text\": %s";
|
||||
convert_urls_into_links($text);
|
||||
$this->assertEqual($text, $correctresult, $failedmsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user