~ubuntu-branches/ubuntu/maverick/gallery2/maverick

« back to all changes in this revision

Viewing changes to modules/imagemagick/test/phpunit/ImageMagickToolkitTest.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/imagemagick/classes/ImageMagickToolkit.class');
22
 
 
23
 
/**
24
 
 * Test ImageMagickToolkit functionality
25
 
 * @package ImageMagick
26
 
 * @subpackage PHPUnit
27
 
 * @author Bharat Mediratta <bharat@menalto.com>
28
 
 * @version $Revision: 15513 $
29
 
 */
30
 
class ImageMagickToolkitTest extends GalleryTestCase {
31
 
 
32
 
    /*
33
 
     * The array with environment information, from ImEnvironments.inc
34
 
     */
35
 
    var $_environments = array();
36
 
 
37
 
    /*
38
 
     * The current environment array item we are processing
39
 
     */
40
 
    var $_currentEnvironment = array();
41
 
 
42
 
    /*
43
 
     * Information about files in our pseudo-platform.
44
 
     * Better would be to store the files information in the Platform, but
45
 
     * since Gallery::getPlatform() will return a copy of the platform, we
46
 
     * cannot keep them there.
47
 
     */
48
 
    var $_files = array();
49
 
 
50
 
    function ImageMagickToolkitTest($methodName) {
51
 
        $this->GalleryTestCase($methodName);
52
 
 
53
 
        /* Load our environments */
54
 
        include(dirname(__FILE__) . '/ImEnvironments.inc');
55
 
        $this->_environments = $imEnvironment;
56
 
    }
57
 
 
58
 
    function setUp() {
59
 
        global $gallery;
60
 
 
61
 
        parent::setUp();
62
 
 
63
 
        $ret = $this->_markPluginParametersForCleanup('module', 'imagemagick');
64
 
        if ($ret) {
65
 
            print $ret->getAsHtml();
66
 
            return $ret;
67
 
        }
68
 
 
69
 
        /* Reset to the defaults -- tearDown will undo this */
70
 
        foreach (array('jpegQuality' => 75) as $key => $value) {
71
 
            $ret = GalleryCoreApi::setPluginParameter('module', 'imagemagick', $key, $value);
72
 
            if ($ret) {
73
 
                print $ret->getAsHtml();
74
 
                return $this->failWithStatus($ret);
75
 
            }
76
 
        }
77
 
 
78
 
        $this->_platform = new ImageMagickToolkitTestPlatform($gallery->getPlatform(),
79
 
                                                              $this->_files, $this);
80
 
        $gallery->setPlatform($this->_platform);
81
 
 
82
 
        /* Get a toolkit to work with */
83
 
        $this->_toolkit =& new ImageMagickToolkit();
84
 
    }
85
 
 
86
 
    /**
87
 
     * Prepare to emulate a different version of IM/GM
88
 
     *
89
 
     * @param array $environment the array item of the environment
90
 
     * @access private
91
 
     */
92
 
    function _setEnvironment($environment) {
93
 
        $environment['path'] = '/' . $environment['name'] . $environment['version'] . '/';
94
 
 
95
 
        $ret = GalleryCoreApi::setPluginParameter('module', 'imagemagick',
96
 
                                                  'path', $environment['path']);
97
 
        if ($ret) {
98
 
            print $ret->getAsHtml();
99
 
            return $this->failWithStatus($ret);
100
 
        }
101
 
 
102
 
        $this->_currentEnvironment = $environment;
103
 
        $this->_platform->setEnvironment($environment);
104
 
 
105
 
        $ret = ImageMagickToolkitHelper::savePlatformParameters();
106
 
        if ($ret) {
107
 
            print $ret->getAsHtml();
108
 
            return $this->failWithStatus($ret);
109
 
        }
110
 
 
111
 
        return true;
112
 
    }
113
 
 
114
 
    function _envName() {
115
 
        return $this->_currentEnvironment['name'] . ' ' . $this->_currentEnvironment['version'];
116
 
    }
117
 
 
118
 
    /**
119
 
     * Helper to test a certain operation
120
 
     *
121
 
     * @param string $mimeType
122
 
     * @param string $operation
123
 
     * @param string $src filename
124
 
     * @param string $dst filename
125
 
     * @param array $params indexed array
126
 
     * @param array $namedParams assoc-array with paramName=>paramValue
127
 
     * @param string $quality (optional)
128
 
     * @return object GalleryStatus
129
 
     * @access private
130
 
     */
131
 
    function _testOperation($mimeType, $operation, $src, $dst, $params, $namedParams,
132
 
                            $quality=null) {
133
 
        $this->_chmodWasCalled = false;
134
 
        list ($ret, $outputMimeType) =
135
 
            $this->_toolkit->performOperation($mimeType, $operation,
136
 
                                              $src, $dst, $params);
137
 
        if ($ret) {
138
 
            return $ret;
139
 
        }
140
 
        $expected = $this->_currentEnvironment['operations'][$operation];
141
 
 
142
 
        if (in_array($mimeType, array('image/tiff', 'application/pdf', 'application/postscript'))) {
143
 
            if ($operation == 'select-page') {
144
 
                $src .= '[' . ($params[0] - 1) . ']';
145
 
            } else {
146
 
                $src .= '[0]';
147
 
            }
148
 
        } else if  ($mimeType == 'image/gif') {
149
 
            foreach (array_keys($expected) as $key) {
150
 
                if (is_int($i = array_search('%src%', $expected[$key]))) {
151
 
                    $expected[$key][$i] = '-deconstruct';
152
 
                }
153
 
                array_unshift($expected[$key], '-coalesce', '%src%');
154
 
            }
155
 
        }
156
 
 
157
 
        $search = array('|%src%|', '|%dst%|');
158
 
        $replace = array($src, $dst);
159
 
        foreach ($namedParams as $key => $value) {
160
 
            $search[] = sprintf('|%%%s%%|', $key);
161
 
            $replace[] = $value;
162
 
        }
163
 
        foreach (array_keys($expected) as $key) {
164
 
            $expected[$key] = preg_replace($search, $replace, $expected[$key]);
165
 
        }
166
 
 
167
 
        if ($outputMimeType == 'image/jpeg' || $outputMimeType == 'image/png') {
168
 
            if (!isset($quality)) {
169
 
                $quality = '75';
170
 
            }
171
 
            foreach (array_keys($expected) as $key) {
172
 
                $expected[$key] = array_merge(array('-quality', $quality), $expected[$key]);
173
 
            }
174
 
        }
175
 
 
176
 
        $this->assertEquals($expected, $this->_files[$dst]['operation'],
177
 
            $this->_currentEnvironment['path'] . " $operation " . implode(' ', $params));
178
 
        $this->assert($this->_chmodWasCalled, 'chmod not called');
179
 
 
180
 
        return null;
181
 
    }
182
 
 
183
 
    function testPerformOperations() {
184
 
        global $gallery;
185
 
        foreach ($this->_environments as $environment) {
186
 
            $this->_setEnvironment($environment);
187
 
 
188
 
            $ret = $this->_testOperation('image/gif', 'thumbnail',
189
 
                                         'test[1000x1000].gif', 'output.gif',
190
 
                                         array(100),
191
 
                                         array('width' => 100, 'height' => 100));
192
 
            if ($ret) {
193
 
                return $this->failWithStatus($ret);
194
 
            }
195
 
 
196
 
            $ret = $this->_testOperation('image/jpeg', 'thumbnail',
197
 
                                         'test[1000x1000].jpg', 'output.jpg',
198
 
                                         array(100),
199
 
                                         array('width' => 100, 'height' => 100));
200
 
            if ($ret) {
201
 
                return $this->failWithStatus($ret);
202
 
            }
203
 
 
204
 
            $ret = $this->_testOperation('image/tiff', 'rotate',
205
 
                                         'test.tiff', 'output.tiff',
206
 
                                         array(90), array('angle' => 90));
207
 
            if ($ret) {
208
 
                return $this->failWithStatus($ret);
209
 
            }
210
 
 
211
 
            $ret = $this->_testOperation('image/bmp', 'rotate',
212
 
                                         'test.bmp', 'output.bmp',
213
 
                                         array(180), array('angle' => 180));
214
 
            if ($ret) {
215
 
                return $this->failWithStatus($ret);
216
 
            }
217
 
 
218
 
            $ret = $this->_testOperation('image/png', 'crop',
219
 
                                         'test[640x480].png', 'output.png',
220
 
                                         array('24.667', '23.5', '51.375', '52'),
221
 
                                         array('width' => '329', 'height' => '250',
222
 
                                               'x' => '158', 'y' => '113'));
223
 
            if ($ret) {
224
 
                return $this->failWithStatus($ret);
225
 
            }
226
 
 
227
 
            $ret = $this->_testOperation('image/gif', 'convert-to-image/png',
228
 
                                         'test.gif', 'output.png',
229
 
                                         array(), array());
230
 
            if ($ret) {
231
 
                return $this->failWithStatus($ret);
232
 
            }
233
 
 
234
 
            $ret = $this->_testOperation('application/pdf', 'select-page',
235
 
                                         'test.pdf', 'output.pdf',
236
 
                                         array('2'), array());
237
 
            if ($ret) {
238
 
                return $this->failWithStatus($ret);
239
 
            }
240
 
 
241
 
            /* Test a basic composite operation (top right corner) */
242
 
            $dataDir = $gallery->getConfig('data.gallery.base');
243
 
            $ret = $this->_testOperation('image/png', 'composite',
244
 
                                         'test.png',   /* composite */
245
 
                                         'output.png', /* composited */
246
 
                                         array('image.gif', /* image */
247
 
                                               'image/gif', /* mimeType */
248
 
                                               5, 5, /* image width, height */
249
 
                                               'top-right', /* alignment type */
250
 
                                               0, 0),  /* image alignment (unused w/ 'top-right') */
251
 
                                         array('image' => $dataDir . 'image.gif',
252
 
                                               'width' => '50',
253
 
                                               'height' => '50',
254
 
                                               'x' => '45',
255
 
                                               'y' => '0'));
256
 
            if ($ret) {
257
 
                return $this->failWithStatus($ret);
258
 
            }
259
 
 
260
 
            /* Test another composite with out of range params that should get corrected */
261
 
            $ret = $this->_testOperation('image/png', 'composite',
262
 
                                         'test.png',   /* composite */
263
 
                                         'output.png', /* composited */
264
 
                                         array('image.gif', /* image */
265
 
                                               'image/gif', /* mimeType */
266
 
                                               50, 50, /* image width, height */
267
 
                                               'manual', /* alignment type */
268
 
                                               151, 151), /* image alignment x, y */
269
 
                                         array('image' => $dataDir . 'image.gif',
270
 
                                               'width' => '50',
271
 
                                               'height' => '50',
272
 
                                               'x' => '0',
273
 
                                               'y' => '0'));
274
 
            if ($ret) {
275
 
                return $this->failWithStatus($ret);
276
 
            }
277
 
 
278
 
            /* Test compress */
279
 
            $this->_files['compressMe.jpg']['size'] = 250 << 10;
280
 
            $this->_platform->_counter = 2;
281
 
            $ret = $this->_testOperation('image/jpeg', 'compress',
282
 
                                         'compressMe.jpg', 'compressed.jpg',
283
 
                                         array(150),
284
 
                                         array(), 58);
285
 
            if ($ret) {
286
 
                return $this->failWithStatus($ret);
287
 
            }
288
 
 
289
 
            if (in_array('image/jpeg-cmyk', $environment['mimeTypes'])) {
290
 
                $ret = $this->_testOperation('image/jpeg-cmyk', 'convert-to-image/jpeg',
291
 
                                             'cmyk.jpg', 'rgb.jpg',
292
 
                                             array(), array());
293
 
                if ($ret) {
294
 
                    return $this->failWithStatus($ret);
295
 
                }
296
 
            }
297
 
 
298
 
            list ($ret, $mimeType) =
299
 
                $this->_toolkit->performOperation('image/png', 'BOGUS',
300
 
                                                  'BOGUS',
301
 
                                                  'BOGUS',
302
 
                                                  array('BOGUS'));
303
 
 
304
 
            $this->assert($ret->getErrorCode() & ERROR_UNSUPPORTED_OPERATION, 'bad op');
305
 
 
306
 
        }
307
 
    }
308
 
 
309
 
    function testPercentParameters() {
310
 
        foreach ($this->_environments as $environment) {
311
 
            $this->_setEnvironment($environment);
312
 
 
313
 
            $ret = $this->_testOperation('image/gif', 'thumbnail',
314
 
                                         'test[1000x1000].gif', 'output.gif',
315
 
                                         array('15%'),
316
 
                                         array('width' => 150, 'height' => 150));
317
 
            if ($ret) {
318
 
                return $this->failWithStatus($ret);
319
 
            }
320
 
 
321
 
            $ret = $this->_testOperation('image/jpeg', 'scale',
322
 
                                         'test[1000x1000].jpg', 'output.jpg',
323
 
                                         array('50%', 400),
324
 
                                         array('width' => 500, 'height' => 400));
325
 
            if ($ret) {
326
 
                return $this->failWithStatus($ret);
327
 
            }
328
 
 
329
 
            $ret = $this->_testOperation('image/png', 'resize',
330
 
                                         'test[1000x1000].png', 'output.png',
331
 
                                         array('60%', '80%'),
332
 
                                         array('width' => 600, 'height' => 800));
333
 
            if ($ret) {
334
 
                return $this->failWithStatus($ret);
335
 
            }
336
 
        }
337
 
    }
338
 
 
339
 
    function testPngQuality() {
340
 
        $ret = GalleryCoreApi::setPluginParameter('module', 'imagemagick', 'jpegQuality', 94);
341
 
        if ($ret) {
342
 
            return $this->failWithStatus($ret);
343
 
        }
344
 
 
345
 
        foreach ($this->_environments as $environment) {
346
 
            $this->_setEnvironment($environment);
347
 
 
348
 
            /*
349
 
             * Make sure that PNG quality uses only the compression, not the filter
350
 
             * so our quality level (94) becomes compression (9) and filter (4).  We
351
 
             * change that in the toolkit to compression (9) and filter (5) for a result
352
 
             * of 95.  When we implement PNG quality correctly, we should change this back.
353
 
             */
354
 
            $ret = $this->_testOperation('image/png', 'rotate',
355
 
                                         'qualityTestIn.png', 'qualityTestOut.png',
356
 
                                         array(90), array('angle' => 90), 95);
357
 
            if ($ret) {
358
 
                return $this->failWithStatus($ret);
359
 
            }
360
 
        }
361
 
    }
362
 
 
363
 
    /**
364
 
     * Ensure multiple "convert" operations in sequence only makes one exec call.  Perform a
365
 
     * thumbnail followed by a crop.  This is not a commonly performed sequence; normally we do the
366
 
     * crop first, however that causes problems with some versions of ImageMagick, and this still
367
 
     * serves as a good test for our sequences.
368
 
     */
369
 
    function testOperationSequence() {
370
 
        $this->_platform->_copyOk = true;
371
 
 
372
 
        foreach ($this->_environments as $environment) {
373
 
            $this->_setEnvironment($environment);
374
 
            $context = array('next.toolkit' => $this->_toolkit, 'next.operation' => 'crop');
375
 
 
376
 
            list ($ret, $outputMimeType, $context) =
377
 
                $this->_toolkit->performOperation('image/png', 'thumbnail',
378
 
                                                  'test[640x480].png', 'outputTmp.png',
379
 
                                                  array('150'), $context);
380
 
            if ($ret) {
381
 
                return $this->failWithStatus($ret);
382
 
            }
383
 
 
384
 
            $this->assertEquals(array(), $this->_files, 'no exec yet ' . $this->_envName());
385
 
            $context['next.toolkit'] = null;
386
 
            $context['next.operation'] = null;
387
 
            $this->assertEquals(array('next.toolkit' => null, 'next.operation' => null,
388
 
                                      'width' => 150, 'height' => 113,
389
 
                                      'imagemagick.transform' => array_merge(
390
 
                                          array('-size', '150x150',
391
 
                                                '-geometry', '150x150'),
392
 
                                          $environment['removeMetaDataSwitch']),
393
 
                                      'imagemagick.mime' => 'image/png'),
394
 
                                $context, 'context after thumbnail ' . $this->_envName());
395
 
 
396
 
            list ($ret, $outputMimeType, $context) =
397
 
                $this->_toolkit->performOperation('image/png', 'crop',
398
 
                                                  'outputTmp.png', 'output.png',
399
 
                                                  array('24.667', '23.5', '51.375', '52'),
400
 
                                                  $context);
401
 
            if ($ret) {
402
 
                return $this->failWithStatus($ret);
403
 
            }
404
 
 
405
 
            $this->assertEquals(
406
 
                array_merge(
407
 
                    array('-quality', 75,
408
 
                          '-geometry', '150x150'),
409
 
                    $environment['removeMetaDataSwitch'],
410
 
                    array('-crop', '77x59+37+27'),
411
 
                    array('outputTmp.png', 'output.png')),
412
 
                $this->_files['output.png']['operation']['convert'], 'output ' . $this->_envName());
413
 
            $this->assertEquals(array('next.toolkit' => null, 'next.operation' => null,
414
 
                                      'width' => 77, 'height' => 59),
415
 
                                $context, 'context at end ' . $this->_envName());
416
 
 
417
 
            unset($this->_files['output.png']);
418
 
        }
419
 
    }
420
 
 
421
 
    /**
422
 
     * Some versions of ImageMagick bomb if you do a -crop followed by a -geometry.  See the
423
 
     * comment in the mock platform for more details.  So make sure that these are NOT done in a
424
 
     * single operation.
425
 
     */
426
 
    function testOperationSequenceCropAndGeometrySeparate() {
427
 
        $this->_platform->_copyOk = true;
428
 
 
429
 
        foreach ($this->_environments as $environment) {
430
 
            $this->_setEnvironment($environment);
431
 
            $context = array('next.toolkit' => $this->_toolkit, 'next.operation' => 'thumbnail');
432
 
 
433
 
            list ($ret, $outputMimeType, $context) =
434
 
                $this->_toolkit->performOperation('image/png', 'crop',
435
 
                                                  'test[640x480].png', 'output1.png',
436
 
                                                  array('24.667', '23.5', '51.375', '52'),
437
 
                                                  $context);
438
 
            if ($ret) {
439
 
                return $this->failWithStatus($ret);
440
 
            }
441
 
 
442
 
            $this->assertEquals(
443
 
                array_merge(
444
 
                    array('-quality', 75, '-crop', '329x250+158+113'),
445
 
                    array('test[640x480].png', 'output1.png')),
446
 
                $this->_files['output1.png']['operation']['convert'], 'output ' .
447
 
                $this->_envName());
448
 
            $this->assertEquals(array('next.toolkit' => $this->_toolkit,
449
 
                                      'next.operation' => 'thumbnail',
450
 
                                      'width' => 329, 'height' => 250),
451
 
                                $context, 'context after crop ' . $this->_envName());
452
 
 
453
 
            $context['next.toolkit'] = null;
454
 
            $context['next.operation'] = null;
455
 
 
456
 
            list ($ret, $outputMimeType, $context) =
457
 
                $this->_toolkit->performOperation('image/png', 'thumbnail',
458
 
                                                  'output1.png', 'output.png',
459
 
                                                  array('150'), $context);
460
 
            if ($ret) {
461
 
                return $this->failWithStatus($ret);
462
 
            }
463
 
 
464
 
            $this->assertEquals(
465
 
                array_merge(
466
 
                    array('-quality', 75, '-size', '150x150', '-geometry', '150x150'),
467
 
                    $environment['removeMetaDataSwitch'],
468
 
                    array('output1.png', 'output.png')),
469
 
                $this->_files['output.png']['operation']['convert'], 'output ' . $this->_envName());
470
 
            $this->assertEquals(array('next.toolkit' => null, 'next.operation' => null,
471
 
                                      'width' => 150, 'height' => 114),
472
 
                                $context, 'context at end ' . $this->_envName());
473
 
 
474
 
            unset($this->_files['output1.png']);
475
 
            unset($this->_files['output.png']);
476
 
        }
477
 
    }
478
 
 
479
 
    /**
480
 
     * Ensure queued operations that affect image size are taken into account
481
 
     * for subsequent operations..
482
 
     */
483
 
    function testOperationSequenceSizeChange() {
484
 
        $this->_platform->_copyOk = true;
485
 
 
486
 
        foreach ($this->_environments as $environment) {
487
 
            $this->_setEnvironment($environment);
488
 
            $context = array('next.toolkit' => $this->_toolkit, 'next.operation' => 'rotate',
489
 
                             'width' => 640, 'height' => 480);
490
 
 
491
 
            list ($ret, $outputMimeType, $context) =
492
 
                $this->_toolkit->performOperation('image/png', 'resize',
493
 
                                                  'test.png', 'output.png',
494
 
                                                  array('320', '240'),
495
 
                                                  $context);
496
 
            if ($ret) {
497
 
                return $this->failWithStatus($ret);
498
 
            }
499
 
 
500
 
            $this->assertEquals(array(), $this->_files, 'no exec yet ' . $this->_envName());
501
 
            $this->assertEquals(array('next.toolkit' => $this->_toolkit,
502
 
                                      'next.operation' => 'rotate',
503
 
                                      'width' => 320, 'height' => 240,
504
 
                                      'imagemagick.transform' => array(
505
 
                                          '-size', '320x240',
506
 
                                          '-geometry', '320x240'
507
 
                                          ),
508
 
                                      'imagemagick.mime' => 'image/png'),
509
 
                                $context, 'context after scale ' . $this->_envName());
510
 
            $context['next.operation'] = 'thumbnail';
511
 
 
512
 
            list ($ret, $outputMimeType, $context) =
513
 
                $this->_toolkit->performOperation('image/png', 'rotate',
514
 
                                                  'output.png', 'output.png',
515
 
                                                  array('90'), $context);
516
 
            if ($ret) {
517
 
                return $this->failWithStatus($ret);
518
 
            }
519
 
 
520
 
            $context['next.toolkit'] = null;
521
 
            $context['next.operation'] = null;
522
 
            $this->assertEquals(array(), $this->_files, 'still no exec ' . $this->_envName());
523
 
            $this->assertEquals(array('next.toolkit' => null, 'next.operation' => null,
524
 
                                      'width' => 240, 'height' => 320,
525
 
                                      'imagemagick.transform' =>
526
 
                                            array('-geometry', '320x240', '-rotate', '90'),
527
 
                                      'imagemagick.mime' => 'image/png'),
528
 
                                $context, 'context after rotate ' . $this->_envName());
529
 
 
530
 
            list ($ret, $outputMimeType, $context) =
531
 
                $this->_toolkit->performOperation('image/png', 'thumbnail',
532
 
                                                  'output.png', 'output.png',
533
 
                                                  array('150'), $context);
534
 
            if ($ret) {
535
 
                return $this->failWithStatus($ret);
536
 
            }
537
 
 
538
 
            $this->assertEquals(array_merge(
539
 
                array('-quality', '75',
540
 
                      '-geometry', '320x240',
541
 
                      '-rotate', '90',
542
 
                      '-geometry', '150x150'),
543
 
                $environment['removeMetaDataSwitch'],
544
 
                array('output.png', 'output.png')),
545
 
                $this->_files['output.png']['operation']['convert'], 'output ' . $this->_envName());
546
 
            $this->assertEquals(array('next.toolkit' => null, 'next.operation' => null,
547
 
                                      'width' => 113, 'height' => 150),
548
 
                                $context, 'context at end ' . $this->_envName());
549
 
 
550
 
            unset($this->_files['output.png']);
551
 
        }
552
 
    }
553
 
 
554
 
    /* Ensure queued operations handle change of mime type correctly */
555
 
    function testOperationSequenceMimeChange() {
556
 
        $this->_platform->_copyOk = true;
557
 
 
558
 
        foreach ($this->_environments as $environment) {
559
 
            $this->_setEnvironment($environment);
560
 
            $context = array('next.toolkit' => $this->_toolkit, 'next.operation' => 'thumbnail');
561
 
 
562
 
            list ($ret, $outputMimeType, $context) =
563
 
                $this->_toolkit->performOperation('application/pdf', 'convert-to-image/jpeg',
564
 
                                                  'test.pdf', 'TEMPFILE', array(), $context);
565
 
            if ($ret) {
566
 
                return $this->failWithStatus($ret);
567
 
            }
568
 
 
569
 
            $context['next.toolkit'] = null;
570
 
            $context['next.operation'] = null;
571
 
            $this->assertEquals(array(), $this->_files, 'no exec yet ' . $this->_envName());
572
 
            $this->assertEquals(array('next.toolkit' => null, 'next.operation' => null,
573
 
                                      'width' => '612', 'height' => '792',
574
 
                                      'imagemagick.transform' => array(),
575
 
                                      'imagemagick.mime' => 'application/pdf'),
576
 
                                $context, 'context after convert ' . $this->_envName());
577
 
            $this->assertEquals('image/jpeg', $outputMimeType, 'jpeg ' . $this->_envName());
578
 
 
579
 
            list ($ret, $outputMimeType, $context) =
580
 
                $this->_toolkit->performOperation('image/jpeg', 'thumbnail',
581
 
                                                  'TEMPFILE', 'output.jpg',
582
 
                                                  array('150'), $context);
583
 
            if ($ret) {
584
 
                return $this->failWithStatus($ret);
585
 
            }
586
 
 
587
 
            $this->assertEquals(array_merge(
588
 
                array('-quality', '75', '-size', '150x150', '-geometry', '150x150'),
589
 
                $environment['removeMetaDataSwitch'],
590
 
                array('TEMPFILE[0]', 'jpeg:output.jpg')),
591
 
                $this->_files['output.jpg']['operation']['convert'], 'output ' . $this->_envName());
592
 
            $this->assertEquals(array('next.toolkit' => null, 'next.operation' => null,
593
 
                                      'width' => 116, 'height' => 150),
594
 
                                $context, 'context at end ' . $this->_envName());
595
 
 
596
 
            unset($this->_files['output.jpg']);
597
 
        }
598
 
    }
599
 
 
600
 
 
601
 
    function testGetProperties() {
602
 
        foreach ($this->_environments as $environment) {
603
 
            $this->_setEnvironment($environment);
604
 
 
605
 
            list ($ret, $results) =
606
 
                $this->_toolkit->getProperty('image/gif', 'dimensions', 'test[10x20].gif');
607
 
            if ($ret) {
608
 
                return $this->failWithStatus($ret);
609
 
            }
610
 
            $this->assertEquals(array(10, 20), $results, 'dimensions ' . $this->_envName());
611
 
 
612
 
            list ($ret, $results) =
613
 
                $this->_toolkit->getProperty('application/pdf', 'page-count', 'test.pdf');
614
 
            if ($ret) {
615
 
                return $this->failWithStatus($ret);
616
 
            }
617
 
            $this->assertEquals(array(2), $results, 'page-count ' . $this->_envName());
618
 
 
619
 
            if (in_array('image/jpeg-cmyk', $environment['mimeTypes'])) {
620
 
                list ($ret, $results) =
621
 
                    $this->_toolkit->getProperty('image/jpeg', 'colorspace', 'cmyk.jpg');
622
 
                if ($ret) {
623
 
                    return $this->failWithStatus($ret);
624
 
                }
625
 
                $this->assertEquals(array('CMYK'), $results, 'colorspace ' . $this->_envName());
626
 
            }
627
 
 
628
 
            list ($ret, $results) =
629
 
                $this->_toolkit->getProperty('image/gif', 'BOGUS', 'BOGUS');
630
 
            $this->assert($ret->getErrorCode() & ERROR_UNIMPLEMENTED,
631
 
                          'bad op ' . $this->_envName());
632
 
        }
633
 
    }
634
 
 
635
 
    function testMergeOperations() {
636
 
        list ($success, $operation, $args) =
637
 
            $this->_toolkit->mergeOperations('crop', array(1, 2, 3, 4), 'crop', array(3, 4, 5, 6));
638
 
        $this->assert($success);
639
 
        $this->assertEquals('crop', $operation);
640
 
        $this->assertEquals(array(3, 4, 5, 6), $args);
641
 
 
642
 
        list ($success, $operation, $args) =
643
 
            $this->_toolkit->mergeOperations('resize', array(1, 2), 'resize', array(3, 4));
644
 
        $this->assert($success);
645
 
        $this->assertEquals('resize', $operation);
646
 
        $this->assertEquals(array(3, 4), $args);
647
 
 
648
 
        list ($success, $operation, $args) =
649
 
            $this->_toolkit->mergeOperations('thumbnail', array(1, 2), 'resize', array(3, 4));
650
 
        $this->assert($success);
651
 
        $this->assertEquals('resize', $operation);
652
 
        $this->assertEquals(array(3, 4), $args);
653
 
 
654
 
        list ($success, $operation, $args) =
655
 
            $this->_toolkit->mergeOperations('thumbnail', array(1, 2), 'thumbnail', array(3, 4));
656
 
        $this->assert($success);
657
 
        $this->assertEquals('thumbnail', $operation);
658
 
        $this->assertEquals(array(3, 4), $args);
659
 
 
660
 
        list ($success, $operation, $args) =
661
 
            $this->_toolkit->mergeOperations('scale', array(1, 2), 'thumbnail', array(3, 4));
662
 
        $this->assert($success);
663
 
        $this->assertEquals('thumbnail', $operation);
664
 
        $this->assertEquals(array(3, 4), $args);
665
 
 
666
 
        list ($success, $operation, $args) =
667
 
            $this->_toolkit->mergeOperations('rotate', array(90), 'rotate', array(90));
668
 
        $this->assert($success);
669
 
        $this->assertEquals('rotate', $operation);
670
 
        $this->assertEquals(array(180), $args);
671
 
 
672
 
        list ($success, $operation, $args) =
673
 
            $this->_toolkit->mergeOperations('rotate', array(90), 'rotate', array(-90));
674
 
        $this->assert($success);
675
 
        $this->assertEquals(null, $operation);
676
 
        $this->assertEquals(null, $args);
677
 
 
678
 
        list ($success, $operation, $args) =
679
 
            $this->_toolkit->mergeOperations('rotate', array(270), 'rotate', array(180));
680
 
        $this->assert($success);
681
 
        $this->assertEquals('rotate', $operation);
682
 
        $this->assertEquals(array(90), $args);
683
 
 
684
 
        list ($success, $operation, $args) =
685
 
            $this->_toolkit->mergeOperations('rotate', array(90), 'rotate', array(-180));
686
 
        $this->assert($success);
687
 
        $this->assertEquals('rotate', $operation);
688
 
        $this->assertEquals(array(-90), $args);
689
 
 
690
 
        list ($success, $operation, $args) =
691
 
            $this->_toolkit->mergeOperations('rotate', array(90), 'rotate', array(180));
692
 
        $this->assert($success);
693
 
        $this->assertEquals('rotate', $operation);
694
 
        $this->assertEquals(array(-90), $args);
695
 
 
696
 
        list ($success, $operation, $args) =
697
 
            $this->_toolkit->mergeOperations('rotate', array(270), 'rotate', array(90));
698
 
        $this->assert($success);
699
 
        $this->assertEquals(null, $operation);
700
 
        $this->assertEquals(null, $args);
701
 
 
702
 
        list ($success, $operation, $args) =
703
 
            $this->_toolkit->mergeOperations('crop', array(1, 2, 3, 4), 'thumbnail', array(3, 4));
704
 
        $this->assert(!$success);
705
 
    }
706
 
 
707
 
    function testDiscoverMimeTypes() {
708
 
        foreach ($this->_environments as $environment) {
709
 
            $this->_setEnvironment($environment);
710
 
 
711
 
            list ($ret, $results) =
712
 
                ImageMagickToolkitHelper::discoverMimeTypes($this->_currentEnvironment['path']);
713
 
            if ($ret) {
714
 
                return $this->failWithStatus($ret);
715
 
            }
716
 
            $this->assertEquals($environment['mimeTypes'], $results);
717
 
        }
718
 
    }
719
 
 
720
 
    function testGetOperationsAndProperties() {
721
 
        foreach ($this->_environments as $environment) {
722
 
            $this->_setEnvironment($environment);
723
 
 
724
 
            list ($ret, $results) = ImageMagickToolkitHelper::getOperationsAndProperties();
725
 
            if ($ret) {
726
 
                return $this->failWithStatus($ret);
727
 
            }
728
 
 
729
 
            $canConvert = array();
730
 
            foreach (array('image/jpeg', 'image/png', 'image/gif', 'image/tiff', 'image/jp2')
731
 
                     as $mimeType) {
732
 
                if (is_int($i = array_search($mimeType, $environment['mimeTypes']))) {
733
 
                    $convertTo = array_merge(
734
 
                        $environment['mimeTypes'], array('image/x-portable-pixmap'));
735
 
                    array_splice($convertTo, $i, 1);
736
 
                    $canConvert['convert-to-' . $mimeType] = array(
737
 
                        'params' => array(),
738
 
                        'description' => 'Convert to ' . $mimeType,
739
 
                        'mimeTypes' => $convertTo,
740
 
                        'outputMimeType' => $mimeType);
741
 
                }
742
 
            }
743
 
            $wantToPage = array('image/tiff', 'application/pdf',
744
 
                                'application/postscript', 'application/photoshop');
745
 
            $canPage = array_intersect($wantToPage, $environment['mimeTypes']);
746
 
            $qualityMimeTypes = array_intersect(array('image/jpeg', 'image/png'),
747
 
                                                $environment['mimeTypes']);
748
 
 
749
 
            $this->assertEquals(array_merge($canConvert, array(
750
 
                'scale' => array(
751
 
                    'params' => array(
752
 
                        array(
753
 
                            'type' => 'int',
754
 
                            'description' => 'target width (# pixels or #% of full size)'),
755
 
                        array(
756
 
                            'type' => 'int',
757
 
                            'description' => '(optional) target height, defaults to same as width')
758
 
                    ),
759
 
                    'description' => 'Scale the image to the target size, maintain aspect ratio',
760
 
                    'mimeTypes' => $environment['mimeTypes'],
761
 
                ),
762
 
                'thumbnail' => array(
763
 
                    'params' => array(
764
 
                        array(
765
 
                            'type' => 'int',
766
 
                            'description' => 'target width (# pixels or #% of full size)'),
767
 
                        array(
768
 
                            'type' => 'int',
769
 
                            'description' => '(optional) target height, defaults to same as width')
770
 
                    ),
771
 
                    'description' => 'Scale the image to the target size, maintain aspect ratio',
772
 
                    'mimeTypes' => $environment['mimeTypes'],
773
 
                ),
774
 
                'resize' => array(
775
 
                    'params' => array(
776
 
                        array(
777
 
                            'type' => 'int',
778
 
                            'description' => 'target width (# pixels or #% of full size)'),
779
 
                        array(
780
 
                            'type' => 'int',
781
 
                            'description' => 'target height (# pixels or #% of full size)')
782
 
                    ),
783
 
                    'description' => 'Resize the image to the target dimensions',
784
 
                    'mimeTypes' => $environment['mimeTypes'],
785
 
                ),
786
 
                'rotate' => array(
787
 
                    'params' => array(
788
 
                        array(
789
 
                            'type' => 'int',
790
 
                            'description' => 'rotation degrees')
791
 
                    ),
792
 
                    'description' => 'Rotate the image',
793
 
                    'mimeTypes' => $environment['mimeTypes'],
794
 
                ),
795
 
                'crop' => array(
796
 
                    'params' => array(
797
 
                        array(
798
 
                            'type' => 'float',
799
 
                            'description' => 'left edge %'),
800
 
                        array(
801
 
                            'type' => 'float',
802
 
                            'description' => 'top edge %'),
803
 
                        array(
804
 
                            'type' => 'float',
805
 
                            'description' => 'width %'),
806
 
                        array(
807
 
                            'type' => 'float',
808
 
                            'description' => 'height %')
809
 
                    ),
810
 
                    'description' => 'Crop the image',
811
 
                    'mimeTypes' => $environment['mimeTypes'],
812
 
                ),
813
 
                'composite' => array(
814
 
                    'params' => array(
815
 
                        array(
816
 
                            'type' => 'string',
817
 
                            'description' => 'overlay path'),
818
 
                        array(
819
 
                            'type' => 'string',
820
 
                            'description' => 'overlay mime type'),
821
 
                        array(
822
 
                            'type' => 'int',
823
 
                            'description' => 'overlay width'),
824
 
                        array(
825
 
                            'type' => 'int',
826
 
                            'description' => 'overlay height'),
827
 
                        array(
828
 
                            'type' => 'string',
829
 
                            'description' => 'alignment type'),
830
 
                        array(
831
 
                            'type' => 'int',
832
 
                            'description' => 'alignment x %'),
833
 
                        array(
834
 
                            'type' => 'int',
835
 
                            'description' => 'alignment y %'),
836
 
                    ),
837
 
                    'description' => 'Overlay source image with a second one',
838
 
                    'mimeTypes' => $environment['mimeTypes'],
839
 
                ),
840
 
                'select-page' => array(
841
 
                    'params' => array(
842
 
                        array(
843
 
                            'type' => 'int',
844
 
                            'description' => 'page number'),
845
 
                    ),
846
 
                    'description' => 'Select a single page from a multi-page file',
847
 
                    'mimeTypes' => $canPage,
848
 
                ),
849
 
                'compress' => array(
850
 
                    'params' => array(
851
 
                        array(
852
 
                            'type' => 'int',
853
 
                            'description' => 'target size in kb')
854
 
                    ),
855
 
                    'description' => 'Reduce image quality to reach target file size',
856
 
                    'mimeTypes' => $qualityMimeTypes
857
 
                ),
858
 
            )), $results['operations'], $this->_envName());
859
 
 
860
 
            $properties = array(
861
 
                'dimensions' => array(
862
 
                    'type' => 'int,int',
863
 
                    'description' => 'Get the width and height of the image',
864
 
                    'mimeTypes' => array_merge(
865
 
                        $environment['mimeTypes'],
866
 
                        array('image/x-portable-pixmap', 'application/x-shockwave-flash'))
867
 
                ),
868
 
                'page-count' => array(
869
 
                    'type' => 'int',
870
 
                    'description' => 'Get the number of pages',
871
 
                    'mimeTypes' => $canPage
872
 
                ),
873
 
            );
874
 
            if (in_array('image/jpeg-cmyk', $environment['mimeTypes'])) {
875
 
                $properties['colorspace'] = array(
876
 
                    'type' => 'string',
877
 
                    'description' => 'Get the colorspace of the image',
878
 
                    'mimeTypes' => array('image/jpeg', 'image/tiff', 'application/photoshop')
879
 
                );
880
 
            }
881
 
            $this->assertEquals($properties, $results['properties'], $this->_envName());
882
 
        }
883
 
    }
884
 
 
885
 
    function testBinaries() {
886
 
        foreach ($this->_environments as $environment) {
887
 
            $this->_setEnvironment($environment);
888
 
 
889
 
            list ($ret, $results) =
890
 
                ImageMagickToolkitHelper::testBinaries($this->_currentEnvironment['path']);
891
 
            if ($ret) {
892
 
                return $this->failWithStatus($ret);
893
 
            }
894
 
 
895
 
            $wanted = array('identify', 'convert', 'combine', 'composite');
896
 
            $expected = array();
897
 
            foreach ($wanted as $binary) {
898
 
                if (in_array($binary, $this->_currentEnvironment['binaries'])) {
899
 
                    $expected[] = array('name' => $binary, 'success' => true);
900
 
                }
901
 
            }
902
 
 
903
 
            $this->assertEquals($expected, $results);
904
 
        }
905
 
 
906
 
        list ($ret, $results) = ImageMagickToolkitHelper::testBinaries('/bogusPath');
907
 
        $this->assert($ret->getErrorCode() & ERROR_BAD_PATH);
908
 
    }
909
 
}
910
 
 
911
 
/**
912
 
 * Test platform
913
 
 *
914
 
 * @package ImageMagick
915
 
 * @subpackage PHPUnit
916
 
 */
917
 
class ImageMagickToolkitTestPlatform {
918
 
 
919
 
    var $_environment = array();
920
 
    var $_files;
921
 
 
922
 
    function ImageMagickToolkitTestPlatform($originalPlatform, &$files, &$test) {
923
 
        $this->_platform = $originalPlatform;
924
 
        $this->_files =& $files;
925
 
        $this->_test =& $test;
926
 
    }
927
 
 
928
 
    function setEnvironment($environment) {
929
 
        $this->_environment = $environment;
930
 
    }
931
 
 
932
 
    function exec($cmd) {
933
 
        list ($ret, $imageMagickPath) =
934
 
            GalleryCoreApi::getPluginParameter('module', 'imagemagick', 'path');
935
 
        if ($ret) {
936
 
            return array($ret, null);
937
 
        }
938
 
 
939
 
        $firstCmd = $cmd[0];
940
 
        if ($this->_environment['binary'] != '') {
941
 
            if (basename($firstCmd[0]) != $this->_environment['binary']) {
942
 
                return array(0, array('unprepared for exec()'));
943
 
            }
944
 
            array_shift($firstCmd);
945
 
        }
946
 
 
947
 
        $output = array();
948
 
        $status = false;
949
 
 
950
 
        $binary = array_shift($firstCmd);
951
 
        $binary = basename($binary);
952
 
        if ($binary == 'identify') {
953
 
            $file = basename(array_shift($firstCmd));
954
 
            $data = $this->_environment['identify'];
955
 
            if ($file == '-format' && count($firstCmd) >= 2) {
956
 
                /* Cmd to identify colorspace */
957
 
                $data = $data['-format'];
958
 
                $file = basename($firstCmd[1]);
959
 
                if (isset($this->_files[$file]['operation']['convert'][0]) &&
960
 
                        $this->_files[$file]['operation']['convert'][0] == '-colorspace') {
961
 
                    $file = 'rgb_file';
962
 
                }
963
 
            }
964
 
            if (isset($data[$file])) {
965
 
                $output = split("\n", $data[$file]);
966
 
            } else {
967
 
                $output = split("\n", $this->_environment['identify']['UNKNOWN']);
968
 
            }
969
 
            $status = true;
970
 
        } else if (($binary == 'convert' && in_array('convert', $this->_environment['binaries']))
971
 
                   || ($binary == 'composite' && in_array('composite',
972
 
                                                          $this->_environment['binaries']))
973
 
                   || ($binary == 'combine' && in_array('combine',
974
 
                                                        $this->_environment['binaries'])) ) {
975
 
            $params = array_slice($firstCmd, 0);
976
 
            $src = basename($firstCmd[count($firstCmd) - 2]);
977
 
            $dst = basename($firstCmd[count($firstCmd) - 1]);
978
 
            if (preg_match('#(.*):(.*)$#', $dst, $matches)) {
979
 
                /* Format 'jpeg:filename.jpg' */
980
 
                $dst = $matches[2];
981
 
            }
982
 
            if ($src == 'testProfile.jpg') {
983
 
                /* ImageMagickToolkitHelper is testing our removeMetaDataSwitch */
984
 
                $params = array_slice($firstCmd, 0, count($firstCmd) - 2);
985
 
                if ($this->_environment['removeMetaDataSwitch'] == $params) {
986
 
                    $this->_files[$dst] = array('size' => 50000);
987
 
                } else {
988
 
                    $this->_files[$dst] = array('size' => 0);
989
 
                }
990
 
                $output = array();
991
 
                $status = true;
992
 
            } else {
993
 
                /*
994
 
                 * ImageMagick 6.1.6 has a bug where if you do -crop followed by -geometry it
995
 
                 * gets confused about the size of the image and the -geometry check applies
996
 
                 * to the original dimensions, instead of the new, cropped dimensions.  This
997
 
                 * can result it in it returning "convert: geometry does not contain image"
998
 
                 * and a 0x0 pixel image.
999
 
                 *
1000
 
                 * I haven't verified that 6.1.3 does this also, but since we don't have a
1001
 
                 * 6.1.6 ImEnvironment yet, I'll credit this bug to 6.1.3 for now.
1002
 
                 */
1003
 
                if ($this->_environment['version'] == '6.1.3' &&
1004
 
                    preg_match('/crop.*geometry/', join(' ', $params))) {
1005
 
                    /*
1006
 
                     * Note: This doesn't exactly simulate what IM does.  It will continue like
1007
 
                     * everything is normal.  We just force the test to fail for now.
1008
 
                     */
1009
 
                    $output = array('convert: geometry does not contain image');
1010
 
                    $status = false;
1011
 
                    print 'Error: invalid -crop followed by -geometry in same convert command!';
1012
 
                } else {
1013
 
                    /*
1014
 
                     * Remember how we converted from $src to $dst, so we can compare it later
1015
 
                     * with what we really wanted
1016
 
                     */
1017
 
                    $this->_files[$dst] = array('operation' => array($binary => $params));
1018
 
                    $output = array();
1019
 
                    $status = true;
1020
 
                }
1021
 
            }
1022
 
        }
1023
 
 
1024
 
        if ($status) {
1025
 
            return array(1, $output);
1026
 
        }
1027
 
        echo $this->_environment['path'] . ": ERROR exec()ing:<pre>";
1028
 
        print_r($cmd);
1029
 
        echo "</pre>\n";
1030
 
        return array(0, array('unprepared for exec()'));
1031
 
    }
1032
 
 
1033
 
    function rename($oldName, $newName) {
1034
 
        $oldBase = basename($oldName);
1035
 
        $newBase = basename($newName);
1036
 
        if (isset($this->_files[$oldBase])) {
1037
 
            $this->_files[$newBase] = $this->_files[$oldBase];
1038
 
            if (isset($this->_files[$newBase]['operation'])) {
1039
 
                foreach (array_keys($this->_files[$newBase]['operation']) as $operation) {
1040
 
                    $count = count($this->_files[$newBase]['operation'][$operation]);
1041
 
                    $val = $this->_files[$newBase]['operation'][$operation][$count - 1];
1042
 
                    if (preg_match('/^(jpeg|png):/', $val, $regs)) {
1043
 
                        $val = $regs[1] . ':' . $newName;
1044
 
                    } else {
1045
 
                        $val = $newName;
1046
 
                    }
1047
 
                    $this->_files[$newBase]['operation'][$operation][$count - 1] = $val;
1048
 
                }
1049
 
            }
1050
 
            unset($this->_files[$oldBase]);
1051
 
            return true;
1052
 
        }
1053
 
        echo $this->_environment['path'] . ": rename($oldName, $newName)<br>\n";
1054
 
        return false;
1055
 
    }
1056
 
 
1057
 
    function isRestrictedByOpenBaseDir($path) {
1058
 
        /* echo $this->_environment['path'] . ": isRestrictedByOpenBaseDir($path)<br>\n"; */
1059
 
        return false;
1060
 
    }
1061
 
 
1062
 
    function file_exists($path) {
1063
 
        if ($path == $this->_environment['path']) {
1064
 
            return true;
1065
 
        }
1066
 
        $dirName = dirname($path) . '/';
1067
 
        $baseName = basename($path);
1068
 
        if ($dirName == $this->_environment['path']) {
1069
 
            if ($this->_environment['binary'] != '' && $baseName == $this->_environment['binary']) {
1070
 
                return true;
1071
 
            }
1072
 
            if ($this->_environment['binary'] == ''
1073
 
                    && in_array($baseName, $this->_environment['binaries']) ) {
1074
 
                return true;
1075
 
            }
1076
 
        }
1077
 
        /*echo $this->_environment['path'] . ": file_exists($path)<br>\n"; */
1078
 
        return false;
1079
 
    }
1080
 
 
1081
 
    function is_dir($path) {
1082
 
        if ($path == $this->_environment['path']) {
1083
 
            return true;
1084
 
        }
1085
 
        /* echo $this->_environment['path'] . ": is_dir($path)<br>\n"; */
1086
 
        return false;
1087
 
    }
1088
 
 
1089
 
    function is_executable($file) {
1090
 
        $dirName = dirname($file) . '/';
1091
 
        $baseName = basename($file);
1092
 
        if ($dirName == $this->_environment['path']) {
1093
 
            if ($this->_environment['binary'] != '' && $baseName == $this->_environment['binary']) {
1094
 
                return true;
1095
 
            }
1096
 
            if ($this->_environment['binary'] == ''
1097
 
                    && in_array($baseName, $this->_environment['binaries']) ) {
1098
 
                return true;
1099
 
            }
1100
 
        }
1101
 
 
1102
 
        echo $this->_environment['path'] . ": is_executable($file)<br>\n";
1103
 
        return false;
1104
 
    }
1105
 
 
1106
 
    function copy($file1, $file2) {
1107
 
        if (isset($this->_copyOk)) {
1108
 
            return 1;
1109
 
        }
1110
 
        echo $this->_environment['path'] . ": copy($file1, $file2)<br>\n";
1111
 
    }
1112
 
 
1113
 
    function filesize($file) {
1114
 
        $basename = basename($file);
1115
 
        if ($basename == 'testProfile.jpg') {
1116
 
            return 100000;
1117
 
        }
1118
 
        if ($basename == 'compressed.jpg') {
1119
 
            switch ($this->_counter--) {
1120
 
            case 2:
1121
 
                return 200 << 10;
1122
 
            case 1:
1123
 
                return 100 << 10;
1124
 
            case 0:
1125
 
                return 150 << 10;
1126
 
            }
1127
 
        }
1128
 
        if (isset($this->_files[$basename]['size'])) {
1129
 
            return $this->_files[$basename]['size'];
1130
 
        }
1131
 
        echo $this->_environment['path'] . ": filesize($file)<br>\n";
1132
 
        return 0;
1133
 
    }
1134
 
 
1135
 
    function tempnam($dir, $prefix) {
1136
 
        $fileName = $dir . $prefix . md5(rand());
1137
 
        $this->_files[basename($fileName)] = 'temp';
1138
 
        /*echo $this->_environment['path'] . ": tempnam($dir, $prefix) = $fileName<br>\n"; */
1139
 
        return $fileName;
1140
 
    }
1141
 
 
1142
 
    function unlink($path) {
1143
 
        $baseName = basename($path);
1144
 
        if (isset($this->_files[$baseName])) {
1145
 
            unset($this->_files[$baseName]);
1146
 
            return true;
1147
 
        }
1148
 
        echo $this->_environment['path'] . ": unlink($path)<br>\n";
1149
 
        return false;
1150
 
    }
1151
 
 
1152
 
    function getimagesize($path) {
1153
 
        $basename = basename($path);
1154
 
        if (preg_match('#\[(\d+)x(\d+)\]#', $basename, $matches)) {
1155
 
            $result = array($matches[1], $matches[2], 1,
1156
 
                            sprintf('height="%d" width="%d"', $matches[1], $matches[2]));
1157
 
        } else {
1158
 
            /*echo $this->_environment['path'] . ": getimagesize($path)<br>\n"; */
1159
 
            $result = false;
1160
 
        }
1161
 
 
1162
 
        return $result;
1163
 
    }
1164
 
 
1165
 
    function getDirectorySeparator() {
1166
 
        return $this->_platform->getDirectorySeparator();
1167
 
    }
1168
 
 
1169
 
    function realpath($path) {
1170
 
        return $this->_platform->realpath($path);
1171
 
    }
1172
 
 
1173
 
    function chdir($path) {
1174
 
        return true;
1175
 
    }
1176
 
 
1177
 
    function getcwd() {
1178
 
        return '/tmp';
1179
 
    }
1180
 
 
1181
 
    function chmod($path, $mode=null) {
1182
 
        $this->_test->_chmodWasCalled = true;
1183
 
        return true;
1184
 
    }
1185
 
}
1186
 
?>