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.
21
GalleryCoreApi::requireOnce('lib/tools/phpunit/ItemAddOptionTestCase.class');
24
* ExifDescriptionOption tests
27
* @author Alan Harder <alan.harder@sun.com>
28
* @author Georg Rehfeld <rehfeld@georg-rehfeld.de>
29
* @author Jozsef R.Nagy <jozsef.rnagy@site.hu>
30
* @version $Revision: 15513 $
32
class ExifDescriptionOptionTest extends ItemAddOptionTestCase {
34
function ExifDescriptionOptionTest($methodName) {
35
$this->ItemAddOptionTestCase($methodName, 'exif', 'ExifDescriptionOption');
41
GalleryCoreApi::requireOnce('modules/exif/classes/ExifHelper.class');
43
list ($ret, $this->_album) = $this->_createRandomAlbum($this->_getRootId());
45
print $ret->getAsHtml();
46
return $this->failWithStatus($ret);
48
$this->_markForCleanup($this->_album);
50
$ret = $this->_markPluginParametersForCleanup('module', 'exif');
52
print $ret->getAsHtml();
53
return $this->failWithStatus($ret);
56
$this->_items = array();
57
list ($ret, $this->_items[0]) = $this->_createRandomDataItem(
58
$this->_album->getId(),
60
array('summary' => 'original summary 0',
61
'description' => 'original description 0'),
62
dirname(__FILE__) . '/../data/descr.jpg');
64
print $ret->getAsHtml();
65
return $this->failWithStatus($ret);
67
list ($ret, $this->_items[1]) = $this->_createRandomDataItem(
68
$this->_album->getId(),
70
array('title' => 'original title',
71
'summary' => 'original summary',
72
'description' => 'original description',
73
'keywords' => 'original keyword 0; original keyword 1'),
74
dirname(__FILE__) . '/../data/exif-iptc-xmp-ps.jpg');
76
print $ret->getAsHtml();
77
return $this->failWithStatus($ret);
80
$this->_noWarnings = array();
81
$this->_noErrors = array();
84
function testCreateDescription() {
85
$ret = GalleryCoreApi::setPluginParameter('module', 'exif', 'addOption',
86
EXIF_ITEM_DESCRIPTION);
88
return $this->failWithStatus($ret);
91
$result = $this->_handleRequestAfterAdd(array(), $this->_items);
92
$this->assertEquals(array($this->_noErrors, $this->_noWarnings), $result);
94
list ($ret, $item) = $this->_items[0]->refresh();
96
return $this->failWithStatus($ret);
99
$this->assertEquals('exif description', $item->getDescription(), 'description 0');
100
$this->assertEquals('original summary 0', $item->getSummary(), 'summary 0');
103
function testMultipleCreateDescription() {
106
for ($j = 1; $j < $totalTestItems; $j++) {
107
list ($ret, $this->_items[$j]) =
108
$this->_createRandomDataItem($this->_album->getId(), 'image/jpeg',
109
array('summary' => "original summary $j",
110
'description' => "original description $j"),
111
dirname(__FILE__) . '/../data/descr.jpg');
113
return $this->failWithStatus($ret);
117
$ret = GalleryCoreApi::setPluginParameter('module', 'exif', 'addOption',
118
EXIF_ITEM_DESCRIPTION);
120
return $this->failWithStatus($ret);
123
$result = $this->_handleRequestAfterAdd(array(), $this->_items);
124
$this->assertEquals(array($this->_noErrors, $this->_noWarnings), $result);
126
for ($j = 0; $j < $totalTestItems; $j++) {
127
list ($ret, $item) = $this->_items[$j]->refresh();
129
return $this->failWithStatus($ret);
131
$this->assertEquals('exif description', $item->getDescription(), "description $j");
132
$this->assertEquals("original summary $j", $item->getSummary(), "summary $j");
136
function testCreateWithCheckDisabled() {
137
$ret = GalleryCoreApi::setPluginParameter('module', 'exif', 'addOption', '0');
139
return $this->failWithStatus($ret);
142
$result = $this->_handleRequestAfterAdd(array(), $this->_items);
143
$this->assertEquals(array($this->_noErrors, $this->_noWarnings), $result);
145
list ($ret, $item) = $this->_items[1]->refresh();
147
return $this->failWithStatus($ret);
150
$this->assertEquals('original title', $item->getTitle(), 'title');
151
$this->assertEquals('original description', $item->getDescription(), 'description');
152
$this->assertEquals('original summary', $item->getSummary(), 'summary');
153
$this->assertEquals('original keyword 0; original keyword 1', $item->getKeywords(),
154
'keywords mismatch');
157
function testMultipleCreateWithCheckDisabled() {
160
for ($j = 1; $j < $totalTestItems; $j++) {
161
list ($ret, $this->_items[$j]) =
162
$this->_createRandomDataItem($this->_album->getId(), 'image/jpeg',
163
array('summary' => "original summary $j",
164
'description' => "original description $j"),
165
dirname(__FILE__) . '/../data/descr.jpg');
167
return $this->failWithStatus($ret);
171
$ret = GalleryCoreApi::setPluginParameter('module', 'exif', 'addOption', '0');
173
return $this->failWithStatus($ret);
176
$result = $this->_handleRequestAfterAdd(array(), $this->_items);
177
$this->assertEquals(array($this->_noErrors, $this->_noWarnings), $result);
179
for ($j = 0; $j < $totalTestItems; $j++) {
180
list ($ret, $item) = $this->_items[$j]->refresh();
182
return $this->failWithStatus($ret);
184
$this->assertEquals("original description $j", $item->getDescription(),
186
$this->assertEquals("original summary $j", $item->getSummary(), "summary $j");
190
function testTitleKeywords() {
191
$ret = GalleryCoreApi::setPluginParameter('module', 'exif', 'addOption',
192
IPTC_ITEM_KEYWORDS | IPTC_ITEM_TITLE);
194
return $this->failWithStatus($ret);
197
$result = $this->_handleRequestAfterAdd(array(), $this->_items);
198
$this->assertEquals(array($this->_noErrors, $this->_noWarnings), $result);
200
list ($ret, $item) = $this->_items[1]->refresh();
202
return $this->failWithStatus($ret);
205
$this->assertEquals('ObjectName, Dokumenttitel', $item->getTitle(), 'title mismatch');
206
$this->assertEquals('keyword0; keyword1; keyword2', $item->getKeywords(),
207
'keywords mismatch');
210
function testRotateOptionOff() {
211
list ($ret, $this->_items[0]) =
212
$this->_createRandomDataItem($this->_album->getId(), 'image/jpeg',
214
dirname(__FILE__) . '/../data/descr.jpg');
216
return $this->failWithStatus($ret);
219
$ret = GalleryCoreApi::setPluginParameter('module', 'exif', 'addOption',
220
EXIF_ITEM_ROTATE_PRESERVE);
222
return $this->failWithStatus($ret);
225
$result = $this->_handleRequestAfterAdd(array(), $this->_items);
226
$this->assertEquals(array($this->_noErrors, $this->_noWarnings), $result);
228
/* Verify that we do *not* have a preferred */
229
list ($ret, $preferredIds) =
230
GalleryCoreApi::fetchPreferredsByItemIds(array($this->_items[0]->getId()));
232
return $this->failWithStatus($ret);
234
$this->assertEquals(0, sizeof($preferredIds), 'there should not be any preferred');
237
function testRotateNoExifDataOptionOn() {
238
list ($ret, $this->_items[0]) =
239
$this->_createRandomDataItem($this->_album->getId(), 'image/test');
241
return $this->failWithStatus($ret);
244
$ret = GalleryCoreApi::setPluginParameter('module', 'exif', 'addOption',
247
return $this->failWithStatus($ret);
250
$result = $this->_handleRequestAfterAdd(array(), $this->_items);
251
$this->assertEquals(array($this->_noErrors, $this->_noWarnings), $result);
256
function testRotateOptionOnOverwriteOriginal() {
257
list ($ret, $this->_items[0]) =
258
$this->_createRandomDataItem($this->_album->getId(), 'image/jpeg',
260
dirname(__FILE__) . '/../data/descr.jpg');
262
return $this->failWithStatus($ret);
265
/* Register a dummy toolkit */
266
$path = 'modules/exif/test/phpunit/ExifDescriptionOptionTest.class';
267
$ret = GalleryCoreApi::registerFactoryImplementation(
268
'GalleryToolkit', 'ExifDescriptionOptionTestToolkit',
269
'ExifDescriptionOptionTestToolkit', $path, 'exifTest', null, 0);
271
return $this->failWithStatus($ret);
273
$this->_markToolkitForCleanup('ExifDescriptionOptionTestToolkit');
275
/* Register operations that we can perform on our mock data items */
276
$ret = GalleryCoreApi::registerToolkitOperation(
277
'ExifDescriptionOptionTestToolkit', array('image/jpeg'), 'rotate',
278
array(array('type' => 'int', 'description' => 'test')), 'test-description', null, 0);
280
return $this->failWithStatus($ret);
283
/* Register property for dimensions */
284
$ret = GalleryCoreApi::registerToolkitProperty('ExifDescriptionOptionTestToolkit',
285
array('image/test'), 'dimensions', 'int,int', 'Get the dimensions');
287
return $this->failWithStatus($ret);
290
/* Save current size */
291
$originalWidth = $this->_items[0]->getWidth();
292
$originalHeight = $this->_items[0]->getHeight();
294
/* Save current serial */
295
$originalSerial = $this->_items[0]->getSerialNumber();
297
/* Initialize a Flag for checking rotation */
299
$gallery->setConfig('rotated', 0);
301
/* Perform the request and verify that we succeeded */
302
$ret = GalleryCoreApi::setPluginParameter('module', 'exif', 'addOption',
305
return $this->failWithStatus($ret);
308
$result = $this->_handleRequestAfterAdd(array(), $this->_items);
309
$this->assertEquals(array($this->_noErrors, $this->_noWarnings), $result);
311
/* Verify that we don't have a preferred */
312
list ($ret, $preferredIds) =
313
GalleryCoreApi::fetchPreferredsByItemIds(array($this->_items[0]->getId()));
315
return $this->failWithStatus($ret);
317
$this->assertEquals(0, sizeof($preferredIds), 'there should be no preferreds');
319
/* Verify that the item serial is NOT the same */
320
list ($ret, $this->_items[0]) = $this->_items[0]->refresh();
322
return $this->failWithStatus($ret);
325
$this->assert($originalSerial != $this->_items[0]->getSerialNumber(),
326
"Item serial should have changed ($originalSerial)");
328
/* Verify that the item has been rotated - by our mock toolkit */
329
$this->assertEquals(1, $gallery->getConfig('rotated'), 'a rotation should have been done');
331
/* and that the new dimensions are correct, set by our toolkit */
332
$newWidth = $this->_items[0]->getWidth();
333
$newHeight = $this->_items[0]->getHeight();
335
$this->assertEquals(10, $newWidth, 'width should be 10');
336
$this->assertEquals(10, $newHeight, 'height should be 10');
340
function testRotateOptionOnPreserveOriginal() {
341
list ($ret, $this->_items[0]) =
342
$this->_createRandomDataItem($this->_album->getId(), 'image/jpeg',
344
dirname(__FILE__) . '/../data/descr.jpg');
346
return $this->failWithStatus($ret);
349
/* Save current serial */
350
$originalSerial = $this->_items[0]->getSerialNumber();
352
/* Perform the request and verify that we succeeded */
353
$ret = GalleryCoreApi::setPluginParameter('module', 'exif', 'addOption',
354
(EXIF_ITEM_ROTATE | EXIF_ITEM_ROTATE_PRESERVE));
356
return $this->failWithStatus($ret);
359
$result = $this->_handleRequestAfterAdd(array(), $this->_items);
360
$this->assertEquals(array($this->_noErrors, $this->_noWarnings), $result);
362
/* Verify that we have a preferred */
363
list ($ret, $preferredIds) =
364
GalleryCoreApi::fetchPreferredsByItemIds(array($this->_items[0]->getId()));
366
return $this->failWithStatus($ret);
368
$this->assertEquals(1, sizeof($preferredIds), 'there should be a preferred');
370
/* Verify that the item serial is the same */
371
list ($ret, $this->_items[0]) = $this->_items[0]->refresh();
373
return $this->failWithStatus($ret);
375
$this->assertEquals($originalSerial, $this->_items[0]->getSerialNumber());
377
/* Verify that the item was rotated */
378
$this->_preferred = array_shift($preferredIds);
379
$this->assertEquals('rotate|90', $this->_preferred->getDerivativeOperations());
384
GalleryCoreApi::requireOnce('modules/core/classes/GalleryToolkit.class');
389
class ExifDescriptionOptionTestToolkit extends GalleryToolkit {
391
* @see GalleryToolkit::performOperation
394
function performOperation($mimeType, $operationName, $sourceFilename,
395
$destFilename, $parameters, $context=array()) {
398
$platform =& $gallery->getPlatform();
399
if ($sourceFilename != $destFilename) {
400
$platform->copy($sourceFilename, $destFilename);
403
$fd = $platform->fopen($destFilename, 'a');
404
$platform->fwrite($fd, $operationName);
405
$platform->fclose($fd);
406
/* Clear cache to ensure new filesize will be seen */
407
$platform->clearstatcache();
409
/* Turn On the Flag */
410
$gallery->setConfig('rotated', 1);
412
return array(null, 'image/test', $context);
415
function getProperty($mimeType, $propertyName, $sourceFilename) {
416
if ($propertyName != 'dimensions') {
417
return array(GalleryCoreApi::error(ERROR_UNSUPPORTED_OPERATION, __FILE__, __LINE__,
418
"$propertyName $sourceFilename"), null);
421
return array(null, array(10, 10));