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 Photo functionality
23
* @package GalleryCore
25
* @author Bharat Mediratta <bharat@menalto.com>
26
* @version $Revision: 15513 $
28
class PhotoTest extends GalleryTestCase {
30
function PhotoTest($methodName) {
31
$this->GalleryTestCase($methodName);
37
/* Register a dummy toolkit */
38
$path = 'modules/core/test/phpunit/PhotoTest.class';
39
$ret = GalleryCoreApi::registerFactoryImplementation(
40
'GalleryToolkit', 'PhotoTestToolkit', 'PhotoTestToolkit',
41
$path, 'coreTest', null);
43
print $ret->getAsHtml();
44
return $this->failWithStatus($ret);
46
$this->_markToolkitForCleanup('PhotoTestToolkit');
48
$ret = GalleryCoreApi::registerToolkitProperty(
49
'PhotoTestToolkit', array('image/test'), 'colorspace', 'string', 'phototest property');
51
return $this->failWithStatus($ret);
55
function testCreateAndDeletePhoto() {
61
list ($ret, $photo) = GalleryCoreApi::newItemByMimeType('image/jpeg');
63
return $this->failWithStatus($ret);
66
list ($ret, $lockId) = GalleryCoreApi::acquireReadLock($this->_getRootId());
68
return $this->failWithStatus($ret);
71
$ret = $photo->create($this->_getRootId(),
72
dirname(__FILE__) . '/../data/test1.jpg',
75
return $this->failWithStatus($ret);
78
$ret = $photo->save();
80
return $this->failWithStatus($ret);
83
$ret = GalleryCoreApi::releaseLocks($lockId);
85
return $this->failWithStatus($ret);
89
* Load the photo back and verify it
91
GalleryDataCache::reset();
93
list ($ret, $newPhoto) = GalleryCoreApi::loadEntitiesById($photo->getId());
95
return $this->failWithStatus($ret);
98
$this->assertEquals($photo, $newPhoto);
103
$ret = GalleryCoreApi::deleteEntityById($photo->getId());
105
return $this->failWithStatus($ret);
109
function testCMYKPhoto() {
110
/* Test that mime type gets -cmyk appended if toolkit says it uses CMYK colorspace */
111
list ($ret, $photo) = GalleryCoreApi::newItemByMimeType('image/test');
113
return $this->failWithStatus($ret);
116
list ($ret, $lockId) = GalleryCoreApi::acquireReadLock($this->_getRootId());
118
return $this->failWithStatus($ret);
121
$ret = $photo->create($this->_getRootId(), __FILE__, 'image/test');
123
return $this->failWithStatus($ret);
126
$ret = $photo->save();
128
return $this->failWithStatus($ret);
130
$this->_markForCleanup($photo);
132
$ret = GalleryCoreApi::releaseLocks($lockId);
134
return $this->failWithStatus($ret);
137
$this->assertEquals('image/test-cmyk', $photo->getMimeType(), 'cmyk mime type');
140
function testRGBPhoto() {
141
/* Test that mime type is not affected if toolkit says it uses RGB colorspace */
142
list ($ret, $photo) = GalleryCoreApi::newItemByMimeType('image/test');
144
return $this->failWithStatus($ret);
147
list ($ret, $lockId) = GalleryCoreApi::acquireReadLock($this->_getRootId());
149
return $this->failWithStatus($ret);
152
$ret = $photo->create($this->_getRootId(),
153
dirname(__FILE__) . '/../data/test1.gif', 'image/test');
155
return $this->failWithStatus($ret);
158
$ret = $photo->save();
160
return $this->failWithStatus($ret);
162
$this->_markForCleanup($photo);
164
$ret = GalleryCoreApi::releaseLocks($lockId);
166
return $this->failWithStatus($ret);
169
$this->assertEquals('image/test', $photo->getMimeType(), 'mime type');
176
* @package GalleryCore
177
* @subpackage PHPUnit
179
class PhotoTestToolkit extends GalleryToolkit {
180
function getProperty($mimeType, $propertyName, $sourceFilename) {
181
/* This will be called by GalleryPhotoItem::create */
182
if ($propertyName == 'colorspace' && $mimeType == 'image/test') {
183
$colorspace = (basename($sourceFilename) == basename(__FILE__)) ? 'CMYK' : 'RGB';
184
return array(null, array($colorspace));
186
return array(GalleryCoreApi::error(ERROR_UNIMPLEMENTED), null);