This commit is contained in:
Xes
2025-08-14 22:41:49 +02:00
parent 2de81ccc46
commit 8ce45119b6
39774 changed files with 4309466 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
<?php
/**
* This file is part of the PHPExiftool package.
*
* (c) Alchemy <support@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPExiftool\Test;
use PHPExiftool\PreviewExtractor;
abstract class AbstractPreviewExtractorTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers PHPExiftool\PreviewExtractor::extract
*/
public function testExtract()
{
$extractor = new PreviewExtractor($this->getExiftool());
$tmpDir = sys_get_temp_dir() . '/tests' . mt_rand(10000, 99999);
mkdir($tmpDir);
$files = $extractor->extract(__DIR__ . '/../../../files/ExifTool.jpg', $tmpDir);
$this->assertInstanceOf('\\DirectoryIterator', $files);
$n = 0;
$unlinks = array();
foreach ($files as $file) {
if ($file->isDot() || $file->isDir()) {
continue;
}
$unlinks[] = $file->getPathname();
$n ++;
}
foreach ($unlinks as $u) {
unlink($u);
}
$this->assertEquals(1, $n);
}
/**
* @expectedException \PHPExiftool\Exception\LogicException
*/
public function testExtractWrongFile()
{
$extractor = new PreviewExtractor($this->getExiftool());
$tmpDir = sys_get_temp_dir() . '/tests' . mt_rand(10000, 99999);
$extractor->extract(__DIR__ . '/ExifTool.jpg', $tmpDir);
}
/**
* @expectedException \PHPExiftool\Exception\LogicException
*/
public function testExtractWrongDir()
{
$extractor = new PreviewExtractor($this->getExiftool());
$tmpDir = sys_get_temp_dir() . '/tests' . mt_rand(10000, 99999);
$extractor->extract(__DIR__ . '/../../../files/ExifTool.jpg', $tmpDir);
}
abstract protected function getExiftool();
}

View File

@@ -0,0 +1,446 @@
<?php
/**
* This file is part of the PHPExiftool package.
*
* (c) Alchemy <support@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPExiftool\Test;
use PHPExiftool\Reader;
abstract class AbstractReaderTest extends \PHPUnit_Framework_TestCase {
/**
* @var Reader
*/
protected $object;
protected static $tmpDir;
protected static $disableSymLinkTest = false;
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
$tmpDir = __DIR__ . '/tmp';
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$command = 'rmdir /q /s ' . escapeshellarg($tmpDir);
} else {
$command = 'rmdir -Rf ' . escapeshellarg($tmpDir);
}
$process = new \Symfony\Component\Process\Process($command);
$process->run();
if (!is_dir($tmpDir)) {
mkdir($tmpDir);
}
self::$tmpDir = $tmpDir . '/exiftool_reader';
if (!is_dir(self::$tmpDir)) {
mkdir(self::$tmpDir);
}
copy(__DIR__.'/../../../files/ExifTool.jpg', self::$tmpDir . '/test2.jpg');
copy(__DIR__.'/../../../files/ExifTool.jpg', self::$tmpDir . '/test.jpg');
if (!is_dir(self::$tmpDir . '/dir')) {
mkdir(self::$tmpDir . '/dir');
}
if (!is_dir(self::$tmpDir . '/usr')) {
mkdir(self::$tmpDir . '/usr');
}
$tmpDir2 = $tmpDir . '/exiftool_reader2';
if (!is_dir($tmpDir2)) {
mkdir($tmpDir2);
}
copy(__DIR__.'/../../../files/ExifTool.jpg', $tmpDir2 . '/test2.jpg');
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
self::$disableSymLinkTest = true;
} elseif (!is_link(self::$tmpDir . '/symlink')) {
if (!@symlink($tmpDir2, self::$tmpDir . '/symlink')) {
self::$disableSymLinkTest = true;
}
}
copy(__DIR__.'/../../../files/plop/CanonRaw.cr2', self::$tmpDir . '/dir/CanonRaw.cr2');
$tmpDir3 = $tmpDir . '/exiftool_reader3';
if (!is_dir($tmpDir3)) {
mkdir($tmpDir3);
}
if (!is_dir($tmpDir3 . '/.svn')) {
mkdir($tmpDir3 . '/.svn');
}
if (!is_dir($tmpDir3 . '/.roro')) {
mkdir($tmpDir3 . '/.roro');
}
if (!is_dir($tmpDir3 . '/.git')) {
mkdir($tmpDir3 . '/.git');
}
touch($tmpDir3 . '/.git/config');
touch($tmpDir3 . '/.roro/.roro.tmp');
copy(__DIR__.'/../../../files/ExifTool.jpg', $tmpDir3 . '/.exiftool.jpg');
}
/**
* @covers PHPExiftool\Reader::__construct
*/
protected function setUp()
{
parent::setUp();
$this->object = $this->getReader();
}
/**
* @covers PHPExiftool\Reader::__destruct
*/
protected function tearDown()
{
$this->object = null;
parent::tearDown();
}
/**
* @covers PHPExiftool\Reader::getIterator
*/
public function testGetIterator()
{
$file = self::$tmpDir . '/test.jpg';
$this->assertInstanceOf('\\Iterator', $this->object->files($file)->getIterator());
}
/**
* @covers PHPExiftool\Reader::append
* @covers PHPExiftool\Reader::all
*/
public function testAppend()
{
$file1 = self::$tmpDir . '/test.jpg';
$file2 = self::$tmpDir . '/test2.jpg';
$file3 = self::$tmpDir . '/dir/CanonRaw.cr2';
$this->assertEquals(1, count($this->object->files($file1)->all()));
$reader = $this->getReader();
$reader->files(array($file2, $file3));
$this->assertEquals(3, count($this->object->append($reader)->all()));
}
/**
* @covers PHPExiftool\Reader::sort
* @covers PHPExiftool\Reader::all
*/
public function testSort()
{
$file1 = self::$tmpDir . '/test.jpg';
$file2 = self::$tmpDir . '/test2.jpg';
$file3 = self::$tmpDir . '/dir/CanonRaw.cr2';
$reader = $this->getReader();
$reader->files(array($file3, $file2, $file1));
$reader->sort(array('directory', 'filename', 'cigarette'));
$results = array();
foreach ($reader->all() as $entity) {
$results[] = basename($entity->getFile());
}
$this->assertSame(array('test.jpg', 'test2.jpg', 'CanonRaw.cr2'), $results);
}
/**
* @covers PHPExiftool\Reader::files
* @covers PHPExiftool\Reader::buildQuery
*/
public function testFiles()
{
$file = self::$tmpDir . '/test.jpg';
$this->object->files($file);
$file = $this->object->files(self::$tmpDir . '/test.jpg')->first()->getFile();
$this->assertEquals(realpath($file), realpath($file));
}
/**
* @covers PHPExiftool\Reader::resetResults
*/
public function testResetFilters()
{
$file = self::$tmpDir . '/test.jpg';
$this->object->files($file)->all();
$file = self::$tmpDir . '/test2.jpg';
$this->object->files($file)->all();
$this->assertEquals(2, count($this->object->all()));
}
/**
* @covers PHPExiftool\Reader::ignoreDotFiles
* @covers PHPExiftool\Reader::all
*/
public function testIgnoreVCS()
{
$this->object->in(self::$tmpDir . '3');
$this->assertEquals(1, count($this->object->all()));
}
/**
* @covers PHPExiftool\Reader::ignoreDotFiles
* @covers PHPExiftool\Reader::all
*/
public function testIgnoreDotFiles()
{
$this->object->in(self::$tmpDir . '3');
$this->assertEquals(1, count($this->object->all()));
$this->object->ignoreDotFiles()->in(self::$tmpDir . '3');
$this->assertEquals(0, count($this->object->all()));
}
/**
* @covers PHPExiftool\Reader::in
* @covers PHPExiftool\Reader::buildQuery
* @covers PHPExiftool\Reader::all
*/
public function testIn()
{
$reader = $this->getReader();
$reader->in(self::$tmpDir);
$this->assertEquals(3, count($reader->all()));
$reader = $this->getReader();
$reader->in(self::$tmpDir . '/dir');
$this->assertEquals(1, count($reader->all()));
$reader = $this->getReader();
$reader->in(__DIR__ . '/../../../../vendor/phpexiftool/exiftool/');
foreach ($reader as $file) {
$this->assertEquals(basename($file->getFile()), $file->getMetadatas()->get('System:FileName')->getValue()->asString());
}
}
/**
* @covers PHPExiftool\Reader::exclude
* @covers PHPExiftool\Reader::computeExcludeDirs
* @covers PHPExiftool\Reader::buildQuery
* @covers PHPExiftool\Reader::all
*/
public function testExclude()
{
$reader = $this->getReader();
$reader
->in(self::$tmpDir)
->exclude(self::$tmpDir . '/dir');
$this->assertEquals(2, count($reader->all()));
}
/**
* @dataProvider getExclude
* @covers PHPExiftool\Reader::computeExcludeDirs
* @covers PHPExiftool\Reader::all
*/
public function testComputeExcludeDirs($dir)
{
$reader = $this->getReader();
$reader
->in(self::$tmpDir)
->exclude($dir)
->all();
}
public function getExclude()
{
return array(
array(self::$tmpDir . '/dir/'),
array(self::$tmpDir . '/dir'),
array('dir'),
array('/dir'),
array('/usr'),
array('usr'),
array('dir/'),
);
}
/**
* @dataProvider getWrongExclude
* @covers PHPExiftool\Reader::computeExcludeDirs
* @covers \PHPExiftool\Exception\RuntimeException
* @expectedException \PHPExiftool\Exception\RuntimeException
*/
public function testComputeExcludeDirsFail($dir)
{
$reader = $this->getReader();
$reader
->in(self::$tmpDir)
->exclude($dir)
->all();
}
public function getWrongExclude()
{
return array(
array(self::$tmpDir . '/dir/dir2'),
array(self::$tmpDir . '/dirlo'),
array('dir/dir2'),
array('/usr/local'),
array('usr/local'),
array('/tmp'),
);
}
/**
* @covers PHPExiftool\Reader::extensions
* @covers PHPExiftool\Reader::buildQuery
* @covers PHPExiftool\Reader::buildQueryAndExecute
*/
public function testExtensions()
{
$reader = $this->getReader();
$reader->in(self::$tmpDir);
$this->assertEquals(3, count($reader->all()));
$reader = $this->getReader();
$reader->in(self::$tmpDir)->notRecursive()->extensions(array('cr2'));
$this->assertEquals(0, count($reader->all()));
$reader = $this->getReader();
$reader->in(self::$tmpDir)->extensions(array('cr2'));
$this->assertEquals(1, count($reader->all()));
$reader = $this->getReader();
$reader->in(self::$tmpDir)->extensions(array('jpg'));
$this->assertEquals(2, count($reader->all()));
$reader = $this->getReader();
$reader->in(self::$tmpDir)->extensions('jpg')->extensions('cr2');
$this->assertEquals(3, count($reader->all()));
$reader = $this->getReader();
$reader->in(self::$tmpDir)->extensions(array('jpg'), false);
$this->assertEquals(1, count($reader->all()));
$reader = $this->getReader();
$reader->in(self::$tmpDir)->extensions(array('cr2', 'jpg'), false)->notRecursive();
$this->assertEquals(0, count($reader->all()));
}
/**
* @covers PHPExiftool\Reader::extensions
* @covers \PHPExiftool\Exception\LogicException
* @expectedException \PHPExiftool\Exception\LogicException
*/
public function testExtensionsMisUse()
{
$reader = $this->getReader();
$reader->extensions('exiftool')->extensions('jpg', false);
}
/**
* @covers PHPExiftool\Reader::followSymLinks
*/
public function testFollowSymLinks()
{
if (self::$disableSymLinkTest) {
$this->markTestSkipped('This system does not support symlinks');
}
$reader = $this->getReader();
$reader->in(self::$tmpDir)
->followSymLinks();
$this->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $reader->all());
$this->assertEquals(4, count($reader->all()));
}
/**
* @covers PHPExiftool\Reader::notRecursive
* @covers PHPExiftool\Reader::buildQuery
*/
public function testNotRecursive()
{
$reader = $this->getReader();
$reader->in(self::$tmpDir)->notRecursive();
$this->assertEquals(2, count($reader->all()));
}
/**
* @covers PHPExiftool\Reader::getOneOrNull
*/
public function testGetOneOrNull()
{
$reader = $this->getReader();
$reader->in(self::$tmpDir)->notRecursive()->extensions(array('jpg', 'cr2'), false);
$this->assertNull($reader->getOneOrNull());
}
/**
* @covers PHPExiftool\Reader::first
* @covers \PHPExiftool\Exception\EmptyCollectionException
* @expectedException \PHPExiftool\Exception\EmptyCollectionException
*/
public function testFirstEmpty()
{
$reader = $this->getReader();
$reader->in(self::$tmpDir)->notRecursive()->extensions(array('jpg', 'cr2'), false);
$reader->first();
}
/**
* @covers PHPExiftool\Reader::first
*/
public function testFirst()
{
$reader = $this->getReader();
$reader
->in(self::$tmpDir);
$this->assertInstanceOf('\\PHPExiftool\\FileEntity', $reader->first());
}
/**
* @covers PHPExiftool\Reader::buildQuery
* @expectedException \PHPExiftool\Exception\LogicException
*/
public function testFail()
{
$reader = $this->getReader();
$reader->all();
}
/**
* @covers PHPExiftool\Reader::all
* @covers PHPExiftool\Reader::buildQueryAndExecute
*/
public function testAll()
{
$reader = $this->getReader();
$reader->in(self::$tmpDir);
$this->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $reader->all());
$this->assertEquals(3, count($reader->all()));
}
abstract protected function getReader();
}

View File

@@ -0,0 +1,359 @@
<?php
/**
* This file is part of the PHPExiftool package.
*
* (c) Alchemy <support@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPExiftool\Test;
use PHPExiftool\Driver;
use PHPExiftool\Writer;
use PHPExiftool\Reader;
use PHPExiftool\RDFParser;
abstract class AbstractWriterTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Writer
*/
protected $object;
protected $in;
protected $inWithICC;
protected $inPlace;
protected $out;
protected function setUp()
{
$this->object = new Writer($this->getExiftool());
$this->in = __DIR__ . '/../../../files/ExifTool.jpg';
$this->inWithICC = __DIR__ . '/../../../files/pixelWithIcc.jpg';
$this->out = __DIR__ . '/../../../files/ExifTool_erased.jpg';
$this->inPlace = __DIR__ . '/../../../files/ExifToolCopied.jpg';
copy($this->in, $this->inPlace);
}
protected function tearDown()
{
if (file_exists($this->out) && is_writable($this->out)) {
unlink($this->out);
}
if (file_exists($this->inPlace) && is_writable($this->inPlace)) {
unlink($this->inPlace);
}
}
/**
* @covers PHPExiftool\Writer::setMode
* @covers PHPExiftool\Writer::isMode
*/
public function testSetMode()
{
$this->object->setMode(Writer::MODE_EXIF2IPTC, true);
$this->assertTrue($this->object->isMode(Writer::MODE_EXIF2IPTC));
$this->object->setMode(Writer::MODE_XMP2EXIF, true);
$this->assertTrue($this->object->isMode(Writer::MODE_XMP2EXIF));
$this->object->setMode(Writer::MODE_EXIF2IPTC, false);
$this->assertFalse($this->object->isMode(Writer::MODE_EXIF2IPTC));
$this->object->setMode(Writer::MODE_XMP2EXIF, true);
$this->assertTrue($this->object->isMode(Writer::MODE_XMP2EXIF));
}
/**
* @covers PHPExiftool\Writer::copy
*/
public function testCopy()
{
$metadatas = new Driver\Metadata\MetadataBag();
$this->object->erase(true, true);
$changedFiles = $this->object->write($this->inWithICC, $metadatas, $this->out);
$this->assertEquals(1, $changedFiles);
$reader = new Reader($this->getExiftool(), new RDFParser());
$metadatasRead = $reader->files($this->out)->first()->getMetadatas();
$this->assertFalse(is_object($metadatasRead->get('IPTC:ObjectName')));
$this->object->copy($this->in, $this->out);
$metadatasRead = $reader->files($this->out)->first()->getMetadatas();
$this->assertTrue(is_object($metadatasRead->get('IPTC:ObjectName')));
$this->assertEquals("Test IPTC picture", $metadatasRead->get('IPTC:ObjectName')->getValue()->asString());
}
/**
* @covers PHPExiftool\Writer::setModule
* @covers PHPExiftool\Writer::hasModule
*/
public function testSetModule()
{
$this->assertFalse($this->object->hasModule(Writer::MODULE_MWG));
$this->object->setModule(Writer::MODULE_MWG, true);
$this->assertTrue($this->object->hasModule(Writer::MODULE_MWG));
$this->object->setModule(Writer::MODULE_MWG, false);
$this->assertFalse($this->object->hasModule(Writer::MODULE_MWG));
}
/**
* @covers PHPExiftool\Writer::write
* @covers PHPExiftool\Writer::erase
*/
public function testEraseWithoutICC()
{
$uniqueId = 'UNI-QUE-ID';
$metadatas = new Driver\Metadata\MetadataBag();
$metadatas->add(new Driver\Metadata\Metadata(new Driver\Tag\IPTC\UniqueDocumentID(), new Driver\Value\Mono($uniqueId)));
$metadatas->add(new Driver\Metadata\Metadata(new Driver\Tag\XMPExif\ImageUniqueID(), new Driver\Value\Mono($uniqueId)));
$this->object->erase(true, false);
$changedFiles = $this->object->write($this->inWithICC, $metadatas, $this->out);
$this->assertEquals(1, $changedFiles);
$reader = new Reader($this->getExiftool(), new RDFParser());
$this->assertGreaterThan(200, count($reader->files($this->in)->first()->getMetadatas()));
$reader = new Reader($this->getExiftool(), new RDFParser());
$this->assertGreaterThan(4, count($reader->files($this->out)->first()->getMetadatas()));
$this->assertLessThan(30, count($reader->files($this->out)->first()->getMetadatas()));
$acceptedMetas = array(
'Exiftool:\w+',
'System:\w+',
'File:\w+',
'Composite:\w+',
'IPTC:CodedCharacterSet',
'IPTC:EnvelopeRecordVersion',
'IPTC:UniqueDocumentID',
'IPTC:ApplicationRecordVersion',
'Photoshop:IPTCDigest',
'XMP-x:XMPToolkit',
'XMP-exif:ImageUniqueID',
'Adobe:DCTEncodeVersion',
'Adobe:APP14Flags0',
'Adobe:APP14Flags1',
'Adobe:ColorTransform',
);
foreach ($reader->files($this->out)->first()->getMetadatas() as $meta) {
$found = false;
foreach ($acceptedMetas as $accepted) {
if (preg_match('/' . $accepted . '/i', $meta->getTag()->getTagname())) {
$found = true;
break;
}
}
if ( ! $found) {
$this->fail(sprintf('Unexpected meta %s found', $meta->getTag()->getTagname()));
}
}
}
public function testEraseWithICC()
{
$uniqueId = 'UNI-QUE-ID';
$metadatas = new Driver\Metadata\MetadataBag();
$metadatas->add(new Driver\Metadata\Metadata(new Driver\Tag\IPTC\UniqueDocumentID(), new Driver\Value\Mono($uniqueId)));
$metadatas->add(new Driver\Metadata\Metadata(new Driver\Tag\XMPExif\ImageUniqueID(), new Driver\Value\Mono($uniqueId)));
$this->object->erase(true, true);
$changedFiles = $this->object->write($this->inWithICC, $metadatas, $this->out);
$this->assertEquals(1, $changedFiles);
$reader = new Reader($this->getExiftool(), new RDFParser());
$this->assertGreaterThan(200, count($reader->files($this->in)->first()->getMetadatas()));
$reader = new Reader($this->getExiftool(), new RDFParser());
$this->assertGreaterThan(4, count($reader->files($this->out)->first()->getMetadatas()));
$acceptedMetas = array(
'Exiftool:\w+',
'System:\w+',
'File:\w+',
'Composite:\w+',
'IPTC:CodedCharacterSet',
'ICC-header:\w+',
'IPTC:EnvelopeRecordVersion',
'IPTC:UniqueDocumentID',
'IPTC:ApplicationRecordVersion',
'Photoshop:IPTCDigest',
'XMP-x:XMPToolkit',
'XMP-exif:ImageUniqueID',
'Adobe:DCTEncodeVersion',
'Adobe:APP14Flags0',
'Adobe:APP14Flags1',
'Adobe:ColorTransform',
);
foreach ($reader->files($this->out)->first()->getMetadatas() as $meta) {
$found = false;
foreach ($acceptedMetas as $accepted) {
if (preg_match('/' . $accepted . '/i', $meta->getTag()->getTagname())) {
$found = true;
break;
}
}
if ( ! $found) {
$this->fail(sprintf('Unexpected meta %s found', $meta->getTag()->getTagname()));
}
}
}
/**
* @covers PHPExiftool\Writer::write
*/
public function testWrite()
{
$metadatas = new Driver\Metadata\MetadataBag();
$metadatas->add(new Driver\Metadata\Metadata(new Driver\Tag\IPTC\ObjectName(), new Driver\Value\Mono('Beautiful Object')));
$metadatas->add(new Driver\Metadata\Metadata(new Driver\Tag\IPTC\ObjectName(), new Driver\Value\Mono('Beautiful Object')));
$metadatas->add(new Driver\Metadata\Metadata(new Driver\Tag\XMPIptcExt\PersonInImage(), new Driver\Value\Multi(array('Romain', 'Nicolas'))));
$changedFiles = $this->object->write($this->in, $metadatas, $this->out);
$this->assertEquals(1, $changedFiles);
$reader = new Reader($this->getExiftool(), new RDFParser());
$metadatasRead = $reader->files($this->out)->first()->getMetadatas();
$this->assertGreaterThan(200, count($metadatasRead));
$this->assertEquals('Beautiful Object', $metadatasRead->get('IPTC:ObjectName')->getValue()->asString());
$this->assertEquals(array('Romain', 'Nicolas'), $metadatasRead->get('XMP-iptcExt:PersonInImage')->getValue()->asArray());
}
/**
* @covers PHPExiftool\Writer::write
*/
public function testWriteInPlace()
{
$metadatas = new Driver\Metadata\MetadataBag();
$metadatas->add(new Driver\Metadata\Metadata(new Driver\Tag\IPTC\ObjectName(), new Driver\Value\Mono('Beautiful Object')));
$metadatas->add(new Driver\Metadata\Metadata(new Driver\Tag\IPTC\ObjectName(), new Driver\Value\Mono('Beautiful Object')));
$metadatas->add(new Driver\Metadata\Metadata(new Driver\Tag\XMPIptcExt\PersonInImage(), new Driver\Value\Multi(array('Romain', 'Nicolas'))));
$changedFiles = $this->object->write($this->inPlace, $metadatas);
$this->assertEquals(1, $changedFiles);
$reader = new Reader($this->getExiftool(), new RDFParser());
$metadatasRead = $reader->files($this->inPlace)->first()->getMetadatas();
$this->assertGreaterThan(200, count($metadatasRead));
$this->assertEquals('Beautiful Object', $metadatasRead->get('IPTC:ObjectName')->getValue()->asString());
$this->assertEquals(array('Romain', 'Nicolas'), $metadatasRead->get('XMP-iptcExt:PersonInImage')->getValue()->asArray());
}
/**
* @covers PHPExiftool\Writer::write
*/
public function testWriteInPlaceErased()
{
$metadatas = new Driver\Metadata\MetadataBag();
$metadatas->add(new Driver\Metadata\Metadata(new Driver\Tag\IPTC\ObjectName(), new Driver\Value\Mono('Beautiful Object')));
$metadatas->add(new Driver\Metadata\Metadata(new Driver\Tag\IPTC\ObjectName(), new Driver\Value\Mono('Beautiful Object')));
$metadatas->add(new Driver\Metadata\Metadata(new Driver\Tag\XMPIptcExt\PersonInImage(), new Driver\Value\Multi(array('Romain', 'Nicolas'))));
$this->object->erase(true);
$changedFiles = $this->object->write($this->inPlace, $metadatas);
$this->assertEquals(1, $changedFiles);
$reader = new Reader($this->getExiftool(), new RDFParser());
$metadatasRead = $reader->files($this->inPlace)->first()->getMetadatas();
$this->assertLessThan(50, count($metadatasRead));
$this->assertEquals('Beautiful Object', $metadatasRead->get('IPTC:ObjectName')->getValue()->asString());
$this->assertEquals(array('Romain', 'Nicolas'), $metadatasRead->get('XMP-iptcExt:PersonInImage')->getValue()->asArray());
}
/**
* @covers PHPExiftool\Writer::write
* @covers PHPExiftool\Exception\InvalidArgumentException
* @expectedException PHPExiftool\Exception\InvalidArgumentException
*/
public function testWriteFail()
{
$this->object->write('ici', new Driver\Metadata\MetadataBag());
}
/**
* @covers PHPExiftool\Writer::addMetadatasArg
*/
public function testAddMetadatasArg()
{
$metadatas = new Driver\Metadata\MetadataBag();
$metadatas->add(new Driver\Metadata\Metadata(new Driver\Tag\IPTC\ObjectName(), new Driver\Value\Mono('Beautiful Object')));
$metadatas->add(new Driver\Metadata\Metadata(new Driver\Tag\XMPIptcExt\PersonInImage(), new Driver\Value\Multi(array('Romain', 'Nicolas'))));
$writer = new WriterTester($this->getExiftool());
$this->assertNotContains('@', trim($writer->getSyncCommandTester()));
$writer->setMode(WriterTester::MODE_EXIF2IPTC, true);
$this->assertContains('@ exif2iptc.args', $writer->getSyncCommandTester());
$writer->setMode(WriterTester::MODE_EXIF2XMP, true);
$this->assertContains('@ exif2xmp.args', $writer->getSyncCommandTester());
$writer->setMode(WriterTester::MODE_IPTC2EXIF, true);
$this->assertContains('@ iptc2exif', $writer->getSyncCommandTester());
$writer->setMode(WriterTester::MODE_IPTC2XMP, true);
$this->assertContains('@ iptc2xmp', $writer->getSyncCommandTester());
$writer->setMode(WriterTester::MODE_GPS2XMP, true);
$this->assertContains('@ gps2xmp', $writer->getSyncCommandTester());
$writer->setMode(WriterTester::MODE_PDF2XMP, true);
$this->assertContains('@ pdf2xmp', $writer->getSyncCommandTester());
$writer->setMode(WriterTester::MODE_XMP2PDF, true);
$this->assertContains('@ xmp2pdf', $writer->getSyncCommandTester());
$writer->setMode(WriterTester::MODE_XMP2GPS, true);
$this->assertContains('@ xmp2gps', $writer->getSyncCommandTester());
$writer->setMode(WriterTester::MODE_XMP2EXIF, true);
$this->assertContains('@ xmp2exif', $writer->getSyncCommandTester());
$writer->setMode(WriterTester::MODE_XMP2IPTC, true);
$this->assertContains('@ xmp2iptc', $writer->getSyncCommandTester());
$writer->setMode(WriterTester::MODE_XMP2IPTC, false);
$this->assertNotContains('@ xmp2iptc', $writer->getSyncCommandTester());
$writer->setModule(WriterTester::MODULE_MWG, true);
$this->assertContains('-use MWG', $writer->addMetadatasArgTester($metadatas));
$writer->setModule(WriterTester::MODULE_MWG, false);
$this->assertNotContains('-use MWG', $writer->addMetadatasArgTester($metadatas));
$this->assertRegExp("/\ -XMP-iptcExt:PersonInImage=['\"]Nicolas['\"]/", $writer->addMetadatasArgTester($metadatas));
}
abstract protected function getExiftool();
}
class WriterTester extends Writer
{
public function addMetadatasArgTester($metadatas)
{
return parent::addMetadatasArg($metadatas);
}
public function getSyncCommandTester()
{
return parent::getSyncCommand();
}
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* This file is part of the PHPExiftool package.
*
* (c) Alchemy <support@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPExiftool\Test\Command;
require_once __DIR__ . '/../AbstractPreviewExtractorTest.php';
use Monolog\Logger;
use Monolog\Handler\NullHandler;
use PHPExiftool\AbstractPreviewExtractorTest;
use PHPExiftool\Exiftool;
class PreviewExtractor extends AbstractPreviewExtractorTest
{
protected function getExiftool()
{
$logger = new Logger('Tests');
$logger->pushHandler(new NullHandler());
return new Exiftool($logger);
}
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* This file is part of the PHPExiftool package.
*
* (c) Alchemy <support@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPExiftool\Test\Command;
require_once __DIR__ . '/../AbstractReaderTest.php';
use Monolog\Logger;
use Monolog\Handler\NullHandler;
use PHPExiftool\Test\AbstractReaderTest;
use PHPExiftool\Reader;
class ReaderTest extends AbstractReaderTest
{
protected function getReader()
{
$logger = new Logger('Test');
$logger->pushHandler(new NullHandler());
return Reader::create($logger);
}
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* This file is part of the PHPExiftool package.
*
* (c) Alchemy <support@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPExiftool\Test\Command;
require_once __DIR__ . '/../AbstractWriterTest.php';
use Monolog\Logger;
use Monolog\Handler\NullHandler;
use PHPExiftool\Exiftool;
use PHPExiftool\Test\AbstractWriterTest;
class WriterTest extends AbstractWriterTest
{
protected function getExiftool()
{
$logger = new Logger('Tests');
$logger->pushHandler(new NullHandler());
return new Exiftool($logger);
}
}

View File

@@ -0,0 +1,38 @@
<?php
/**
* This file is part of the PHPExiftool package.
*
* (c) Alchemy <support@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPExiftool\Test\Driver\Metadata;
use PHPExiftool\Driver\Metadata\MetadataBag;
class MetadataBagTest extends \PHPUnit_Framework_TestCase
{
/**
* @var MetadataBag
*/
protected $object;
protected function setUp()
{
$this->object = new MetadataBag();
}
/**
* @covers PHPExiftool\Driver\Metadata\MetadataBag::filterKeysByRegExp
*/
public function testFilterKeysByRegExp()
{
$this->object->set('oneKey', 'oneValue');
$this->object->set('oneSecondKey', 'anotherValue');
$this->object->set('thirdKey', 'thirdValue');
$this->assertEquals(2, count($this->object->filterKeysByRegExp('/one.*/')));
}
}

View File

@@ -0,0 +1,56 @@
<?php
/**
* This file is part of the PHPExiftool package.
*
* (c) Alchemy <support@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPExiftool\Test\Driver\Metadata;
use PHPExiftool\Driver\AbstractTag;
use PHPExiftool\Driver\Value\Mono;
use PHPExiftool\Driver\Metadata\Metadata;
class MetadataTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Metadata
*/
protected $object;
protected $tag;
protected $value;
/**
* @covers \PHPExiftool\Driver\Metadata\Metadata::__construct
*/
protected function setUp()
{
$this->tag = new TagTest();
$this->value = new Mono('valeur');
$this->object = new Metadata(new TagTest, $this->value, new \SplFileInfo(__FILE__));
}
/**
* @covers \PHPExiftool\Driver\Metadata\Metadata::getTag
*/
public function testGetTag()
{
$this->assertEquals($this->object->getTag(), $this->tag);
}
/**
* @covers \PHPExiftool\Driver\Metadata\Metadata::getValue
*/
public function testGetValue()
{
$this->assertEquals($this->object->getValue(), $this->value);
}
}
class TagTest extends AbstractTag
{
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* This file is part of the PHPExiftool package.
*
* (c) Alchemy <support@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPExiftool\Test\Driver;
use PHPExiftool\Driver\TagFactory;
class TagFactoryTest extends \PHPUnit_Framework_TestCase
{
/**
* @var TagFactory
*/
protected $object;
/**
* @covers \PHPExiftool\Driver\TagFactory::GetFromRDFTagname
* @covers \PHPExiftool\Driver\TagFactory::classnameFromTagname
*/
public function testGetFromRDFTagname()
{
$tag = TagFactory::getFromRDFTagname('IPTC:SupplementalCategories');
$this->assertInstanceOf('\PHPExiftool\Driver\Tag\IPTC\SupplementalCategories', $tag);
$tag = TagFactory::getFromRDFTagname('XMPExif:ApertureValue');
$this->assertInstanceOf('\PHPExiftool\Driver\Tag\XMPExif\ApertureValue', $tag);
try {
$tag = TagFactory::getFromRDFTagname('XMPExif:AnunexistingTag');
$this->fail('Should raise a TagUnknown exception');
} catch (\PHPExiftool\Exception\TagUnknown $e) {
}
}
/**
* @covers \PHPExiftool\Driver\TagFactory::GetFromRDFTagname
* @covers \PHPExiftool\Exception\TagUnknown
* @expectedException \PHPExiftool\Exception\TagUnknown
*/
public function testGetFromRDFTagnameFail()
{
TagFactory::getFromRDFTagname('XMPExif:AnunexistingTag');
}
/**
* @covers \PHPExiftool\Driver\TagFactory::HasFromRDFTagname
*/
public function testHasFromRDFTagname()
{
$this->assertTrue(TagFactory::hasFromRDFTagname('IPTC:SupplementalCategories'));
$this->assertFalse(TagFactory::hasFromRDFTagname('XMPExif:AnunexistingTag'));
}
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* This file is part of the PHPExiftool package.
*
* (c) Alchemy <support@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPExiftool\Test\Driver;
use PHPExiftool\Driver\TagProvider;
class TagProviderTest extends \PHPUnit_Framework_TestCase
{
private $object;
protected function setUp()
{
$this->object = new TagProvider;
}
public function testGetAll()
{
$this->assertInternalType('array', $this->object->getAll());
}
public function testGetLookupTable()
{
$this->assertInternalType('array', $this->object->getLookupTable());
}
}

View File

@@ -0,0 +1,82 @@
<?php
/**
* This file is part of the PHPExiftool package.
*
* (c) Alchemy <support@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPExiftool\Test\Driver;
use Symfony\Component\Finder\Finder;
class TagTest extends \PHPUnit_Framework_TestCase {
/**
* @var Tag
*/
protected $object;
/**
* @covers \PHPExiftool\Driver\AbstractTag::getDescription
* @covers \PHPExiftool\Driver\AbstractTag::getGroupName
* @covers \PHPExiftool\Driver\AbstractTag::getName
* @covers \PHPExiftool\Driver\AbstractTag::getTagname
* @covers \PHPExiftool\Driver\AbstractTag::getId
* @covers \PHPExiftool\Driver\AbstractTag::getValues
* @covers \PHPExiftool\Driver\AbstractTag::isMulti
* @covers \PHPExiftool\Driver\AbstractTag::isWritable
* @covers \PHPExiftool\Driver\AbstractTag::isBinary
*/
public function testConsistency()
{return;
$finder = new Finder();
$finder->files()->in(array(__DIR__ . '/../../../../../lib/PHPExiftool/Driver/Tag/'));
foreach ($finder as $file) {
$classname = substr(
str_replace(
array(realpath(__DIR__ . '/../../../../../lib'), '/')
, array('', '\\')
, $file->getRealPath()
), 0, -4);
$tag = new $classname;
/* @var $tag \PHPExiftool\Driver\Tag */
$this->assertTrue(is_scalar($tag->getDescription()));
$this->assertTrue(is_scalar($tag->getGroupName()));
$this->assertTrue(is_scalar($tag->getName()));
$this->assertTrue(is_scalar($tag->getTagname()));
$this->assertTrue(is_scalar($tag->getId()));
if ($tag->getValues() !== null)
$this->assertTrue(is_array($tag->getValues()));
if ($tag->isMulti())
$this->assertTrue($tag->isMulti());
else
$this->assertFalse($tag->isMulti());
if ($tag->isWritable())
$this->assertTrue($tag->isWritable());
else
$this->assertFalse($tag->isWritable(), $tag->getTagname() . " is writable");
if ($tag->isBinary())
$this->assertTrue($tag->isBinary());
else
$this->assertFalse($tag->isBinary());
$tag->getMaxLength();
$this->assertEquals(0, $tag->getMinLength());
unset($tag);
}
}
}

View File

@@ -0,0 +1,102 @@
<?php
/**
* This file is part of the PHPExiftool package.
*
* (c) Alchemy <support@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPExiftool\Test\Driver\Value;
use PHPExiftool\Driver\Value\Binary;
use PHPExiftool\Driver\Value\ValueInterface;
class BinaryTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Binary
*/
protected $object;
/**
* @covers PHPExiftool\Driver\Value\Binary::__construct
*/
protected function setUp()
{
$this->object = new Binary('Binary');
}
/**
* @covers PHPExiftool\Driver\Value\Binary::getType
*/
public function testGetType()
{
$this->assertEquals(ValueInterface::TYPE_BINARY, $this->object->getType());
}
/**
* @covers PHPExiftool\Driver\Value\Binary::asString
*/
public function testAsString()
{
$this->assertEquals('Binary', $this->object->asString());
}
/**
* @covers PHPExiftool\Driver\Value\Binary::asBase64
*/
public function testAsBase64()
{
$this->assertEquals(base64_encode('Binary'), $this->object->asBase64());
}
/**
* @covers PHPExiftool\Driver\Value\Binary::set
*/
public function testSetValue()
{
$this->object->set('Daisy');
$this->assertEquals('Daisy', $this->object->asString());
}
/**
* @covers PHPExiftool\Driver\Value\Binary::setBase64Value
*/
public function testSetBase64Value()
{
$this->object->setBase64Value('UmlyaSBGaWZpIGV0IExvdWxvdQ==');
$this->assertEquals('Riri Fifi et Loulou', $this->object->asString());
}
/**
* @covers PHPExiftool\Driver\Value\Binary::setBase64Value
* @covers \PHPExiftool\Exception\InvalidArgumentException
* @expectedException \PHPExiftool\Exception\InvalidArgumentException
*/
public function testSetWrongBase64Value()
{
$this->object->setBase64Value('Riri Fifi et Loulou !');
}
/**
* @covers PHPExiftool\Driver\Value\Binary::loadFromBase64
*/
public function testLoadFromBase64()
{
$object = Binary::loadFromBase64('VW5jbGUgU2Nyb29nZQ==');
$this->assertEquals('Uncle Scrooge', $object->asString());
$this->assertEquals('VW5jbGUgU2Nyb29nZQ==', $object->asBase64());
}
/**
* @covers PHPExiftool\Driver\Value\Binary::loadFromBase64
* @covers \PHPExiftool\Exception\InvalidArgumentException
* @expectedException \PHPExiftool\Exception\InvalidArgumentException
*/
public function testLoadFromWrongBase64()
{
$object = Binary::loadFromBase64('Uncle Scrooge !!!');
}
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* This file is part of the PHPExiftool package.
*
* (c) Alchemy <support@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPExiftool\Test\Driver\Value;
use PHPExiftool\Driver\Value\Mono;
use PHPExiftool\Driver\Value\ValueInterface;
class MonoTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Mono
*/
protected $object;
/**
* @covers PHPExiftool\Driver\Value\Mono::__construct
*/
protected function setUp()
{
$this->object = new Mono('Hello !');
}
/**
* @covers PHPExiftool\Driver\Value\Mono::getType
*/
public function testGetType()
{
$this->assertEquals(ValueInterface::TYPE_MONO, $this->object->getType());
}
/**
* @covers PHPExiftool\Driver\Value\Mono::asString
*/
public function testAsString()
{
$this->assertEquals('Hello !', $this->object->asString());
}
/**
* @covers PHPExiftool\Driver\Value\Mono::set
*/
public function testSetValue()
{
$this->object->set('World !');
$this->assertEquals('World !', $this->object->asString());
}
}

View File

@@ -0,0 +1,64 @@
<?php
/**
* This file is part of the PHPExiftool package.
*
* (c) Alchemy <support@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPExiftool\Test\Driver\Value;
use PHPExiftool\Driver\Value\Multi;
use PHPExiftool\Driver\Value\ValueInterface;
class MultiTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Multi
*/
protected $object;
/**
* @covers PHPExiftool\Driver\Value\Multi::__construct
*/
protected function setUp()
{
$this->object = new Multi(array('hello', 'world !'));
}
/**
* @covers PHPExiftool\Driver\Value\Multi::getType
*/
public function testGetType()
{
$this->assertEquals(ValueInterface::TYPE_MULTI, $this->object->getType());
}
/**
* @covers PHPExiftool\Driver\Value\Multi::asArray
*/
public function testAsArray()
{
$this->assertEquals(array('hello', 'world !'), $this->object->asArray());
}
/**
* @covers PHPExiftool\Driver\Value\Multi::addValue
*/
public function testAddValue()
{
$this->object->addValue('tim');
$this->assertEquals(array('hello', 'world !', 'tim'), $this->object->asArray());
}
/**
* @covers PHPExiftool\Driver\Value\Multi::reset
*/
public function testReset()
{
$this->object->reset();
$this->assertEquals(array(), $this->object->asArray());
}
}

View File

@@ -0,0 +1,63 @@
<?php
/**
* This file is part of the PHPExiftool package.
*
* (c) Alchemy <support@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPExiftool\Test;
use PHPExiftool\ExiftoolServer;
class ExiftoolServerTest extends \PHPUnit_Framework_TestCase
{
protected $exiftool;
public function setUp()
{
$this->exiftool = new ExiftoolServer();
$this->exiftool->start();
}
public function tearDown()
{
$this->exiftool->stop();
}
/**
* @covers PHPExiftool\ExiftoolServer::executeCommand
*/
public function testExecuteCommand()
{
$this->assertRegExp('/\d+\.\d+/', $this->exiftool->executeCommand('-ver'));
}
/**
* @covers PHPExiftool\ExiftoolServer::executeCommand
* @covers \PHPExiftool\Exception\RuntimeException
* @expectedException \PHPExiftool\Exception\RuntimeException
*/
public function testExecuteCommandFailed()
{
$this->markTestSkipped('Currently disable server support');
$this->exiftool->executeCommand('-prout');
}
public function testReset()
{
$this->exiftool->reset();
$this->exiftool->start();
$this->assertTrue($this->exiftool->isRunning());
}
public function testStop()
{
$this->exiftool->stop();
$this->assertFalse($this->exiftool->isRunning());
}
}

View File

@@ -0,0 +1,48 @@
<?php
/**
* This file is part of the PHPExiftool package.
*
* (c) Alchemy <support@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPExiftool\Test;
use Monolog\Logger;
use Monolog\Handler\NullHandler;
use PHPExiftool\Exiftool;
class ExiftoolTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers PHPExiftool\Exiftool::executeCommand
*/
public function testExecuteCommand()
{
$exiftool = new Exiftool($this->getlogger());
$this->assertRegExp('/\d+\.\d+/', $exiftool->executeCommand('-ver'));
}
/**
* @covers PHPExiftool\Exiftool::executeCommand
* @covers \PHPExiftool\Exception\RuntimeException
* @expectedException \PHPExiftool\Exception\RuntimeException
*/
public function testExecuteCommandFailed()
{
$exiftool = new Exiftool($this->getlogger());
$exiftool->executeCommand('-prout');
}
private function getlogger()
{
$logger = new Logger('Tests');
$logger->pushHandler(new NullHandler());
return $logger;
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* This file is part of the PHPExiftool package.
*
* (c) Alchemy <support@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPExiftool\Test;
use PHPExiftool\FileEntity;
use PHPExiftool\RDFParser;
class FileEntityTest extends \PHPUnit_Framework_TestCase
{
/**
* @var FileEntity
*/
protected $object;
/**
* @covers PHPExiftool\FileEntity::__construct
*/
protected function setUp()
{
$dom = new \DOMDocument();
$dom->loadXML(file_get_contents(__DIR__ . '/../../../files/ExifTool.xml'));
$this->object = new FileEntity('testFile', $dom, new RDFParser());
}
/**
* @covers PHPExiftool\FileEntity::getIterator
*/
public function testGetIterator()
{
$this->assertInstanceOf('\\Iterator', $this->object->getIterator());
}
/**
* @covers PHPExiftool\FileEntity::getFile
*/
public function testGetFile()
{
$this->assertInternalType('string', $this->object->getFile());
}
/**
* @covers PHPExiftool\FileEntity::getMetadatas
*/
public function testGetMetadatas()
{
$this->assertInstanceOf('\\PHPExiftool\Driver\Metadata\MetadataBag', $this->object->getMetadatas());
$this->assertEquals(349, count($this->object->getMetadatas()));
}
/**
* @covers PHPExiftool\FileEntity::executeQuery
*/
public function testExecuteQuery()
{
$this->assertInstanceOf('\\PHPExiftool\\Driver\\Value\\Mono', $this->object->executeQuery('IFD0:Copyright'));
$this->assertEquals('Copyright 2004 Phil Harvey', $this->object->executeQuery('IFD0:Copyright')->asString());
$this->assertInstanceOf('\\PHPExiftool\\Driver\\Value\\Binary', $this->object->executeQuery('CIFF:FreeBytes'));
$this->assertInstanceOf('\\PHPExiftool\\Driver\\Value\\Multi', $this->object->executeQuery('XMP-dc:Subject'));
$this->assertEquals(array('ExifTool', 'Test', 'XMP'), $this->object->executeQuery('XMP-dc:Subject')->asArray());
}
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* This file is part of the PHPExiftool package.
*
* (c) Alchemy <support@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPExiftool\Test;
use Monolog\Logger;
use Monolog\Handler\NullHandler;
use PHPExiftool\InformationDumper;
use PHPExiftool\Exiftool;
class InformationDumperTest extends \PHPUnit_Framework_TestCase
{
/**
* @var InformationDumper
*/
protected $object;
protected function setUp()
{
$logger = new Logger('Tests');
$logger->pushHandler(new NullHandler());
$this->object = new InformationDumper(new Exiftool($logger));
}
/**
* @covers PHPExiftool\InformationDumper::listDatas
*/
public function testListDatas()
{
$this->object->listDatas();
}
/**
* @covers PHPExiftool\InformationDumper::listDatas
* @covers \PHPExiftool\Exception\InvalidArgumentException
* @expectedException \PHPExiftool\Exception\InvalidArgumentException
*/
public function testListDatasInvalidType()
{
$this->object->listDatas('Scrooge');
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* This file is part of the PHPExiftool package.
*
* (c) Alchemy <support@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPExiftool\Test;
use PHPExiftool\PHPExiftoolServiceProvider;
use Silex\Application;
class PHPExiftoolServiceProviderTest extends \PHPUnit_Framework_TestCase
{
public function testRegister()
{
$app = $this->getApplication();
$app->register(new PHPExiftoolServiceProvider);
$this->assertInstanceOf('PHPExiftool\\Reader', $app['exiftool.reader']);
$this->assertInstanceOf('PHPExiftool\\Writer', $app['exiftool.writer']);
$this->assertInstanceOf('PHPExiftool\\Exiftool', $app['exiftool.processor']);
$this->assertInstanceOf('PHPExiftool\\PreviewExtractor', $app['exiftool.preview-extractor']);
}
protected function getApplication()
{
return new Application();
}
}

View File

@@ -0,0 +1,139 @@
<?php
/**
* This file is part of the PHPExiftool package.
*
* (c) Alchemy <support@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPExiftool\Test;
use PHPExiftool\RDFParser;
class RDFParserTest extends \PHPUnit_Framework_TestCase
{
/**
* @var RDFParser
*/
protected $object;
protected function setUp()
{
$this->object = new RDFParser;
}
/**
* @covers PHPExiftool\RDFParser::open
*/
public function testOpen()
{
$this->object->open(file_get_contents(__DIR__ . '/../../../files/simplefile.xml'));
}
/**
* @covers PHPExiftool\RDFParser::close
*/
public function testClose()
{
$this->object->close();
}
/**
* @covers PHPExiftool\RDFParser::ParseEntities
* @covers PHPExiftool\RDFParser::getDom
* @covers PHPExiftool\RDFParser::getDomXpath
* @covers PHPExiftool\RDFParser::getNamespacesFromXml
*/
public function testParseEntities()
{
$entities = $this->object
->open(file_get_contents(__DIR__ . '/../../../files/simplefile.xml'))
->parseEntities();
$this->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $entities);
$this->assertEquals(1, count($entities));
$this->assertInstanceOf('\\PHPExiftool\\FileEntity', $entities->first());
}
/**
* @covers PHPExiftool\RDFParser::ParseEntities
* @covers PHPExiftool\RDFParser::getDom
* @covers PHPExiftool\RDFParser::getDomXpath
* @covers \PHPExiftool\Exception\LogicException
* @expectedException \PHPExiftool\Exception\LogicException
*/
public function testParseEntitiesWithoutDom()
{
$this->object->parseEntities();
}
/**
* @covers PHPExiftool\RDFParser::ParseEntities
* @covers PHPExiftool\RDFParser::getDom
* @covers PHPExiftool\RDFParser::getDomXpath
* @covers \PHPExiftool\Exception\ParseError
* @covers \PHPExiftool\Exception\RuntimeException
* @expectedException \PHPExiftool\Exception\RuntimeException
*/
public function testParseEntitiesWrongDom()
{
$this->object->open('wrong xml')->parseEntities();
}
/**
* @covers PHPExiftool\RDFParser::ParseMetadatas
* @covers PHPExiftool\RDFParser::getDom
* @covers PHPExiftool\RDFParser::getDomXpath
*/
public function testParseMetadatas()
{
$metadatas = $this->object
->open(file_get_contents(__DIR__ . '/../../../files/ExifTool.xml'))
->ParseMetadatas();
$this->assertInstanceOf('\\PHPExiftool\\Driver\\Metadata\\MetadataBag', $metadatas);
$this->assertEquals(349, count($metadatas));
}
/**
* @covers PHPExiftool\RDFParser::Query
* @covers PHPExiftool\RDFParser::readNodeValue
*/
public function testQuery()
{
$xml = "<?xml version='1.0' encoding='UTF-8'?>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
<rdf:Description xmlns:NeutronSpace='http://ns.exiftool.ca/NeutronSpace/1.0/'>
<NeutronSpace:SpecialRomain>Hello World !</NeutronSpace:SpecialRomain>
<NeutronSpace:SpecialRomainbase64 rdf:datatype='http://www.w3.org/2001/XMLSchema#base64Binary'>SGVsbG8gYmFzZTY0ICE=</NeutronSpace:SpecialRomainbase64>
<NeutronSpace:Multi>
<rdf:Bag>
<rdf:li>romain</rdf:li>
<rdf:li>neutron</rdf:li>
</rdf:Bag>
</NeutronSpace:Multi>
</rdf:Description>
</rdf:RDF>";
$this->object->open($xml);
$metadata_simple = $this->object->Query('NeutronSpace:SpecialRomain');
$metadata_base64 = $this->object->Query('NeutronSpace:SpecialRomainbase64');
$metadata_multi = $this->object->Query('NeutronSpace:Multi');
$null_datas = $this->object->Query('NeutronSpace:NoData');
$null_datas_2 = $this->object->Query('NamespaceUnknown:NoData');
$this->assertNull($null_datas);
$this->assertNull($null_datas_2);
$this->assertInstanceOf('\\PHPExiftool\\Driver\\Value\\Mono', $metadata_simple);
$this->assertInstanceOf('\\PHPExiftool\\Driver\\Value\\Binary', $metadata_base64);
$this->assertInstanceOf('\\PHPExiftool\\Driver\\Value\\Multi', $metadata_multi);
$this->assertEquals('Hello World !', $metadata_simple->asString());
$this->assertEquals('Hello base64 !', $metadata_base64->asString());
$this->assertEquals(array('romain', 'neutron'), $metadata_multi->asArray());
}
}

View File

@@ -0,0 +1,44 @@
<?php
/**
* This file is part of the PHPExiftool package.
*
* (c) Alchemy <support@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPExiftool\Test\Server;
require_once __DIR__ . '/../AbstractPreviewExtractorTest.php';
use PHPExiftool\Test\AbstractPreviewExtractorTest;
use PHPExiftool\ExiftoolServer;
class PreviewExtractor extends AbstractPreviewExtractorTest
{
protected $exiftool;
public function setUp()
{
$this->markTestSkipped('Currently disable server support');
$this->exiftool = new ExiftoolServer;
$this->exiftool->start();
parent::setUp();
}
public function tearDown()
{
parent::tearDown();
if ($this->exiftool) {
$this->exiftool->stop();
}
}
protected function getExiftool()
{
return $this->exiftool;
}
}

View File

@@ -0,0 +1,45 @@
<?php
/**
* This file is part of the PHPExiftool package.
*
* (c) Alchemy <support@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPExiftool\Test\Server;
require_once __DIR__ . '/../AbstractReaderTest.php';
use PHPExiftool\Test\AbstractReaderTest;
use PHPExiftool\ExiftoolServer;
use PHPExiftool\Reader;
use PHPExiftool\RDFParser;
class ReaderTest extends AbstractReaderTest
{
protected $exiftool;
protected function setUp()
{
$this->exiftool = new ExiftoolServer();
$this->exiftool->start();
parent::setUp();
}
protected function tearDown()
{
parent::tearDown();
if ($this->exiftool) {
$this->exiftool->stop();
}
}
protected function getReader()
{
return new Reader($this->exiftool, new RDFParser());
}
}

View File

@@ -0,0 +1,44 @@
<?php
/**
* This file is part of the PHPExiftool package.
*
* (c) Alchemy <support@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPExiftool\Test\Server;
require_once __DIR__ . '/../AbstractWriterTest.php';
use PHPExiftool\ExiftoolServer;
use PHPExiftool\Test\AbstractWriterTest;
class WriterTest extends AbstractWriterTest
{
protected $exiftool;
public function setUp()
{
$this->markTestSkipped('Currently disable server support');
$this->exiftool = new ExiftoolServer();
$this->exiftool->start();
parent::setUp();
}
public function tearDown()
{
parent::tearDown();
if ($this->exiftool) {
$this->exiftool->stop();
}
}
protected function getExiftool()
{
return $this->exiftool;
}
}