/** * 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 getting the name of a tool. */ public function test_get_name() { $course1 = $this->getDataGenerator()->create_course(); $data = new stdClass(); $data->courseid = $course1->id; $tool1 = $this->create_tool($data); $name = \enrol_lti\helper::get_name($tool1); $this->assertEquals('Course: Test course 1', $name); $tool1->name = 'Shared course'; $name = \enrol_lti\helper::get_name($tool1); $this->assertEquals('Shared course', $name); }
/** * Constructor test. */ public function test_constructor() { global $CFG, $SITE; $tool = $this->tool; $tp = new tool_provider($tool->id); $this->assertNull($tp->consumer); $this->assertNull($tp->returnUrl); $this->assertNull($tp->resourceLink); $this->assertNull($tp->context); $this->assertNotNull($tp->dataConnector); $this->assertEquals('', $tp->defaultEmail); $this->assertEquals(ToolProvider::ID_SCOPE_ID_ONLY, $tp->idScope); $this->assertFalse($tp->allowSharing); $this->assertEquals(ToolProvider::CONNECTION_ERROR_MESSAGE, $tp->message); $this->assertNull($tp->reason); $this->assertEmpty($tp->details); $this->assertEquals($CFG->wwwroot, $tp->baseUrl); $this->assertNotNull($tp->vendor); $this->assertEquals($SITE->shortname, $tp->vendor->id); $this->assertEquals($SITE->fullname, $tp->vendor->name); $this->assertEquals($SITE->summary, $tp->vendor->description); $token = helper::generate_proxy_token($tool->id); $name = helper::get_name($tool); $description = helper::get_description($tool); $this->assertNotNull($tp->product); $this->assertEquals($token, $tp->product->id); $this->assertEquals($name, $tp->product->name); $this->assertEquals($description, $tp->product->description); $this->assertNotNull($tp->requiredServices); $this->assertEmpty($tp->optionalServices); $this->assertNotNull($tp->resourceHandlers); }