diff --git a/tests/PhraseanetPHPUnitAbstract.class.inc b/tests/PhraseanetPHPUnitAbstract.class.inc index 12c17abc61..30749f4207 100644 --- a/tests/PhraseanetPHPUnitAbstract.class.inc +++ b/tests/PhraseanetPHPUnitAbstract.class.inc @@ -705,7 +705,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase $finder->name($name)->in(__DIR__ . '/testfiles/'); foreach ($finder as $file) { - return $file->getRealPath(); + return $file; } throw new Exception(sprintf('File %d not found', $i)); @@ -716,7 +716,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase PhraseanetPHPUnitAbstract::$recordsInitialized[] = $i; - $file = new Alchemy\Phrasea\Border\File(\MediaVorus\MediaVorus::guess($resolvePathfile($i), $collection)); + $file = new Alchemy\Phrasea\Border\File(\MediaVorus\MediaVorus::guess($resolvePathfile($i)), $collection); $record = record_adapter::createFromFile($file); diff --git a/tests/collectionTest.php b/tests/collectionTest.php index 6038ee0fd4..165ebb2378 100644 --- a/tests/collectionTest.php +++ b/tests/collectionTest.php @@ -82,7 +82,7 @@ class collectionTest extends PhraseanetPHPUnitAuthenticatedAbstract public function testGet_record_amount() { self::$object->empty_collection(); - $file = new Alchemy\Phrasea\Border\File(\MediaVorus\MediaVorus::guess(new \SplFileInfo(__DIR__ . '/testfiles/cestlafete.jpg'), self::$object)); + $file = new Alchemy\Phrasea\Border\File(\MediaVorus\MediaVorus::guess(new \SplFileInfo(__DIR__ . '/testfiles/cestlafete.jpg')), self::$object); record_adapter::createFromFile($file); $this->assertTrue(self::$object->get_record_amount() === 1); self::$object->empty_collection(); @@ -129,7 +129,7 @@ class collectionTest extends PhraseanetPHPUnitAuthenticatedAbstract public function testGet_record_details() { - $file = new Alchemy\Phrasea\Border\File(\MediaVorus\MediaVorus::guess(new \SplFileInfo(__DIR__ . '/testfiles/cestlafete.jpg'), self::$object)); + $file = new Alchemy\Phrasea\Border\File(\MediaVorus\MediaVorus::guess(new \SplFileInfo(__DIR__ . '/testfiles/cestlafete.jpg')), self::$object); $record = record_adapter::createFromFile($file); $details = self::$object->get_record_details(); diff --git a/tests/record/adapterTest.php b/tests/record/adapterTest.php index 5df823b5b5..982732a69a 100644 --- a/tests/record/adapterTest.php +++ b/tests/record/adapterTest.php @@ -12,16 +12,6 @@ class record_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract public static function setUpBeforeClass() { parent::setUpBeforeClass(); - $system_file = static::$records['record_1']->get_hd_file(); - $databox = static::$records['record_1']->get_databox(); - $metadatas = $system_file->extract_metadatas($databox->get_meta_structure()); - static::$records['record_1']->set_metadatas($metadatas['metadatas']); - - $databox = static::$records['record_23']->get_databox(); - $system_file = static::$records['record_23']->get_hd_file(); - $metadatas = $system_file->extract_metadatas($databox->get_meta_structure()); - static::$records['record_23']->set_metadatas($metadatas['metadatas']); - /** * Reset thumbtitle in order to have consistent tests (testGet_title) @@ -202,7 +192,7 @@ class record_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract public function testGet_mime() { - $this->assertEquals('image/x-canon-cr2', static::$records['record_1']->get_mime()); + $this->assertRegExp('/image\/\w+/', static::$records['record_1']->get_mime()); } public function testGet_status() @@ -485,7 +475,7 @@ class record_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract public function testGet_hd_file() { - $this->assertInstanceOf('system_file', static::$records['record_1']->get_hd_file()); + $this->assertInstanceOf('\SplFileInfo', static::$records['record_1']->get_hd_file()); } /** diff --git a/tests/system/system_fileTest.php b/tests/system/system_fileTest.php deleted file mode 100644 index 5ca8d79d5f..0000000000 --- a/tests/system/system_fileTest.php +++ /dev/null @@ -1,271 +0,0 @@ -objects['indd'] = new system_file(__DIR__ . '/../../vendor/phpexiftool/exiftool/t/images/InDesign.indd'); - $this->objects['wav'] = new system_file(__DIR__ . '/../testfiles/test012.wav'); - $this->objects['jpg'] = new system_file(__DIR__ . '/../../vendor/phpexiftool/exiftool/t/images/Casio.jpg'); - } - - public function testGet_mime() - { - $this->assertEquals('application/octet-stream', $this->objects['indd']->get_mime()); - $this->assertEquals('audio/x-wav', $this->objects['wav']->get_mime()); - $this->assertEquals('image/jpeg', $this->objects['jpg']->get_mime()); - } - - public function testIs_raw_image() - { - $this->assertFalse($this->objects['indd']->is_raw_image()); - $this->assertFalse($this->objects['wav']->is_raw_image()); - $this->assertFalse($this->objects['jpg']->is_raw_image()); - } - - public function testGet_extension() - { - $this->assertEquals('indd', $this->objects['indd']->get_extension()); - $this->assertEquals('wav', $this->objects['wav']->get_extension()); - $this->assertEquals('jpg', $this->objects['jpg']->get_extension()); - } - - public function testGet_sha256() - { - $this->assertEquals('50a49257863f510b4e7f0de795884a89aeefdd701069db414a472f0ede7b0c98', $this->objects['indd']->get_sha256()); - $this->assertEquals('690e00c90a97ea24a2bd69abe410dc0fc3b6b69ddc20b1d572d0a953a4617eed', $this->objects['wav']->get_sha256()); - $this->assertEquals('c08fed0e193a1549c130d79814d30a3ac3fcd81980e261c4947ff45691628f92', $this->objects['jpg']->get_sha256()); - } - - public function testGet_phrasea_type() - { - $this->assertEquals('unknown', $this->objects['indd']->get_phrasea_type()); - $this->assertEquals('audio', $this->objects['wav']->get_phrasea_type()); - $this->assertEquals('image', $this->objects['jpg']->get_phrasea_type()); - } - - public function testGetPath() - { - $supposed = __DIR__ . '/../../vendor/phpexiftool/exiftool/t/images/'; - $this->assertEquals($supposed, $this->objects['indd']->getPath()); - } - - /** - * @todo Implement testHas_uuid(). - */ - public function testHas_uuid() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @todo Implement testRead_uuid(). - */ - public function testRead_uuid() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @todo Implement testWrite_uuid(). - */ - public function testWrite_uuid() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @todo Implement testIs_new_in_base(). - */ - public function testIs_new_in_base() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @todo Implement testGenerate_and_write(). - */ - public function testGenerate_and_write() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @todo Implement testWrite(). - */ - public function testWrite() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - public function testMkdir() - { - $path = __DIR__ . '/test/dir/to/create/'; - if (is_dir($path)) { - $this->fail('unable to create directory : directory already extists'); - } - system_file::mkdir($path); - $this->assertTrue(is_dir($path)); - rmdir($path); - $path = dirname($path); - rmdir($path); - $path = dirname($path); - rmdir($path); - $path = dirname($path); - rmdir(__DIR__ . '/test'); - $path = dirname($path); - } - - public function testChmod() - { - $file = __DIR__ . '/../testfiles/cestlafete.jpg'; - $dir = __DIR__ . '/testchmod'; - system_file::mkdir($dir); - - chmod($file, 0700); - chmod($dir, 0700); - $system_file = new system_file($file); - $system_dir = new system_file($dir); - $system_file->chmod(); - $system_dir->chmod(); - clearstatcache(); - $this->assertEquals('0766', substr(sprintf('%o', fileperms($file)), -4)); - $this->assertEquals('0755', substr(sprintf('%o', fileperms($dir)), -4)); - rmdir($dir); - } - - public function testEmpty_directory() - { - $file = __DIR__ . '/../testfiles/cestlafete.jpg'; - $dir = __DIR__ . '/testchmod'; - system_file::mkdir($dir); - - copy($file, $dir . '/v1.test'); - copy($file, $dir . '/v2.test'); - copy($file, $dir . '/v3.test'); - - $system_file = new system_file($dir); - $system_file->empty_directory(); - - $this->assertFalse(is_file($dir . '/v1.test')); - $this->assertFalse(is_file($dir . '/v2.test')); - $this->assertFalse(is_file($dir . '/v3.test')); - - rmdir($dir); - } - - public function testSet_phrasea_tech_field() - { - $this->objects['wav']->set_phrasea_tech_field('un', '1'); - $this->objects['wav']->set_phrasea_tech_field('trois', '3'); - $this->objects['wav']->set_phrasea_tech_field('deux', '2'); - - try { - $this->objects['wav']->set_phrasea_tech_field(' ', '2'); - $this->fail(); - } catch (Exception_InvalidArgument $e) { - - } - - $this->assertEquals('1', $this->objects['wav']->get_phrasea_tech_field('un')); - $this->assertEquals('2', $this->objects['wav']->get_phrasea_tech_field('deux')); - $this->assertEquals('3', $this->objects['wav']->get_phrasea_tech_field('trois')); - } - - public function testGet_phrasea_tech_field() - { - $this->assertNull($this->objects['wav']->get_phrasea_tech_field('qsdfqsdfsqd')); - } - - public function testExtract_metadatas() - { - $appbox = appbox::get_instance(\bootstrap::getCore()); - $databox = null; - foreach ($appbox->get_databoxes() as $d) { - $databox = $d; - break; - } - $this->assertInstanceOf('databox', $databox); - $metadatas = $this->objects['wav']->extract_metadatas($databox->get_meta_structure()); - - $this->assertTrue(is_array($metadatas)); - $this->assertArrayHasKey('metadatas', $metadatas); - $this->assertArrayHasKey('status', $metadatas); - foreach ($metadatas['metadatas'] as $metadata) { - $this->assertTrue(is_array($metadata)); - $this->assertArrayHasKey('meta_struct_id', $metadata); - $this->assertArrayHasKey('meta_id', $metadata); - $this->assertArrayHasKey('value', $metadata); - $this->assertTrue(is_scalar($metadata['value'])); - $this->assertNull($metadata['meta_id']); - $this->assertTrue(is_int($metadata['meta_struct_id'])); - $this->assertTrue($metadata['meta_struct_id'] > 0); - } - } - - public function testExtract_metadatasWithCaption() - { - $appbox = appbox::get_instance(\bootstrap::getCore()); - $databox = null; - foreach ($appbox->get_databoxes() as $d) { - $databox = $d; - break; - } - $this->assertInstanceOf('databox', $databox); - - $file = new system_file(__DIR__ . '/../testfiles/extractfile.jpg'); - $caption = new system_file(__DIR__ . '/../testfiles/extractfile.xml'); - - $metadatas = $file->extract_metadatas($databox->get_meta_structure(), $caption); - - $meta_id_found = array(); - - $this->assertTrue(is_array($metadatas)); - $this->assertArrayHasKey('metadatas', $metadatas); - $this->assertArrayHasKey('status', $metadatas); - foreach ($metadatas['metadatas'] as $metadata) { - $this->assertTrue(is_array($metadata)); - $this->assertArrayHasKey('meta_struct_id', $metadata); - $this->assertArrayHasKey('meta_id', $metadata); - $this->assertArrayHasKey('value', $metadata); - $this->assertTrue(is_scalar($metadata['value'])); - $this->assertNull($metadata['meta_id']); - $this->assertTrue(is_int($metadata['meta_struct_id'])); - $this->assertTrue($metadata['meta_struct_id'] > 0); - - $databox_field = databox_field::get_instance($databox, $metadata['meta_struct_id']); - - if ( ! $databox_field->is_multi() && isset($meta_id_found[$metadata['meta_struct_id']])) { - $this->fail('There should not be multiple mono values'); - } - - $meta_id_found[$metadata['meta_struct_id']] = $metadata['meta_struct_id']; - } - } -}