Example #1
0
 /**
  * Test for data_connector::deleteUser().
  */
 public function test_delete_user()
 {
     $dc = new data_connector();
     $consumer = new ToolConsumer(null, $dc);
     $consumer->name = 'TestName';
     $consumer->setKey('TestKey');
     $consumer->secret = 'TestSecret';
     $consumer->save();
     $resourcelink = ResourceLink::fromConsumer($consumer, 'testresourcelinkid');
     $resourcelink->save();
     $user = User::fromResourceLink($resourcelink, '');
     $user->ltiResultSourcedId = 'testLtiResultSourcedId';
     $user->firstname = 'First';
     $user->lastname = 'Last';
     $user->fullname = 'Full name';
     $user->email = '*****@*****.**';
     $user->roles = ['a', 'b'];
     $user->groups = ['1', '2'];
     $user->save();
     // Delete user.
     $this->assertTrue($dc->deleteUser($user));
     // User record should have been deleted from the DB.
     $this->assertFalse($dc->loadUser($user));
     // User object should have been initialised().
     $this->assertEmpty($user->firstname);
     $this->assertEmpty($user->lastname);
     $this->assertEmpty($user->fullname);
     $this->assertEmpty($user->email);
     $this->assertEmpty($user->roles);
     $this->assertEmpty($user->groups);
     $this->assertNull($user->ltiResultSourcedId);
     $this->assertNull($user->created);
     $this->assertNull($user->updated);
 }
Example #2
0
 /**
  * Builds a ToolConsumer object from a record object from the DB.
  *
  * @param stdClass $record The DB record object.
  * @param ToolConsumer $consumer
  */
 protected function build_tool_consumer_object($record, ToolConsumer $consumer)
 {
     $consumer->setRecordId($record->id);
     $consumer->name = $record->name;
     $key = empty($record->consumerkey) ? $record->consumerkey256 : $record->consumerkey;
     $consumer->setKey($key);
     $consumer->secret = $record->secret;
     $consumer->ltiVersion = $record->ltiversion;
     $consumer->consumerName = $record->consumername;
     $consumer->consumerVersion = $record->consumerversion;
     $consumer->consumerGuid = $record->consumerguid;
     $consumer->profile = json_decode($record->profile);
     $consumer->toolProxy = $record->toolproxy;
     $settings = unserialize($record->settings);
     if (!is_array($settings)) {
         $settings = array();
     }
     $consumer->setSettings($settings);
     $consumer->protected = $record->protected == 1;
     $consumer->enabled = $record->enabled == 1;
     $consumer->enableFrom = null;
     if (!is_null($record->enablefrom)) {
         $consumer->enableFrom = $record->enablefrom;
     }
     $consumer->enableUntil = null;
     if (!is_null($record->enableuntil)) {
         $consumer->enableUntil = $record->enableuntil;
     }
     $consumer->lastAccess = null;
     if (!is_null($record->lastaccess)) {
         $consumer->lastAccess = $record->lastaccess;
     }
     $consumer->created = $record->created;
     $consumer->updated = $record->updated;
 }
Example #3
0
 /**
  * Send the tool proxy to the Tool Consumer
  *
  * @return boolean True if the tool proxy was accepted
  */
 public function doToolProxyService()
 {
     // Create tool proxy
     $toolProxyService = $this->findService('application/vnd.ims.lti.v2.toolproxy+json', array('POST'));
     $secret = DataConnector::getRandomString(12);
     $toolProxy = new MediaType\ToolProxy($this, $toolProxyService, $secret);
     $http = $this->consumer->doServiceRequest($toolProxyService, 'POST', 'application/vnd.ims.lti.v2.toolproxy+json', json_encode($toolProxy));
     $ok = $http->ok && $http->status == 201 && isset($http->responseJson->tool_proxy_guid) && strlen($http->responseJson->tool_proxy_guid) > 0;
     if ($ok) {
         $this->consumer->setKey($http->responseJson->tool_proxy_guid);
         $this->consumer->secret = $toolProxy->security_contract->shared_secret;
         $this->consumer->toolProxy = json_encode($toolProxy);
         $this->consumer->save();
     }
     return $ok;
 }
 /**
  * Test for data_connector::get_resourcelink_from_context()
  */
 public function test_get_resourcelink_from_context()
 {
     $dc = new data_connector();
     $consumer = new ToolConsumer(null, $dc);
     $consumer->name = 'TestName';
     $consumer->setKey('TestKey');
     $consumer->secret = 'TestSecret';
     $consumer->save();
     $settings = ['a', 'b', 'c'];
     $lticontextid = 'testlticontextid';
     $context = Context::fromConsumer($consumer, $lticontextid);
     $context->settings = $settings;
     $context->save();
     // No ResourceLink associated with the Context yet.
     $this->assertNull($dc->get_resourcelink_from_context($context));
     // Create and save ResourceLink from the Context.
     $resourcelink = ResourceLink::fromContext($context, 'testresourcelinkid');
     $resourcelink->save();
     $dc->loadResourceLink($resourcelink);
     // Assert that the resource link and the one fetched by get_resourcelink_from_context() are the same.
     $this->assertEquals($resourcelink, $dc->get_resourcelink_from_context($context));
 }