/**
  * Testing that a log file is generated when logging is turned on.
  */
 public function test_handle_log()
 {
     global $CFG;
     $this->resetAfterTest();
     $handler = new service_exception_handler(true);
     ob_start();
     $handler->handle(new Exception('Error happened'));
     ob_end_clean();
     $this->assertTrue(is_dir($CFG->dataroot . '/temp/mod_lti'));
     $files = glob($CFG->dataroot . '/temp/mod_lti/mod_lti_response*');
     $this->assertEquals(1, count($files));
 }
示例#2
0
 * @package mod_lti
 * @copyright  Copyright (c) 2011 Moodlerooms Inc. (http://www.moodlerooms.com)
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @author     Chris Scribner
 */
define('NO_DEBUG_DISPLAY', true);
define('NO_MOODLE_COOKIES', true);
require_once __DIR__ . "/../../config.php";
require_once $CFG->dirroot . '/mod/lti/locallib.php';
require_once $CFG->dirroot . '/mod/lti/servicelib.php';
// TODO: Switch to core oauthlib once implemented - MDL-30149.
use mod_lti\service_exception_handler;
use moodle\mod\lti;
$rawbody = file_get_contents("php://input");
$logrequests = lti_should_log_request($rawbody);
$errorhandler = new service_exception_handler($logrequests);
// Register our own error handler so we can always send valid XML response.
set_exception_handler(array($errorhandler, 'handle'));
if ($logrequests) {
    lti_log_request($rawbody);
}
foreach (lti\OAuthUtil::get_headers() as $name => $value) {
    if ($name === 'Authorization') {
        // TODO: Switch to core oauthlib once implemented - MDL-30149.
        $oauthparams = lti\OAuthUtil::split_header($value);
        $consumerkey = $oauthparams['oauth_consumer_key'];
        break;
    }
}
if (empty($consumerkey)) {
    throw new Exception('Consumer key is missing.');