]> git.mjollnir.org Git - moodle.git/commitdiff
Unit tests for MDL-9295 - clean_param with PARAM_URL/PARAM_LOCALURL. Merged from...
authortjhunt <tjhunt>
Tue, 30 Oct 2007 10:46:26 +0000 (10:46 +0000)
committertjhunt <tjhunt>
Tue, 30 Oct 2007 10:46:26 +0000 (10:46 +0000)
lib/simpletest/testmoodlelib.php

index 7a33665a10e2b5dd4315911d0862bdc7529bb926..0189051c13922b12a75268d3a147ca421ede4f8f 100644 (file)
@@ -169,6 +169,7 @@ class moodlelib_test extends UnitTestCase {
      */
     function test_clean_param()
     {
+        global $CFG;
         // Test unknown parameter type
         
         // Test Raw param
@@ -177,7 +178,20 @@ class moodlelib_test extends UnitTestCase {
         
         $this->assertEqual(clean_param('#()*#,9789\'".,<42897></?$(*DSFMO#$*)(SDJ)($*)', PARAM_CLEAN), 
             '#()*#,9789\\\'\".,');
-        
+
+        // Test PARAM_URL and PARAM_LOCALURL a bit
+        $this->assertEqual(clean_param('http://google.com/', PARAM_URL), 'http://google.com/');
+        $this->assertEqual(clean_param('http://some.very.long.and.silly.domain/with/a/path/', PARAM_URL), 'http://some.very.long.and.silly.domain/with/a/path/');
+        $this->assertEqual(clean_param('http://localhost/', PARAM_URL), 'http://localhost/');
+        $this->assertEqual(clean_param('http://0.255.1.1/numericip.php', PARAM_URL), 'http://0.255.1.1/numericip.php');
+        $this->assertEqual(clean_param('/just/a/path', PARAM_URL), '/just/a/path');
+        $this->assertEqual(clean_param('funny:thing', PARAM_URL), '');
+
+        $this->assertEqual(clean_param('http://google.com/', PARAM_LOCALURL), '');
+        $this->assertEqual(clean_param('http://some.very.long.and.silly.domain/with/a/path/', PARAM_LOCALURL), '');
+        $this->assertEqual(clean_param($CFG->wwwroot, PARAM_LOCALURL), $CFG->wwwroot);
+        $this->assertEqual(clean_param('/just/a/path', PARAM_LOCALURL), '/just/a/path');
+        $this->assertEqual(clean_param('funny:thing', PARAM_LOCALURL), '');
     }
 
     function test_make_user_directory() {