~ubuntu-branches/ubuntu/hardy/gallery2/hardy-security

« back to all changes in this revision

Viewing changes to modules/thumbnail/test/phpunit/CustomThumbnailOptionTest.class

  • Committer: Bazaar Package Importer
  • Author(s): Michael C. Schultheiss
  • Date: 2006-04-16 16:42:35 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060416164235-8uy0u4bfjdxpge2o
Tags: 2.1.1-1
* New upstream release (Closes: #362936)
  + Bugfixes for Postgres7 (Closes: #359000, #362152)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 * $RCSfile: CustomThumbnailOptionTest.class,v $
4
4
 *
5
5
 * Gallery - a web based photo album viewer and editor
6
 
 * Copyright (C) 2000-2005 Bharat Mediratta
 
6
 * Copyright (C) 2000-2006 Bharat Mediratta
7
7
 *
8
8
 * This program is free software; you can redistribute it and/or modify
9
9
 * it under the terms of the GNU General Public License as published by
20
20
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
21
21
 */
22
22
/**
23
 
 * @version $Revision: 1.13 $ $Date: 2005/08/23 03:49:56 $
 
23
 * @version $Revision: 1.16 $ $Date: 2006/01/10 04:43:09 $
24
24
 * @package Thumbnail
25
25
 * @subpackage PHPUnit
26
26
 * @author Alan Harder <alan.harder@sun.com>
29
29
/**
30
30
 * Load required classes
31
31
 */
32
 
GalleryCoreApi::relativeRequireOnce('lib/tools/phpunit/ItemEditOptionTestCase.class');
33
 
GalleryCoreApi::relativeRequireOnce('modules/thumbnail/classes/ThumbnailHelper.class');
 
32
GalleryCoreApi::requireOnce('lib/tools/phpunit/ItemEditOptionTestCase.class');
 
33
GalleryCoreApi::requireOnce('modules/thumbnail/classes/ThumbnailHelper.class');
34
34
 
35
35
/**
36
36
 * CustomThumbnailOption tests
49
49
 
50
50
        $ret = GalleryCoreApi::registerFactoryImplementation(
51
51
          'GalleryToolkit', 'CustomThumbnailOptionTestToolkit', 'CustomThumbnailOptionTestToolkit',
52
 
          'modules/thumbnail/test/phpunit/CustomThumbnailOptionTest.class', 'thumbnailTest', null);
53
 
        if ($ret->isError()) {
 
52
          'modules/thumbnail/test/phpunit/CustomThumbnailOptionTest.class', 'thumbnail', null);
 
53
        if ($ret) {
54
54
            print $ret->getAsHtml();
55
55
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
56
56
        }
60
60
                array('image/test'), 'thumbnail',
61
61
                array(array('type' => 'int', 'description' => 'foo'),
62
62
                      array('type' => 'int', 'description' => 'foo')), 'test-description');
63
 
        if ($ret->isError()) {
 
63
        if ($ret) {
 
64
            print $ret->getAsHtml();
 
65
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
66
        }
 
67
        $ret = GalleryCoreApi::registerToolkitOperation('CustomThumbnailOptionTestToolkit',
 
68
                array('image/test'), 'composite',
 
69
                array(array('type' => 'string', 'description' => 'foo'),
 
70
                      array('type' => 'string', 'description' => 'foo'),
 
71
                      array('type' => 'int', 'description' => 'foo'),
 
72
                      array('type' => 'int', 'description' => 'foo'),
 
73
                      array('type' => 'string', 'description' => 'foo'),
 
74
                      array('type' => 'int', 'description' => 'foo'),
 
75
                      array('type' => 'int', 'description' => 'foo')), 'test-description');
 
76
        if ($ret) {
64
77
            print $ret->getAsHtml();
65
78
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
66
79
        }
67
80
 
68
81
        list ($ret, $this->_album) = $this->_createRandomAlbum($this->_getRootId());
69
 
        if ($ret->isError()) {
 
82
        if ($ret) {
70
83
            print $ret->getAsHtml();
71
84
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
72
85
        }
74
87
 
75
88
        list ($ret, $this->_item) = $this->_createRandomDataItem($this->_album->getId(),
76
89
            'text/test', array(), __FILE__, 'GalleryUnknownItem');
77
 
        if ($ret->isError()) {
 
90
        if ($ret) {
78
91
            print $ret->getAsHtml();
79
92
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
80
93
        }
81
94
 
82
95
        list ($ret, $this->_image) = $this->_createRandomDataItem($this->_album->getId(),
83
96
            'image/test', array(), __FILE__, 'GalleryPhotoItem');
84
 
        if ($ret->isError()) {
 
97
        if ($ret) {
85
98
            print $ret->getAsHtml();
86
99
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
87
100
        }
88
101
 
89
102
        list ($ret, $this->_derivative) =
90
103
            $this->_createDerivative($this->_image, $this->_image->getId(),
91
 
                DERIVATIVE_TYPE_IMAGE_THUMBNAIL, 'thumbnail|200', 'image/test');
92
 
        if ($ret->isError()) {
 
104
                DERIVATIVE_TYPE_IMAGE_THUMBNAIL, 'rotate|90;crop|20,20,50,50;thumbnail|200;' .
 
105
                'composite|path/test.png,image/png,20,20,top-left,0,0;unknownop|10', 'image/test');
 
106
        if ($ret) {
93
107
            print $ret->getAsHtml();
94
108
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
95
109
        }
99
113
        $form = array('name' => array(1 => 'test.gif'),
100
114
                      'type' => array(1 => 'image/gif'),
101
115
                      'tmp_name' => array(1 =>
102
 
                            dirname(__FILE__) . '/../../../core/test/data/test1.gif'));
 
116
                            GalleryCoreApi::getPluginBaseDir('module', 'core')
 
117
                                . 'modules/core/test/data/test1.jpg'));
103
118
 
104
119
        list ($error, $warning) = $this->_handleRequestAfterEdit($form, $this->_item);
105
120
        $this->assertEquals(array('form[CustomThumbnailOption][error][imageMime]'), $error);
111
126
        $form = array('name' => array(1 => 'test.jpg'),
112
127
                      'type' => array(1 => 'image/jpeg'),
113
128
                      'tmp_name' => array(1 =>
114
 
                            dirname(__FILE__) . '/../../../core/test/data/test1.jpg'));
 
129
                            GalleryCoreApi::getPluginBaseDir('module', 'core')
 
130
                                . 'modules/core/test/data/test1.jpg'));
115
131
 
116
132
        $result = $this->_handleRequestAfterEdit($form, $this->_item);
117
133
        $this->assertEquals(array(array(), array()), $result);
118
134
 
119
135
        list ($ret, $thumbnailImage) = ThumbnailHelper::fetchThumbnail($this->_item->getId());
120
 
        if ($ret->isError()) {
 
136
        if ($ret) {
121
137
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
122
138
        }
123
139
        $this->assert(isset($thumbnailImage), 'thumbnailImage');
124
140
 
125
141
        list ($ret, $thumbnails) =
126
142
            GalleryCoreApi::fetchThumbnailsByItemIds(array($this->_item->getId()));
127
 
        if ($ret->isError()) {
 
143
        if ($ret) {
128
144
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
129
145
        }
130
146
        $this->assertEquals(array($this->_item->getId()), array_keys($thumbnails), 'derivative');
138
154
        $this->assertEquals(array(array(), array()), $result);
139
155
 
140
156
        list ($ret, $thumbnailImage) = ThumbnailHelper::fetchThumbnail($this->_item->getId());
141
 
        if ($ret->isError()) {
 
157
        if ($ret) {
142
158
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
143
159
        }
144
160
        $this->assert(!isset($thumbnailImage), 'removed thumbnailImage');
145
161
 
146
162
        list ($ret, $thumbnails) =
147
163
            GalleryCoreApi::fetchThumbnailsByItemIds(array($this->_item->getId()));
148
 
        if ($ret->isError()) {
 
164
        if ($ret) {
149
165
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
150
166
        }
151
167
        $this->assertEquals(array(), $thumbnails, 'removed derivative');
156
172
        $form = array('name' => array(1 => 'test.jpg'),
157
173
                      'type' => array(1 => 'image/jpeg'),
158
174
                      'tmp_name' => array(1 =>
159
 
                            dirname(__FILE__) . '/../../../core/test/data/test1.jpg'));
 
175
                            GalleryCoreApi::getPluginBaseDir('module', 'core')
 
176
                                . 'modules/core/test/data/test1.jpg'));
160
177
 
161
178
        $result = $this->_handleRequestAfterEdit($form, $this->_item);
162
179
        $this->assertEquals(array(array(), array()), $result);
163
180
 
164
181
        list ($ret, $thumbnailImage) = ThumbnailHelper::fetchThumbnail($this->_item->getId());
165
 
        if ($ret->isError()) {
 
182
        if ($ret) {
166
183
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
167
184
        }
168
185
        $this->assert(isset($thumbnailImage), 'thumbnailImage');
169
186
 
170
187
        list ($ret, $thumbnails) =
171
188
            GalleryCoreApi::fetchThumbnailsByItemIds(array($this->_item->getId()));
172
 
        if ($ret->isError()) {
 
189
        if ($ret) {
173
190
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
174
191
        }
175
192
        $this->assertEquals(array($this->_item->getId()), array_keys($thumbnails), 'derivative');
179
196
 
180
197
        /* Delete thumbnail from item and ensure ThumbnailImage is deleted too */
181
198
        $ret = GalleryCoreApi::deleteEntityById($thumbnail->getId());
182
 
        if ($ret->isError()) {
 
199
        if ($ret) {
183
200
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
184
201
        }
185
202
 
186
203
        list ($ret, $thumbnailImage) = ThumbnailHelper::fetchThumbnail($this->_item->getId());
187
 
        if ($ret->isError()) {
 
204
        if ($ret) {
188
205
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
189
206
        }
190
207
        $this->assert(!isset($thumbnailImage), 'thumbnailImage should have been deleted');
192
209
        if (isset($thumbnailImage)) {
193
210
            /* In case test failed, delete ThumbnailImage */
194
211
            $ret = GalleryCoreApi::deleteEntityById($thumbnailImage->getId());
195
 
            if ($ret->isError()) {
 
212
            if ($ret) {
196
213
                return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
197
214
            }
198
215
        }
203
220
        $form = array('name' => array(1 => 'test.jpg'),
204
221
                      'type' => array(1 => 'image/jpeg'),
205
222
                      'tmp_name' => array(1 =>
206
 
                            dirname(__FILE__) . '/../../../core/test/data/test1.jpg'));
 
223
                            GalleryCoreApi::getPluginBaseDir('module', 'core')
 
224
                                . 'modules/core/test/data/test1.jpg'));
207
225
 
208
226
        $result = $this->_handleRequestAfterEdit($form, $this->_image);
209
227
        $this->assertEquals(array(array(), array()), $result);
210
228
 
211
229
        list ($ret, $thumbnailImage) = ThumbnailHelper::fetchThumbnail($this->_image->getId());
212
 
        if ($ret->isError()) {
 
230
        if ($ret) {
213
231
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
214
232
        }
215
233
        $this->assert(isset($thumbnailImage), 'thumbnailImage');
216
234
 
217
235
        list ($ret, $thumbnails) =
218
236
            GalleryCoreApi::fetchThumbnailsByItemIds(array($this->_image->getId()));
219
 
        if ($ret->isError()) {
 
237
        if ($ret) {
220
238
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
221
239
        }
222
240
        $this->assertEquals(array($this->_image->getId()), array_keys($thumbnails), 'derivative');
223
241
        $thumbnail = array_shift($thumbnails);
224
242
        $this->assertEquals($thumbnailImage->getId(),
225
243
                            $thumbnail->getDerivativeSourceId(), 'source');
 
244
        $this->assertEquals('thumbnail|200;composite|path/test.png,image/png,20,20,top-left,0,0',
 
245
                            $thumbnail->getDerivativeOperations(),
 
246
                            'operations should keep thumbnail,composite and drop others');
226
247
 
227
248
        /* Remove custom thumbnail.. */
228
249
        $form = array('CustomThumbnailOption' => array('delete' => '1'));
230
251
        $this->assertEquals(array(array(), array()), $result);
231
252
 
232
253
        list ($ret, $thumbnailImage) = ThumbnailHelper::fetchThumbnail($this->_image->getId());
233
 
        if ($ret->isError()) {
 
254
        if ($ret) {
234
255
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
235
256
        }
236
257
        $this->assert(!isset($thumbnailImage), 'removed thumbnailImage');
237
258
 
238
259
        list ($ret, $thumbnails) =
239
260
            GalleryCoreApi::fetchThumbnailsByItemIds(array($this->_image->getId()));
240
 
        if ($ret->isError()) {
 
261
        if ($ret) {
241
262
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
242
263
        }
243
264
        $this->assertEquals(array($this->_image->getId()),
244
265
                            array_keys($thumbnails), 'got derivative');
245
 
        $thumbnail = array_shift($thumbnails);
246
 
        $this->assertEquals($this->_image->getId(),
247
 
                            $thumbnail->getDerivativeSourceId(), 'got source');
 
266
        if (!empty($thumbnails)) {
 
267
            $thumbnail = array_shift($thumbnails);
 
268
            $this->assertEquals($this->_image->getId(),
 
269
                                $thumbnail->getDerivativeSourceId(), 'got source');
 
270
            $this->assertEquals(
 
271
                'thumbnail|200;composite|path/test.png,image/png,20,20,top-left,0,0',
 
272
                $thumbnail->getDerivativeOperations(),
 
273
                'operations should keep thumbnail,composite and drop others');
 
274
        }
248
275
    }
249
276
 
250
277
    function testAlbumHighlight() {
252
279
        $form = array('name' => array(1 => 'test.jpg'),
253
280
                      'type' => array(1 => 'application/unknown'),
254
281
                      'tmp_name' => array(1 =>
255
 
                            dirname(__FILE__) . '/../../../core/test/data/test1.jpg'));
 
282
                            GalleryCoreApi::getPluginBaseDir('module', 'core')
 
283
                                . 'modules/core/test/data/test1.jpg'));
256
284
 
257
285
        $result = $this->_handleRequestAfterEdit($form, $this->_album);
258
286
        $this->assertEquals(array(array(), array()), $result);
259
287
 
260
288
        list ($ret, $thumbnailImage) = ThumbnailHelper::fetchThumbnail($this->_album->getId());
261
 
        if ($ret->isError()) {
 
289
        if ($ret) {
262
290
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
263
291
        }
264
292
        if (!isset($thumbnailImage)) {
268
296
 
269
297
        list ($ret, $thumbnails) =
270
298
            GalleryCoreApi::fetchThumbnailsByItemIds(array($this->_album->getId()));
271
 
        if ($ret->isError()) {
 
299
        if ($ret) {
272
300
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
273
301
        }
274
302
        $this->assertEquals(array($this->_album->getId()), array_keys($thumbnails), 'highlight');
282
310
        $this->assertEquals(array(array(), array()), $result);
283
311
 
284
312
        list ($ret, $thumbnailImage) = ThumbnailHelper::fetchThumbnail($this->_album->getId());
285
 
        if ($ret->isError()) {
 
313
        if ($ret) {
286
314
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
287
315
        }
288
316
        $this->assert(!isset($thumbnailImage), 'removed thumbnailImage');
289
317
 
290
318
        list ($ret, $thumbnails) =
291
319
            GalleryCoreApi::fetchThumbnailsByItemIds(array($this->_album->getId()));
292
 
        if ($ret->isError()) {
 
320
        if ($ret) {
293
321
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
294
322
        }
295
323
        $this->assertEquals(array($this->_album->getId()),
301
329
 
302
330
    function testEmptyAlbumHighlight() {
303
331
        list ($ret, $album) = $this->_createRandomAlbum($this->_album->getId());
304
 
        if ($ret->isError()) {
 
332
        if ($ret) {
305
333
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
306
334
        }
307
335
 
309
337
        $form = array('name' => array(1 => 'test.jpg'),
310
338
                      'type' => array(1 => 'image/jpeg'),
311
339
                      'tmp_name' => array(1 =>
312
 
                            dirname(__FILE__) . '/../../../core/test/data/test1.jpg'));
 
340
                            GalleryCoreApi::getPluginBaseDir('module', 'core')
 
341
                                . 'modules/core/test/data/test1.jpg'));
313
342
 
314
343
        $result = $this->_handleRequestAfterEdit($form, $album);
315
344
        $this->assertEquals(array(array(), array()), $result);
316
345
 
317
346
        list ($ret, $thumbnailImage) = ThumbnailHelper::fetchThumbnail($album->getId());
318
 
        if ($ret->isError()) {
 
347
        if ($ret) {
319
348
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
320
349
        }
321
350
        $this->assert(isset($thumbnailImage), 'thumbnailImage');
322
351
 
323
352
        list ($ret, $thumbnails) = GalleryCoreApi::fetchThumbnailsByItemIds(array($album->getId()));
324
 
        if ($ret->isError()) {
 
353
        if ($ret) {
325
354
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
326
355
        }
327
356
        $this->assertEquals(array($album->getId()), array_keys($thumbnails), 'highlight');
335
364
        $this->assertEquals(array(array(), array()), $result);
336
365
 
337
366
        list ($ret, $thumbnailImage) = ThumbnailHelper::fetchThumbnail($album->getId());
338
 
        if ($ret->isError()) {
 
367
        if ($ret) {
339
368
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
340
369
        }
341
370
        $this->assert(!isset($thumbnailImage), 'removed thumbnailImage');
342
371
 
343
372
        list ($ret, $thumbnails) = GalleryCoreApi::fetchThumbnailsByItemIds(array($album->getId()));
344
 
        if ($ret->isError()) {
 
373
        if ($ret) {
345
374
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
346
375
        }
347
376
        $this->assertEquals(array(), $thumbnails, 'no highlight');
353
382
        $form = array('name' => array(1 => 'test.jpg'),
354
383
                      'type' => array(1 => 'image/jpeg'),
355
384
                      'tmp_name' => array(1 =>
356
 
                            dirname(__FILE__) . '/../../../core/test/data/test1.jpg'));
 
385
                            GalleryCoreApi::getPluginBaseDir('module', 'core')
 
386
                                . 'modules/core/test/data/test1.jpg'));
357
387
 
358
388
        $result = $this->_handleRequestAfterEdit($form, $this->_album);
359
389
        $this->assertEquals(array(array(), array()), $result);
360
390
 
361
391
        /* Call GalleryCoreApi::guaranteeAlbumHasThumbnail */
362
392
        list ($ret, $success) = GalleryCoreApi::guaranteeAlbumHasThumbnail($this->_album->getId());
363
 
        if ($ret->isError()) {
 
393
        if ($ret) {
364
394
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
365
395
        }
366
396
        $this->assert($success, 'guarantee');
367
397
 
368
398
        list ($ret, $thumbnailImage) = ThumbnailHelper::fetchThumbnail($this->_album->getId());
369
 
        if ($ret->isError()) {
 
399
        if ($ret) {
370
400
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
371
401
        }
372
402
        $this->assert(isset($thumbnailImage), 'thumbnailImage');
373
403
 
374
404
        list ($ret, $thumbnails) =
375
405
            GalleryCoreApi::fetchThumbnailsByItemIds(array($this->_album->getId()));
376
 
        if ($ret->isError()) {
 
406
        if ($ret) {
377
407
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
378
408
        }
379
409
        $this->assertEquals(array($this->_album->getId()), array_keys($thumbnails), 'highlight');