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

« back to all changes in this revision

Viewing changes to modules/ffmpeg/test/phpunit/AdminFfmpegControllerTest.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: AdminFfmpegControllerTest.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.15 $ $Date: 2005/08/23 03:49:42 $
 
23
 * @version $Revision: 1.18 $ $Date: 2006/01/21 10:10:35 $
24
24
 * @package Ffmpeg
25
25
 * @subpackage PHPUnit
26
26
 * @author Bharat Mediratta <bharat@menalto.com>
42
42
        parent::setUp();
43
43
 
44
44
        $ret = $this->_markPluginParametersForCleanup('module', 'ffmpeg');
45
 
        if ($ret->isError()) {
46
 
            print $ret->getAsHtml();
47
 
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
48
 
        }
49
 
 
50
 
        $gallery->_platform = new AdminFfmpegControllerTestPlatform();
 
45
        if ($ret) {
 
46
            print $ret->getAsHtml();
 
47
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
48
        }
 
49
 
 
50
        list ($ret, $this->_movie) =
 
51
            $this->_createRandomDataItem($this->_getRootId(), 'video/mpeg');
 
52
        if ($ret) {
 
53
            print $ret->getAsHtml();
 
54
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
55
        }
 
56
        $this->_markForCleanup($this->_movie);
 
57
 
 
58
        list ($ret, $this->_thumbnail) = $this->_createDerivative(
 
59
            $this->_movie, $this->_movie->getId(), DERIVATIVE_TYPE_IMAGE_THUMBNAIL,
 
60
            'convert-to-image/jpeg;thumbnail|150');
 
61
        if ($ret) {
 
62
            print $ret->getAsHtml();
 
63
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
64
        }
 
65
 
 
66
        $this->_savePlatform =& $gallery->getPlatform();
 
67
        $gallery->setPlatform(new AdminFfmpegControllerTestPlatform());
51
68
    }
52
69
 
53
70
    function testSaveGoodPath() {
64
81
                            $results);
65
82
 
66
83
        /* Verify the settings went in properly */
67
 
        list ($ret, $path) = GalleryCoreApi::getPluginParameter('module', 'ffmpeg', 'path');
68
 
        if ($ret->isError()) {
69
 
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
70
 
        }
71
 
        $this->assertEquals('/validPath/ffmpeg', $path);
 
84
        list ($ret, $params) = GalleryCoreApi::fetchAllPluginParameters('module', 'ffmpeg');
 
85
        if ($ret) {
 
86
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
87
        }
 
88
        $this->assertEquals('/validPath/ffmpeg', $params['path']);
 
89
        $this->assertEquals('0', $params['useWatermark']);
 
90
    }
 
91
 
 
92
    function testSaveUseWatermark() {
 
93
        GalleryUtilities::putRequestVariable('form[action][save]', 1);
 
94
        GalleryUtilities::putRequestVariable('form[path]', '/validPath/ffmpeg');
 
95
        GalleryUtilities::putRequestVariable('form[useWatermark]', 1);
 
96
 
 
97
        /* Perform the request and verify that we succeeded */
 
98
        $results = $this->handleRequest();
 
99
        $this->assertEquals(array('redirect' => array('view' => 'core.SiteAdmin',
 
100
                                                      'subView' => 'ffmpeg.AdminFfmpeg'),
 
101
                                  'status' => array('saved' => 1),
 
102
                                  'error' => array()),
 
103
                            $results);
 
104
 
 
105
        /* Verify the settings went in properly */
 
106
        list ($ret, $params) = GalleryCoreApi::fetchAllPluginParameters('module', 'ffmpeg');
 
107
        if ($ret) {
 
108
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
109
        }
 
110
        $this->assertEquals('/validPath/ffmpeg', $params['path']);
 
111
        $this->assertEquals('1', $params['useWatermark']);
72
112
    }
73
113
 
74
114
    function testSaveIncompletePath() {
86
126
 
87
127
        /* Verify the settings went in properly */
88
128
        list ($ret, $path) = GalleryCoreApi::getPluginParameter('module', 'ffmpeg', 'path');
89
 
        if ($ret->isError()) {
 
129
        if ($ret) {
90
130
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
91
131
        }
92
132
        $this->assertEquals('/incompletePath/ffmpeg', $path);
169
209
                                  'error' => array('form[error][path][missing]')),
170
210
                            $results);
171
211
    }
 
212
 
 
213
    function testAddRemoveWatermark() {
 
214
        global $gallery;
 
215
        $gallery->setPlatform($this->_savePlatform);
 
216
 
 
217
        $ret = $this->_saveThumbnailOps();
 
218
        if ($ret) {
 
219
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
220
        }
 
221
 
 
222
        list ($ret, $path) = GalleryCoreApi::getPluginParameter('module', 'ffmpeg', 'path');
 
223
        if ($ret) {
 
224
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
225
        }
 
226
 
 
227
        GalleryUtilities::putRequestVariable('form[path]', $path);
 
228
        GalleryUtilities::putRequestVariable('form[action][save]', 1);
 
229
        GalleryUtilities::putRequestVariable('form[addWatermark]', 1);
 
230
 
 
231
        $results = $this->handleRequest();
 
232
        $this->assertEquals(array('redirect' => array('view' => 'core.SiteAdmin',
 
233
                                                      'subView' => 'ffmpeg.AdminFfmpeg'),
 
234
                                  'status' => array('added' => 1, 'saved' => 1),
 
235
                                  'error' => array()),
 
236
                            $results);
 
237
 
 
238
        list ($ret, $thumbnail) = $this->_thumbnail->refresh();
 
239
        if ($ret) {
 
240
            $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
241
        }
 
242
 
 
243
        $this->assertEquals('convert-to-image/jpeg;thumbnail|150;composite|plugins_data/modules/' .
 
244
            'ffmpeg/filmreel.png,image/png,12,399,top-left,0,0;composite|plugins_data/modules/' .
 
245
            'ffmpeg/filmreel.png,image/png,12,399,top-right,0,0',
 
246
            $thumbnail->getDerivativeOperations(), 'add watermark');
 
247
 
 
248
        GalleryUtilities::putRequestVariable('form[addWatermark]', 0);
 
249
        GalleryUtilities::putRequestVariable('form[removeWatermark]', 1);
 
250
 
 
251
        $results = $this->handleRequest();
 
252
        $this->assertEquals(array('redirect' => array('view' => 'core.SiteAdmin',
 
253
                                                      'subView' => 'ffmpeg.AdminFfmpeg'),
 
254
                                  'status' => array('removed' => 1, 'saved' => 1),
 
255
                                  'error' => array()),
 
256
                            $results);
 
257
 
 
258
        list ($ret, $thumbnail) = $this->_thumbnail->refresh();
 
259
        if ($ret) {
 
260
            $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
261
        }
 
262
 
 
263
        $this->assertEquals('convert-to-image/jpeg;thumbnail|150',
 
264
            $thumbnail->getDerivativeOperations(), 'remove watermark');
 
265
 
 
266
        $ret = $this->_restoreThumbnailOps();
 
267
        if ($ret) {
 
268
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
269
        }
 
270
    }
 
271
 
 
272
    function _saveThumbnailOps() {
 
273
        global $gallery;
 
274
        $query = '
 
275
        SELECT [GalleryDerivative::id], [GalleryDerivative::derivativeOperations]
 
276
        FROM [GalleryDerivative], [GalleryChildEntity], [GalleryEntity]
 
277
        WHERE [GalleryDerivative::id] = [GalleryChildEntity::id]
 
278
          AND [GalleryChildEntity::parentId] = [GalleryEntity::id]
 
279
          AND [GalleryEntity::entityType] = \'GalleryMovieItem\'';
 
280
        list ($ret, $searchResults) = $gallery->search($query);
 
281
        if ($ret) {
 
282
            return $ret->wrap(__FILE__, __LINE__);
 
283
        }
 
284
        $this->_thumbnailOps = array();
 
285
        while ($result = $searchResults->nextResult()) {
 
286
            $this->_thumbnailOps[(int)$result[0]] = $result[1];
 
287
        }
 
288
        return null;
 
289
    }
 
290
 
 
291
    function _restoreThumbnailOps() {
 
292
        if (empty($this->_thumbnailOps)) {
 
293
            return null;
 
294
        }
 
295
        list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock(array_keys($this->_thumbnailOps));
 
296
        if ($ret) {
 
297
            return $ret->wrap(__FILE__, __LINE__);
 
298
        }
 
299
        list ($ret, $thumbnails) =
 
300
            GalleryCoreApi::loadEntitiesById(array_keys($this->_thumbnailOps));
 
301
        if ($ret) {
 
302
            GalleryCoreApi::releaseLocks($lockId);
 
303
            return $ret->wrap(__FILE__, __LINE__);
 
304
        }
 
305
        foreach ($thumbnails as $thumbnail) {
 
306
            $thumbnail->setDerivativeOperations($this->_thumbnailOps[$thumbnail->getId()]);
 
307
            $ret = $thumbnail->save();
 
308
            if ($ret) {
 
309
                GalleryCoreApi::releaseLocks($lockId);
 
310
                return $ret->wrap(__FILE__, __LINE__);
 
311
            }
 
312
        }
 
313
        $ret = GalleryCoreApi::releaseLocks($lockId);
 
314
        if ($ret) {
 
315
            return $ret->wrap(__FILE__, __LINE__);
 
316
        }
 
317
        return null;
 
318
    }
172
319
}
173
320
 
174
321
/**