~ubuntu-branches/ubuntu/quantal/gallery2/quantal

« 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: 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
 
 * AdminFfmpeg controller tests
23
 
 * @package Ffmpeg
24
 
 * @subpackage PHPUnit
25
 
 * @author Bharat Mediratta <bharat@menalto.com>
26
 
 * @version $Revision: 15513 $
27
 
 */
28
 
class AdminFfmpegControllerTest extends GalleryControllerTestCase {
29
 
 
30
 
    function AdminFfmpegControllerTest($methodName) {
31
 
        $this->GalleryControllerTestCase($methodName, 'ffmpeg.AdminFfmpeg');
32
 
    }
33
 
 
34
 
    function setUp() {
35
 
        global $gallery;
36
 
        parent::setUp();
37
 
 
38
 
        $ret = $this->_markPluginParametersForCleanup('module', 'ffmpeg');
39
 
        if ($ret) {
40
 
            print $ret->getAsHtml();
41
 
            return $this->failWithStatus($ret);
42
 
        }
43
 
 
44
 
        list ($ret, $this->_movie) =
45
 
            $this->_createRandomDataItem($this->_getRootId(), 'video/mpeg');
46
 
        if ($ret) {
47
 
            print $ret->getAsHtml();
48
 
            return $this->failWithStatus($ret);
49
 
        }
50
 
        $this->_markForCleanup($this->_movie);
51
 
 
52
 
        list ($ret, $this->_thumbnail) = $this->_createDerivative(
53
 
            $this->_movie, $this->_movie->getId(), DERIVATIVE_TYPE_IMAGE_THUMBNAIL,
54
 
            'convert-to-image/jpeg;thumbnail|150');
55
 
        if ($ret) {
56
 
            print $ret->getAsHtml();
57
 
            return $this->failWithStatus($ret);
58
 
        }
59
 
 
60
 
        $this->_savePlatform =& $gallery->getPlatform();
61
 
        $gallery->setPlatform(new AdminFfmpegControllerTestPlatform());
62
 
    }
63
 
 
64
 
    function testSaveGoodPath() {
65
 
        /* Use valid inputs */
66
 
        GalleryUtilities::putRequestVariable('form[action][save]', 1);
67
 
        GalleryUtilities::putRequestVariable('form[path]', '/validPath/ffmpeg');
68
 
 
69
 
        /* Perform the request and verify that we succeeded */
70
 
        $results = $this->handleRequest();
71
 
        $this->assertEquals(array('redirect' => array('view' => 'core.SiteAdmin',
72
 
                                                      'subView' => 'ffmpeg.AdminFfmpeg'),
73
 
                                  'status' => array('saved' => 1),
74
 
                                  'error' => array()),
75
 
                            $results);
76
 
 
77
 
        /* Verify the settings went in properly */
78
 
        list ($ret, $params) = GalleryCoreApi::fetchAllPluginParameters('module', 'ffmpeg');
79
 
        if ($ret) {
80
 
            return $this->failWithStatus($ret);
81
 
        }
82
 
        $this->assertEquals('/validPath/ffmpeg', $params['path']);
83
 
        $this->assertEquals('0', $params['useWatermark']);
84
 
    }
85
 
 
86
 
    function testSaveUseWatermark() {
87
 
        GalleryUtilities::putRequestVariable('form[action][save]', 1);
88
 
        GalleryUtilities::putRequestVariable('form[path]', '/validPath/ffmpeg');
89
 
        GalleryUtilities::putRequestVariable('form[useWatermark]', 1);
90
 
 
91
 
        /* Perform the request and verify that we succeeded */
92
 
        $results = $this->handleRequest();
93
 
        $this->assertEquals(array('redirect' => array('view' => 'core.SiteAdmin',
94
 
                                                      'subView' => 'ffmpeg.AdminFfmpeg'),
95
 
                                  'status' => array('saved' => 1),
96
 
                                  'error' => array()),
97
 
                            $results);
98
 
 
99
 
        /* Verify the settings went in properly */
100
 
        list ($ret, $params) = GalleryCoreApi::fetchAllPluginParameters('module', 'ffmpeg');
101
 
        if ($ret) {
102
 
            return $this->failWithStatus($ret);
103
 
        }
104
 
        $this->assertEquals('/validPath/ffmpeg', $params['path']);
105
 
        $this->assertEquals('1', $params['useWatermark']);
106
 
    }
107
 
 
108
 
    function testSaveIncompletePath() {
109
 
        /* Use valid inputs */
110
 
        GalleryUtilities::putRequestVariable('form[action][save]', 1);
111
 
        GalleryUtilities::putRequestVariable('form[path]', '/incompletePath/');
112
 
 
113
 
        /* Perform the request and verify that we succeeded */
114
 
        $results = $this->handleRequest();
115
 
        $this->assertEquals(array('redirect' => array('view' => 'core.SiteAdmin',
116
 
                                                      'subView' => 'ffmpeg.AdminFfmpeg'),
117
 
                                  'status' => array('saved' => 1),
118
 
                                  'error' => array()),
119
 
                            $results);
120
 
 
121
 
        /* Verify the settings went in properly */
122
 
        list ($ret, $path) = GalleryCoreApi::getPluginParameter('module', 'ffmpeg', 'path');
123
 
        if ($ret) {
124
 
            return $this->failWithStatus($ret);
125
 
        }
126
 
        $this->assertEquals('/incompletePath/ffmpeg', $path);
127
 
    }
128
 
 
129
 
    function testReset() {
130
 
        GalleryUtilities::putRequestVariable('form[action][reset]', 1);
131
 
 
132
 
        $results = $this->handleRequest();
133
 
        $this->assertEquals(array('redirect' => array('view' => 'core.SiteAdmin',
134
 
                                                      'subView' => 'ffmpeg.AdminFfmpeg'),
135
 
                                  'status' => array(),
136
 
                                  'error' => array()),
137
 
                            $results);
138
 
    }
139
 
 
140
 
    function testCancel() {
141
 
        GalleryUtilities::putRequestVariable('form[action][cancel]', 1);
142
 
 
143
 
        $results = $this->handleRequest();
144
 
        $this->assertEquals(array('redirect' => array('view' => 'core.SiteAdmin',
145
 
                                                      'subView' => 'core.AdminPlugins'),
146
 
                                  'status' => array(),
147
 
                                  'error' => array()),
148
 
                            $results);
149
 
    }
150
 
 
151
 
    function testSaveTestErrorPath() {
152
 
        /* Use valid inputs */
153
 
        GalleryUtilities::putRequestVariable('form[action][save]', 1);
154
 
        GalleryUtilities::putRequestVariable('form[path]', '/validPathBadBinary/ffmpeg');
155
 
 
156
 
        /* Perform the request and verify that we failed */
157
 
        $results = $this->handleRequest();
158
 
        $this->assertEquals(array('delegate' => array('view' => 'core.SiteAdmin',
159
 
                                                      'subView' => 'ffmpeg.AdminFfmpeg'),
160
 
                                  'status' => array(),
161
 
                                  'error' => array('form[error][path][testError]')),
162
 
                                  $results);
163
 
    }
164
 
 
165
 
    function testSaveBadPath() {
166
 
        /* Use valid inputs */
167
 
        GalleryUtilities::putRequestVariable('form[action][save]', 1);
168
 
        GalleryUtilities::putRequestVariable('form[path]', '/invalidPath/ffmpeg');
169
 
 
170
 
        /* Perform the request and verify that we failed */
171
 
        $results = $this->handleRequest();
172
 
        $this->assertEquals(array('delegate' => array('view' => 'core.SiteAdmin',
173
 
                                                      'subView' => 'ffmpeg.AdminFfmpeg'),
174
 
                                  'status' => array(),
175
 
                                  'error' => array('form[error][path][badPath]')),
176
 
                            $results);
177
 
    }
178
 
 
179
 
    function testNotExecutablePath() {
180
 
        /* Use valid inputs */
181
 
        GalleryUtilities::putRequestVariable('form[action][save]', 1);
182
 
        GalleryUtilities::putRequestVariable('form[path]', '/notExecutablePath/ffmpeg');
183
 
 
184
 
        /* Perform the request and verify that we failed */
185
 
        $results = $this->handleRequest();
186
 
        $this->assertEquals(array('delegate' => array('view' => 'core.SiteAdmin',
187
 
                                                      'subView' => 'ffmpeg.AdminFfmpeg'),
188
 
                                  'status' => array(),
189
 
                                  'error' => array('form[error][path][notExecutable]')),
190
 
                            $results);
191
 
    }
192
 
 
193
 
    function testSaveMissingPath() {
194
 
        /* Use valid inputs */
195
 
        GalleryUtilities::putRequestVariable('form[action][save]', 1);
196
 
        GalleryUtilities::putRequestVariable('form[path]', '');
197
 
 
198
 
        /* Perform the request and verify that we failed */
199
 
        $results = $this->handleRequest();
200
 
        $this->assertEquals(array('delegate' => array('view' => 'core.SiteAdmin',
201
 
                                                      'subView' => 'ffmpeg.AdminFfmpeg'),
202
 
                                  'status' => array(),
203
 
                                  'error' => array('form[error][path][missing]')),
204
 
                            $results);
205
 
    }
206
 
 
207
 
    function testAddRemoveWatermark() {
208
 
        global $gallery;
209
 
        $gallery->setPlatform($this->_savePlatform);
210
 
 
211
 
        $ret = $this->_saveThumbnailOps();
212
 
        if ($ret) {
213
 
            return $this->failWithStatus($ret);
214
 
        }
215
 
 
216
 
        list ($ret, $path) = GalleryCoreApi::getPluginParameter('module', 'ffmpeg', 'path');
217
 
        if ($ret) {
218
 
            return $this->failWithStatus($ret);
219
 
        }
220
 
 
221
 
        GalleryUtilities::putRequestVariable('form[path]', $path);
222
 
        GalleryUtilities::putRequestVariable('form[action][save]', 1);
223
 
        GalleryUtilities::putRequestVariable('form[addWatermark]', 1);
224
 
 
225
 
        $results = $this->handleRequest();
226
 
        $this->assertEquals(array('redirect' => array('view' => 'core.SiteAdmin',
227
 
                                                      'subView' => 'ffmpeg.AdminFfmpeg'),
228
 
                                  'status' => array('added' => 1, 'saved' => 1),
229
 
                                  'error' => array()),
230
 
                            $results);
231
 
 
232
 
        list ($ret, $thumbnail) = $this->_thumbnail->refresh();
233
 
        if ($ret) {
234
 
            $this->failWithStatus($ret);
235
 
        }
236
 
 
237
 
        $this->assertEquals('convert-to-image/jpeg;thumbnail|150;composite|plugins_data/modules/' .
238
 
            'ffmpeg/filmreel.png,image/png,12,399,top-left,0,0;composite|plugins_data/modules/' .
239
 
            'ffmpeg/filmreel.png,image/png,12,399,top-right,0,0',
240
 
            $thumbnail->getDerivativeOperations(), 'add watermark');
241
 
 
242
 
        GalleryUtilities::putRequestVariable('form[addWatermark]', 0);
243
 
        GalleryUtilities::putRequestVariable('form[removeWatermark]', 1);
244
 
 
245
 
        $results = $this->handleRequest();
246
 
        $this->assertEquals(array('redirect' => array('view' => 'core.SiteAdmin',
247
 
                                                      'subView' => 'ffmpeg.AdminFfmpeg'),
248
 
                                  'status' => array('removed' => 1, 'saved' => 1),
249
 
                                  'error' => array()),
250
 
                            $results);
251
 
 
252
 
        list ($ret, $thumbnail) = $this->_thumbnail->refresh();
253
 
        if ($ret) {
254
 
            $this->failWithStatus($ret);
255
 
        }
256
 
 
257
 
        $this->assertEquals('convert-to-image/jpeg;thumbnail|150',
258
 
            $thumbnail->getDerivativeOperations(), 'remove watermark');
259
 
 
260
 
        $ret = $this->_restoreThumbnailOps();
261
 
        if ($ret) {
262
 
            return $this->failWithStatus($ret);
263
 
        }
264
 
    }
265
 
 
266
 
    function _saveThumbnailOps() {
267
 
        global $gallery;
268
 
        $query = '
269
 
        SELECT [GalleryDerivative::id], [GalleryDerivative::derivativeOperations]
270
 
        FROM [GalleryDerivative], [GalleryChildEntity], [GalleryEntity]
271
 
        WHERE [GalleryDerivative::id] = [GalleryChildEntity::id]
272
 
          AND [GalleryChildEntity::parentId] = [GalleryEntity::id]
273
 
          AND [GalleryEntity::entityType] = \'GalleryMovieItem\'';
274
 
        list ($ret, $searchResults) = $gallery->search($query);
275
 
        if ($ret) {
276
 
            return $ret;
277
 
        }
278
 
        $this->_thumbnailOps = array();
279
 
        while ($result = $searchResults->nextResult()) {
280
 
            $this->_thumbnailOps[(int)$result[0]] = $result[1];
281
 
        }
282
 
        return null;
283
 
    }
284
 
 
285
 
    function _restoreThumbnailOps() {
286
 
        if (empty($this->_thumbnailOps)) {
287
 
            return null;
288
 
        }
289
 
        list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock(array_keys($this->_thumbnailOps));
290
 
        if ($ret) {
291
 
            return $ret;
292
 
        }
293
 
        list ($ret, $thumbnails) =
294
 
            GalleryCoreApi::loadEntitiesById(array_keys($this->_thumbnailOps));
295
 
        if ($ret) {
296
 
            GalleryCoreApi::releaseLocks($lockId);
297
 
            return $ret;
298
 
        }
299
 
        foreach ($thumbnails as $thumbnail) {
300
 
            $thumbnail->setDerivativeOperations($this->_thumbnailOps[$thumbnail->getId()]);
301
 
            $ret = $thumbnail->save();
302
 
            if ($ret) {
303
 
                GalleryCoreApi::releaseLocks($lockId);
304
 
                return $ret;
305
 
            }
306
 
        }
307
 
        $ret = GalleryCoreApi::releaseLocks($lockId);
308
 
        if ($ret) {
309
 
            return $ret;
310
 
        }
311
 
        return null;
312
 
    }
313
 
}
314
 
 
315
 
/**
316
 
 * Test platform for this test
317
 
 *
318
 
 * @package Ffmpeg
319
 
 * @subpackage PHPUnit
320
 
 */
321
 
class AdminFfmpegControllerTestPlatform {
322
 
    function getDirectorySeparator() {
323
 
        return '/';
324
 
    }
325
 
 
326
 
    function file_exists($path) {
327
 
        switch ($path) {
328
 
        case '/validPath/ffmpeg':
329
 
        case '/validPathBadBinary/ffmpeg':
330
 
        case '/notExecutablePath/ffmpeg':
331
 
        case '/incompletePath/':
332
 
        case '/incompletePath/ffmpeg':
333
 
            return true;
334
 
        }
335
 
 
336
 
        return false;
337
 
    }
338
 
 
339
 
    function is_dir($dir) {
340
 
        switch ($dir) {
341
 
        case '/validPath/':
342
 
        case '/validPathBadBinary/':
343
 
        case '/incompletePath/':
344
 
            return true;
345
 
        }
346
 
 
347
 
        return false;
348
 
    }
349
 
 
350
 
    function is_file($path) {
351
 
        switch ($path) {
352
 
        case '/validPath/ffmpeg':
353
 
        case '/validPathBadBinary/ffmpeg':
354
 
        case '/notExecutablePath/ffmpeg':
355
 
        case '/incompletePath/ffmpeg':
356
 
            return true;
357
 
        }
358
 
 
359
 
        return false;
360
 
    }
361
 
 
362
 
    function is_executable($path) {
363
 
        switch ($path) {
364
 
        case '/validPath/ffmpeg':
365
 
        case '/validPathBadBinary/ffmpeg':
366
 
        case '/incompletePath/ffmpeg':
367
 
            return true;
368
 
        }
369
 
 
370
 
        return false;
371
 
    }
372
 
 
373
 
    function unlink($args) {
374
 
        // do nothing
375
 
    }
376
 
 
377
 
    function isRestrictedByOpenBaseDir($path) {
378
 
        return false;
379
 
    }
380
 
 
381
 
    function exec($args) {
382
 
        switch ($args[0][0]) {
383
 
        case '/validPath/ffmpeg':
384
 
        case '/incompletePath/ffmpeg':
385
 
            return array(1, array('Input audio/video file formats: mpeg'));
386
 
 
387
 
        default:
388
 
            return array(0, array());
389
 
        }
390
 
    }
391
 
}
392
 
?>