]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-20826 convert_urls_into_links() - add some test to reveal (side?) problems
authorEloy Lafuente <stronk7@moodle.org>
Mon, 30 Nov 2009 02:06:43 +0000 (02:06 +0000)
committerEloy Lafuente <stronk7@moodle.org>
Mon, 30 Nov 2009 02:06:43 +0000 (02:06 +0000)
and allow comparing of alternatives. Merged from 19_STABLE

lib/simpletest/testweblib.php

index 94fcaf56cf6c2cf234a7cad20ec3ce3cf0f7be75..bb35e7f9b68c5e67874159f4a3a205a4d5860283 100644 (file)
@@ -88,16 +88,6 @@ class web_test extends UnitTestCase {
         $this->assertEqual(fix_non_standard_entities('&#x00A3;&#0228;'), '&#x00A3;&#0228;');
     }
 
-    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&amp;j=2' => 'URL: <a href="http://www.moodle.org/s/i=1&amp;j=2" target="_blank">www.moodle.org/s/i=1&amp;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&amp;j=2.' => 'URL: <a href="http://www.moodle.org/s/i=1&amp;j=2" target="_blank">www.moodle.org/s/i=1&amp;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&lt;/p> text' => 'URL: <p>text <a href="http://www.moodle.org" target="_blank">www.moodle.org</a>&lt;/p> text'
+                 );
+        foreach ($texts as $text => $correctresult) {
+            $failedmsg = "Testing text: \"$text\": %s";
+            convert_urls_into_links($text);
+            $this->assertEqual($text, $correctresult, $failedmsg);
+        }
+    }
 }