|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // This file is part of BasicLTI4Moodle 00018 // 00019 // BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability) 00020 // consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web 00021 // based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI 00022 // specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS 00023 // are already supporting or going to support BasicLTI. This project Implements the consumer 00024 // for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas. 00025 // BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem 00026 // at the GESSI research group at UPC. 00027 // SimpleLTI consumer for Moodle is an implementation of the early specification of LTI 00028 // by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a 00029 // Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier. 00030 // 00031 // BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis 00032 // of the Universitat Politecnica de Catalunya http://www.upc.edu 00033 // Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu 00034 00051 defined('MOODLE_INTERNAL') || die; 00052 00053 require_once($CFG->dirroot . '/mod/lti/locallib.php'); 00054 require_once($CFG->dirroot . '/mod/lti/servicelib.php'); 00055 00056 class lti_locallib_test extends UnitTestCase { 00057 public static $includecoverage = array('mod/lti/locallib.php'); 00058 00059 public function test_split_custom_parameters() { 00060 $this->assertEqual(lti_split_custom_parameters("x=1\ny=2"), 00061 array('custom_x' => '1', 'custom_y'=> '2')); 00062 00063 $this->assertEqual(lti_split_custom_parameters('x=1;y=2'), 00064 array('custom_x' => '1', 'custom_y'=> '2')); 00065 00066 $this->assertEqual(lti_split_custom_parameters('Review:Chapter=1.2.56'), 00067 array('custom_review_chapter' => '1.2.56')); 00068 00069 $this->assertEqual(lti_split_custom_parameters('Complex!@#$^*(){}[]KEY=Complex!@#$^*(){}[]Value'), 00070 array('custom_complex____________key' => 'Complex!@#$^*(){}[]Value')); 00071 } 00072 00079 public function disabled_test_sign_parameters() { 00080 $correct = array ( 'context_id' => '12345', 'context_label' => 'SI124', 'context_title' => 'Social Computing', 'ext_submit' => 'Click Me', 'lti_message_type' => 'basic-lti-launch-request', 'lti_version' => 'LTI-1p0', 'oauth_consumer_key' => 'lmsng.school.edu', 'oauth_nonce' => '47458148e33a8f9dafb888c3684cf476', 'oauth_signature' => 'qWgaBIezihCbeHgcwUy14tZcyDQ=', 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_timestamp' => '1307141660', 'oauth_version' => '1.0', 'resource_link_id' => '123', 'resource_link_title' => 'Weekly Blog', 'roles' => 'Learner', 'tool_consumer_instance_guid' => 'lmsng.school.edu', 'user_id' => '789'); 00081 00082 $requestparams = array('resource_link_id' => '123', 'resource_link_title' => 'Weekly Blog', 'user_id' => '789', 'roles' => 'Learner', 'context_id' => '12345', 'context_label' => 'SI124', 'context_title' => 'Social Computing'); 00083 00084 $parms = lti_sign_parameters($requestparams, 'http://www.imsglobal.org/developer/LTI/tool.php', 'POST', 00085 'lmsng.school.edu', 'secret', 'Click Me', 'lmsng.school.edu' /*, $org_desc*/); 00086 $this->assertTrue(isset($parms['oauth_nonce'])); 00087 $this->assertTrue(isset($parms['oauth_signature'])); 00088 $this->assertTrue(isset($parms['oauth_timestamp'])); 00089 00090 // Those things that are hard to mock 00091 $correct['oauth_nonce'] = $parms['oauth_nonce']; 00092 $correct['oauth_signature'] = $parms['oauth_signature']; 00093 $correct['oauth_timestamp'] = $parms['oauth_timestamp']; 00094 ksort($parms); 00095 ksort($correct); 00096 $this->assertEqual($parms, $correct); 00097 } 00098 00105 public function disabled_test_parse_grade_replace_message() { 00106 $message = ' 00107 <imsx_POXEnvelopeRequest xmlns = "http://www.imsglobal.org/lis/oms1p0/pox"> 00108 <imsx_POXHeader> 00109 <imsx_POXRequestHeaderInfo> 00110 <imsx_version>V1.0</imsx_version> 00111 <imsx_messageIdentifier>999998123</imsx_messageIdentifier> 00112 </imsx_POXRequestHeaderInfo> 00113 </imsx_POXHeader> 00114 <imsx_POXBody> 00115 <replaceResultRequest> 00116 <resultRecord> 00117 <sourcedGUID> 00118 <sourcedId>{"data":{"instanceid":"2","userid":"2"},"hash":"0b5078feab59b9938c333ceaae21d8e003a7b295e43cdf55338445254421076b"}</sourcedId> 00119 </sourcedGUID> 00120 <result> 00121 <resultScore> 00122 <language>en-us</language> 00123 <textString>0.92</textString> 00124 </resultScore> 00125 </result> 00126 </resultRecord> 00127 </replaceResultRequest> 00128 </imsx_POXBody> 00129 </imsx_POXEnvelopeRequest> 00130 '; 00131 00132 $parsed = lti_parse_grade_replace_message(new SimpleXMLElement($message)); 00133 00134 $this->assertEqual($parsed->userid, '2'); 00135 $this->assertEqual($parsed->instanceid, '2'); 00136 $this->assertEqual($parsed->sourcedidhash, '0b5078feab59b9938c333ceaae21d8e003a7b295e43cdf55338445254421076b'); 00137 00138 $ltiinstance = (object)array('servicesalt' => '4e5fcc06de1d58.44963230'); 00139 00140 lti_verify_sourcedid($ltiinstance, $parsed); 00141 } 00142 }