~ubuntu-branches/ubuntu/quantal/gallery2/quantal

« back to all changes in this revision

Viewing changes to modules/core/test/phpunit/PhotoTest.class

  • Committer: Bazaar Package Importer
  • Author(s): Michael C. Schultheiss
  • Date: 2007-09-10 20:22:19 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070910202219-0jsuntvqge4ade6b
Tags: 2.2.3-2
Add Slovak translation of Debconf templates.  (Thanks to 
Ivan Masá.  Closes: #441671)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/*
3
 
 * Gallery - a web based photo album viewer and editor
4
 
 * Copyright (C) 2000-2007 Bharat Mediratta
5
 
 *
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.
10
 
 *
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.
15
 
 *
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.
19
 
 */
20
 
 
21
 
/**
22
 
 * Test Photo functionality
23
 
 * @package GalleryCore
24
 
 * @subpackage PHPUnit
25
 
 * @author Bharat Mediratta <bharat@menalto.com>
26
 
 * @version $Revision: 15513 $
27
 
 */
28
 
class PhotoTest extends GalleryTestCase {
29
 
 
30
 
    function PhotoTest($methodName) {
31
 
        $this->GalleryTestCase($methodName);
32
 
    }
33
 
 
34
 
    function setUp() {
35
 
        parent::setUp();
36
 
 
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);
42
 
        if ($ret) {
43
 
            print $ret->getAsHtml();
44
 
            return $this->failWithStatus($ret);
45
 
        }
46
 
        $this->_markToolkitForCleanup('PhotoTestToolkit');
47
 
 
48
 
        $ret = GalleryCoreApi::registerToolkitProperty(
49
 
            'PhotoTestToolkit', array('image/test'), 'colorspace', 'string', 'phototest property');
50
 
        if ($ret) {
51
 
            return $this->failWithStatus($ret);
52
 
        }
53
 
    }
54
 
 
55
 
    function testCreateAndDeletePhoto() {
56
 
        global $gallery;
57
 
 
58
 
        /*
59
 
         * Create the photo
60
 
         */
61
 
        list ($ret, $photo) = GalleryCoreApi::newItemByMimeType('image/jpeg');
62
 
        if ($ret) {
63
 
            return $this->failWithStatus($ret);
64
 
        }
65
 
 
66
 
        list ($ret, $lockId) = GalleryCoreApi::acquireReadLock($this->_getRootId());
67
 
        if ($ret) {
68
 
            return $this->failWithStatus($ret);
69
 
        }
70
 
 
71
 
        $ret = $photo->create($this->_getRootId(),
72
 
                              dirname(__FILE__) . '/../data/test1.jpg',
73
 
                              'image/jpeg');
74
 
        if ($ret) {
75
 
            return $this->failWithStatus($ret);
76
 
        }
77
 
 
78
 
        $ret = $photo->save();
79
 
        if ($ret) {
80
 
            return $this->failWithStatus($ret);
81
 
        }
82
 
 
83
 
        $ret = GalleryCoreApi::releaseLocks($lockId);
84
 
        if ($ret) {
85
 
            return $this->failWithStatus($ret);
86
 
        }
87
 
 
88
 
        /*
89
 
         * Load the photo back and verify it
90
 
         */
91
 
        GalleryDataCache::reset();
92
 
 
93
 
        list ($ret, $newPhoto) = GalleryCoreApi::loadEntitiesById($photo->getId());
94
 
        if ($ret) {
95
 
            return $this->failWithStatus($ret);
96
 
        }
97
 
 
98
 
        $this->assertEquals($photo, $newPhoto);
99
 
 
100
 
        /*
101
 
         * Delete the photo
102
 
         */
103
 
        $ret = GalleryCoreApi::deleteEntityById($photo->getId());
104
 
        if ($ret) {
105
 
            return $this->failWithStatus($ret);
106
 
        }
107
 
    }
108
 
 
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');
112
 
        if ($ret) {
113
 
            return $this->failWithStatus($ret);
114
 
        }
115
 
 
116
 
        list ($ret, $lockId) = GalleryCoreApi::acquireReadLock($this->_getRootId());
117
 
        if ($ret) {
118
 
            return $this->failWithStatus($ret);
119
 
        }
120
 
 
121
 
        $ret = $photo->create($this->_getRootId(), __FILE__, 'image/test');
122
 
        if ($ret) {
123
 
            return $this->failWithStatus($ret);
124
 
        }
125
 
 
126
 
        $ret = $photo->save();
127
 
        if ($ret) {
128
 
            return $this->failWithStatus($ret);
129
 
        }
130
 
        $this->_markForCleanup($photo);
131
 
 
132
 
        $ret = GalleryCoreApi::releaseLocks($lockId);
133
 
        if ($ret) {
134
 
            return $this->failWithStatus($ret);
135
 
        }
136
 
 
137
 
        $this->assertEquals('image/test-cmyk', $photo->getMimeType(), 'cmyk mime type');
138
 
    }
139
 
 
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');
143
 
        if ($ret) {
144
 
            return $this->failWithStatus($ret);
145
 
        }
146
 
 
147
 
        list ($ret, $lockId) = GalleryCoreApi::acquireReadLock($this->_getRootId());
148
 
        if ($ret) {
149
 
            return $this->failWithStatus($ret);
150
 
        }
151
 
 
152
 
        $ret = $photo->create($this->_getRootId(),
153
 
                              dirname(__FILE__) . '/../data/test1.gif', 'image/test');
154
 
        if ($ret) {
155
 
            return $this->failWithStatus($ret);
156
 
        }
157
 
 
158
 
        $ret = $photo->save();
159
 
        if ($ret) {
160
 
            return $this->failWithStatus($ret);
161
 
        }
162
 
        $this->_markForCleanup($photo);
163
 
 
164
 
        $ret = GalleryCoreApi::releaseLocks($lockId);
165
 
        if ($ret) {
166
 
            return $this->failWithStatus($ret);
167
 
        }
168
 
 
169
 
        $this->assertEquals('image/test', $photo->getMimeType(), 'mime type');
170
 
    }
171
 
}
172
 
 
173
 
/**
174
 
 * Test toolkit
175
 
 *
176
 
 * @package GalleryCore
177
 
 * @subpackage PHPUnit
178
 
 */
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));
185
 
        }
186
 
        return array(GalleryCoreApi::error(ERROR_UNIMPLEMENTED), null);
187
 
    }
188
 
}
189
 
?>