public function testGetTimestamp() { $result = TinCan\Util::getTimestamp(); // // this isn't intended to match all ISO8601 just *our* format of it, so it should // catch regressions, at least more than will be accepted by an LRS which is really // ultimately what we want in our tests // $this->assertRegExp('/\\d\\d\\d\\d-[01]\\d-[0123]\\dT[012]\\d:[012345]\\d:[012345]\\d\\.\\d\\d\\d[-+]\\d\\d:\\d\\d/', $result); }
public function testAsVersion() { $args = ['objectType' => 'SubStatement', 'actor' => ['mbox' => COMMON_MBOX, 'objectType' => 'Agent'], 'verb' => ['id' => COMMON_VERB_ID, 'display' => ['en-US' => 'experienced']], 'object' => ['objectType' => 'Activity', 'id' => COMMON_ACTIVITY_ID, 'definition' => ['type' => 'Invalid type', 'name' => ['en-US' => 'Test'], 'extensions' => ['http://someuri' => 'some value']]], 'context' => ['contextActivities' => ['parent' => [['objectType' => 'Activity', 'id' => COMMON_ACTIVITY_ID . '/1', 'definition' => ['name' => ['en-US' => 'Test: 1']]]]], 'registration' => TinCan\Util::getUUID()], 'result' => ['completion' => true, 'success' => false, 'score' => ['raw' => '97', 'min' => '65', 'max' => '100', 'scaled' => '.97']]]; $obj = new SubStatement($args); $obj->getTarget()->getDefinition()->getDescription()->set('en-ES', 'Testo descriptiono'); $args['object']['definition']['description'] = ['en-ES' => 'Testo descriptiono']; $obj->getTarget()->getDefinition()->getName()->unset('en-US'); unset($args['object']['definition']['name']); $versioned = $obj->asVersion('1.0.0'); $this->assertEquals($args, $versioned, 'version 1.0.0'); }
public function testAsVersion() { $args = ['actor' => ['mbox' => COMMON_MBOX, 'objectType' => 'Agent'], 'verb' => ['id' => COMMON_VERB_ID, 'display' => ['en-US' => 'experienced']], 'object' => ['objectType' => 'Activity', 'id' => COMMON_ACTIVITY_ID, 'definition' => ['type' => 'Invalid type', 'name' => ['en-US' => 'Test'], 'extensions' => ['http://someuri' => 'some value']]], 'context' => ['contextActivities' => ['parent' => [['objectType' => 'Activity', 'id' => COMMON_ACTIVITY_ID . '/1', 'definition' => ['name' => ['en-US' => 'Test: 1']]]]], 'registration' => TinCan\Util::getUUID()], 'result' => ['completion' => true, 'success' => false, 'score' => ['raw' => '97', 'min' => '65', 'max' => '100', 'scaled' => '.97']], 'version' => '1.0.0', 'attachments' => [['usageType' => 'http://test', 'display' => ['en-US' => 'test display'], 'contentType' => 'text/plain; charset=ascii', 'length' => 0, 'sha2' => hash('sha256', json_encode(['foo', 'bar']))]]]; $obj = new Statement($args); $obj->stamp(); $args['id'] = $obj->getId(); $args['timestamp'] = $obj->getTimestamp(); $obj->getTarget()->getDefinition()->getDescription()->set('en-ES', 'Testo descriptiono'); $args['object']['definition']['description'] = ['en-ES' => 'Testo descriptiono']; $obj->getTarget()->getDefinition()->getName()->unset('en-US'); unset($args['object']['definition']['name']); $versioned = $obj->asVersion('1.0.0'); $this->assertEquals($args, $versioned, 'version 1.0.0'); }
public function testCompareWithSignature() { $actor1 = new TinCan\Agent(['mbox' => COMMON_MBOX]); $actor2 = new TinCan\Agent(['account' => ['homePage' => COMMON_ACCT_HOMEPAGE, 'name' => COMMON_ACCT_NAME]]); $verb1 = new TinCan\Verb(['id' => COMMON_VERB_ID]); $verb2 = new TinCan\Verb(['id' => COMMON_VERB_ID . '/2']); $activity1 = new TinCan\Activity(['id' => COMMON_ACTIVITY_ID]); $activity2 = new TinCan\Activity(['id' => COMMON_ACTIVITY_ID . '/2']); $context1 = new TinCan\Context(['registration' => TinCan\Util::getUUID()]); $context2 = new TinCan\Context(['contextActivities' => [['parent' => [COMMON_ACTIVITY_ID . '/parent']], ['grouping' => [COMMON_ACTIVITY_ID]]]]); $result1 = new TinCan\Result(['raw' => 87]); $result2 = new TinCan\Result(['response' => 'a']); $timestamp1 = '2015-01-28T14:23:37.159Z'; $timestamp1_tz = '2015-01-28T08:23:37.159-06:00'; $timestamp1_subsecond = '2015-01-28T14:23:37.348Z'; $timestamp2 = '2015-01-28T15:49:11.089Z'; $full = ['actor' => $actor1, 'verb' => $verb1, 'target' => $activity1, 'context' => $context1, 'result' => $result1, 'timestamp' => $timestamp1]; $cases = [['description' => 'all null', 'objArgs' => []], ['description' => 'actor', 'objArgs' => ['actor' => $actor1]], ['description' => 'verb', 'objArgs' => ['verb' => $verb1]], ['description' => 'object', 'objArgs' => ['target' => $activity1]], ['description' => 'result', 'objArgs' => ['result' => $result1]], ['description' => 'context', 'objArgs' => ['context' => $context1]], ['description' => 'timestamp', 'objArgs' => ['timestamp' => $timestamp1]], ['description' => 'all', 'objArgs' => $full], ['description' => 'timestamp timezone difference', 'objArgs' => ['timestamp' => $timestamp1], 'sigArgs' => ['timestamp' => $timestamp1_tz]], ['description' => 'timestamp subsecond difference', 'objArgs' => ['timestamp' => $timestamp1], 'sigArgs' => ['timestamp' => $timestamp1_subsecond], 'reason' => 'Comparison of timestamp failed: value is not the same'], ['description' => 'actor only: mismatch', 'objArgs' => ['actor' => $actor1], 'sigArgs' => ['actor' => $actor2], 'reason' => 'Comparison of actor failed: Comparison of mbox failed: value is not the same'], ['description' => 'verb only: mismatch', 'objArgs' => ['verb' => $verb1], 'sigArgs' => ['verb' => $verb2], 'reason' => 'Comparison of verb failed: Comparison of id failed: value is not the same'], ['description' => 'object only: mismatch', 'objArgs' => ['target' => $activity1], 'sigArgs' => ['target' => $activity2], 'reason' => 'Comparison of target failed: Comparison of id failed: value is not the same'], ['description' => 'result only: mismatch', 'objArgs' => ['result' => $result1], 'sigArgs' => ['result' => $result2], 'reason' => 'Comparison of result failed: Comparison of response failed: value not present in this or signature'], ['description' => 'context only: mismatch', 'objArgs' => ['context' => $context1], 'sigArgs' => ['context' => $context2], 'reason' => 'Comparison of context failed: Comparison of registration failed: value not present in this or signature'], ['description' => 'timestamp only: mismatch', 'objArgs' => ['timestamp' => $timestamp1], 'sigArgs' => ['timestamp' => $timestamp2], 'reason' => 'Comparison of timestamp failed: value is not the same'], ['description' => 'full: actor mismatch', 'objArgs' => $full, 'sigArgs' => array_replace($full, ['actor' => $actor2]), 'reason' => 'Comparison of actor failed: Comparison of mbox failed: value is not the same'], ['description' => 'full: verb mismatch', 'objArgs' => $full, 'sigArgs' => array_replace($full, ['verb' => $verb2]), 'reason' => 'Comparison of verb failed: Comparison of id failed: value is not the same'], ['description' => 'full: target mismatch', 'objArgs' => $full, 'sigArgs' => array_replace($full, ['target' => $activity2]), 'reason' => 'Comparison of target failed: Comparison of id failed: value is not the same'], ['description' => 'full: result mismatch', 'objArgs' => $full, 'sigArgs' => array_replace($full, ['result' => $result2]), 'reason' => 'Comparison of result failed: Comparison of response failed: value not present in this or signature'], ['description' => 'full: context mismatch', 'objArgs' => $full, 'sigArgs' => array_replace($full, ['context' => $context2]), 'reason' => 'Comparison of context failed: Comparison of registration failed: value not present in this or signature'], ['description' => 'full: timestamp mismatch', 'objArgs' => $full, 'sigArgs' => array_replace($full, ['timestamp' => $timestamp2]), 'reason' => 'Comparison of timestamp failed: value is not the same']]; $this->runSignatureCases("TinCan\\SubStatement", $cases); }
public function testClearState() { $lrs = new RemoteLRS(self::$endpoint, self::$version, self::$username, self::$password); $response = $lrs->clearState(new TinCan\Activity(['id' => COMMON_ACTIVITY_ID]), new TinCan\Agent(['mbox' => COMMON_MBOX]), ['registration' => TinCan\Util::getUUID()]); $this->assertInstanceOf('TinCan\\LRSResponse', $response); }
//TODO: there may be a better way to check completion. Out of scope for current project. $(document).ready(function() { setInterval(function() { $('#tincanlaunch_attemptprogress').load('completion_check.php?id=<?php echo $id; ?> &n=<?php echo $n; ?> '); }, 30000); //TODO: make this interval a configuration setting }); </script> <?php //generate a registration id for any new attempt $tinCanPHPUtil = new \TinCan\Util(); $registrationid = $tinCanPHPUtil->getUUID(); $getregistrationdatafromlrsstate = tincanlaunch_get_global_parameters_and_get_state("http://tincanapi.co.uk/stateapikeys/registrations"); $lrsrespond = $getregistrationdatafromlrsstate->httpResponse['status']; if ($lrsrespond != 200 && $lrsrespond != 404) { //On clicking new attempt, save the registration details to the LRS State and launch a new attempt echo "<div class='alert alert-error'>" . get_string('tincanlaunch_notavailable', 'tincanlaunch') . "</div>"; if ($CFG->debug == 32767) { echo "<p>Error attempting to get registration data from State API.</p>"; echo "<pre>"; var_dump($getregistrationdatafromlrsstate); echo "</pre>"; } die; } $registrationdatafromlrs = json_decode($getregistrationdatafromlrsstate->content->getContent(), true);
public function testCompareWithSignature() { $id1 = TinCan\Util::getUUID(); $id2 = TinCan\Util::getUUID(); $actor1 = new TinCan\Agent(['mbox' => COMMON_MBOX]); $actor2 = new TinCan\Agent(['account' => ['homePage' => COMMON_ACCT_HOMEPAGE, 'name' => COMMON_ACCT_NAME]]); $verb1 = new TinCan\Verb(['id' => COMMON_VERB_ID]); $verb2 = new TinCan\Verb(['id' => COMMON_VERB_ID . '/2']); $activity1 = new TinCan\Activity(['id' => COMMON_ACTIVITY_ID]); $activity2 = new TinCan\Activity(['id' => COMMON_ACTIVITY_ID . '/2']); $context1 = new TinCan\Context(['registration' => TinCan\Util::getUUID()]); $context2 = new TinCan\Context(['contextActivities' => [['parent' => [COMMON_ACTIVITY_ID . '/parent']], ['grouping' => [COMMON_ACTIVITY_ID]]]]); $result1 = new TinCan\Result(['raw' => 87]); $result2 = new TinCan\Result(['response' => 'a']); $timestamp1 = '2015-01-28T14:23:37.159Z'; $timestamp1_tz = '2015-01-28T08:23:37.159-06:00'; $timestamp1_subsecond = '2015-01-28T14:23:37.348Z'; $timestamp2 = '2015-01-28T15:49:11.089Z'; $attachments1 = new TinCan\Attachment(['usageType' => 'http://id.tincanapi.com/attachment/supporting_media', 'display' => ['en-US' => 'Test Display'], 'contentType' => 'application/json', 'content' => json_encode(['foo', 'bar'])]); $attachments2 = new TinCan\Attachment(['usageType' => 'http://id.tincanapi.com/attachment/supporting_media', 'display' => ['en-US' => 'Test Display'], 'contentType' => 'application/json', 'content' => json_encode(['bar', 'foo'])]); $full = ['id' => $id1, 'actor' => $actor1, 'verb' => $verb1, 'target' => $activity1, 'context' => $context1, 'result' => $result1, 'timestamp' => $timestamp1, 'attachments' => [$attachments1]]; $cases = [['description' => 'all null', 'objArgs' => []], ['description' => 'id', 'objArgs' => ['id' => $id1]], ['description' => 'actor', 'objArgs' => ['actor' => $actor1]], ['description' => 'verb', 'objArgs' => ['verb' => $verb1]], ['description' => 'object', 'objArgs' => ['target' => $activity1]], ['description' => 'result', 'objArgs' => ['result' => $result1]], ['description' => 'context', 'objArgs' => ['context' => $context1]], ['description' => 'timestamp', 'objArgs' => ['timestamp' => $timestamp1]], ['description' => 'attachments', 'objArgs' => ['attachments' => [$attachments1]]], ['description' => 'all', 'objArgs' => $full], ['description' => 'timestamp timezone difference', 'objArgs' => ['timestamp' => $timestamp1], 'sigArgs' => ['timestamp' => $timestamp1_tz]], ['description' => 'timestamp subsecond difference', 'objArgs' => ['timestamp' => $timestamp1], 'sigArgs' => ['timestamp' => $timestamp1_subsecond], 'reason' => 'Comparison of timestamp failed: value is not the same'], ['description' => 'id this only: mismatch', 'objArgs' => ['id' => $id1], 'sigArgs' => [], 'reason' => 'Comparison of id failed: value not in signature'], ['description' => 'id sig only: mismatch', 'objArgs' => [], 'sigArgs' => ['id' => $id1], 'reason' => 'Comparison of id failed: value not in this'], ['description' => 'id only: mismatch', 'objArgs' => ['id' => $id1], 'sigArgs' => ['id' => $id2], 'reason' => 'Comparison of id failed: value is not the same'], ['description' => 'actor only: mismatch', 'objArgs' => ['actor' => $actor1], 'sigArgs' => ['actor' => $actor2], 'reason' => 'Comparison of actor failed: Comparison of mbox failed: value is not the same'], ['description' => 'verb only: mismatch', 'objArgs' => ['verb' => $verb1], 'sigArgs' => ['verb' => $verb2], 'reason' => 'Comparison of verb failed: Comparison of id failed: value is not the same'], ['description' => 'object only: mismatch', 'objArgs' => ['target' => $activity1], 'sigArgs' => ['target' => $activity2], 'reason' => 'Comparison of target failed: Comparison of id failed: value is not the same'], ['description' => 'result only: mismatch', 'objArgs' => ['result' => $result1], 'sigArgs' => ['result' => $result2], 'reason' => 'Comparison of result failed: Comparison of response failed: value not present in this or signature'], ['description' => 'context only: mismatch', 'objArgs' => ['context' => $context1], 'sigArgs' => ['context' => $context2], 'reason' => 'Comparison of context failed: Comparison of registration failed: value not present in this or signature'], ['description' => 'timestamp only: mismatch', 'objArgs' => ['timestamp' => $timestamp1], 'sigArgs' => ['timestamp' => $timestamp2], 'reason' => 'Comparison of timestamp failed: value is not the same'], ['description' => 'attachments this only: mismatch', 'objArgs' => ['attachments' => [$attachments1]], 'sigArgs' => ['attachments' => []], 'reason' => 'Comparison of attachments list failed: array lengths differ'], ['description' => 'attachments sig only: mismatch', 'objArgs' => ['attachments' => []], 'sigArgs' => ['attachments' => [$attachments2]], 'reason' => 'Comparison of attachments list failed: array lengths differ'], ['description' => 'attachments only: mismatch', 'objArgs' => ['attachments' => [$attachments1]], 'sigArgs' => ['attachments' => [$attachments2]], 'reason' => 'Comparison of attachment 0 failed: Comparison of sha2 failed: value is not the same'], ['description' => 'full: id mismatch', 'objArgs' => $full, 'sigArgs' => array_replace($full, ['id' => $id2]), 'reason' => 'Comparison of id failed: value is not the same'], ['description' => 'full: actor mismatch', 'objArgs' => $full, 'sigArgs' => array_replace($full, ['actor' => $actor2]), 'reason' => 'Comparison of actor failed: Comparison of mbox failed: value is not the same'], ['description' => 'full: verb mismatch', 'objArgs' => $full, 'sigArgs' => array_replace($full, ['verb' => $verb2]), 'reason' => 'Comparison of verb failed: Comparison of id failed: value is not the same'], ['description' => 'full: target mismatch', 'objArgs' => $full, 'sigArgs' => array_replace($full, ['target' => $activity2]), 'reason' => 'Comparison of target failed: Comparison of id failed: value is not the same'], ['description' => 'full: result mismatch', 'objArgs' => $full, 'sigArgs' => array_replace($full, ['result' => $result2]), 'reason' => 'Comparison of result failed: Comparison of response failed: value not present in this or signature'], ['description' => 'full: context mismatch', 'objArgs' => $full, 'sigArgs' => array_replace($full, ['context' => $context2]), 'reason' => 'Comparison of context failed: Comparison of registration failed: value not present in this or signature'], ['description' => 'full: timestamp mismatch', 'objArgs' => $full, 'sigArgs' => array_replace($full, ['timestamp' => $timestamp2]), 'reason' => 'Comparison of timestamp failed: value is not the same'], ['description' => 'full: attachments mismatch', 'objArgs' => $full, 'sigArgs' => array_replace($full, ['attachments' => [$attachments2]]), 'reason' => 'Comparison of attachment 0 failed: Comparison of sha2 failed: value is not the same']]; $this->runSignatureCases("TinCan\\Statement", $cases); }
public function testGetUUID() { $result = TinCan\Util::getUUID(); $this->assertRegExp(TinCan\Util::UUID_REGEX, $result); }