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

« back to all changes in this revision

Viewing changes to modules/core/test/phpunit/ToolkitTest.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
 
GalleryCoreApi::requireOnce('modules/core/classes/GalleryToolkit.class');
22
 
 
23
 
/**
24
 
 * Test Toolkit functionality
25
 
 * @package GalleryCore
26
 
 * @subpackage PHPUnit
27
 
 * @author Bharat Mediratta <bharat@menalto.com>
28
 
 * @version $Revision: 15513 $
29
 
 */
30
 
class ToolkitTest extends GalleryTestCase {
31
 
 
32
 
    function ToolkitTest($methodName) {
33
 
        $this->GalleryTestCase($methodName);
34
 
    }
35
 
 
36
 
    function setUp() {
37
 
        parent::setUp();
38
 
 
39
 
        /* Register a dummy toolkit */
40
 
        $path = 'modules/core/test/phpunit/ToolkitTest.class';
41
 
        $ret = GalleryCoreApi::registerFactoryImplementation(
42
 
            'GalleryToolkit', 'TestToolkit', 'TestToolkit',
43
 
            $path, 'coreTest', null);
44
 
        if ($ret) {
45
 
            print $ret->getAsHtml();
46
 
            return $this->failWithStatus($ret);
47
 
        }
48
 
 
49
 
        $ret = GalleryCoreApi::registerFactoryImplementation(
50
 
            'GalleryToolkit', 'TestToolkit2', 'TestToolkit2',
51
 
            $path, 'coreTest', null);
52
 
        if ($ret) {
53
 
            print $ret->getAsHtml();
54
 
            return $this->failWithStatus($ret);
55
 
        }
56
 
        $this->_markToolkitForCleanup('TestToolkit');
57
 
        $this->_markToolkitForCleanup('TestToolkit2');
58
 
    }
59
 
 
60
 
    function testOperation() {
61
 
        $params = array(array('type' => 'test-type1',
62
 
                              'description' => 'test-description1'),
63
 
                        array('type' => 'test-type2',
64
 
                              'description' => 'test-description2')
65
 
                        );
66
 
        $ret = GalleryCoreApi::registerToolkitOperation('TestToolkit',
67
 
                                                       array('test/type'),
68
 
                                                       'test-operation',
69
 
                                                       $params,
70
 
                                                       'test-description',
71
 
                                                       'test/outputType');
72
 
        if ($ret) {
73
 
            return $this->failWithStatus($ret);
74
 
        }
75
 
 
76
 
        /* Get the operation */
77
 
        list ($ret, $operations) = GalleryCoreApi::getToolkitOperations('test/type');
78
 
        if ($ret) {
79
 
            return $this->failWithStatus($ret);
80
 
        }
81
 
 
82
 
        $this->assertEquals(1, sizeof($operations));
83
 
        $this->assertEquals('test-operation', $operations[0]['name']);
84
 
        $this->assertEquals('test/outputType', $operations[0]['outputMimeType']);
85
 
        $this->assertEquals('test-description', $operations[0]['description']);
86
 
        $this->assertEquals($params, $operations[0]['parameters']);
87
 
 
88
 
        /* Get the toolkit */
89
 
        list ($ret, $toolkit, $outputMimeType) =
90
 
            GalleryCoreApi::getToolkitByOperation('test/type', 'test-operation');
91
 
        if ($ret) {
92
 
            return $this->failWithStatus($ret);
93
 
        }
94
 
 
95
 
        $this->assertEquals(new TestToolkit(), $toolkit);
96
 
        $this->assertEquals('test/outputType', $outputMimeType);
97
 
 
98
 
        /* Register another toolkit with same operation/mimetype, higher priority */
99
 
        $ret = GalleryCoreApi::registerToolkitOperation('TestToolkit2',
100
 
                                                       array('test/type'),
101
 
                                                       'test-operation',
102
 
                                                       $params,
103
 
                                                       'test-description2',
104
 
                                                       'test/outputType', 3);
105
 
        if ($ret) {
106
 
            return $this->failWithStatus($ret);
107
 
        }
108
 
 
109
 
        /* Get the toolkit */
110
 
        list ($ret, $toolkit, $outputMimeType) =
111
 
            GalleryCoreApi::getToolkitByOperation('test/type', 'test-operation');
112
 
        if ($ret) {
113
 
            return $this->failWithStatus($ret);
114
 
        }
115
 
 
116
 
        $this->assertEquals(new TestToolkit2(), $toolkit);
117
 
        $this->assertEquals('test/outputType', $outputMimeType);
118
 
 
119
 
        /* Unregister */
120
 
        $ret = GalleryCoreApi::unregisterToolkit('TestToolkit');
121
 
        if ($ret) {
122
 
            return $this->failWithStatus($ret);
123
 
        }
124
 
        $ret = GalleryCoreApi::unregisterToolkit('TestToolkit2');
125
 
        if ($ret) {
126
 
            return $this->failWithStatus($ret);
127
 
        }
128
 
 
129
 
        /* Get the toolkit */
130
 
        list ($ret, $toolkit, $outputMimeType) =
131
 
            GalleryCoreApi::getToolkitByOperation('test/type', 'test-operation');
132
 
        if ($ret) {
133
 
            return $this->failWithStatus($ret);
134
 
        }
135
 
 
136
 
        $this->assertEquals(null, $toolkit);
137
 
    }
138
 
 
139
 
    function testProperty() {
140
 
        $ret = GalleryCoreApi::registerToolkitProperty('TestToolkit',
141
 
                                                      array('test/type'),
142
 
                                                      'test-property',
143
 
                                                      'int',
144
 
                                                      'test-description');
145
 
        if ($ret) {
146
 
            return $this->failWithStatus($ret);
147
 
        }
148
 
 
149
 
        /* Get the property */
150
 
        list ($ret, $properties) = GalleryCoreApi::getToolkitProperties('test/type');
151
 
        if ($ret) {
152
 
            return $this->failWithStatus($ret);
153
 
        }
154
 
 
155
 
        $this->assertEquals(1, sizeof($properties));
156
 
        $this->assertEquals('test-property', $properties[0]['name']);
157
 
        $this->assertEquals('int', $properties[0]['type']);
158
 
        $this->assertEquals('test-description', $properties[0]['description']);
159
 
 
160
 
        /* Get the toolkit */
161
 
        list ($ret, $toolkit) =
162
 
            GalleryCoreApi::getToolkitByProperty('test/type', 'test-property');
163
 
        if ($ret) {
164
 
            return $this->failWithStatus($ret);
165
 
        }
166
 
 
167
 
        $this->assertEquals(new TestToolkit(), $toolkit);
168
 
 
169
 
        /* Unregister */
170
 
        $ret = GalleryCoreApi::unregisterToolkit('TestToolkit');
171
 
        if ($ret) {
172
 
            return $this->failWithStatus($ret);
173
 
        }
174
 
 
175
 
        /* Get the toolkit */
176
 
        list ($ret, $toolkit) =
177
 
            GalleryCoreApi::getToolkitByProperty('test/type', 'test-property');
178
 
        if ($ret) {
179
 
            return $this->failWithStatus($ret);
180
 
        }
181
 
 
182
 
        $this->assertEquals(null, $toolkit);
183
 
    }
184
 
 
185
 
    function testPropertyMultipleToolkits() {
186
 
        $ret = GalleryCoreApi::registerToolkitProperty('TestToolkit',
187
 
                                                      array('test/type'),
188
 
                                                      'test-property',
189
 
                                                      'int',
190
 
                                                      'test-description');
191
 
        if ($ret) {
192
 
            return $this->failWithStatus($ret);
193
 
        }
194
 
        $ret = GalleryCoreApi::registerToolkitProperty('TestToolkit2',
195
 
                                                      array('test/type'),
196
 
                                                      'test-property',
197
 
                                                      'int',
198
 
                                                      'test-description');
199
 
        if ($ret) {
200
 
            return $this->failWithStatus($ret);
201
 
        }
202
 
 
203
 
        /* Get the toolkits */
204
 
        list ($ret, $toolkits) =
205
 
            GalleryCoreApi::getToolkitsByProperty('test/type', 'test-property');
206
 
        if ($ret) {
207
 
            return $this->failWithStatus($ret);
208
 
        }
209
 
 
210
 
        /* Order is non-deterministic (varies by db) */
211
 
        $this->assert((GalleryUtilities::isA($toolkits[0], 'TestToolkit') &&
212
 
                       GalleryUtilities::isA($toolkits[1], 'TestToolkit2')) ||
213
 
                      (GalleryUtilities::isA($toolkits[0], 'TestToolkit2') &&
214
 
                       GalleryUtilities::isA($toolkits[1], 'TestToolkit')),
215
 
                      'toolkit mismatch');
216
 
 
217
 
        /* Unregister */
218
 
        $ret = GalleryCoreApi::unregisterToolkit('TestToolkit2');
219
 
        if ($ret) {
220
 
            return $this->failWithStatus($ret);
221
 
        }
222
 
        $ret = GalleryCoreApi::unregisterToolkit('TestToolkit');
223
 
        if ($ret) {
224
 
            return $this->failWithStatus($ret);
225
 
        }
226
 
 
227
 
        /* Get the toolkits */
228
 
        list ($ret, $toolkitIds) =
229
 
            GalleryCoreApi::getToolkitByProperty('test/type', 'test-property');
230
 
        if ($ret) {
231
 
            return $this->failWithStatus($ret);
232
 
        }
233
 
 
234
 
        $this->assertEquals(null, $toolkitIds);
235
 
    }
236
 
 
237
 
    function testOperationSequence() {
238
 
        $params = array(array('type' => 'test-type1',
239
 
                              'description' => 'test-description1'),
240
 
                        array('type' => 'test-type2',
241
 
                              'description' => 'test-description2')
242
 
                        );
243
 
        $ret = GalleryCoreApi::registerToolkitOperation('TestToolkit',
244
 
                                                       array('test/type1', 'test/unused'),
245
 
                                                       'test-operation1',
246
 
                                                       $params,
247
 
                                                       'test-description',
248
 
                                                       'test/type2');
249
 
        if ($ret) {
250
 
            return $this->failWithStatus($ret);
251
 
        }
252
 
 
253
 
        $ret = GalleryCoreApi::registerToolkitOperation('TestToolkit',
254
 
                                                       array('test/type2'),
255
 
                                                       'test-operation2',
256
 
                                                       $params,
257
 
                                                       'test-description',
258
 
                                                       'test/type3');
259
 
        if ($ret) {
260
 
            return $this->failWithStatus($ret);
261
 
        }
262
 
 
263
 
        list ($ret, $isSupported, $outputMimeType) =
264
 
            GalleryCoreApi::isSupportedOperationSequence('test/type1',
265
 
                                                         'test-operation1|1,2;test-operation2|1,2');
266
 
        if ($ret) {
267
 
            return $this->failWithStatus($ret);
268
 
        }
269
 
 
270
 
        $this->assert($isSupported, '1-1');
271
 
        $this->assertEquals('test/type3', $outputMimeType, '1-2');
272
 
 
273
 
        /* Unregister operation for single mime-type */
274
 
        $ret = GalleryCoreApi::unregisterToolkitOperation('TestToolkit', 'test-operation1',
275
 
                                         array('test/unused', 'test/nonexist'));
276
 
        if ($ret) {
277
 
            return $this->failWithStatus($ret);
278
 
        }
279
 
 
280
 
        list ($ret, $isSupported, $outputMimeType) =
281
 
            GalleryCoreApi::isSupportedOperationSequence('test/type1',
282
 
                                                         'test-operation1|1,2;test-operation2|1,2');
283
 
        if ($ret) {
284
 
            return $this->failWithStatus($ret);
285
 
        }
286
 
 
287
 
        $this->assert($isSupported, '2-1');
288
 
        $this->assertEquals('test/type3', $outputMimeType, '2-2');
289
 
 
290
 
        /* Unregister single operation */
291
 
        $ret = GalleryCoreApi::unregisterToolkitOperation('TestToolkit', 'test-operation2');
292
 
        if ($ret) {
293
 
            return $this->failWithStatus($ret);
294
 
        }
295
 
 
296
 
        list ($ret, $isSupported, $outputMimeType) =
297
 
            GalleryCoreApi::isSupportedOperationSequence('test/type1',
298
 
                                                         'test-operation1|1,2;test-operation2|1,2');
299
 
        if ($ret) {
300
 
            return $this->failWithStatus($ret);
301
 
        }
302
 
 
303
 
        $this->assert(!$isSupported, '3-1');
304
 
 
305
 
        /* Unregister toolkit */
306
 
        $ret = GalleryCoreApi::unregisterToolkit('TestToolkit');
307
 
        if ($ret) {
308
 
            return $this->failWithStatus($ret);
309
 
        }
310
 
 
311
 
        list ($ret, $isSupported, $outputMimeType) =
312
 
            GalleryCoreApi::isSupportedOperationSequence('test/type1',
313
 
                                                         'test-operation1|1,2;test-operation2|1,2');
314
 
        if ($ret) {
315
 
            return $this->failWithStatus($ret);
316
 
        }
317
 
 
318
 
        $this->assert(!$isSupported, '4-1');
319
 
    }
320
 
 
321
 
    function testGetOperationMimeTypes() {
322
 
 
323
 
        $params = array(array('type' => 'test-type1',
324
 
                              'description' => 'test-description1'),
325
 
                        array('type' => 'test-type2',
326
 
                              'description' => 'test-description2')
327
 
                        );
328
 
        $ret = GalleryCoreApi::registerToolkitOperation('TestToolkit',
329
 
                                                       array('test/type', 'test/type2'),
330
 
                                                       'test-operation',
331
 
                                                       $params,
332
 
                                                       'test-description',
333
 
                                                       'test/outputType');
334
 
        if ($ret) {
335
 
            return $this->failWithStatus($ret);
336
 
        }
337
 
 
338
 
        list ($ret, $data) = GalleryCoreApi::getToolkitOperationMimeTypes('test-operation');
339
 
        if ($ret) {
340
 
            return $this->failWithStatus($ret);
341
 
        }
342
 
        $this->assert(isset($data['test/type']) && in_array('TestToolkit', $data['test/type']),
343
 
                      'Operation mime type');
344
 
    }
345
 
 
346
 
    function testEstimateDerivativeDimensions() {
347
 
        list ($ret, $source) = GalleryCoreApi::newItemByMimeType('image/jpeg');
348
 
        if ($ret) {
349
 
            return $this->failWithStatus($ret);
350
 
        }
351
 
        $this->assert(GalleryUtilities::isA($source, 'GalleryPhotoItem'));
352
 
 
353
 
        $source->setWidth(1024);
354
 
        $source->setHeight(768);
355
 
 
356
 
        list ($ret, $derivative) =
357
 
            GalleryCoreApi::newFactoryInstanceByHint('GalleryDerivative', $source->getEntityType());
358
 
        if ($ret) {
359
 
            return $this->failWithStatus($ret);
360
 
        }
361
 
        $this->assert(GalleryUtilities::isA($derivative, 'GalleryDerivativeImage'));
362
 
 
363
 
        $derivative->setDerivativeOperations('thumbnail|200');
364
 
        $derivative->setWidth(0);
365
 
        $derivative->setHeight(0);
366
 
 
367
 
        $ret = GalleryCoreApi::estimateDerivativeDimensions($derivative, $source);
368
 
        if ($ret) {
369
 
            return $this->failWithStatus($ret);
370
 
        }
371
 
 
372
 
        $this->assertEquals(200, $derivative->getWidth());
373
 
        $this->assertEquals(150, $derivative->getHeight());
374
 
    }
375
 
 
376
 
    function testEstimateDerivativeDimensions2() {
377
 
        list ($ret, $source) = GalleryCoreApi::newItemByMimeType('image/jpeg');
378
 
        if ($ret) {
379
 
            return $this->failWithStatus($ret);
380
 
        }
381
 
        $this->assert(GalleryUtilities::isA($source, 'GalleryPhotoItem'));
382
 
 
383
 
        $source->setWidth(1024);
384
 
        $source->setHeight(768);
385
 
 
386
 
        list ($ret, $derivative) =
387
 
            GalleryCoreApi::newFactoryInstanceByHint('GalleryDerivative', $source->getEntityType());
388
 
        if ($ret) {
389
 
            return $this->failWithStatus($ret);
390
 
        }
391
 
        $this->assert(GalleryUtilities::isA($derivative, 'GalleryDerivativeImage'));
392
 
 
393
 
        $derivative->setDerivativeOperations('scale|150');
394
 
        $derivative->setWidth(0);
395
 
        $derivative->setHeight(0);
396
 
 
397
 
        $ret = GalleryCoreApi::estimateDerivativeDimensions($derivative, $source);
398
 
        if ($ret) {
399
 
            return $this->failWithStatus($ret);
400
 
        }
401
 
 
402
 
        $this->assertEquals(150, $derivative->getWidth());
403
 
        $this->assertEquals(113, $derivative->getHeight());
404
 
    }
405
 
 
406
 
    function testEstimateDerivativeDimensions3() {
407
 
        list ($ret, $source) = GalleryCoreApi::newItemByMimeType('image/jpeg');
408
 
        if ($ret) {
409
 
            return $this->failWithStatus($ret);
410
 
        }
411
 
        $this->assert(GalleryUtilities::isA($source, 'GalleryPhotoItem'));
412
 
 
413
 
        $source->setWidth(1024);
414
 
        $source->setHeight(768);
415
 
 
416
 
        list ($ret, $derivative) =
417
 
            GalleryCoreApi::newFactoryInstanceByHint('GalleryDerivative', $source->getEntityType());
418
 
        if ($ret) {
419
 
            return $this->failWithStatus($ret);
420
 
        }
421
 
        $this->assert(GalleryUtilities::isA($derivative, 'GalleryDerivativeImage'));
422
 
 
423
 
        $derivative->setDerivativeOperations('crop|1,2,3,4;scale|150');
424
 
        $derivative->setWidth(0);
425
 
        $derivative->setHeight(0);
426
 
 
427
 
        $ret = GalleryCoreApi::estimateDerivativeDimensions($derivative, $source);
428
 
        if ($ret) {
429
 
            return $this->failWithStatus($ret);
430
 
        }
431
 
 
432
 
        $this->assertEquals(0, $derivative->getWidth());
433
 
        $this->assertEquals(0, $derivative->getHeight());
434
 
    }
435
 
 
436
 
    function testEstimateDerivativeDimensions4() {
437
 
        /*
438
 
         * Test that if the direct source is a derivative too and has smaller dimensions
439
 
         * then we assume the "real" source is larger and allow upscaling in our estimate.
440
 
         * This means our estimate could be too high if the real source actually is smaller
441
 
         * than the desired size, but it will be corrected once the derivative is built.
442
 
         */
443
 
        list ($ret, $orig) = GalleryCoreApi::newItemByMimeType('image/jpeg');
444
 
        if ($ret) {
445
 
            return $this->failWithStatus($ret);
446
 
        }
447
 
        $this->assert(GalleryUtilities::isA($orig, 'GalleryPhotoItem'), 'photo item');
448
 
 
449
 
        $orig->setWidth(400);
450
 
        $orig->setHeight(300);
451
 
 
452
 
        list ($ret, $source) =
453
 
            GalleryCoreApi::newFactoryInstanceByHint('GalleryDerivative', $orig->getEntityType());
454
 
        if ($ret) {
455
 
            return $this->failWithStatus($ret);
456
 
        }
457
 
        $this->assert(GalleryUtilities::isA($source, 'GalleryDerivativeImage'), 'source deriv');
458
 
 
459
 
        $source->setDerivativeOperations('thumbnail|100');
460
 
        $source->setWidth(100);
461
 
        $source->setHeight(75);
462
 
 
463
 
        list ($ret, $derivative) =
464
 
            GalleryCoreApi::newFactoryInstanceByHint('GalleryDerivative', $orig->getEntityType());
465
 
        if ($ret) {
466
 
            return $this->failWithStatus($ret);
467
 
        }
468
 
        $this->assert(GalleryUtilities::isA($derivative, 'GalleryDerivativeImage'), 'target deriv');
469
 
 
470
 
        $derivative->setDerivativeOperations('thumbnail|200');
471
 
        $derivative->setWidth(0);
472
 
        $derivative->setHeight(0);
473
 
 
474
 
        $ret = GalleryCoreApi::estimateDerivativeDimensions($derivative, $source);
475
 
        if ($ret) {
476
 
            return $this->failWithStatus($ret);
477
 
        }
478
 
 
479
 
        $this->assertEquals(200, $derivative->getWidth(), 'width 1');
480
 
        $this->assertEquals(150, $derivative->getHeight(), 'height 1');
481
 
 
482
 
        /*
483
 
         * Now verify if the direct source is not a derivative and is smaller than the
484
 
         * desired size that we don't upsample.
485
 
         */
486
 
        $orig->setWidth(123);
487
 
        $orig->setHeight(66);
488
 
 
489
 
        $ret = GalleryCoreApi::estimateDerivativeDimensions($derivative, $orig);
490
 
        if ($ret) {
491
 
            return $this->failWithStatus($ret);
492
 
        }
493
 
 
494
 
        $this->assertEquals(123, $derivative->getWidth(), 'width 2');
495
 
        $this->assertEquals(66, $derivative->getHeight(), 'height 2');
496
 
    }
497
 
 
498
 
    function testApplyTransform() {
499
 
        $toolkit = new GalleryToolkit();
500
 
 
501
 
        /* Rotate transform of cropped operation results in rotated coordinates*/
502
 
        list ($success, $result) =
503
 
            $toolkit->applyTransform('rotate|90', 'rotate|90;crop|15,15,40,50');
504
 
        $this->assert($success);
505
 
        $this->assertEquals('rotate|90;crop|35,15,50,40', $result, 'test 1');
506
 
 
507
 
        /* Rotate transform of nothing returns nothing */
508
 
        list ($success, $result) = $toolkit->applyTransform('rotate|90', '');
509
 
        $this->assert($success);
510
 
        $this->assertEquals('', $result, 'test 2');
511
 
 
512
 
        /* Empty transform of cropped opreation returns original values */
513
 
        list ($success, $result) = $toolkit->applyTransform('', 'rotate|90;crop|15,15,40,50');
514
 
        $this->assert($success);
515
 
        $this->assertEquals('rotate|90;crop|15,15,40,50', $result, 'test 3');
516
 
 
517
 
        /* Reverse rotate transform of cropped operation results in rotated coordinates*/
518
 
        list ($success, $result) =
519
 
            $toolkit->applyTransform('rotate|90', 'rotate|90;crop|15,15,40,50', true);
520
 
        $this->assert($success);
521
 
        $this->assertEquals('rotate|90;crop|15,45,50,40', $result, 'test 4');
522
 
    }
523
 
 
524
 
    function testApplyTransformLocale() {
525
 
        /*
526
 
         * Verify that percentages don't get written like 12,5 if the current locale
527
 
         * uses a comma for the fraction separator.
528
 
         */
529
 
        $currentLocale = setlocale(LC_ALL, '0');
530
 
        foreach (array('de_DE', 'german') as $locale) {
531
 
            if (($newLocale = GalleryTranslator::_setlocale(LC_ALL, $locale)) !== false) {
532
 
                break;
533
 
            }
534
 
        }
535
 
        if (empty($newLocale)) {
536
 
            return $this->assert(false, 'Unable to select German locale');
537
 
        }
538
 
 
539
 
        $toolkit = new GalleryToolkit();
540
 
 
541
 
        /* Rotate transform of cropped operation results in rotated coordinates */
542
 
        list ($success, $result) =
543
 
            $toolkit->applyTransform('rotate|90', 'rotate|90;crop|15,20.5,40.62,50');
544
 
        $this->assert($success);
545
 
        $this->assertEquals('rotate|90;crop|29.5,15,50,40.62', $result, 'test 1');
546
 
 
547
 
        setlocale(LC_ALL, $currentLocale);
548
 
    }
549
 
 
550
 
    function testGetMaximumManagedPriority() {
551
 
        $ret = GalleryCoreApi::registerToolkitOperation('TestToolkit',
552
 
                array('test/type'), 'test-operation', array(),
553
 
                'test-description', 'test/outputType', 40);
554
 
        if ($ret) {
555
 
            return $this->failWithStatus($ret);
556
 
        }
557
 
 
558
 
        list ($ret, $priority) = GalleryCoreApi::getMaximumManagedToolkitPriority();
559
 
        if ($ret) {
560
 
            return $this->failWithStatus($ret);
561
 
        }
562
 
 
563
 
        $this->assertEquals(40, $priority);
564
 
    }
565
 
 
566
 
    function testGetRedundantPriorities() {
567
 
        $ret = GalleryCoreApi::registerToolkitOperation('TestToolkit',
568
 
                array('test/type'), 'test-operation', array(),
569
 
                'test-description', 'test/outputType', 30);
570
 
        if ($ret) {
571
 
            return $this->failWithStatus($ret);
572
 
        }
573
 
 
574
 
        $ret = GalleryCoreApi::registerToolkitOperation('TestToolkit2',
575
 
                array('test/type'), 'test-operation', array(),
576
 
                'test-description', 'test/outputType', 27);
577
 
        if ($ret) {
578
 
            return $this->failWithStatus($ret);
579
 
        }
580
 
 
581
 
        list ($ret, $list) = GalleryCoreApi::getRedundantToolkitPriorities();
582
 
        if ($ret) {
583
 
            return $this->failWithStatus($ret);
584
 
        }
585
 
 
586
 
        $this->assert(count($list) >= 2, 'count');
587
 
        $this->assertEquals(30, $list['TestToolkit'], 'TestToolkit');
588
 
        $this->assertEquals(27, $list['TestToolkit2'], 'TestToolkit2');
589
 
    }
590
 
 
591
 
    function testGetToolkitPriorityById() {
592
 
        $ret = GalleryCoreApi::registerToolkitOperation('TestToolkit',
593
 
                array('test/type'), 'test-operation', array(),
594
 
                'test-description', 'test/outputType', 30);
595
 
        if ($ret) {
596
 
            return $this->failWithStatus($ret);
597
 
        }
598
 
 
599
 
        /* Validate that toolkit priority is returned correctly */
600
 
        list ($ret, $priority) = GalleryCoreApi::getToolkitPriorityById('TestToolkit');
601
 
        if ($ret) {
602
 
            return $this->failWithStatus($ret);
603
 
        }
604
 
        $this->assertEquals(30, $priority, 'Toolkit Priority Doesn\'t Match');
605
 
 
606
 
        /* Test return for an undefined toolkit */
607
 
        list ($ret, $priority) = GalleryCoreApi::getToolkitPriorityById('TestToolkit2');
608
 
        if ($ret) {
609
 
            return $this->failWithStatus($ret);
610
 
        }
611
 
        $this->assertEquals(null, $priority, 'Returned value for undefined toolkit');
612
 
    }
613
 
 
614
 
    function testMergeOperations() {
615
 
        $toolkit = new TestToolkit();
616
 
        $this->assertEquals(array(true, 'thumbnail', array(150)),
617
 
            $toolkit->mergeOperations('thumbnail', array(100), 'thumbnail', array(150)),
618
 
            'thumbnail');
619
 
        $this->assertEquals(array(true, 'scale', array(800)),
620
 
            $toolkit->mergeOperations('scale', array(600, 500), 'scale', array(800)),
621
 
            'scale');
622
 
        $this->assertEquals(array(true, 'resize', array(640, 480)),
623
 
            $toolkit->mergeOperations('resize', array(800, 600), 'resize', array(640, 480)),
624
 
            'resize');
625
 
        $this->assertEquals(array(true, 'scale', array(800, 600)),
626
 
            $toolkit->mergeOperations('thumbnail', array(200), 'scale', array(800, 600)),
627
 
            'thumbnail scale');
628
 
        $this->assertEquals(array(true, 'resize', array(640, 480)),
629
 
            $toolkit->mergeOperations('scale', array(800, 600), 'resize', array(640, 480)),
630
 
            'scale resize');
631
 
        $this->assertEquals(array(true, 'thumbnail', array(150)),
632
 
            $toolkit->mergeOperations('resize', array(900, 700), 'thumbnail', array(150)),
633
 
            'resize thumbnail');
634
 
        $this->assertEquals(array(true, 'crop', array(20, 20, 60, 60)),
635
 
            $toolkit->mergeOperations('crop', array(40, 40, 20, 20), 'crop', array(20, 20, 60, 60)),
636
 
            'crop');
637
 
        $this->assertEquals(array(false, null, null), $toolkit->mergeOperations(
638
 
                'composite', array('img', 'image/png', 30, 20, 'top-left', 0, 0),
639
 
                'composite', array('myimage', 'image/gif', 60, 60, 'center', 0, 0)),
640
 
            'composite should not merge');
641
 
        $this->assertEquals(array(true, 'rotate', array(180)),
642
 
            $toolkit->mergeOperations('rotate', array(90), 'rotate', array(90)),
643
 
            'rotate 90 90');
644
 
        $this->assertEquals(array(true, 'rotate', array(180)),
645
 
            $toolkit->mergeOperations('rotate', array(-90), 'rotate', array(-90)),
646
 
            'rotate -90 -90');
647
 
        $this->assertEquals(array(true, 'rotate', array(-90)),
648
 
            $toolkit->mergeOperations('rotate', array(180), 'rotate', array(90)),
649
 
            'rotate 180 90');
650
 
        $this->assertEquals(array(true, null, null),
651
 
            $toolkit->mergeOperations('rotate', array(180), 'rotate', array(180)),
652
 
            'rotate 180 180');
653
 
    }
654
 
 
655
 
    function testUnregisterToolkitsByModuleId() {
656
 
        $params = array(array('type' => 'test-type1', 'description' => 'test-description1'));
657
 
        $ret = GalleryCoreApi::registerToolkitOperation('TestToolkit',
658
 
                                                       array('test/type'),
659
 
                                                       'test-operation',
660
 
                                                       $params,
661
 
                                                       'test-description',
662
 
                                                       'test/outputType');
663
 
        if ($ret) {
664
 
            return $this->failWithStatus($ret);
665
 
        }
666
 
 
667
 
        $ret = GalleryCoreApi::registerToolkitProperty(
668
 
            'TestToolkit2', array('test/type'), 'test-property',
669
 
            'int', 'test-description');
670
 
        if ($ret) {
671
 
            return $this->failWithStatus($ret);
672
 
        }
673
 
 
674
 
        $ret = GalleryCoreApi::unregisterToolkitsByModuleId('coreTest');
675
 
        if ($ret) {
676
 
            return $this->failWithStatus($ret);
677
 
        }
678
 
 
679
 
        /* Get the operation */
680
 
        list ($ret, $operations) = GalleryCoreApi::getToolkitOperations('test/type');
681
 
        if ($ret) {
682
 
            return $this->failWithStatus($ret);
683
 
        }
684
 
        $this->assertEquals(0, sizeof($operations), 'all operations should be gone');
685
 
 
686
 
        list ($ret, $properties) = GalleryCoreApi::getToolkitProperties('test/type');
687
 
        if ($ret) {
688
 
            return $this->failWithStatus($ret);
689
 
        }
690
 
        $this->assertEquals(0, sizeof($properties), 'all properties should be gone');
691
 
    }
692
 
}
693
 
 
694
 
/**
695
 
 * Mock toolkit
696
 
 *
697
 
 * @package GalleryCore
698
 
 * @subpackage PHPUnit
699
 
 */
700
 
class TestToolkit extends GalleryToolkit { }
701
 
class TestToolkit2 { }
702
 
?>