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
* SizeLimitOption tests
27
* @author Felix Rabinovich <felix@rabinovich.org>
28
* @version $Revision: 15513 $
30
class SetSizeOptionTest extends ItemAddOptionTestCase {
32
function SetSizeOptionTest($methodName) {
33
$this->ItemAddOptionTestCase($methodName, 'sizelimit', 'SetSizeOption');
41
/* create custom platform to return dummy filesize, imagesize, etc. */
42
$gallery->setPlatform(new SetSizeOptionTestPlatform($gallery->getPlatform()));
44
/* Register dummy toolkit and operations */
45
$ret = GalleryCoreApi::registerFactoryImplementation(
46
'GalleryToolkit', 'SetSizeOptionTestToolkit', 'SetSizeOptionTestToolkit',
47
'modules/sizelimit/test/phpunit/SetSizeOptionTest.class', 'sizelimitTest', null);
49
print $ret->getAsHtml();
50
return $this->failWithStatus($ret);
52
$this->_markToolkitForCleanup('SetSizeOptionTestToolkit');
54
/* applying size limits uses 'compress' */
55
$ret = GalleryCoreApi::registerToolkitOperation('SetSizeOptionTestToolkit',
56
array('image/known'), 'compress',
57
array(array('type' => 'int', 'description' => 'size')), 'desc');
59
print $ret->getAsHtml();
60
return $this->failWithStatus($ret);
63
/* applying dimension limits uses 'scale' */
64
$ret = GalleryCoreApi::registerToolkitOperation('SetSizeOptionTestToolkit',
65
array('image/known'), 'scale',
66
array(array('type' => 'int', 'description' => 'width'),
67
array('type' => 'int', 'description' => 'height')), 'desc');
69
print $ret->getAsHtml();
70
return $this->failWithStatus($ret);
73
/* we will return dimensions to whoever asks */
74
$ret = GalleryCoreApi::registerToolkitProperty('SetSizeOptionTestToolkit',
75
array('image/known', 'image/unknown'), 'dimensions', 'int,int', 'desc');
77
print $ret->getAsHtml();
78
return $this->failWithStatus($ret);
81
list ($ret, $this->_album) = $this->_createRandomAlbum($this->_getRootId());
83
print $ret->getAsHtml();
84
return $this->failWithStatus($ret);
86
$this->_markForCleanup($this->_album);
88
$this->_items = array();
89
/* Sample photo image file that can be resized/compressed */
90
list ($ret, $this->_items[0]) =
91
$this->_createRandomDataItem($this->_album->getId(), 'image/known',
92
array('summary' => 'original summary 0',
93
'description' => 'original description 0'));
95
print $ret->getAsHtml();
96
return $this->failWithStatus($ret);
99
$this->_itemsUnknown = array();
100
/* Not all file types can be resized/compressed. Here is an example of such item */
101
list ($ret, $this->_itemsUnknown[0]) =
102
$this->_createRandomDataItem($this->_album->getId(), 'image/unknown',
103
array('summary' => 'plagiarized summary',
104
'description' => 'plagiarized description'));
106
print $ret->getAsHtml();
107
return $this->failWithStatus($ret);
110
/* For translation */
111
list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'sizelimit');
113
print $ret->getAsHtml();
114
return $this->failWithStatus($ret);
117
$this->_noWarnings = array(array());
118
$this->_noErrors = array();
120
$this->_expectWarnings = array(array(
121
$module->translate(array('text' => 'WARNING: Cannot resize mime type %s',
122
'arg1' => $this->_itemsUnknown[0]->getMimeType())),
123
$module->translate(array('text' => 'WARNING: Cannot compress mime type %s',
124
'arg1' => $this->_itemsUnknown[0]->getMimeType()))));
125
$this->_expectResize = array('scale');
126
$this->_expectCompress = array('compress');
129
function testAppropriate() {
130
list ($ret, $appropriate) = $this->_option->isAppropriate($this->_album, null);
132
return $this->failWithStatus($ret);
134
$this->assert($appropriate, 'appropriate');
137
/* change dimensions, don't keep original */
138
function testChangeDimNoOriginal() {
140
$platform =& $gallery->getPlatform();
142
foreach (array('width' => 768, 'height' => 1024, 'keepOriginal' => 0) as $key => $value) {
143
$ret = GalleryCoreApi::setPluginParameter('module', 'sizelimit',
144
$key, $value, $this->_album->getId());
146
return $this->failWithStatus($ret);
149
list ($errors, $warnings) = $this->_handleRequestAfterAdd(array(), $this->_items);
150
$this->assertEquals($this->_noErrors, $errors);
151
$this->assertEquals($this->_noWarnings, $warnings);
153
list ($ret, $this->_items[0]) = $this->_items[0]->refresh();
155
return $this->failWithStatus($ret);
158
$this->assertEquals(768, $this->_items[0]->getWidth(), 'Width');
159
$this->assertEquals(1024, $this->_items[0]->getHeight(), 'Height');
160
$operation = GalleryUtilities::getRequestVariables('operation');
161
$this->assertEquals($this->_expectResize, $operation, 'operation');
162
$this->assertEquals(2, $this->_items[0]->getSerialNumber(), 'Serial Number');
163
$platform->clearstatcache();
164
$ret = $this->_items[0]->rescan();
166
return $this->failWithStatus($ret);
170
/* change dimensions on multiple items, don't keep originals */
171
function testMultipleChangeDimNoOriginal() {
173
$platform =& $gallery->getPlatform();
174
foreach (array('width' => 768, 'height' => 1024, 'keepOriginal' => 0) as $key => $value) {
175
$ret = GalleryCoreApi::setPluginParameter('module', 'sizelimit', $key, $value,
176
$this->_album->getId());
178
return $this->failWithStatus($ret);
183
for ($j = 1; $j < $totalTestItems; $j++) {
184
list ($ret, $this->_items[$j]) =
185
$this->_createRandomDataItem($this->_album->getId(), 'image/known',
186
array('summary' => "original summary $j",
187
'description' => "original description $j"));
189
return $this->failWithStatus($ret);
192
$this->_noWarnings[] = $this->_noWarnings[$j-1];
193
$this->_expectResize[] = $this->_expectResize[$j-1];
196
list ($errors, $warnings) = $this->_handleRequestAfterAdd(array(), $this->_items);
197
$this->assertEquals($this->_noErrors, $errors);
198
$this->assertEquals($this->_noWarnings, $warnings);
200
for ($j = 0; $j < $totalTestItems; $j++) {
201
list ($ret, $this->_items[$j]) = $this->_items[$j]->refresh();
203
return $this->failWithStatus($ret);
205
$this->assertEquals(768, $this->_items[$j]->getWidth(), "Width $j");
206
$this->assertEquals(1024, $this->_items[$j]->getHeight(), "Height $j");
207
$this->assertEquals(2, $this->_items[$j]->getSerialNumber(), "Serial Number $j");
208
$platform->clearstatcache();
209
$ret = $this->_items[$j]->rescan();
211
return $this->failWithStatus($ret);
214
$operation = GalleryUtilities::getRequestVariables('operation');
215
$this->assertEquals($this->_expectResize, $operation, 'operation');
218
/* change dimensions, keep original */
219
function testChangeDimKeepOriginal() {
222
foreach (array('width' => 768, 'height' => 1024, 'keepOriginal' => 1) as $key => $value) {
223
$ret = GalleryCoreApi::setPluginParameter('module', 'sizelimit',
224
$key, $value, $this->_album->getId());
226
return $this->failWithStatus($ret);
229
list ($errors, $warnings) = $this->_handleRequestAfterAdd(array(), $this->_items);
230
$this->assertEquals($this->_noErrors, $errors);
231
$this->assertEquals($this->_noWarnings, $warnings);
233
/* Check to see if we have a preferred source */
234
list ($ret, $resized) =
235
GalleryCoreApi::fetchPreferredSource($this->_items[0]);
237
return $this->failWithStatus($ret);
239
if (!GalleryUtilities::isExactlyA($resized, 'GalleryDerivativeImage')) {
240
return $this->failWithStatus($ret);
242
$ret = $resized->rebuildCache();
244
return $this->failWithStatus($ret);
246
$this->assertEquals(768, $resized->getWidth(), 'Width');
247
$this->assertEquals(1024, $resized->getHeight(), 'Height');
248
$operation = GalleryUtilities::getRequestVariables('operation');
249
$this->assertEquals($this->_expectResize, $operation, 'operation');
252
/* change dimensions on multiple items, keep originals */
253
function testMultipleChangeDimKeepOriginal() {
256
foreach (array('width' => 768, 'height' => 1024, 'keepOriginal' => 1) as $key => $value) {
257
$ret = GalleryCoreApi::setPluginParameter('module', 'sizelimit',
258
$key, $value, $this->_album->getId());
260
return $this->failWithStatus($ret);
265
for ($j = 1; $j < $totalTestItems; $j++) {
266
list ($ret, $this->_items[$j]) =
267
$this->_createRandomDataItem($this->_album->getId(), 'image/known',
268
array('summary' => "original summary $j",
269
'description' => "original description $j"));
271
return $this->failWithStatus($ret);
274
$this->_noWarnings[] = $this->_noWarnings[$j-1];
275
$this->_expectResize[] = $this->_expectResize[$j-1];
278
list ($errors, $warnings) = $this->_handleRequestAfterAdd(array(), $this->_items);
279
$this->assertEquals($this->_noErrors, $errors);
280
$this->assertEquals($this->_noWarnings, $warnings);
283
for ($j = 0; $j < $totalTestItems; $j++) {
284
/* Check to see if we have a preferred source */
285
list ($ret, $resized) =
286
GalleryCoreApi::fetchPreferredSource($this->_items[$j]);
288
return $this->failWithStatus($ret);
290
if (!GalleryUtilities::isExactlyA($resized, 'GalleryDerivativeImage')) {
291
return $this->assert(false, 'Not a derivative image');
293
$ret = $resized->rebuildCache();
295
return $this->failWithStatus($ret);
297
$this->assertEquals(768, $resized->getWidth(), 'Width');
298
$this->assertEquals(1024, $resized->getHeight(), 'Height');
300
$operation = GalleryUtilities::getRequestVariables('operation');
301
$this->assertEquals($this->_expectResize, $operation, 'operation');
304
/* change size, don't keep original */
305
function testChangeSizeNoOriginal() {
307
$platform =& $gallery->getPlatform();
309
foreach (array('size' => 1000, 'keepOriginal' => 0) as $key => $value) {
310
$ret = GalleryCoreApi::setPluginParameter('module', 'sizelimit',
311
$key, $value, $this->_album->getId());
313
return $this->failWithStatus($ret);
316
list ($errors, $warnings) = $this->_handleRequestAfterAdd(array(), $this->_items);
317
$this->assertEquals($this->_noErrors, $errors);
318
$this->assertEquals($this->_noWarnings, $warnings);
319
$platform->clearstatcache();
321
list ($ret, $this->_items[0]) = $this->_items[0]->refresh();
323
return $this->failWithStatus($ret);
326
/* check item size (in KB) */
327
$this->assertEquals(1000, $this->_items[0]->getSize(), 'Size');
328
$operation = GalleryUtilities::getRequestVariables('operation');
329
$this->assertEquals($this->_expectCompress, $operation, 'operation');
330
list ($ret, $preferred) =
331
GalleryCoreApi::fetchPreferredSource($this->_items[0]);
333
return $this->failWithStatus($ret);
335
$this->assertEquals($this->_items[0], $preferred, 'No preferred');
338
/* change size on multiple items, don't keep originals */
339
function testMultipleChangeSizeNoOriginal() {
341
$platform =& $gallery->getPlatform();
343
foreach (array('size' => 1000, 'keepOriginal' => 0) as $key => $value) {
344
$ret = GalleryCoreApi::setPluginParameter('module', 'sizelimit',
345
$key, $value, $this->_album->getId());
347
return $this->failWithStatus($ret);
352
for ($j = 1; $j < $totalTestItems; $j++) {
353
list ($ret, $this->_items[$j]) =
354
$this->_createRandomDataItem($this->_album->getId(), 'image/known',
355
array('summary' => "original summary $j",
356
'description' => "original description $j"));
358
return $this->failWithStatus($ret);
361
$this->_noWarnings[] = $this->_noWarnings[$j-1];
362
$this->_expectCompress[] = $this->_expectCompress[$j-1];
365
list ($errors, $warnings) = $this->_handleRequestAfterAdd(array(), $this->_items);
366
$this->assertEquals($this->_noErrors, $errors);
367
$this->assertEquals($this->_noWarnings, $warnings);
369
for ($j = 0; $j < $totalTestItems; $j++) {
370
$platform->clearstatcache();
372
list ($ret, $this->_items[$j]) = $this->_items[$j]->refresh();
374
return $this->failWithStatus($ret);
377
/* check item size (in KB) */
378
$this->assertEquals(1000, $this->_items[$j]->getSize(), 'Size');
379
list ($ret, $preferred) =
380
GalleryCoreApi::fetchPreferredSource($this->_items[$j]);
382
return $this->failWithStatus($ret);
384
$this->assertEquals($this->_items[$j], $preferred, 'No preferred');
386
$operation = GalleryUtilities::getRequestVariables('operation');
387
$this->assertEquals($this->_expectCompress, $operation, 'operation');
390
/* change size, keep original */
391
function testChangeSizeKeepOriginal() {
392
foreach (array('size' => 1000, 'keepOriginal' => 1) as $key => $value) {
393
$ret = GalleryCoreApi::setPluginParameter('module', 'sizelimit',
394
$key, $value, $this->_album->getId());
396
return $this->failWithStatus($ret);
399
list ($errors, $warnings) = $this->_handleRequestAfterAdd(array(), $this->_items);
400
$this->assertEquals($this->_noErrors, $errors);
401
$this->assertEquals($this->_noWarnings, $warnings);
403
/* Check to see if we have a preferred source */
404
list ($ret, $resized) =
405
GalleryCoreApi::fetchPreferredSource($this->_items[0]);
407
return $this->failWithStatus($ret);
409
if (!GalleryUtilities::isExactlyA($resized, 'GalleryDerivativeImage')) {
410
return $this->assert(false, 'Not a derivative');
412
$ret = $resized->rebuildCache();
414
return $this->failWithStatus($ret);
417
/* check derivative size */
418
$this->assertEquals(1000, $resized->getDerivativeSize(), 'Size');
419
$operation = GalleryUtilities::getRequestVariables('operation');
420
$this->assertEquals($this->_expectCompress, $operation, 'operation');
423
/* change size on multiple items, keep originals */
424
function testMultipleChangeSizeKeepOriginal() {
425
foreach (array('size' => 1000, 'keepOriginal' => 1) as $key => $value) {
426
$ret = GalleryCoreApi::setPluginParameter('module', 'sizelimit',
427
$key, $value, $this->_album->getId());
429
return $this->failWithStatus($ret);
434
for ($j = 1; $j < $totalTestItems; $j++) {
435
list ($ret, $this->_items[$j]) =
436
$this->_createRandomDataItem($this->_album->getId(), 'image/known',
437
array('summary' => "original summary $j",
438
'description' => "original description $j"));
440
return $this->failWithStatus($ret);
443
$this->_noWarnings[] = $this->_noWarnings[$j-1];
444
$this->_expectCompress[] = $this->_expectCompress[$j-1];
447
list ($errors, $warnings) = $this->_handleRequestAfterAdd(array(), $this->_items);
448
$this->assertEquals($this->_noErrors, $errors);
449
$this->assertEquals($this->_noWarnings, $warnings);
451
for ($j = 0; $j < $totalTestItems; $j++) {
452
/* Check to see if we have a preferred source */
453
list ($ret, $resized) =
454
GalleryCoreApi::fetchPreferredSource($this->_items[$j]);
456
return $this->failWithStatus($ret);
458
if (!GalleryUtilities::isExactlyA($resized, 'GalleryDerivativeImage')) {
459
return $this->assert(false, 'Not a derivative');
461
$ret = $resized->rebuildCache();
463
return $this->failWithStatus($ret);
466
/* check derivative size */
467
$this->assertEquals(1000, $resized->getDerivativeSize(), 'Size');
469
$operation = GalleryUtilities::getRequestVariables('operation');
470
$this->assertEquals($this->_expectCompress, $operation, 'operation');
473
/* change dimensions AND size, keep original */
474
function testChangeBothKeepOriginal() {
476
$platform =& $gallery->getPlatform();
477
$this->_expectResizeCompress = array_merge($this->_expectResize, $this->_expectCompress);
478
foreach (array('width' => 768, 'height' => 1024, 'size' => 1000, 'keepOriginal' => 1)
480
$ret = GalleryCoreApi::setPluginParameter('module', 'sizelimit',
481
$key, $value, $this->_album->getId());
483
return $this->failWithStatus($ret);
486
list ($errors, $warnings) = $this->_handleRequestAfterAdd(array(), $this->_items);
487
$this->assertEquals($this->_noErrors, $errors);
488
$this->assertEquals($this->_noWarnings, $warnings);
490
/* Check to see if we have a preferred source */
491
list ($ret, $resized) = GalleryCoreApi::fetchPreferredSource($this->_items[0]);
493
return $this->failWithStatus($ret);
495
if (!GalleryUtilities::isExactlyA($resized, 'GalleryDerivativeImage')) {
496
return $this->assert(false, 'Not a derivative');
498
$ret = $resized->rebuildCache();
500
return $this->failWithStatus($ret);
502
$this->assertEquals('scale|768,1024;compress|1000',
503
$resized->getDerivativeOperations(), 'Operations');
504
$this->assertEquals(768, $resized->getWidth(), 'Width');
505
$this->assertEquals(1024, $resized->getHeight(), 'Height');
506
$this->assertEquals(1000, $resized->getDerivativeSize(), 'Size');
507
$operation = GalleryUtilities::getRequestVariables('operation');
508
$this->assertEquals($this->_expectResizeCompress, $operation, 'operation');
511
/* change dimensions AND size on multiple items, keep originals */
512
function testMultipleChangeBothKeepOriginal() {
513
$this->_expectResizeCompress = array_merge($this->_expectResize, $this->_expectCompress);
514
foreach (array('width' => 768, 'height' => 1024, 'size' => 1000, 'keepOriginal' => 1)
516
$ret = GalleryCoreApi::setPluginParameter('module', 'sizelimit',
517
$key, $value, $this->_album->getId());
519
return $this->failWithStatus($ret);
524
for ($j = 1; $j < $totalTestItems; $j++) {
525
list ($ret, $this->_items[$j]) =
526
$this->_createRandomDataItem($this->_album->getId(), 'image/known',
527
array('summary' => "original summary $j",
528
'description' => "original description $j"));
530
return $this->failWithStatus($ret);
533
$this->_noWarnings[] = $this->_noWarnings[$j-1];
534
$this->_expectResizeCompress[] = $this->_expectResizeCompress[($j*2)-2];
535
$this->_expectResizeCompress[] = $this->_expectResizeCompress[($j*2)-1];
538
list ($errors, $warnings) = $this->_handleRequestAfterAdd(array(), $this->_items);
539
$this->assertEquals($this->_noErrors, $errors);
540
$this->assertEquals($this->_noWarnings, $warnings);
542
for ($j = 0; $j < $totalTestItems; $j++) {
543
/* Check to see if we have a preferred source */
544
list ($ret, $resized) = GalleryCoreApi::fetchPreferredSource($this->_items[$j]);
546
return $this->failWithStatus($ret);
548
if (!GalleryUtilities::isExactlyA($resized, 'GalleryDerivativeImage')) {
549
return $this->assert(false, 'Not a derivative');
551
$ret = $resized->rebuildCache();
553
return $this->failWithStatus($ret);
555
$this->assertEquals('scale|768,1024;compress|1000',
556
$resized->getDerivativeOperations(),
558
$this->assertEquals(768, $resized->getWidth(), 'Width');
559
$this->assertEquals(1024, $resized->getHeight(), 'Height');
560
$this->assertEquals(1000, $resized->getDerivativeSize(), 'Size');
562
$operation = GalleryUtilities::getRequestVariables('operation');
563
$this->assertEquals($this->_expectResizeCompress, $operation, 'operation');
566
/* change dimensions AND size, don't keep original */
567
function testChangeBothNoOriginal() {
569
$platform =& $gallery->getPlatform();
570
$this->_expectResizeCompress = array_merge($this->_expectResize, $this->_expectCompress);
571
foreach (array('width' => 768, 'height' => 1024, 'size' => 1000, 'keepOriginal' => 0)
573
$ret = GalleryCoreApi::setPluginParameter('module', 'sizelimit',
574
$key, $value, $this->_album->getId());
576
return $this->failWithStatus($ret);
579
list ($errors, $warnings) = $this->_handleRequestAfterAdd(array(), $this->_items);
580
$this->assertEquals($this->_noErrors, $errors);
581
$this->assertEquals($this->_noWarnings, $warnings);
583
list ($ret, $this->_items[0]) = $this->_items[0]->refresh();
585
return $this->failWithStatus($ret);
588
$this->assertEquals(768, $this->_items[0]->getWidth(), 'Width');
589
$this->assertEquals(1024, $this->_items[0]->getHeight(), 'Height');
590
$operation = GalleryUtilities::getRequestVariables('operation');
591
$this->assertEquals($this->_expectResizeCompress, $operation, 'operation');
592
$platform->clearstatcache();
593
$ret = $this->_items[0]->rescan();
595
return $this->failWithStatus($ret);
597
$this->assertEquals(1000, $this->_items[0]->getSize(), 'Size');
600
/* change dimensions AND size on multiple items, don't keep originals */
601
function testMultipleChangeBothNoOriginal() {
603
$platform =& $gallery->getPlatform();
604
$this->_expectResizeCompress = array_merge($this->_expectResize, $this->_expectCompress);
605
foreach (array('width' => 768, 'height' => 1024, 'size' => 1000, 'keepOriginal' => 0)
607
$ret = GalleryCoreApi::setPluginParameter('module', 'sizelimit',
608
$key, $value, $this->_album->getId());
610
return $this->failWithStatus($ret);
615
for ($j = 1; $j < $totalTestItems; $j++) {
616
list ($ret, $this->_items[$j]) =
617
$this->_createRandomDataItem($this->_album->getId(), 'image/known',
618
array('summary' => "original summary $j",
619
'description' => "original description $j"));
621
return $this->failWithStatus($ret);
624
$this->_noWarnings[] = $this->_noWarnings[$j-1];
625
$this->_expectResizeCompress[] = $this->_expectResizeCompress[($j*2)-2];
626
$this->_expectResizeCompress[] = $this->_expectResizeCompress[($j*2)-1];
629
list ($errors, $warnings) = $this->_handleRequestAfterAdd(array(), $this->_items);
630
$this->assertEquals($this->_noErrors, $errors);
631
$this->assertEquals($this->_noWarnings, $warnings);
633
for ($j = 0; $j < $totalTestItems; $j++) {
634
list ($ret, $item) = $this->_items[$j]->refresh();
636
return $this->failWithStatus($ret);
638
$this->assertEquals(768, $item->getWidth(), 'Width');
639
$this->assertEquals(1024, $item->getHeight(), 'Height');
640
$platform->clearstatcache();
641
$ret = $item->rescan();
643
return $this->failWithStatus($ret);
645
$this->assertEquals(1000, $item->getSize(), 'Size');
647
$operation = GalleryUtilities::getRequestVariables('operation');
648
$this->assertEquals($this->_expectResizeCompress, $operation, 'operation');
651
/* try to change size and dimensions for unsupported file format */
652
function testUnknownFormat() {
653
foreach (array('width' => 768, 'height' => 1024, 'size' => 1000, 'keepOriginal' => 0)
655
$ret = GalleryCoreApi::setPluginParameter('module', 'sizelimit',
656
$key, $value, $this->_album->getId());
658
return $this->failWithStatus($ret);
661
list ($errors, $warnings) = $this->_handleRequestAfterAdd(array(), $this->_itemsUnknown);
662
$this->assertEquals($this->_noErrors, $errors);
663
$this->assertEquals($this->_expectWarnings, $warnings);
666
/* try to change size and dimensions for unsupported file format on multiple files */
667
function testMultipleUnknownFormat() {
668
foreach (array('width' => 768, 'height' => 1024, 'size' => 1000, 'keepOriginal' => 0)
670
$ret = GalleryCoreApi::setPluginParameter('module', 'sizelimit',
671
$key, $value, $this->_album->getId());
673
return $this->failWithStatus($ret);
677
$singleExpectedWarning = $this->_expectWarnings[0];
680
for ($j = 1; $j < $totalTestItems; $j++) {
681
list ($ret, $this->_itemsUnknown[$j]) =
682
$this->_createRandomDataItem($this->_album->getId(), 'image/unknown',
683
array('summary' => "plagiarized summary $j",
684
'description' => "plagiarized description $j"));
686
return $this->failWithStatus($ret);
689
$this->_expectWarnings[] = $singleExpectedWarning;
692
list ($errors, $warnings) = $this->_handleRequestAfterAdd(array(), $this->_itemsUnknown);
693
$this->assertEquals($this->_noErrors, $errors);
694
$this->assertEquals($this->_expectWarnings, $warnings);
697
/* ensure no change when image is already smaller than limits (don't stretch) */
698
function testBelowLimits() {
699
foreach (array('width' => 1800, 'height' => 2400, 'size' => 30000, 'keepOriginal' => 0)
701
$ret = GalleryCoreApi::setPluginParameter('module', 'sizelimit',
702
$key, $value, $this->_album->getId());
704
return $this->failWithStatus($ret);
707
list ($errors, $warnings) = $this->_handleRequestAfterAdd(array(), $this->_items);
708
$this->assertEquals($this->_noErrors, $errors);
709
$this->assertEquals($this->_noWarnings, $warnings);
711
list ($ret, $this->_items[0]) = $this->_items[0]->refresh();
713
return $this->failWithStatus($ret);
716
$this->assertEquals(1728, $this->_items[0]->getWidth(), 'Width');
717
$this->assertEquals(2304, $this->_items[0]->getHeight(), 'Height');
718
$operation = GalleryUtilities::getRequestVariables('operation');
719
$this->assertEquals('', $operation, 'no operation');
720
$this->assertEquals(1, $this->_items[0]->getSerialNumber(), 'Serial Number');
723
/* change dimensions, delete larger resizes */
724
function testChangeDimDropResizes() {
726
$platform =& $gallery->getPlatform();
727
$id = $this->_items[0]->getId();
728
$item =& $this->_items[0];
730
/* Add resizes and a thumbnail, that is usually done before sizelimit does its job */
731
list ($ret, $thumbnail) = $this->_createDerivative($item, $id,
732
DERIVATIVE_TYPE_IMAGE_THUMBNAIL,
736
return $this->failWithStatus($ret);
739
list ($ret, $tooLargeResize) = $this->_createDerivative($item, $id,
740
DERIVATIVE_TYPE_IMAGE_RESIZE,
744
return $this->failWithStatus($ret);
746
list ($ret, $smallResize) = $this->_createDerivative($item, $id,
747
DERIVATIVE_TYPE_IMAGE_RESIZE,
751
return $this->failWithStatus($ret);
753
$ret = $this->_verifyEntity($tooLargeResize);
754
$this->assertEquals(null, $ret, 'verify large resize before test');
755
$ret = $this->_verifyEntity($smallResize);
756
$this->assertEquals(null, $ret, 'verify small resize before test');
757
$ret = $this->_verifyEntity($thumbnail);
758
$this->assertEquals(null, $ret, 'verify thumb before test');
760
/* Set the sizelimit settings for the album */
761
foreach (array('width' => 768, 'height' => 1024, 'keepOriginal' => 0) as $key => $value) {
762
$ret = GalleryCoreApi::setPluginParameter('module', 'sizelimit',
763
$key, $value, $this->_album->getId());
765
return $this->failWithStatus($ret);
768
/* Execute the test */
769
list ($errors, $warnings) = $this->_handleRequestAfterAdd(array(), array($item));
770
$this->assertEquals($this->_noErrors, $errors);
771
$this->assertEquals($this->_noWarnings, $warnings);
773
list ($ret, $item) = $item->refresh();
775
return $this->failWithStatus($ret);
778
$this->assertEquals(768, $item->getWidth(), 'Width');
779
$this->assertEquals(1024, $item->getHeight(), 'Height');
780
$operation = GalleryUtilities::getRequestVariables('operation');
781
$this->assertEquals($this->_expectResize, $operation, 'operation');
782
$this->assertEquals(2, $item->getSerialNumber(), 'Serial Number');
783
$platform->clearstatcache();
785
/* We should have a new thumb and one resize should be deleted */
786
$ret = $this->_verifyMissing($tooLargeResize->getId());
787
$this->assertEquals(null, $ret, 'verify missing large resize');
788
$ret = $this->_verifyEntity($smallResize);
789
$this->assertEquals(null, $ret, 'verify small resize');
790
$ret = $this->_verifyEntity($thumbnail);
791
$this->assertEquals(null, $ret, 'verify that the same thumb still exists');
792
list ($ret, $thumbTable) = GalleryCoreApi::fetchThumbnailsByItemIds(array($id));
794
return $this->failWithStatus($ret);
796
if (!empty($thumbTable[$id])) {
797
$this->assertEquals($thumbnail->getId(), $thumbTable[$id]->getId(),
798
'same old thumbnail');
800
$this->assert(false, 'no thumbnail for our item id after test');
809
* @subpackage PHPUnit
811
class SetSizeOptionTestPlatform extends GalleryPlatform {
813
function SetSizeOptionTestPlatform($originalPlatform) {
814
$this->_savedPlatform = $originalPlatform;
815
GalleryUtilities::putRequestVariable('resizePerformed', false);
816
GalleryUtilities::putRequestVariable('compressPerformed', false);
819
function filesize($file) {
820
$size = GalleryUtilities::getRequestVariables('size_' . basename($file));
827
function getimagesize($file) {
828
$imagesize = GalleryUtilities::getRequestVariables('imagesize_' . basename($file));
830
/* doing it this way keeps CodeAudit happy */
831
return array($imagesize[0], $imagesize[1]);
833
return array(1728, 2304);
836
function file_exists($filename) {
837
$compressPerformed = GalleryUtilities::getRequestVariables('compressPerformed');
838
$resizePerformed = GalleryUtilities::getRequestVariables('resizePerformed');
840
/* if we created a derivative make-believe that the file exists */
841
if ($resizePerformed || $compressPerformed) {
844
return $this->_savedPlatform->file_exists($filename);
848
function unlink($filename) {
849
/* if it is a derivative - we didn't really create it */
850
if ($this->_savedPlatform->file_exists($filename)) {
851
return $this->_savedPlatform->unlink($filename);
861
class SetSizeOptionTestToolkit extends GalleryToolkit {
863
* @see GalleryToolkit::performOperation
865
function performOperation($mimeType, $operationName, $sourceFilename,
866
$destFilename, $parameters, $context=array()) {
867
/* Here we are pretending that conversion happened by setting the flag */
868
switch($operationName) {
870
GalleryUtilities::putRequestVariable('compressPerformed', true);
871
GalleryUtilities::putRequestVariable('size_' . basename($destFilename), 1000);
875
GalleryUtilities::putRequestVariable('resizePerformed', true);
876
GalleryUtilities::putRequestVariable(
877
'imagesize_' . basename($destFilename), array(768, 1024));
882
array(GalleryCoreApi::error(ERROR_UNIMPLEMENTED), null, null);
885
$operations = array();
886
$operationRequest = GalleryUtilities::getRequestVariables('operation');
887
if (!empty($operationRequest)) {
888
$operations = $operationRequest;
890
$operations[] = $operationName;
891
GalleryUtilities::putRequestVariable('operation', $operations);
893
return array(null, $mimeType, $context);
897
* @see GalleryToolkit::getProperty
899
function getProperty($mimeType, $propertyName, $file) {
902
/* Our 'mime type' has to support dimensions */
903
switch($propertyName) {
905
$platform =& $gallery->getPlatform();
906
$results = $platform->getimagesize($file);
907
$results = array((int)$results[0], (int)$results[1]);
911
return array(GalleryCoreApi::error(ERROR_UNIMPLEMENTED), null);
914
return array(null, $results);