예제 #1
0
 /**
  * @covers Alchemy\Phrasea\Border\File::getUUID
  */
 public function testNewUuid()
 {
     $file = __DIR__ . '/../../../../files/temporay.jpg';
     if (file_exists($file)) {
         unlink($file);
     }
     copy(__DIR__ . '/../../../../files/p4logo.jpg', $file);
     $borderFile = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess($file), self::$DI['collection']);
     $uuid = $borderFile->getUUID(true, false);
     $this->assertTrue(\uuid::is_valid($uuid));
     $this->assertEquals($uuid, $borderFile->getUUID());
     $borderFile = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess($file), self::$DI['collection']);
     $newuuid = $borderFile->getUUID(true, true);
     $this->assertTrue(\uuid::is_valid($newuuid));
     $this->assertNotEquals($uuid, $newuuid);
     $this->assertEquals($newuuid, $borderFile->getUUID());
     $borderFile = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess($file), self::$DI['collection']);
     $uuid = $borderFile->getUUID();
     $this->assertTrue(\uuid::is_valid($uuid));
     $this->assertEquals($uuid, $newuuid);
     $this->assertEquals($uuid, $borderFile->getUUID());
     if (file_exists($file)) {
         unlink($file);
     }
 }
예제 #2
0
 public function testIs_valid()
 {
     for ($i = 0; $i < 1000; $i++) {
         $uuid = uuid::generate_v4();
         if (!uuid::is_valid($uuid)) {
             $this->fail('Generation d\'un uuid v4 invalide');
         }
         $uuid = uuid::generate_v5($uuid, random::generatePassword(12));
         if (!uuid::is_valid($uuid)) {
             $this->fail('Generation d\'un uuid v5 invalide');
         }
         $uuid = uuid::generate_v3($uuid, random::generatePassword(12));
         if (!uuid::is_valid($uuid)) {
             $this->fail('Generation d\'un uuid v3 invalide');
         }
         unset($uuid);
     }
 }
예제 #3
0
 public function testGet_uuid()
 {
     $this->assertTrue(uuid::is_valid(self::$DI['record_1']->get_uuid()));
 }
예제 #4
0
 /**
  * Checks for UUID in metadatas
  *
  * @todo Check if a file exists with the same checksum
  * @todo Check if an UUID is contained in the attributes, replace It if
  *              necessary
  *
  * @param  boolean $generate if true, if no uuid found, a valid one is generated
  * @param  boolean $write    if true, writes uuid in all available metadatas
  * @return File
  */
 public function getUUID($generate = false, $write = false)
 {
     if ($this->uuid && !$write) {
         return $this->uuid;
     }
     $availableUUIDs = ['XMP-exif:ImageUniqueID', 'SigmaRaw:ImageUniqueID', 'IPTC:UniqueDocumentID', 'ExifIFD:ImageUniqueID', 'Canon:ImageUniqueID'];
     if (!$this->uuid) {
         $metadatas = $this->media->getMetadatas();
         $uuid = null;
         foreach ($availableUUIDs as $meta) {
             if ($metadatas->containsKey($meta)) {
                 $candidate = $metadatas->get($meta)->getValue()->asString();
                 if (\uuid::is_valid($candidate)) {
                     $uuid = $candidate;
                     break;
                 }
             }
         }
         if (!$uuid && $generate) {
             /**
              * @todo Check if a file exists with the same checksum
              */
             $uuid = \uuid::generate_v4();
         }
         $this->uuid = $uuid;
     }
     if ($write) {
         $value = new MonoValue($this->uuid);
         $metadatas = new ExiftoolMetadataBag();
         foreach ($availableUUIDs as $tagname) {
             $metadatas->add(new Metadata(TagFactory::getFromRDFTagname($tagname), $value));
         }
         /**
          * PHPExiftool throws exception on some files not supported
          */
         try {
             $this->app['exiftool.writer']->reset();
             $this->app['exiftool.writer']->write($this->getFile()->getRealPath(), $metadatas);
         } catch (PHPExiftoolException $e) {
         }
     }
     return $this->uuid;
 }
예제 #5
0
 protected function evaluateGoodStory($story)
 {
     $this->assertArrayHasKey('databox_id', $story);
     $this->assertTrue(is_int($story['databox_id']));
     $this->assertArrayHasKey('story_id', $story);
     $this->assertTrue(is_int($story['story_id']));
     $this->assertArrayHasKey('updated_on', $story);
     $this->assertDateAtom($story['updated_on']);
     $this->assertArrayHasKey('created_on', $story);
     $this->assertDateAtom($story['created_on']);
     $this->assertArrayHasKey('collection_id', $story);
     $this->assertTrue(is_int($story['collection_id']));
     $this->assertArrayHasKey('thumbnail', $story);
     $this->assertArrayHasKey('uuid', $story);
     $this->assertArrayHasKey('@entity@', $story);
     $this->assertEquals(\API_V1_adapter::OBJECT_TYPE_STORY, $story['@entity@']);
     $this->assertTrue(\uuid::is_valid($story['uuid']));
     if (!is_null($story['thumbnail'])) {
         $this->assertTrue(is_array($story['thumbnail']));
         $this->assertArrayHasKey('player_type', $story['thumbnail']);
         $this->assertTrue(is_string($story['thumbnail']['player_type']));
         $this->assertArrayHasKey('permalink', $story['thumbnail']);
         $this->assertArrayHasKey('mime_type', $story['thumbnail']);
         $this->assertTrue(is_string($story['thumbnail']['mime_type']));
         $this->assertArrayHasKey('height', $story['thumbnail']);
         $this->assertTrue(is_int($story['thumbnail']['height']));
         $this->assertArrayHasKey('width', $story['thumbnail']);
         $this->assertTrue(is_int($story['thumbnail']['width']));
         $this->assertArrayHasKey('filesize', $story['thumbnail']);
         $this->assertTrue(is_int($story['thumbnail']['filesize']));
     }
     $this->assertArrayHasKey('records', $story);
     $this->assertInternalType('array', $story['records']);
     foreach ($story['metadatas'] as $key => $metadata) {
         if (null !== $metadata) {
             $this->assertInternalType('string', $metadata);
         }
         if ($key === '@entity@') {
             continue;
         }
         $this->assertEquals(0, strpos($key, 'dc:'));
     }
     $this->assertArrayHasKey('@entity@', $story['metadatas']);
     $this->assertEquals(\API_V1_adapter::OBJECT_TYPE_STORY_METADATA_BAG, $story['metadatas']['@entity@']);
     foreach ($story['records'] as $record) {
         $this->evaluateGoodRecord($record);
     }
 }