]> git.mjollnir.org Git - moodle.git/commitdiff
test for questionlib on MOODLE_19_QUESTIONS branch
authorjamiesensei <jamiesensei>
Sat, 30 Jun 2007 03:50:52 +0000 (03:50 +0000)
committerjamiesensei <jamiesensei>
Sat, 30 Jun 2007 03:50:52 +0000 (03:50 +0000)
lib/simpletest/testquestionlib.php [new file with mode: 0644]

diff --git a/lib/simpletest/testquestionlib.php b/lib/simpletest/testquestionlib.php
new file mode 100644 (file)
index 0000000..73572e7
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Unit tests for (some of) ../questionlib.php.
+ *
+ * @copyright &copy; Jamie Pratt
+ * @author Jamie Pratt
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package question
+ */
+
+if (!defined('MOODLE_INTERNAL')) {
+    die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
+}
+global $CFG;
+require_once($CFG->libdir.'/questionlib.php');
+class questionlib_test extends UnitTestCase {
+
+    function setUp() {
+    }
+
+    function tearDown() {
+    }
+
+    function test_find_file_links_from_html() {
+        global $CFG;
+        $this->assertEqual(array_keys(find_file_links_from_html("hello <a href='{$CFG->wwwroot}/file.php/2/gg/go.php'>hello</a>", 2)),
+                                    array("gg/go.php"));
+        $this->assertEqual(array_keys(find_file_links_from_html("hello <a href=\"{$CFG->wwwroot}/file.php/2/gg/go.php\">hello</a>", 2)),
+                                     array("gg/go.php"));
+        $this->assertEqual(array_keys(find_file_links_from_html('hello <a href=\''.$CFG->wwwroot.'/file.php/1/ggo/fghfgh/sdfsdf/sdf/go.php\'>hello</a>', 1)),
+                array('ggo/fghfgh/sdfsdf/sdf/go.php'));
+        $this->assertEqual(array_keys(find_file_links_from_html('hello <a href=\''.$CFG->wwwroot.'/file.php?file=/1/ggo/fghfgh/sdfsdf/sdf/go.php\'>hello</a>'.
+                                "hello <a href='{$CFG->wwwroot}/file.php/2/gg/go.php'>hello</a>" . "hello <a href='{$CFG->wwwroot}/file.php/2/gg/go.php'>hello</a>" .
+                                "hello <a href='{$CFG->wwwroot}/file.php/2/gg/go.php'>hello</a>" ."hello <a href='{$CFG->wwwroot}/file.php/2/gg/go.php'>hello</a>",1)),
+                array('ggo/fghfgh/sdfsdf/sdf/go.php'));
+        $this->assertEqual(array_keys(find_file_links_from_html('hello <img src=\''.$CFG->wwwroot.'/file.php/1/ggo/fghfgh/sdfsdf/sdf/go.php\' />', 1)),
+                array('ggo/fghfgh/sdfsdf/sdf/go.php'));
+    }
+}
+?>