Example #1
0
 public function testAsVersion()
 {
     $args = ['registration' => Util::getUUID(), 'instructor' => ['objectType' => 'Agent', 'name' => 'test agent'], 'team' => ['objectType' => 'Group', 'name' => 'test group'], 'contextActivities' => ['category' => [['objectType' => 'Activity', 'id' => 'test category']]], 'revision' => 'test revision', 'platform' => 'test platform', 'language' => 'test language', 'statement' => ['objectType' => 'StatementRef', 'id' => Util::getUUID()], 'extensions' => ['test extension']];
     $obj = new Context($args);
     $versioned = $obj->asVersion('1.0.0');
     $this->assertEquals($versioned, $args, "platform only: 1.0.0");
 }
 public function testAsVersion()
 {
     $args = ['objectType' => 'StatementRef', 'id' => Util::getUUID()];
     $obj = new StatementRef($args);
     $versioned = $obj->asVersion('1.0.0');
     $this->assertEquals($versioned, $args, "version 1.0.0");
 }
 public function testAttachmentsString()
 {
     $text_content = "Content created at: " . Util::getTimestamp();
     $statement = new Statement(['actor' => ['mbox' => COMMON_MBOX], 'verb' => ['id' => COMMON_VERB_ID], 'object' => new Activity(['id' => COMMON_ACTIVITY_ID . '/StatementVariationsTest/AttachmentsString']), 'attachments' => [['usageType' => 'http://id.tincanapi.com/attachment/supporting_media', 'display' => ['en-US' => 'StatementVariantsTest::testAttachmentsString'], 'contentType' => 'text/plain; charset=ascii', 'content' => $text_content]]]);
     foreach (self::$lrss as $lrs) {
         $response = $lrs->saveStatement($statement);
         $this->assertInstanceOf('TinCan\\LRSResponse', $response);
         $this->assertTrue($response->success, "successful request");
     }
 }
Example #4
0
 public function testGetTimestamp()
 {
     $result = 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);
 }
Example #5
0
 public function testCompareWithSignature()
 {
     $success = ['success' => true, 'reason' => null];
     $failure = ['success' => false, 'reason' => null];
     $id = Util::getUUID();
     $obj = new StatementRef(['id' => $id]);
     $sig = new StatementRef(['id' => $id]);
     $this->assertSame($success, $obj->compareWithSignature($sig), 'id only: match');
     $sig->setId(Util::getUUID());
     $failure['reason'] = 'Comparison of id failed: value is not the same';
     $this->assertSame($failure, $obj->compareWithSignature($sig), 'id only: mismatch');
 }
 public function testCompareWithSignature()
 {
     $actor1 = new Agent(['mbox' => COMMON_MBOX]);
     $actor2 = new Agent(['account' => ['homePage' => COMMON_ACCT_HOMEPAGE, 'name' => COMMON_ACCT_NAME]]);
     $verb1 = new Verb(['id' => COMMON_VERB_ID]);
     $verb2 = new Verb(['id' => COMMON_VERB_ID . '/2']);
     $activity1 = new Activity(['id' => COMMON_ACTIVITY_ID]);
     $activity2 = new Activity(['id' => COMMON_ACTIVITY_ID . '/2']);
     $context1 = new Context(['registration' => Util::getUUID()]);
     $context2 = new Context(['contextActivities' => [['parent' => [COMMON_ACTIVITY_ID . '/parent']], ['grouping' => [COMMON_ACTIVITY_ID]]]]);
     $result1 = new Result(['raw' => 87]);
     $result2 = new 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);
 }
Example #7
0
 public function testCompareWithSignature()
 {
     $id1 = Util::getUUID();
     $id2 = Util::getUUID();
     $actor1 = new Agent(['mbox' => COMMON_MBOX]);
     $actor2 = new Agent(['account' => ['homePage' => COMMON_ACCT_HOMEPAGE, 'name' => COMMON_ACCT_NAME]]);
     $verb1 = new Verb(['id' => COMMON_VERB_ID]);
     $verb2 = new Verb(['id' => COMMON_VERB_ID . '/2']);
     $activity1 = new Activity(['id' => COMMON_ACTIVITY_ID]);
     $activity2 = new Activity(['id' => COMMON_ACTIVITY_ID . '/2']);
     $context1 = new Context(['registration' => Util::getUUID()]);
     $context2 = new Context(['contextActivities' => [['parent' => [COMMON_ACTIVITY_ID . '/parent']], ['grouping' => [COMMON_ACTIVITY_ID]]]]);
     $result1 = new Result(['raw' => 87]);
     $result2 = new 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 Attachment(['usageType' => 'http://id.tincanapi.com/attachment/supporting_media', 'display' => ['en-US' => 'Test Display'], 'contentType' => 'application/json', 'content' => json_encode(['foo', 'bar'])]);
     $attachments2 = new 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);
 }
Example #8
0
 public function testClearState()
 {
     $lrs = new RemoteLRS(self::$endpoint, self::$version, self::$username, self::$password);
     $response = $lrs->clearState(new Activity(['id' => COMMON_ACTIVITY_ID]), new Agent(['mbox' => COMMON_MBOX]), ['registration' => Util::getUUID()]);
     $this->assertInstanceOf('TinCan\\LRSResponse', $response);
 }
Example #9
0
 public function testCompareWithSignature()
 {
     $registration1 = Util::getUUID();
     $registration2 = Util::getUUID();
     $instructor1 = new TinCan\Agent(['mbox' => COMMON_MBOX]);
     $instructor2 = new TinCan\Agent(['account' => ['homePage' => COMMON_ACCT_HOMEPAGE, 'name' => COMMON_ACCT_NAME]]);
     $team1 = new TinCan\Agent(['mbox' => COMMON_MBOX]);
     $team2 = new TinCan\Agent(['account' => ['homePage' => COMMON_ACCT_HOMEPAGE, 'name' => COMMON_ACCT_NAME]]);
     $contextActivities1 = new TinCan\ContextActivities(['parent' => [COMMON_ACTIVITY_ID]]);
     $contextActivities2 = new TinCan\ContextActivities(['parent' => [COMMON_ACTIVITY_ID . '/parent']], ['grouping' => [COMMON_ACTIVITY_ID]]);
     $ref1 = new TinCan\StatementRef(['id' => Util::getUUID()]);
     $ref2 = new TinCan\StatementRef(['id' => Util::getUUID()]);
     $extensions1 = new TinCan\Extensions([COMMON_EXTENSION_ID_1 => 'test1', COMMON_EXTENSION_ID_2 => 'test2']);
     $extensions2 = new TinCan\Extensions([COMMON_EXTENSION_ID_1 => 'test1']);
     $full = ['registration' => $registration1, 'instructor' => $instructor1, 'team' => $team1, 'contextActivities' => $contextActivities1, 'revision' => '1', 'platform' => 'mobile', 'language' => 'en-US', 'statement' => $ref1, 'extensions' => $extensions1];
     $cases = [['description' => 'all null', 'objArgs' => []], ['description' => 'registration', 'objArgs' => ['registration' => $registration1]], ['description' => 'instructor', 'objArgs' => ['instructor' => $instructor1]], ['description' => 'team', 'objArgs' => ['team' => $team1]], ['description' => 'contextActivities', 'objArgs' => ['contextActivities' => $contextActivities1]], ['description' => 'revision', 'objArgs' => ['revision' => '1']], ['description' => 'platform', 'objArgs' => ['platform' => 'mobile']], ['description' => 'language', 'objArgs' => ['language' => 'en-US']], ['description' => 'statement', 'objArgs' => ['statement' => $ref1]], ['description' => 'extensions', 'objArgs' => ['extensions' => $extensions1]], ['description' => 'all', 'objArgs' => $full], ['description' => 'registration only: mismatch', 'objArgs' => ['registration' => $registration1], 'sigArgs' => ['registration' => $registration2], 'reason' => 'Comparison of registration failed: value is not the same'], ['description' => 'instructor only: mismatch', 'objArgs' => ['instructor' => $instructor1], 'sigArgs' => ['instructor' => $instructor2], 'reason' => 'Comparison of instructor failed: Comparison of mbox failed: value is not the same'], ['description' => 'team only: mismatch', 'objArgs' => ['team' => $team1], 'sigArgs' => ['team' => $team2], 'reason' => 'Comparison of team failed: Comparison of mbox failed: value is not the same'], ['description' => 'contextActivities only: mismatch', 'objArgs' => ['contextActivities' => $contextActivities1], 'sigArgs' => ['contextActivities' => $contextActivities2], 'reason' => 'Comparison of contextActivities failed: Comparison of parent failed: array lengths differ'], ['description' => 'revision only: mismatch', 'objArgs' => ['revision' => '1'], 'sigArgs' => ['revision' => '2'], 'reason' => 'Comparison of revision failed: value is not the same'], ['description' => 'platform only: mismatch', 'objArgs' => ['platform' => 'mobile'], 'sigArgs' => ['platform' => 'desktop'], 'reason' => 'Comparison of platform failed: value is not the same'], ['description' => 'language only: mismatch', 'objArgs' => ['language' => 'en-US'], 'sigArgs' => ['language' => 'en-GB'], 'reason' => 'Comparison of language failed: value is not the same'], ['description' => 'statement only: mismatch', 'objArgs' => ['statement' => $ref1], 'sigArgs' => ['statement' => $ref2], 'reason' => 'Comparison of statement failed: Comparison of id failed: value is not the same'], ['description' => 'extensions only: mismatch', 'objArgs' => ['extensions' => $extensions1], 'sigArgs' => ['extensions' => $extensions2], 'reason' => 'Comparison of extensions failed: http://id.tincanapi.com/extension/location not in signature'], ['description' => 'full: registration mismatch', 'objArgs' => $full, 'sigArgs' => array_replace($full, ['registration' => $registration2]), 'reason' => 'Comparison of registration failed: value is not the same'], ['description' => 'full: instructor mismatch', 'objArgs' => $full, 'sigArgs' => array_replace($full, ['instructor' => $instructor2]), 'reason' => 'Comparison of instructor failed: Comparison of mbox failed: value is not the same'], ['description' => 'full: team mismatch', 'objArgs' => $full, 'sigArgs' => array_replace($full, ['team' => $team2]), 'reason' => 'Comparison of team failed: Comparison of mbox failed: value is not the same'], ['description' => 'full: contextActivities mismatch', 'objArgs' => $full, 'sigArgs' => array_replace($full, ['contextActivities' => $contextActivities2]), 'reason' => 'Comparison of contextActivities failed: Comparison of parent failed: array lengths differ'], ['description' => 'full: revision mismatch', 'objArgs' => $full, 'sigArgs' => array_replace($full, ['revision' => '2']), 'reason' => 'Comparison of revision failed: value is not the same'], ['description' => 'full: platform mismatch', 'objArgs' => $full, 'sigArgs' => array_replace($full, ['platform' => 'desktop']), 'reason' => 'Comparison of platform failed: value is not the same'], ['description' => 'full: language mismatch', 'objArgs' => $full, 'sigArgs' => array_replace($full, ['language' => 'en-GB']), 'reason' => 'Comparison of language failed: value is not the same'], ['description' => 'full: statement mismatch', 'objArgs' => $full, 'sigArgs' => array_replace($full, ['statement' => $ref2]), 'reason' => 'Comparison of statement failed: Comparison of id failed: value is not the same'], ['description' => 'full: extensions mismatch', 'objArgs' => $full, 'sigArgs' => array_replace($full, ['extensions' => $extensions2]), 'reason' => 'Comparison of extensions failed: http://id.tincanapi.com/extension/location not in signature']];
     $this->runSignatureCases("TinCan\\Context", $cases);
 }
Example #10
0
 public function stamp()
 {
     $this->setId(Util::getUUID());
     $this->setTimestamp(Util::getTimestamp());
     return $this;
 }