3
* Gallery - a web based photo album viewer and editor
4
* Copyright (C) 2000-2007 Bharat Mediratta
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or (at
9
* your option) any later version.
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
22
* Test ExifExtractor functionality
26
* @author Alan Harder <alan.harder@sun.com>
27
* @author Georg Rehfeld <rehfeld@georg-rehfeld.de>
28
* @version $Revision: 15513 $
30
class ExifExtractorTest extends GalleryTestCase {
32
function ExifExtractorTest($methodName) {
33
$this->GalleryTestCase($methodName);
37
* Create an album for testing
43
/* Create a new subalbum and add some jpegs */
44
list ($ret, $this->_album) = $this->_createRandomAlbum($this->_getRootId());
46
$this->failWithStatus($ret);
49
$this->_markForCleanup($this->_album);
51
list ($ret, $lockId) = GalleryCoreApi::acquireReadLock($this->_album->getId());
53
$this->failWithStatus($ret);
56
$corePrefix = GalleryCoreApi::getPluginBaseDir('module', 'core');
57
$exifPrefix = GalleryCoreApi::getPluginBaseDir('module', 'exif');
58
$imagePaths = array($exifPrefix . 'modules/exif/test/data/CanonS30.small.jpg',
59
$corePrefix . 'modules/core/test/data/test2.gif',
60
$exifPrefix . 'modules/exif/test/data/CanonS30.small.jpg',
61
$exifPrefix . 'modules/exif/test/data/iptc-irfanview.jpg',
62
$corePrefix . 'modules/core/test/data/test1.jpg');
64
for ($i = 0; $i < count($imagePaths); $i++) {
65
list ($ret, $photoId) = $this->_addPhoto(
66
$this->_album->getId(), $imagePaths[$i], $i + 1);
68
$this->failWithStatus($ret);
70
$photoIds[] = $photoId;
72
$ret = GalleryCoreApi::releaseLocks($lockId);
74
$this->failWithStatus($ret);
77
list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'exif');
78
if ($ret || !isset($module)) {
79
$this->failWithStatus($ret);
82
GalleryCoreApi::newFactoryInstance('ExifInterface_1_0', 'ExifExtractor');
83
if ($ret || !isset($exif)) {
84
$this->failWithStatus($ret);
87
$this->_photoIds = $photoIds;
91
function _addPhoto($parentId, $imagePath, $index) {
93
GalleryCoreApi::newFactoryInstance('GalleryEntity', 'GalleryPhotoItem');
95
return array($ret, null);
97
list ($ret, $mimeType) = GalleryCoreApi::getMimeType($imagePath);
99
return array($ret, null);
101
$ret = $photo->create($parentId, $imagePath, $mimeType,
102
'testitem_' . time() . substr($imagePath, -4));
104
return array($ret, null);
106
$photo->setTitle("Item #$index");
107
$photo->setSummary("Summary $index");
108
$photo->setDescription("Description $index");
109
$ret = $photo->save();
111
return array($ret, null);
114
list ($ret, $thumbId) = $this->_addDerivative($photo,
115
'thumbnail', DERIVATIVE_TYPE_IMAGE_THUMBNAIL, 'thumbnail|150');
117
return array($ret, null);
119
return array(null, $photo->getId());
122
function _addDerivative($photo, $toolkitType,
123
$derivativeType, $derivativeOperation) {
124
list ($ret, $toolkit, $outputMimeType) =
125
GalleryCoreApi::getToolkitByOperation($photo->getMimeType(), $toolkitType);
126
if ($ret || !isset($toolkit)) {
127
return array($ret, null);
129
list ($ret, $derivative) =
130
GalleryCoreApi::newFactoryInstanceByHint('GalleryDerivative', $photo->getEntityType());
132
return array($ret, null);
134
if (!isset($derivative)) {
135
return array(GalleryCoreApi::error(ERROR_MISSING_OBJECT), null);
138
$ret = $derivative->create($photo->getId(), $derivativeType);
140
return array($ret, null);
142
$derivative->setDerivativeSourceId($photo->getId());
143
$derivative->setDerivativeOperations($derivativeOperation);
144
$derivative->setMimeType($outputMimeType);
145
$ret = $derivative->save();
147
return array($ret, null);
149
return array(null, $derivative->getId());
152
function testOneItemAllDataExif() {
153
list ($ret, $data) = $this->_exif->getMetaData($this->_photoIds[0]);
154
$this->assert(!$ret && isset($data[$this->_photoIds[0]]));
155
$this->assertEquals('1/60 sec',
156
$data[$this->_photoIds[0]]['ShutterSpeedValue']['value']);
159
function testOneItemAllDataIptc() {
160
list ($ret, $data) = $this->_exif->getMetaData($this->_photoIds[3]);
161
$this->assert(!$ret && isset($data[$this->_photoIds[3]]));
162
$this->assertEquals('Caption: IPTC/Caption',
163
$data[$this->_photoIds[3]]['IPTC/Caption']['value']);
166
function testMultiItemAllData() {
167
list ($ret, $data) = $this->_exif->getMetaData(
168
array($this->_photoIds[0], $this->_photoIds[2], $this->_photoIds[3]));
169
$this->assert(!$ret && isset($data));
170
$this->assertEquals(3, count($data), 'Data size');
171
$this->assertEquals('1/60 sec',
172
$data[$this->_photoIds[0]]['ShutterSpeedValue']['value']);
173
$this->assertEquals(sprintf('%.2f mm', 21.31),
174
$data[$this->_photoIds[2]]['FocalLength']['value']);
175
$this->assertEquals('Caption: IPTC/Caption',
176
$data[$this->_photoIds[3]]['IPTC/Caption']['value']);
179
function testMultiItemMixedTypeAllData() {
180
list ($ret, $data) = $this->_exif->getMetaData($this->_photoIds);
181
$this->assert(!$ret && isset($data));
182
$this->assertEquals(4, count($data), 'Data size');
183
$this->assertEquals('1/60 sec',
184
$data[$this->_photoIds[0]]['ShutterSpeedValue']['value']);
185
$this->assertEquals(sprintf('%.2f mm', 21.31),
186
$data[$this->_photoIds[2]]['FocalLength']['value']);
187
$this->assertEquals('Caption: IPTC/Caption',
188
$data[$this->_photoIds[3]]['IPTC/Caption']['value']);
191
function testMultiItemSomeData() {
192
list ($ret, $data) = $this->_exif->getMetaData(
193
$this->_photoIds, array('DateTime', 'ShutterSpeedValue', 'IPTC/Byline'));
194
$this->assert(!$ret && isset($data));
195
$this->assertEquals(4, count($data), 'Data size');
196
$this->assertEquals('1/60 sec',
197
$data[$this->_photoIds[0]]['ShutterSpeedValue']['value']);
198
$this->assert(!isset($data[$this->_photoIds[2]]['FocalLength']));
199
$this->assert(!isset($data[$this->_photoIds[2]]['IPTC/Byline']));
200
$this->assertEquals('Byline: IPTC/Byline',
201
$data[$this->_photoIds[3]]['IPTC/Byline']['value']);
202
$this->assert(!isset($data[$this->_photoIds[3]]['FocalLength']));