コード例 #1
0
ファイル: lib_test.php プロジェクト: dg711/moodle
 /**
  * Test for enrol_lti_plugin::delete_instance().
  */
 public function test_delete_instance()
 {
     global $DB;
     // Create tool enrolment instance.
     $data = new stdClass();
     $data->enrolstartdate = time();
     $data->secret = 'secret';
     $tool = $this->getDataGenerator()->create_lti_tool($data);
     // Create consumer and related data.
     $dataconnector = new data_connector();
     $consumer = new ToolConsumer('testkey', $dataconnector);
     $consumer->secret = $tool->secret;
     $consumer->ltiVersion = ToolProvider::LTI_VERSION1;
     $consumer->name = 'TEST CONSUMER NAME';
     $consumer->consumerName = 'TEST CONSUMER INSTANCE NAME';
     $consumer->consumerGuid = 'TEST CONSUMER INSTANCE GUID';
     $consumer->consumerVersion = 'TEST CONSUMER INFO VERSION';
     $consumer->enabled = true;
     $consumer->protected = true;
     $consumer->save();
     $resourcelink = ResourceLink::fromConsumer($consumer, 'testresourcelinkid');
     $resourcelink->save();
     $ltiuser = User::fromResourceLink($resourcelink, '');
     $ltiuser->ltiResultSourcedId = 'testLtiResultSourcedId';
     $ltiuser->ltiUserId = 'testuserid';
     $ltiuser->email = '*****@*****.**';
     $ltiuser->save();
     $tp = new tool_provider($tool->id);
     $tp->user = $ltiuser;
     $tp->resourceLink = $resourcelink;
     $tp->consumer = $consumer;
     $tp->map_tool_to_consumer();
     $mappingparams = ['toolid' => $tool->id, 'consumerid' => $tp->consumer->getRecordId()];
     // Check first that the related records exist.
     $this->assertTrue($DB->record_exists('enrol_lti_tool_consumer_map', $mappingparams));
     $this->assertTrue($DB->record_exists('enrol_lti_lti2_consumer', ['id' => $consumer->getRecordId()]));
     $this->assertTrue($DB->record_exists('enrol_lti_lti2_resource_link', ['id' => $resourcelink->getRecordId()]));
     $this->assertTrue($DB->record_exists('enrol_lti_lti2_user_result', ['id' => $ltiuser->getRecordId()]));
     // Perform deletion.
     $enrollti = new enrol_lti_plugin();
     $instance = $DB->get_record('enrol', ['id' => $tool->enrolid]);
     $enrollti->delete_instance($instance);
     // Check that the related records have been deleted.
     $this->assertFalse($DB->record_exists('enrol_lti_tool_consumer_map', $mappingparams));
     $this->assertFalse($DB->record_exists('enrol_lti_lti2_consumer', ['id' => $consumer->getRecordId()]));
     $this->assertFalse($DB->record_exists('enrol_lti_lti2_resource_link', ['id' => $resourcelink->getRecordId()]));
     $this->assertFalse($DB->record_exists('enrol_lti_lti2_user_result', ['id' => $ltiuser->getRecordId()]));
     // Check that the enrolled users and the tool instance has been deleted.
     $this->assertFalse($DB->record_exists('enrol_lti_users', ['toolid' => $tool->id]));
     $this->assertFalse($DB->record_exists('enrol_lti_tools', ['id' => $tool->id]));
     $this->assertFalse($DB->record_exists('enrol', ['id' => $instance->id]));
 }
コード例 #2
0
 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();
 }
コード例 #3
0
ファイル: tool_provider_test.php プロジェクト: dg711/moodle
 /**
  * Exposes tool_provider::onRegister().
  */
 public function onRegister()
 {
     parent::onRegister();
 }