Merge branch 'MDL-55314-master' of https://github.com/mrmark/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2016-08-02 17:16:07 +02:00
commit e0519d032d
3 changed files with 15 additions and 6 deletions

View File

@ -2700,24 +2700,32 @@ function lti_load_tool_from_cartridge($url, $lti) {
function lti_load_cartridge($url, $map, $propertiesmap = array()) {
global $CFG;
require_once($CFG->libdir. "/filelib.php");
// TODO MDL-46023 Replace this code with a call to the new library.
$origentity = libxml_disable_entity_loader(true);
$curl = new curl();
$response = $curl->get($url);
// TODO MDL-46023 Replace this code with a call to the new library.
$origerrors = libxml_use_internal_errors(true);
$origentity = libxml_disable_entity_loader(true);
libxml_clear_errors();
$document = new DOMDocument();
@$document->loadXML($response, LIBXML_DTDLOAD | LIBXML_DTDATTR);
$cartridge = new DomXpath($document);
$errors = libxml_get_errors();
libxml_clear_errors();
libxml_use_internal_errors($origerrors);
libxml_disable_entity_loader($origentity);
if (count($errors) > 0) {
$message = 'Failed to load cartridge.';
foreach ($errors as $error) {
$message .= "\n" . trim($error->message, "\n\r\t .") . " at line " . $error->line;
}
throw new moodle_exception($message);
throw new moodle_exception('errorreadingfile', '', '', $url, $message);
}
$toolinfo = array();
@ -2735,7 +2743,7 @@ function lti_load_cartridge($url, $map, $propertiesmap = array()) {
}
}
}
libxml_disable_entity_loader($origentity);
return $toolinfo;
}

View File

@ -52,7 +52,8 @@ class mod_lti_external_testcase extends externallib_advanced_testcase {
// Setup test data.
$this->course = $this->getDataGenerator()->create_course();
$this->lti = $this->getDataGenerator()->create_module('lti', array('course' => $this->course->id));
$this->lti = $this->getDataGenerator()->create_module('lti',
array('course' => $this->course->id, 'toolurl' => 'http://localhost/not/real/tool.php'));
$this->context = context_module::instance($this->lti->cmid);
$this->cm = get_coursemodule_from_instance('lti', $this->lti->id);

View File

@ -41,7 +41,7 @@ class mod_lti_generator extends testing_module_generator {
$record = (object) (array) $record;
if (!isset($record->toolurl)) {
$record->toolurl = 'http://www.imsglobal.org/developers/LTI/test/v1p1/tool.php';
$record->toolurl = '';
}
if (!isset($record->resourcekey)) {
$record->resourcekey = '12345';