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');
 }
Beispiel #2
0
 public function testProperties()
 {
     $str_datetime = '2014-12-15T19:16:05+00:00';
     $str_datetime_tz = '2014-12-15T13:16:05-06:00';
     $datetime = new \DateTime();
     $datetime->setDate(2014, 12, 15);
     $datetime->setTime(19, 16, 05);
     $statement = new Statement();
     $statement->setStored($datetime);
     $statement->setTimestamp($datetime);
     $document = new State();
     $document->setTimestamp($datetime);
     $this->assertEquals($statement->getStored(), $str_datetime, 'stored matches');
     $this->assertEquals($statement->getTimestamp(), $str_datetime, 'timestamp matches');
     $this->assertEquals($document->getTimestamp(), $str_datetime, 'document timestamp matches');
     $datetime->setTimezone(new DateTimeZone('America/Chicago'));
     $statement->setStored($datetime);
     $statement->setTimestamp($datetime);
     $document->setTimestamp($datetime);
     $this->assertEquals($statement->getStored(), $str_datetime_tz, 'stored matches');
     $this->assertEquals($statement->getTimestamp(), $str_datetime_tz, 'timestamp matches');
     $this->assertEquals($document->getTimestamp(), $str_datetime_tz, 'document timestamp matches');
 }
Beispiel #3
0
 public function testSignAndVerifyNoPubKey()
 {
     $obj = new Statement(['actor' => ['mbox' => COMMON_MBOX], 'verb' => ['id' => COMMON_VERB_ID], 'object' => new Activity(['id' => COMMON_ACTIVITY_ID . '/StatementTest/testSignAndVerify'])]);
     $obj->sign('file://' . $GLOBALS['KEYs']['private'], $GLOBALS['KEYs']['password']);
     $result = $obj->verify();
     $this->assertFalse($result['success'], 'success return value');
     $this->assertSame($result['reason'], 'No public key found or provided for verification', 'reason');
 }
 public function testSignedAndVerifiedX5c()
 {
     $statement = new Statement(['actor' => ['mbox' => COMMON_MBOX], 'verb' => ['id' => COMMON_VERB_ID], 'object' => new Activity(['id' => COMMON_ACTIVITY_ID . '/StatementVariationsTest/Signed'])]);
     $statement->sign('file://' . $GLOBALS['KEYs']['private'], $GLOBALS['KEYs']['password'], ['x5c' => 'file://' . $GLOBALS['KEYs']['public']]);
     foreach (self::$lrss as $lrs) {
         $saveResponse = $lrs->saveStatement($statement);
         $this->assertInstanceOf('TinCan\\LRSResponse', $saveResponse);
         if (!$saveResponse->success) {
             print_r($saveResponse);
         }
         $this->assertTrue($saveResponse->success, "successful request");
         $retrieveResponse = $lrs->retrieveStatement($saveResponse->content->getId(), ['attachments' => true]);
         $this->assertInstanceOf('TinCan\\LRSResponse', $retrieveResponse);
         $this->assertTrue($retrieveResponse->success);
         $this->assertInstanceOf('TinCan\\Statement', $retrieveResponse->content);
         $verificationResult = $retrieveResponse->content->verify();
         $this->assertTrue($verificationResult['success'], 'verify signature');
     }
 }