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

« back to all changes in this revision

Viewing changes to modules/core/test/phpunit/ItemMoveSingleControllerTest.class

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 * $RCSfile: ItemMoveSingleControllerTest.class,v $
4
4
 *
5
5
 * Gallery - a web based photo album viewer and editor
6
 
 * Copyright (C) 2000-2005 Bharat Mediratta
 
6
 * Copyright (C) 2000-2006 Bharat Mediratta
7
7
 *
8
8
 * This program is free software; you can redistribute it and/or modify
9
9
 * it under the terms of the GNU General Public License as published by
20
20
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
21
21
 */
22
22
/**
23
 
 * @version $Revision: 1.17 $ $Date: 2005/08/23 03:49:33 $
 
23
 * @version $Revision: 1.19 $ $Date: 2006/01/13 03:39:32 $
24
24
 * @package GalleryCore
25
25
 * @subpackage PHPUnit
26
26
 * @author Bharat Mediratta <bharat@menalto.com>
45
45
        $ret = GalleryCoreApi::registerFactoryImplementation(
46
46
            'GalleryToolkit', 'ItemMoveSingleTestToolkit', 'ItemMoveSingleTestToolkit', $path,
47
47
            'coreTest', null);
48
 
        if ($ret->isError()) {
 
48
        if ($ret) {
49
49
            print $ret->getAsHtml();
50
50
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
51
51
        }
57
57
                array(array('type' => 'int', 'description' => 'foo'),
58
58
                      array('type' => 'int', 'description' => 'foo')),
59
59
                'test-description');
60
 
        if ($ret->isError()) {
 
60
        if ($ret) {
61
61
            print $ret->getAsHtml();
62
62
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
63
63
        }
66
66
                array(array('type' => 'int', 'description' => 'foo'),
67
67
                      array('type' => 'int', 'description' => 'foo')),
68
68
                'test-description');
69
 
        if ($ret->isError()) {
 
69
        if ($ret) {
70
70
            print $ret->getAsHtml();
71
71
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
72
72
        }
76
76
                      array('type' => 'float', 'description' => 'foo'),
77
77
                      array('type' => 'float', 'description' => 'foo'),
78
78
                      array('type' => 'float', 'description' => 'foo')), 'test-description');
79
 
        if ($ret->isError()) {
 
79
        if ($ret) {
80
80
            print $ret->getAsHtml();
81
81
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
82
82
        }
83
83
 
84
84
        list ($ret, $this->_rootAlbum) = $this->_createRandomAlbum($this->_getRootId());
85
 
        if ($ret->isError()) {
 
85
        if ($ret) {
86
86
            print $ret->getAsHtml();
87
87
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
88
88
        }
91
91
        $this->_setDerivativePreferences($this->_rootAlbum->getId(), 150, 300, 400);
92
92
 
93
93
        list ($ret, $this->_destinationAlbum) = $this->_createRandomAlbum($this->_getRootId());
94
 
        if ($ret->isError()) {
 
94
        if ($ret) {
95
95
            print $ret->getAsHtml();
96
96
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
97
97
        }
102
102
        /* Create a data item */
103
103
        list ($ret, $this->_item) = $this->_createRandomDataItem(
104
104
                $this->_rootAlbum->getId(), 'image/test', array('width' => 1000));
105
 
        if ($ret->isError()) {
 
105
        if ($ret) {
106
106
            print $ret->getAsHtml();
107
107
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
108
108
        }
113
113
        $itemId = array_shift($args);
114
114
        $thumbSize = array_shift($args);
115
115
        $ret = GalleryCoreApi::removeDerivativePreferencesForItem($itemId);
116
 
        if ($ret->isError()) {
 
116
        if ($ret) {
117
117
            print $ret->getAsHtml();
118
118
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
119
119
        }
120
120
        $ret = GalleryCoreApi::addDerivativePreference(0, $itemId,
121
121
                   DERIVATIVE_TYPE_IMAGE_THUMBNAIL, 'thumbnail|' . $thumbSize);
122
 
        if ($ret->isError()) {
 
122
        if ($ret) {
123
123
            print $ret->getAsHtml();
124
124
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
125
125
        }
126
126
        foreach ($args as $i => $resizeSize) {
127
127
            $ret = GalleryCoreApi::addDerivativePreference($i+1, $itemId,
128
128
                        DERIVATIVE_TYPE_IMAGE_RESIZE, 'scale|' . $resizeSize);
129
 
            if ($ret->isError()) {
 
129
            if ($ret) {
130
130
                print $ret->getAsHtml();
131
131
                return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
132
132
            }
139
139
        }
140
140
        $data = array();
141
141
        list ($ret, $thumbnails) = GalleryCoreApi::fetchThumbnailsByItemIds($itemIds);
142
 
        if ($ret->isError()) {
 
142
        if ($ret) {
143
143
            print $ret->getAsHtml();
144
144
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
145
145
        }
148
148
                                 'op' => $deriv->getDerivativeOperations());
149
149
        }
150
150
        list ($ret, $resizes) = GalleryCoreApi::fetchResizesByItemIds($itemIds);
151
 
        if ($ret->isError()) {
 
151
        if ($ret) {
152
152
            print $ret->getAsHtml();
153
153
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
154
154
        }
168
168
        /* Create derivatives according to prefs of original album */
169
169
        $ret = GalleryCoreApi::addExistingItemToAlbum(
170
170
                                $this->_item, $this->_rootAlbum->getId(), true);
171
 
        if ($ret->isError()) {
 
171
        if ($ret) {
172
172
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
173
173
        }
174
174
 
182
182
 
183
183
        GalleryUtilities::putRequestVariable('itemId', $this->_item->getId());
184
184
        GalleryUtilities::putRequestVariable('form[action][move]', 1);
185
 
        GalleryUtilities::putRequestVariable('form[destination]', $this->_destinationAlbum->getId());
 
185
        GalleryUtilities::putRequestVariable('form[destination]',
 
186
                                             $this->_destinationAlbum->getId());
186
187
 
187
188
        $results = $this->handleRequest();
188
189
        $this->assertEquals(array('redirect' => array('view' => 'core.ItemAdmin',
194
195
 
195
196
        /* Verify parent sequence */
196
197
        list ($ret, $parentSequence) = GalleryCoreApi::fetchParentSequence($this->_item->getId());
197
 
        if ($ret->isError()) {
 
198
        if ($ret) {
198
199
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
199
200
        }
200
201
        $this->assertEquals(array($this->_getRootId(),
224
225
 
225
226
        /* Verify parent sequence */
226
227
        list ($ret, $parentSequence) = GalleryCoreApi::fetchParentSequence($this->_item->getId());
227
 
        if ($ret->isError()) {
 
228
        if ($ret) {
228
229
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
229
230
        }
230
231
        $this->assertEquals(array($this->_getRootId(),
276
277
     */
277
278
    function testMoveItemIntoChild() {
278
279
        list ($ret, $this->_childAlbum) = $this->_createRandomAlbum($this->_rootAlbum->getId());
279
 
        if ($ret->isError()) {
 
280
        if ($ret) {
280
281
            print $ret->getAsHtml();
281
282
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
282
283
        }
299
300
    function testMoveItemIntoAlbumWithNoPermissions() {
300
301
        GalleryUtilities::putRequestVariable('itemId', $this->_item->getId());
301
302
        GalleryUtilities::putRequestVariable('form[action][move]', 1);
302
 
        GalleryUtilities::putRequestVariable('form[destination]', $this->_destinationAlbum->getId());
 
303
        GalleryUtilities::putRequestVariable('form[destination]',
 
304
                                             $this->_destinationAlbum->getId());
303
305
 
304
306
        $ret = GalleryCoreApi::removeItemPermissions($this->_destinationAlbum->getId());
305
 
        if ($ret->isError()) {
 
307
        if ($ret) {
306
308
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
307
309
        }
308
310
 
316
318
    function testMoveItemWithNoDeletePermissions() {
317
319
        GalleryUtilities::putRequestVariable('itemId', $this->_item->getId());
318
320
        GalleryUtilities::putRequestVariable('form[action][move]', 1);
319
 
        GalleryUtilities::putRequestVariable('form[destination]', $this->_destinationAlbum->getId());
 
321
        GalleryUtilities::putRequestVariable('form[destination]',
 
322
                                             $this->_destinationAlbum->getId());
320
323
 
321
324
        $ret = GalleryCoreApi::removeItemPermissions($this->_item->getId());
322
 
        if ($ret->isError()) {
 
325
        if ($ret) {
323
326
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
324
327
        }
325
328
 
334
337
        /* Create derivatives according to prefs of original album */
335
338
        $ret = GalleryCoreApi::addExistingItemToAlbum(
336
339
                                $this->_item, $this->_rootAlbum->getId(), true);
337
 
        if ($ret->isError()) {
 
340
        if ($ret) {
338
341
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
339
342
        }
340
343
 
341
344
        /* Add crop operation */
342
345
        list ($ret, $thumbnails) =
343
346
            GalleryCoreApi::fetchThumbnailsByItemIds(array($this->_item->getId()));
344
 
        if ($ret->isError()) {
 
347
        if ($ret) {
345
348
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
346
349
        }
347
350
        $thumb = $thumbnails[$this->_item->getId()];
348
351
        list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($thumb->getId());
349
 
        if ($ret->isError()) {
 
352
        if ($ret) {
350
353
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
351
354
        }
352
355
        $thumb->setDerivativeOperations('crop|0,0,50,50;' . $thumb->getDerivativeOperations());
353
356
        $ret = $thumb->save();
354
 
        if ($ret->isError()) {
 
357
        if ($ret) {
355
358
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
356
359
        }
357
360
        $ret = GalleryCoreApi::releaseLocks($lockId);
358
 
        if ($ret->isError()) {
 
361
        if ($ret) {
359
362
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
360
363
        }
361
364
 
362
365
        /* Verify derivatives were created ok */
363
366
        $sizes = $this->_getDerivativeSizes($this->_item->getId());
364
367
        $this->assertEquals(array(
365
 
            array('type' => DERIVATIVE_TYPE_IMAGE_THUMBNAIL, 'op' => 'crop|0,0,50,50;thumbnail|150'),
 
368
            array('type' => DERIVATIVE_TYPE_IMAGE_THUMBNAIL,
 
369
                  'op' => 'crop|0,0,50,50;thumbnail|150'),
366
370
            array('type' => DERIVATIVE_TYPE_IMAGE_RESIZE, 'op' => 'scale|300'),
367
371
            array('type' => DERIVATIVE_TYPE_IMAGE_RESIZE, 'op' => 'scale|400')),
368
372
            $sizes, 'Initial derivative sizes');
369
373
 
370
374
        GalleryUtilities::putRequestVariable('itemId', $this->_item->getId());
371
375
        GalleryUtilities::putRequestVariable('form[action][move]', 1);
372
 
        GalleryUtilities::putRequestVariable('form[destination]', $this->_destinationAlbum->getId());
 
376
        GalleryUtilities::putRequestVariable('form[destination]',
 
377
                                             $this->_destinationAlbum->getId());
373
378
 
374
379
        $results = $this->handleRequest();
375
380
        $this->assertEquals(array('redirect' => array('view' => 'core.ItemAdmin',
382
387
        /* Verify derivatives were recreated with preferences of new parent album */
383
388
        $sizes = $this->_getDerivativeSizes($this->_item->getId());
384
389
        $this->assertEquals(array(
385
 
            array('type' => DERIVATIVE_TYPE_IMAGE_THUMBNAIL, 'op' => 'crop|0,0,50,50;thumbnail|200'),
 
390
            array('type' => DERIVATIVE_TYPE_IMAGE_THUMBNAIL,
 
391
                  'op' => 'crop|0,0,50,50;thumbnail|200'),
386
392
            /* Order differs because old 400 kept as-is, and old 300 is reused for 600. */
387
393
            array('type' => DERIVATIVE_TYPE_IMAGE_RESIZE, 'op' => 'scale|600'),
388
394
            array('type' => DERIVATIVE_TYPE_IMAGE_RESIZE, 'op' => 'scale|400'),