ajaxlib MDL-16693 Fixed fringe condition in ajaxlib and added test

This commit is contained in:
samhemelryk 2009-06-22 02:59:02 +00:00
parent 6dbcaceef1
commit d76b8a2068
2 changed files with 11 additions and 1 deletions

View 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;

View 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';