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

« back to all changes in this revision

Viewing changes to modules/itemadd/test/phpunit/ItemAddFromServerTest.class

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/*
3
 
 * Gallery - a web based photo album viewer and editor
4
 
 * Copyright (C) 2000-2007 Bharat Mediratta
5
 
 *
6
 
 * This program is free software; you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; either version 2 of the License, or (at
9
 
 * your option) any later version.
10
 
 *
11
 
 * This program is distributed in the hope that it will be useful, but
12
 
 * WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 
 * General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
19
 
 */
20
 
 
21
 
/**
22
 
 * ItemAddFromServer plugin test
23
 
 * @package ItemAdd
24
 
 * @subpackage PHPUnit
25
 
 * @author Bharat Mediratta <bharat@menalto.com>
26
 
 * @version $Revision: 15513 $
27
 
 */
28
 
class ItemAddFromServerTest extends ItemAddPluginTestCase {
29
 
 
30
 
    function ItemAddFromServerTest($methodName) {
31
 
        $this->ItemAddPluginTestCase($methodName, 'itemadd', 'ItemAddFromServer');
32
 
    }
33
 
 
34
 
    function setUp() {
35
 
        global $gallery;
36
 
 
37
 
        parent::setUp();
38
 
 
39
 
        list ($ret, $this->_rootAlbum) =
40
 
            $this->_createRandomAlbum($this->_getRootId(), array('orderBy' => 'orderWeight'));
41
 
        if ($ret) {
42
 
            print $ret->getAsHtml();
43
 
            return $this->failWithStatus($ret);
44
 
        }
45
 
        $this->_markForCleanup($this->_rootAlbum);
46
 
 
47
 
        list ($ret, $this->_lockId) = GalleryCoreApi::acquireReadLock($this->_rootAlbum->getId());
48
 
        if ($ret) {
49
 
            print $ret->getAsHtml();
50
 
            return $this->failWithStatus($ret);
51
 
        }
52
 
 
53
 
        $this->_symlinkAllowedPlatform =
54
 
            new ItemAddFromServerTestPlatform($gallery->getPlatform(), true);
55
 
        $this->_symlinkDisallowedPlatform =
56
 
            new ItemAddFromServerTestPlatform($gallery->getPlatform(), false);
57
 
 
58
 
        $ret = $this->_markPluginParametersForCleanup('module', 'itemadd');
59
 
        if ($ret) {
60
 
            print $ret->getAsHtml();
61
 
            return $this->failWithStatus($ret);
62
 
        }
63
 
 
64
 
        $this->_baseDir = dirname(dirname(__FILE__));
65
 
        $ret = GalleryCoreApi::setPluginParameter('module', 'itemadd', 'uploadLocalServer.dir.1',
66
 
                                                  $this->_baseDir);
67
 
        if ($ret) {
68
 
            print $ret->getAsHtml();
69
 
            return $this->failWithStatus($ret);
70
 
        }
71
 
        $ret = GalleryCoreApi::setPluginParameter('module', 'itemadd', 'uploadLocalServer.dir.2',
72
 
                                                  $gallery->getConfig('data.gallery.base'));
73
 
        if ($ret) {
74
 
            print $ret->getAsHtml();
75
 
            return $this->failWithStatus($ret);
76
 
        }
77
 
        $ret = GalleryCoreApi::removePluginParameter('module', 'itemadd',
78
 
                                                     'uploadLocalServer.dir.3');
79
 
        if ($ret) {
80
 
            print $ret->getAsHtml();
81
 
            return $this->failWithStatus($ret);
82
 
        }
83
 
 
84
 
        $gallery->setPlatform($this->_symlinkAllowedPlatform);
85
 
    }
86
 
 
87
 
    function tearDown() {
88
 
        $ret = GalleryCoreApi::releaseLocks($this->_lockId);
89
 
        if ($ret) {
90
 
           return $this->failWithStatus($ret);
91
 
        }
92
 
 
93
 
        parent::tearDown();
94
 
    }
95
 
 
96
 
    function testIsAppropriate() {
97
 
        $ret = GalleryCoreApi::setPluginParameter('module', 'itemadd', 'fromserver', 'off');
98
 
        if ($ret) {
99
 
            return $this->failWithStatus($ret);
100
 
        }
101
 
        list ($ret, $isAppropriate) = $this->_plugin->isAppropriate();
102
 
        if ($ret) {
103
 
            return $this->failWithStatus($ret);
104
 
        }
105
 
        $this->assertEquals(false, $isAppropriate, 'off');
106
 
 
107
 
        $ret = GalleryCoreApi::setPluginParameter('module', 'itemadd', 'fromserver', 'admin');
108
 
        if ($ret) {
109
 
            return $this->failWithStatus($ret);
110
 
        }
111
 
        list ($ret, $isAppropriate) = $this->_plugin->isAppropriate();
112
 
        if ($ret) {
113
 
            return $this->failWithStatus($ret);
114
 
        }
115
 
        $this->assertEquals(true, $isAppropriate, 'admin for admin');
116
 
 
117
 
        $this->_becomeGuestUser();
118
 
        list ($ret, $isAppropriate) = $this->_plugin->isAppropriate();
119
 
        if ($ret) {
120
 
            return $this->failWithStatus($ret);
121
 
        }
122
 
        $this->assertEquals(false, $isAppropriate, 'admin for guest');
123
 
 
124
 
        $ret = GalleryCoreApi::setPluginParameter('module', 'itemadd', 'fromserver', 'on');
125
 
        if ($ret) {
126
 
            return $this->failWithStatus($ret);
127
 
        }
128
 
        list ($ret, $isAppropriate) = $this->_plugin->isAppropriate();
129
 
        if ($ret) {
130
 
            return $this->failWithStatus($ret);
131
 
        }
132
 
        $this->assertEquals(true, $isAppropriate, 'on');
133
 
    }
134
 
 
135
 
    /*
136
 
     * call _testAddChildrenFromLocalServer with the '$useSymlink'
137
 
     * parameter set to false, thus specifying that the files should be copied.
138
 
     */
139
 
    function testAddChildrenFromLocalServer() {
140
 
        return $this->_testAddChildrenFromLocalServer(false);
141
 
    }
142
 
 
143
 
 
144
 
    /*
145
 
     * call _testAddChildrenFromLocalServer specifying that we want to use
146
 
     * a symlink. Also specify that the symlink should be supported (and
147
 
     * thus the mock platform object that supports symlinks will be used.
148
 
     */
149
 
    function testAddChildrenFromLocalServerUsingSymlinkWithSymlinkSupported() {
150
 
        return $this->_testAddChildrenFromLocalServer(true, true);
151
 
    }
152
 
 
153
 
 
154
 
    /*
155
 
     * call _testAddChildrenFromLocalServer specifying that we want to use
156
 
     * a symlink. Also specify that the symlink should >not< be supported
157
 
     * (and thus the mock platform object that does not support symlinks will be used.
158
 
     */
159
 
    function testAddChildrenFromLocalServerUsingSymlinkWithSymlinkNotSupported() {
160
 
        return $this->_testAddChildrenFromLocalServer(true, false);
161
 
    }
162
 
 
163
 
 
164
 
    /*
165
 
     * call _testAddChildrenFromLocalServer with setTitle (set to base filename)
166
 
     */
167
 
    function testAddChildrenFromLocalServerSetTitle() {
168
 
        return $this->_testAddChildrenFromLocalServer(false, true, true, false, true);
169
 
    }
170
 
 
171
 
 
172
 
    /*
173
 
     * call _testAddChildrenFromLocalServer with setTitle/setDescription (set to base filename)
174
 
     */
175
 
    function testAddChildrenFromLocalServerSetTitleDescription() {
176
 
        return $this->_testAddChildrenFromLocalServer(false, true, true, false, true, false, true);
177
 
    }
178
 
 
179
 
    function testAddChildrenFromLocalServerRecursive() {
180
 
        return $this->_testAddChildrenFromLocalServer(false, true, false, true);
181
 
    }
182
 
 
183
 
    function testAddChildrenFromLocalServerRecursiveUsingSymlinkWithSymlinkSupported() {
184
 
        return $this->_testAddChildrenFromLocalServer(true, true, false, true);
185
 
    }
186
 
 
187
 
    function testAddChildrenFromLocalServerRecursiveUsingSymlinkWithSymlinkNotSupported() {
188
 
        return $this->_testAddChildrenFromLocalServer(true, false, false, true);
189
 
    }
190
 
 
191
 
    function testAddChildrenFromLocalServerRecursiveSetSummaryDescription() {
192
 
        return $this->_testAddChildrenFromLocalServer(false, true, false, true, false, true, true);
193
 
    }
194
 
 
195
 
    /**
196
 
     * All 'testAddChildrenFromLocalServer*' tests are very similar, hence
197
 
     * they all run through this method. The two parameters to this method
198
 
     * are: '$useSymlink', which is a boolean specifying if we should try
199
 
     * to add the files using a symlink or not.  The second param is
200
 
     * '$shouldSucceed'.  Since windows based OSes don't support symlinks,
201
 
     * G2 will not support adding a file using symlinks on those OSes.
202
 
     * We have two different mock platform objects, one that supports
203
 
     * symlinks and one that does not.  If we expect using a symlink to
204
 
     * fail, we bail check for that condition, and then bail out immediately.
205
 
     */
206
 
    function _testAddChildrenFromLocalServer($useSymlink, $symlinkSupported=true,
207
 
                                             $addFiles=true, $addDirectories=false,
208
 
                                             $setTitle=false, $setSummary=false,
209
 
                                             $setDescription=false) {
210
 
        global $gallery;
211
 
 
212
 
        /*
213
 
         * Use b<->a comparison here and rsort below because sanitizeInputValues on
214
 
         * form input will sanitize apo\'strophe.jpg and move it to the "end" of the
215
 
         * array, no matter what order we use to construct form[localServerFiles].
216
 
         * rsort keeps this item at the end anyway, so we get the expected results.
217
 
         */
218
 
        $sortAddedFilesFunc = create_function('$a, $b',
219
 
                'return strcmp($b[\'fileName\'], $a[\'fileName\']);');
220
 
 
221
 
        if ($symlinkSupported) {
222
 
            $gallery->setPlatform($this->_symlinkAllowedPlatform);
223
 
        } else {
224
 
            $gallery->setPlatform($this->_symlinkDisallowedPlatform);
225
 
        }
226
 
 
227
 
        /* Use valid inputs */
228
 
        GalleryUtilities::putRequestVariable('form[action][addFromLocalServer]', 1);
229
 
        if ($setTitle) {
230
 
            GalleryUtilities::putRequestVariable('form[set][title]', 1);
231
 
        }
232
 
        if ($setSummary) {
233
 
            GalleryUtilities::putRequestVariable('form[set][summary]', 1);
234
 
        }
235
 
        if ($setDescription) {
236
 
            GalleryUtilities::putRequestVariable('form[set][description]', 1);
237
 
        }
238
 
 
239
 
        $platform =& $gallery->getPlatform();
240
 
        $dirSep = $platform->getDirectorySeparator();
241
 
        $baseDir = $this->_baseDir . $dirSep . 'data';
242
 
        $fileKeys = array();
243
 
 
244
 
        if ($addFiles) {
245
 
            /* Some simple filenames and some with special characters */
246
 
            $files = array('test1.gif', 'test1.jpg', 'test2.gif', 'test[3].gif',
247
 
                           'apo\'strophe.jpg', "t\xebst.png");
248
 
            rsort($files);
249
 
 
250
 
            $escapedBasenames =
251
 
                array('test1', 'test1', 'test2', 'test[3]', 'apo\'strophe', "t\xebst");
252
 
            rsort($escapedBasenames);
253
 
 
254
 
            foreach ($files as $fileName) {
255
 
                $fileName = urlencode($fileName);
256
 
                GalleryUtilities::putRequestVariable(
257
 
                    'form[localServerFiles][' . $fileName . '][selected]', 1);
258
 
                if ($useSymlink) {
259
 
                    GalleryUtilities::putRequestVariable(
260
 
                        'form[localServerFiles][' . $fileName . '][useSymlink]', 1);
261
 
                }
262
 
            }
263
 
        }
264
 
 
265
 
        if ($addDirectories) {
266
 
            $files = array('test1.gif', 'test1.jpg', 'test2.gif', 'test[3].gif', 'test4.gif');
267
 
            rsort($files);
268
 
 
269
 
            $escapedBasenames = array('test1', 'test1',  'test2', 'test[3]', 'test4');
270
 
            rsort($escapedBasenames);
271
 
 
272
 
            $dirs = array('localUploadDir', "subD\xeer", '..');
273
 
            foreach ($dirs as $dirName) {
274
 
                $dirName = urlencode($dirName);
275
 
                GalleryUtilities::putRequestVariable(
276
 
                        'form[localServerDirectories][' . $dirName . '][selected]', 1);
277
 
                if ($useSymlink) {
278
 
                    GalleryUtilities::putRequestVariable(
279
 
                            'form[localServerDirectories][' . $dirName . '][useSymlink]', 1);
280
 
                }
281
 
            }
282
 
            /* .. is invalid and will be ignored, don't expect it in results */
283
 
            unset($dirs[2]);
284
 
        }
285
 
 
286
 
        GalleryUtilities::putRequestVariable('form[localServerPath]',
287
 
                                             GalleryCoreApi::convertToUtf8($baseDir));
288
 
 
289
 
        /* Perform the request and verify that we succeeded */
290
 
        if ($symlinkSupported) {
291
 
            $results = $this->handleRequest($this->_rootAlbum);
292
 
        } else {
293
 
            $results = $this->handleRequest($this->_rootAlbum, ERROR_UNSUPPORTED_OPERATION);
294
 
            /* Set the mock platform back to the one that supports symlink for consistency */
295
 
            $gallery->setPlatform($this->_symlinkAllowedPlatform);
296
 
            return;
297
 
        }
298
 
        $this->assertEquals(array(), $results[0]);
299
 
 
300
 
        /* We don't know the ids, but we can verify everything else */
301
 
        $i = 0;
302
 
        $this->assertEquals(count($files), count($results[1]['addedFiles']), 'added count');
303
 
        usort($results[1]['addedFiles'], $sortAddedFilesFunc);
304
 
        foreach ($files as $file) {
305
 
            $this->assertEquals(GalleryCoreApi::convertToUtf8($file),
306
 
                                $results[1]['addedFiles'][$i]['fileName'], 'added #' . $i);
307
 
            $this->assert(isset($results[1]['addedFiles'][$i]['id']));
308
 
            $i++;
309
 
        }
310
 
 
311
 
        /* Verify item attributes (like order weight) */
312
 
        list ($ret, $ids) = GalleryCoreApi::fetchChildItemIds($this->_rootAlbum);
313
 
        if ($ret) {
314
 
            return $this->failWithStatus($ret);
315
 
        }
316
 
        if ($addDirectories) {
317
 
            $this->assertEquals(count($dirs), count($ids), 'top child count');
318
 
            list ($ret, $subalbums) = GalleryCoreApi::loadEntitiesById($ids);
319
 
            if ($ret) {
320
 
                return $this->failWithStatus($ret);
321
 
            }
322
 
            list ($ret, $ids) = GalleryCoreApi::fetchChildItemIds($subalbums[0]);
323
 
            if ($ret) {
324
 
                return $this->failWithStatus($ret);
325
 
            }
326
 
            foreach ($dirs as $dirName) {
327
 
                $subalbum = array_shift($subalbums);
328
 
                $this->assert(GalleryUtilities::isA($subalbum, 'GalleryAlbumItem'), 'subalbum');
329
 
                $dirName = $platform->legalizePathComponent($dirName);
330
 
                $this->assertEquals($dirName, $subalbum->getPathComponent(), 'subalbum path');
331
 
            }
332
 
        }
333
 
        $addDirectoriesString = $addDirectories ? ' addDirectories' : ' !addDirectories';
334
 
        $this->assertEquals(count($files), count($ids), 'child count' . $addDirectoriesString);
335
 
 
336
 
        list ($ret, $items) = GalleryCoreApi::loadEntitiesById($ids);
337
 
        if ($ret) {
338
 
            return $this->failWithStatus($ret);
339
 
        }
340
 
 
341
 
        /* Organize items array by id */
342
 
        $newItems = array();
343
 
        foreach ($items as $item) {
344
 
            $newItems[$item->getId()] = $item;
345
 
        }
346
 
        $items = $newItems;
347
 
 
348
 
        $seenWeights = array();
349
 
        $i = 0;
350
 
        foreach ($escapedBasenames as $base) {
351
 
            $item =& $items[$results[1]['addedFiles'][$i]['id']];
352
 
            if (!isset($item)) {
353
 
                $this->assert(false, 'Item ' . $i++ . ' missing');
354
 
                continue;
355
 
            }
356
 
            $expectedName = GalleryCoreApi::convertToUtf8($base);
357
 
            $this->assertEquals($setTitle ? $expectedName : '', $item->getTitle(), 'title');
358
 
            $this->assertEquals($setSummary ? $expectedName : '', $item->getSummary(),
359
 
                                'summary');
360
 
            $this->assertEquals($setDescription ? $expectedName : '', $item->getDescription(),
361
 
                                'description');
362
 
 
363
 
            $this->assertEquals($platform->legalizePathComponent($files[$i]),
364
 
                                $item->getPathComponent(), 'path component ' . $i);
365
 
 
366
 
            list ($ret, $viewCount) = GalleryCoreApi::fetchItemViewCount($item->getId());
367
 
            if ($ret) {
368
 
                return $this->failWithStatus($ret);
369
 
            }
370
 
            $this->assertEquals(0, $viewCount);
371
 
 
372
 
            list ($ret, $orderWeight) = GalleryCoreApi::fetchItemOrderWeight($item->getId());
373
 
            if ($ret) {
374
 
                return $this->failWithStatus($ret);
375
 
            }
376
 
            $this->assert(!isset($seenWeights[$item->getParentId()][$orderWeight]),
377
 
                          'Seen this weight before: ' . $orderWeight);
378
 
            $seenWeights[$item->getParentId()][$orderWeight] = 1;
379
 
            $i++;
380
 
        }
381
 
    }
382
 
 
383
 
    function testInvalidLocalServerPath() {
384
 
        GalleryUtilities::putRequestVariable('form[action][addFromLocalServer]', 1);
385
 
        GalleryUtilities::putRequestVariable('form[localServerPath]', '/');
386
 
        GalleryUtilities::putRequestVariable(
387
 
            'form[localServerFiles][ItemAddFromServerTest.foo][selected]', 1);
388
 
        $this->handleRequest($this->_rootAlbum, ERROR_BAD_PARAMETER);
389
 
    }
390
 
 
391
 
    /**
392
 
     * Checks if the urlencoded filename gets correctly converted to a nice filename
393
 
     * in pathComponent, title and summary
394
 
     */
395
 
    function testAddFromServerFilenameToFields() {
396
 
        global $gallery;
397
 
        $platform =& $gallery->getPlatform();
398
 
        $dirSep = $platform->getDirectorySeparator();
399
 
        $baseDir = $this->_baseDir . $dirSep . 'data';
400
 
 
401
 
        GalleryUtilities::putRequestVariable('form[action][addFromLocalServer]', 1);
402
 
        GalleryUtilities::putRequestVariable('form[localServerPath]', $baseDir);
403
 
        GalleryUtilities::putRequestVariable('form[set][title]', 1);
404
 
        GalleryUtilities::putRequestVariable('form[set][summary]', 1);
405
 
        /* This is what the browser will send us (urlencoded): */
406
 
        GalleryUtilities::putRequestVariable(
407
 
            'form[localServerFiles][' . urlencode('December - <#952>.jpg') . '][selected]', 1);
408
 
 
409
 
        $results = $this->handleRequest($this->_rootAlbum);
410
 
        $this->assertEquals(array(), $results[0]);
411
 
        $this->assertEquals(1, count($results[1]));
412
 
        $this->assertEquals(1, count($results[1]['addedFiles']));
413
 
 
414
 
        list ($ret, $item) = GalleryCoreApi::loadEntitiesById($results[1]['addedFiles'][0]['id']);
415
 
        if ($ret) {
416
 
            return $this->failWithStatus($ret);
417
 
        }
418
 
        $this->assertEquals('December - _#952_.jpg', $item->getPathComponent(), 'pathComponent');
419
 
        $this->assertEquals('December - &lt;#952&gt;', $item->getTitle(), 'title');
420
 
        $this->assertEquals('December - &lt;#952&gt;', $item->getSummary(), 'summary');
421
 
        $this->assertEquals('', $item->getDescription(), 'description');
422
 
    }
423
 
 
424
 
    /**
425
 
     * Checks that we disallow recursive add from our own g2data directory.
426
 
     */
427
 
    function testAddFromServerG2DataDir() {
428
 
        global $gallery;
429
 
 
430
 
        list ($ret, $path) = $this->_rootAlbum->fetchPath();
431
 
        if ($ret) {
432
 
            return $this->failWithStatus($ret);
433
 
        }
434
 
 
435
 
        GalleryUtilities::putRequestVariable('form[action][addFromLocalServer]', 1);
436
 
        GalleryUtilities::putRequestVariable('form[localServerPath]', dirname($path));
437
 
        GalleryUtilities::putRequestVariable('form[set][title]', 1);
438
 
        GalleryUtilities::putRequestVariable('form[localServerDirectories][' .
439
 
            urlencode(basename($path)) . '][selected]', 1);
440
 
 
441
 
        $results = $this->handleRequest($this->_rootAlbum);
442
 
        $this->assertEquals(array(array(), array()), $results);
443
 
    }
444
 
 
445
 
    function testAddFromServerMalformedInput() {
446
 
        /* Test that manually constructed input can't get outside our approved dirs */
447
 
        global $gallery;
448
 
        $platform =& $gallery->getPlatform();
449
 
        $dirSep = $platform->getDirectorySeparator();
450
 
        $baseDir = $this->_baseDir . $dirSep;
451
 
 
452
 
        GalleryUtilities::putRequestVariable('form[action][addFromLocalServer]', 1);
453
 
        GalleryUtilities::putRequestVariable('form[localServerPath]', $baseDir);
454
 
        GalleryUtilities::putRequestVariable('form[localServerFiles][..%2Ffoo][selected]', 1);
455
 
        GalleryUtilities::putRequestVariable('form[localServerDirectories][..%2Fbar][selected]', 1);
456
 
        GalleryUtilities::putRequestVariable('form[set][title]', 1);
457
 
 
458
 
        $results = $this->handleRequest($this->_rootAlbum);
459
 
        $this->assertEquals(array(array(), array()), $results);
460
 
    }
461
 
 
462
 
    function testAddFromServerEntityDir() {
463
 
        /* Test that characters in dirname that get entitized still work ok */
464
 
        global $gallery;
465
 
        $platform =& $gallery->getPlatform();
466
 
        $dirSep = $platform->getDirectorySeparator();
467
 
        $baseDir = $this->_baseDir . $dirSep . 'data' . $dirSep;
468
 
 
469
 
        GalleryUtilities::putRequestVariable('form[action][addFromLocalServer]', 1);
470
 
        GalleryUtilities::putRequestVariable('form[localServerPath]', $baseDir . '<My "Files">');
471
 
        GalleryUtilities::putRequestVariable('form[localServerFiles][foo][selected]', 1);
472
 
        GalleryUtilities::putRequestVariable('form[set][title]', 1);
473
 
 
474
 
        $results = $this->handleRequest($this->_rootAlbum);
475
 
        if (empty($results[1]['addedFiles'][0]['id'])) {
476
 
            $this->assert(false, 'missing id of added item');
477
 
        } else {
478
 
            $id = $results[1]['addedFiles'][0]['id'];
479
 
            $this->assertEquals(array(array(), array('addedFiles' =>
480
 
                array(array('fileName' => 'foo', 'id' => $id, 'warnings' => array())))), $results);
481
 
        }
482
 
    }
483
 
}
484
 
 
485
 
/**
486
 
 * Test platform
487
 
 */
488
 
class ItemAddFromServerTestPlatform extends GalleryPlatform {
489
 
    function ItemAddFromServerTestPlatform($delegate, $symlinkSupported) {
490
 
        $this->_delegate = $delegate;
491
 
        $dirSep = $this->_dirSep = $delegate->getDirectorySeparator();
492
 
        $this->_symlinkSupported = $symlinkSupported;
493
 
        $this->_baseDir = dirname(dirname(__FILE__)) . "{$dirSep}data{$dirSep}";
494
 
        $this->_baseDirRecursive = dirname(dirname(__FILE__)) .
495
 
                "{$dirSep}..{$dirSep}data{$dirSep}localUploadDir{$dirSep}";
496
 
    }
497
 
 
498
 
    /*
499
 
     * Simply collapse .. clauses out of paths.  If we use realpath() it'll try to verify that the
500
 
     * path actually exists (which it won't, in some cases)
501
 
     */
502
 
    function realpath($path) {
503
 
        return preg_replace('#[^\\\/]+[\\\/]\.\.([\\\/]|$)#', '', $path);
504
 
    }
505
 
 
506
 
    function file_exists($path) {
507
 
        switch ($path) {
508
 
        case $this->_baseDir . 'December - <#952>.jpg':
509
 
        case $this->_baseDir . '<My "Files">' . $this->_dirSep . 'foo':
510
 
        case $this->_baseDir . "t\xebst.png":
511
 
        case $this->_baseDir . 'apo\'strophe.jpg':
512
 
        case $this->_baseDirRecursive . 'apo\'strophe.jpg':
513
 
            /* The windows path is a little weird -- but we can live with it */
514
 
        case $this->_baseDir . '\\apo\'strophe.jpg':
515
 
            return true;
516
 
 
517
 
        default:
518
 
            return $this->_delegate->file_exists($path);
519
 
        }
520
 
    }
521
 
 
522
 
    function copy($source, $dest) {
523
 
        switch ($source) {
524
 
        case $this->_baseDir . 'December - <#952>.jpg':
525
 
        case $this->_baseDir . '<My "Files">' . $this->_dirSep . 'foo':
526
 
        case $this->_baseDir . "t\xebst.png":
527
 
        case $this->_baseDir . 'apo\'strophe.jpg':
528
 
        case $this->_baseDirRecursive . 'apo\'strophe.jpg':
529
 
            /* The windows path is a little weird -- but we can live with it */
530
 
        case $this->_baseDir . '\\apo\'strophe.jpg':
531
 
        case $this->_baseDirRecursive . '\\apo\'strophe.jpg':
532
 
            $source = $this->_baseDir . 'test1.jpg';
533
 
            break;
534
 
        }
535
 
        return $this->_delegate->copy($source, $dest);
536
 
    }
537
 
 
538
 
    function symlink($source, $dest) {
539
 
        switch ($source) {
540
 
        case $this->_baseDir . 'December - <#952>.jpg':
541
 
        case $this->_baseDir . "t\xebst.png":
542
 
        case $this->_baseDir . 'apo\'strophe.jpg':
543
 
        case $this->_baseDirRecursive . 'apo\'strophe.jpg':
544
 
            /* The windows path is a little weird -- but we can live with it */
545
 
        case $this->_baseDir . '\\apo\'strophe.jpg':
546
 
        case $this->_baseDirRecursive . '\\apo\'strophe.jpg':
547
 
            $source = $this->_baseDir . 'test1.jpg';
548
 
            break;
549
 
        }
550
 
 
551
 
        if ($this->_delegate->isSymlinkSupported()) {
552
 
            return $this->_delegate->symlink($source, $dest);
553
 
        } else {
554
 
            return $this->copy($source, $dest);
555
 
        }
556
 
    }
557
 
 
558
 
    function isSymlinkSupported() {
559
 
        return $this->_symlinkSupported;
560
 
    }
561
 
 
562
 
    function opendir($path) {
563
 
        if ($path == $this->_baseDir . "subD\xeer") {
564
 
            return 'testHandle';
565
 
        }
566
 
        return $this->_delegate->opendir($path);
567
 
    }
568
 
 
569
 
    function readdir($resource) {
570
 
        if ($resource === 'testHandle') {
571
 
            return false;
572
 
        }
573
 
        return $this->_delegate->readdir($resource);
574
 
    }
575
 
 
576
 
    function closedir($resource) {
577
 
        if ($resource === 'testHandle') {
578
 
            return true;
579
 
        }
580
 
        return $this->_delegate->closedir($resource);
581
 
    }
582
 
 
583
 
    function exec($cmd) {
584
 
        /* In case add of jpeg tries to get 'colorspace' property */
585
 
        return array(true, array(''), array());
586
 
    }
587
 
}
588
 
?>