/** * Create a new instance of tool_provider to handle all the LTI tool provider interactions. * * @param int $toolid The id of the tool to be provided. */ public function __construct($toolid) { global $CFG, $SITE; $token = helper::generate_proxy_token($toolid); $tool = helper::get_lti_tool($toolid); $this->tool = $tool; $dataconnector = new data_connector(); parent::__construct($dataconnector); // Override debugMode and set to the configured value. $this->debugMode = $CFG->debugdeveloper; $this->baseUrl = $CFG->wwwroot; $toolpath = helper::get_launch_url($toolid); $toolpath = $this->strip_base_url($toolpath); $vendorid = $SITE->shortname; $vendorname = $SITE->fullname; $vendordescription = trim(html_to_text($SITE->summary)); $this->vendor = new Item($vendorid, $vendorname, $vendordescription, $CFG->wwwroot); $name = helper::get_name($tool); $description = helper::get_description($tool); $icon = helper::get_icon($tool)->out(); $icon = $this->strip_base_url($icon); $this->product = new Item($token, $name, $description, helper::get_proxy_url($tool), '1.0'); $requiredmessages = [new Message('basic-lti-launch-request', $toolpath, ['Context.id', 'CourseSection.title', 'CourseSection.label', 'CourseSection.sourcedId', 'CourseSection.longDescription', 'CourseSection.timeFrame.begin', 'ResourceLink.id', 'ResourceLink.title', 'ResourceLink.description', 'User.id', 'User.username', 'Person.name.full', 'Person.name.given', 'Person.name.family', 'Person.email.primary', 'Person.sourcedId', 'Person.name.middle', 'Person.address.street1', 'Person.address.locality', 'Person.address.country', 'Person.address.timezone', 'Person.phone.primary', 'Person.phone.mobile', 'Person.webaddress', 'Membership.role', 'Result.sourcedId', 'Result.autocreate'])]; $optionalmessages = []; $this->resourceHandlers[] = new ResourceHandler(new Item($token, helper::get_name($tool), $description), $icon, $requiredmessages, $optionalmessages); $this->requiredServices[] = new ServiceDefinition(['application/vnd.ims.lti.v2.toolproxy+json'], ['POST']); $this->requiredServices[] = new ServiceDefinition(['application/vnd.ims.lis.v2.membershipcontainer+json'], ['GET']); }
/** * Test set up. * * This is executed before running any tests in this file. */ public function setUp() { global $SESSION; $this->resetAfterTest(); manager::init_empty_session(); // Set this user as the admin. $this->setAdminUser(); $data = new stdClass(); $data->enrolstartdate = time(); $data->secret = 'secret'; $toolrecord = $this->getDataGenerator()->create_lti_tool($data); $this->tool = helper::get_lti_tool($toolrecord->id); $SESSION->notifications = []; }
public function setUp() { $this->resetAfterTest(); // Set this user as the admin. $this->setAdminUser(); $this->task = new dummy_sync_members_task(); $generator = $this->getDataGenerator(); $course = $generator->create_course(); $tooldata = ['courseid' => $course->id, 'membersyncmode' => helper::MEMBER_SYNC_ENROL_AND_UNENROL, 'membersync' => 1]; $tool = $generator->create_lti_tool((object) $tooldata); $this->tool = helper::get_lti_tool($tool->id); $dataconnector = $this->task->get_dataconnector(); $this->consumer = new ToolConsumer('Consumer1Key', $dataconnector); $this->consumer->name = 'Consumer1'; $this->consumer->secret = 'Consumer1Secret'; $this->consumer->save(); $toolprovider = new tool_provider($this->tool->id); $toolprovider->consumer = $this->consumer; $toolprovider->map_tool_to_consumer(); $imageurl = $this->getExternalTestFileUrl('test.jpg'); $count = 10; $this->members = []; for ($i = 1; $i <= $count; $i++) { $user = new User(); $user->firstname = 'Firstname' . $i; $user->lastname = 'Lastname' . $i; $user->ltiUserId = 'user' . $i; // Set user image values for some users. if ($i % 3 == 0) { $user->image = $imageurl; } $this->members[] = $user; } $this->context = Context::fromConsumer($this->consumer, 'testlticontextid'); $this->context->save(); $this->resourcelink = ResourceLink::fromContext($this->context, 'testresourcelinkid'); $this->resourcelink->save(); }
$toolid = null; $token = null; $filearguments = get_file_argument(); $arguments = explode('/', trim($filearguments, '/')); if (count($arguments) >= 2) { // Can put cartridge.xml at the end, or anything really. list($toolid, $token) = $arguments; } $toolid = optional_param('id', $toolid, PARAM_INT); $token = optional_param('token', $token, PARAM_ALPHANUM); // Only show the cartridge if the token parameter is correct. // If we do not compare with a shared secret, someone could very easily // guess an id for the enrolment. if (!\enrol_lti\helper::verify_tool_token($toolid, $token)) { throw new \moodle_exception('incorrecttoken', 'enrol_lti'); } $tool = \enrol_lti\helper::get_lti_tool($toolid); if (!is_enabled_auth('lti')) { print_error('pluginnotenabled', 'auth', '', get_string('pluginname', 'auth_lti')); } else { if (!enrol_is_enabled('lti')) { print_error('enrolisdisabled', 'enrol_lti'); } else { if ($tool->status != ENROL_INSTANCE_ENABLED) { print_error('enrolisdisabled', 'enrol_lti'); } else { header('Content-Type: text/xml; charset=utf-8'); echo \enrol_lti\helper::create_cartridge($toolid); } } }
/** * Test that we can not enrol when the enrolment has finished. */ public function test_enrol_user_enrolment_finished() { global $DB; // Set up the LTI enrolment tool. $data = new stdClass(); $data->enrolenddate = time() - DAYSECS; // Make sure it is in the past. $tool = $this->create_tool($data); // Now get all the information we need. $tool = \enrol_lti\helper::get_lti_tool($tool->id); // Try and enrol a user - should not happen. $result = \enrol_lti\helper::enrol_user($tool, $this->user1->id); // Check that this user was not enrolled and we are told why. $this->assertEquals(\enrol_lti\helper::ENROLMENT_FINISHED, $result); $this->assertEquals(0, $DB->count_records('user_enrolments', array('enrolid' => $tool->enrolid))); }