/** * Testing service error handling. */ public function test_handle() { $handler = new service_exception_handler(false); $handler->set_message_id('123'); $handler->set_message_type('testRequest'); $handler->handle(new Exception('Error happened')); $this->expectOutputRegex('/imsx_codeMajor>failure/'); $this->expectOutputRegex('/imsx_description>Error happened/'); $this->expectOutputRegex('/imsx_messageRefIdentifier>123/'); $this->expectOutputRegex('/imsx_operationRefIdentifier>testRequest/'); $this->expectOutputRegex('/imsx_POXBody><testResponse/'); }
throw new Exception('Message signature not valid'); } // TODO MDL-46023 Replace this code with a call to the new library. $origentity = libxml_disable_entity_loader(true); $xml = simplexml_load_string($rawbody); if (!$xml) { libxml_disable_entity_loader($origentity); throw new Exception('Invalid XML content'); } libxml_disable_entity_loader($origentity); $body = $xml->imsx_POXBody; foreach ($body->children() as $child) { $messagetype = $child->getName(); } // We know more about the message, update error handler to send better errors. $errorhandler->set_message_id(lti_parse_message_id($xml)); $errorhandler->set_message_type($messagetype); switch ($messagetype) { case 'replaceResultRequest': $parsed = lti_parse_grade_replace_message($xml); $ltiinstance = $DB->get_record('lti', array('id' => $parsed->instanceid)); if (!lti_accepts_grades($ltiinstance)) { throw new Exception('Tool does not accept grades'); } lti_verify_sourcedid($ltiinstance, $parsed); lti_set_session_user($parsed->userid); $gradestatus = lti_update_grade($ltiinstance, $parsed->userid, $parsed->launchid, $parsed->gradeval); if (!$gradestatus) { throw new Exception('Grade replace response'); } $responsexml = lti_get_response_xml('success', 'Grade replace response', $parsed->messageid, 'replaceResultResponse');