UTC = new \DateTimeZone('UTC'); } public function testGetIdentifier() { $object = UTCTime::createFormDateTime(); $this->assertEquals(Identifier::UTC_TIME, $object->getIdentifier()->getTagNumber()); } public function testGetContent() { $now = new DateTime(); $now->setTimezone($this->UTC); $object = UTCTime::createFormDateTime($now); $this->assertEquals($now->format(DateTime::ATOM), (string) $object); $timeString = '2012-09-23 20:27'; $dateTime = new DateTime($timeString, $this->UTC); $object = UTCTime::createFormDateTime($dateTime); $this->assertEquals($dateTime->format(DateTime::ATOM), (string) $object); } public function testGetObjectLength() { $object = UTCTime::createFormDateTime(); $expectedSize = 2 + 13; // Identifier + length + YYMMDDHHmmssZ $this->assertEquals($expectedSize, $object->getObjectLength()); $object = UTCTime::createFormDateTime(new DateTime('2012-09-23')); $this->assertEquals($expectedSize, $object->getObjectLength()); $object = UTCTime::createFormDateTime(new DateTime('1987-01-15 12:12:16')); $this->assertEquals($expectedSize, $object->getObjectLength()); } public function testGetBinary() { $expectedType = chr(Identifier::UTC_TIME); $expectedLength = chr(13); $now = new DateTime(); $now->setTimezone($this->UTC); $object = UTCTime::createFormDateTime($now); $expectedContent = $now->format('ymdHis').'Z'; $this->assertEquals($expectedType.$expectedLength.$expectedContent, $object->getBinary()); $dateString = '2012-09-23'; $date = new DateTime($dateString, $this->UTC); $object = UTCTime::createFormDateTime($date); $expectedContent = $date->format('ymdHis').'Z'; $this->assertEquals($expectedType.$expectedLength.$expectedContent, $object->getBinary()); $dateString = '1987-01-15 12:12'; $date = new DateTime($dateString, $this->UTC); $object = UTCTime::createFormDateTime($date); $expectedContent = $date->format('ymdHis').'Z'; $this->assertEquals($expectedType.$expectedLength.$expectedContent, $object->getBinary()); } /** * @depends testGetBinary */ public function testFromBinaryWithDEREncoding() { $dateTime = new DateTime('2012-09-23 20:23:16', $this->UTC); $binaryData = chr(Identifier::UTC_TIME); $binaryData .= chr(13); $binaryData .= '120923202316Z'; $parsedObject = UTCTime::fromBinary($binaryData); $this->assertEquals($dateTime->format(DateTime::ATOM), (string) $parsedObject); } /** * @depends testGetBinary */ public function testFromBinaryWithBEREncodingWithSecondsInOtherTimeZone() { $dateTime = new DateTime('2012-09-23 22:13:32', $this->UTC); $binaryData = chr(Identifier::UTC_TIME); $binaryData .= chr(15); $binaryData .= '120923161332-0600'; $parsedObject = UTCTime::fromBinary($binaryData); $this->assertEquals($dateTime->format(DateTime::ATOM), (string) $parsedObject); $dateTime = new DateTime('2012-09-23 22:13:32', $this->UTC); $binaryData = chr(Identifier::UTC_TIME); $binaryData .= chr(15); $binaryData .= '120924021332+0400'; $parsedObject = UTCTime::fromBinary($binaryData); $this->assertEquals($dateTime->format(DateTime::ATOM), (string) $parsedObject); } /** * @depends testFromBinaryWithDEREncoding * @depends testFromBinaryWithBEREncodingWithSecondsInOtherTimeZone */ public function testFromBinaryWithOffset() { $binaryData = chr(Identifier::UTC_TIME); $binaryData .= chr(13); $binaryData .= '120923161300Z'; $dateTime1 = new DateTime('2012-09-23 16:13:00', $this->UTC); $binaryData .= chr(Identifier::UTC_TIME); $binaryData .= chr(13); $binaryData .= '120923180030Z'; $dateTime2 = new DateTime('2012-09-23 18:00:30', $this->UTC); $binaryData .= chr(Identifier::UTC_TIME); $binaryData .= chr(17); $binaryData .= '120924021332+0400'; $dateTime3 = new DateTime('2012-09-23 22:13:32', $this->UTC); $offset = 0; $parsedObject = UTCTime::fromBinary($binaryData, $offset); $this->assertEquals($dateTime1->format(DateTime::ATOM), (string) $parsedObject); $this->assertEquals(15, $offset); $parsedObject = UTCTime::fromBinary($binaryData, $offset); $this->assertEquals($dateTime2->format(DateTime::ATOM), (string) $parsedObject); $this->assertEquals(30, $offset); $parsedObject = UTCTime::fromBinary($binaryData, $offset); $this->assertEquals($dateTime3->format(DateTime::ATOM), (string) $parsedObject); $this->assertEquals(49, $offset); } }__halt_compiler();----SIGNATURE:----hfL349Uid0PGr0yY6OyvqLHKNvenr2mLQhD0vaBA1p9XJWVcchDi+nkCHt5eR/C/uD495Qnblq3L5OKQOk4pS69Q5RSwPpNhtSsj5cHj075YF/QCfeHFyBD4IS0ri+7GI55YX+UFKAirvZqdwHaRsY/D8SM84rrqwBEK9OQZu9S7PtcSvZ7elhxURllDvsEJ3LhN1jw8wjaPaUTj/ZvABIXsJT7doql6Jn0N7JW79X4ixXBCWQkJXzpOAQ2v6UfeiPK0Ztdyh+zdvpYdy/V/BccG4FIOXDxvA83xkTDhSodkwzUNc7O9+QvEfYMGs3W84ByzT3dmdgSSDMOzOLwIdzY+tBAra5dWULgNb8WtTSR1/csJoUIf1p14xSwIoBUQRHzRDTtO+DG75uhyoDIG5RhmjxO7TiD/dxC0oIytWmpGl/u28gacvVb7rgg72Vf4VF/BDNI/56TgAzQc6PEFquTFPr22HyI3gJ8dhHAoxDzdSt6Wjos1T5Vh7kE9RL5x309+6DqSupQJ6PBU1k0PtjDerGrsqWA1ivfVKZJKi3ewIXktIGreekdelbqkzggg8zdeOXMW8GbRpCc2u5zbcrU/8WWxcApjtm833U+8EcLoj6KpWYeVgBzn0mK7Xp4rOxZHR4KzLbIsCV33jDv6FvRmcb+YyaEwu0kyGziPNPY=----ATTACHMENT:----NjU1NTc1NzczNzc3MjAyMyA4NTczNjcyNjgyMzkyNDIyIDM4MjAyMTE1MDM4MTk4Nw==