]> git.mjollnir.org Git - moodle.git/commitdiff
ajaxlib MDL-16693 Fixed fringe condition in ajaxlib and added test
authorsamhemelryk <samhemelryk>
Mon, 22 Jun 2009 02:59:02 +0000 (02:59 +0000)
committersamhemelryk <samhemelryk>
Mon, 22 Jun 2009 02:59:02 +0000 (02:59 +0000)
lib/ajax/ajaxlib.php
lib/ajax/simpletest/testajaxlib.php

index 725923970b8ecb6f0ffb49b769d764f2a3296664..7bdbc3a45793cec0295c2f78ac91ccb3edf0c177 100644 (file)
@@ -119,7 +119,8 @@ class page_requirements_manager {
     public function js($jsfile, $fullurl = false) {
         global $CFG;
         if (!$fullurl) {
-            if (!file_exists($CFG->dirroot . '/' . $jsfile)) {
+            // strtok is used to trim off any GET string arguments before looking for the file
+            if (!file_exists($CFG->dirroot . '/' . strtok($jsfile, '?'))) {
                 throw new coding_exception('Attept to require a JavaScript file that does not exist.', $jsfile);
             }
             $url = $CFG->httpswwwroot . '/' . $jsfile;
index 1b144cad2f2c98bbc31fee5c98789ede8f10dbd5..aed4e16956c6cad89c96909008a19ab94c17c82e 100644 (file)
@@ -320,6 +320,15 @@ class page_requirements_manager_test extends ajaxlib_unit_test_base {
         $this->assertContains($html, $CFG->httpswwwroot . '/' . $jsfile);
     }
 
+    public function test_requiring_js_with_argument() {
+        global $CFG;
+        $jsfile = 'lib/javascript-static.js?d=434'; // Just needs to be a JS file that exists.
+        $this->requires->js($jsfile);
+
+        $html = $this->requires->get_end_code();
+        $this->assertContains($html, $CFG->httpswwwroot . '/' . $jsfile);
+    }
+
     public function test_nonexistant_js_throws_exception() {
         $cssfile = 'js/file/that/does/not/exist.js';