3
* Gallery - a web based photo album viewer and editor
4
* Copyright (C) 2000-2007 Bharat Mediratta
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.
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.
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.
22
* AdminFfmpeg controller tests
25
* @author Bharat Mediratta <bharat@menalto.com>
26
* @version $Revision: 15513 $
28
class AdminFfmpegControllerTest extends GalleryControllerTestCase {
30
function AdminFfmpegControllerTest($methodName) {
31
$this->GalleryControllerTestCase($methodName, 'ffmpeg.AdminFfmpeg');
38
$ret = $this->_markPluginParametersForCleanup('module', 'ffmpeg');
40
print $ret->getAsHtml();
41
return $this->failWithStatus($ret);
44
list ($ret, $this->_movie) =
45
$this->_createRandomDataItem($this->_getRootId(), 'video/mpeg');
47
print $ret->getAsHtml();
48
return $this->failWithStatus($ret);
50
$this->_markForCleanup($this->_movie);
52
list ($ret, $this->_thumbnail) = $this->_createDerivative(
53
$this->_movie, $this->_movie->getId(), DERIVATIVE_TYPE_IMAGE_THUMBNAIL,
54
'convert-to-image/jpeg;thumbnail|150');
56
print $ret->getAsHtml();
57
return $this->failWithStatus($ret);
60
$this->_savePlatform =& $gallery->getPlatform();
61
$gallery->setPlatform(new AdminFfmpegControllerTestPlatform());
64
function testSaveGoodPath() {
65
/* Use valid inputs */
66
GalleryUtilities::putRequestVariable('form[action][save]', 1);
67
GalleryUtilities::putRequestVariable('form[path]', '/validPath/ffmpeg');
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),
77
/* Verify the settings went in properly */
78
list ($ret, $params) = GalleryCoreApi::fetchAllPluginParameters('module', 'ffmpeg');
80
return $this->failWithStatus($ret);
82
$this->assertEquals('/validPath/ffmpeg', $params['path']);
83
$this->assertEquals('0', $params['useWatermark']);
86
function testSaveUseWatermark() {
87
GalleryUtilities::putRequestVariable('form[action][save]', 1);
88
GalleryUtilities::putRequestVariable('form[path]', '/validPath/ffmpeg');
89
GalleryUtilities::putRequestVariable('form[useWatermark]', 1);
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),
99
/* Verify the settings went in properly */
100
list ($ret, $params) = GalleryCoreApi::fetchAllPluginParameters('module', 'ffmpeg');
102
return $this->failWithStatus($ret);
104
$this->assertEquals('/validPath/ffmpeg', $params['path']);
105
$this->assertEquals('1', $params['useWatermark']);
108
function testSaveIncompletePath() {
109
/* Use valid inputs */
110
GalleryUtilities::putRequestVariable('form[action][save]', 1);
111
GalleryUtilities::putRequestVariable('form[path]', '/incompletePath/');
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),
121
/* Verify the settings went in properly */
122
list ($ret, $path) = GalleryCoreApi::getPluginParameter('module', 'ffmpeg', 'path');
124
return $this->failWithStatus($ret);
126
$this->assertEquals('/incompletePath/ffmpeg', $path);
129
function testReset() {
130
GalleryUtilities::putRequestVariable('form[action][reset]', 1);
132
$results = $this->handleRequest();
133
$this->assertEquals(array('redirect' => array('view' => 'core.SiteAdmin',
134
'subView' => 'ffmpeg.AdminFfmpeg'),
140
function testCancel() {
141
GalleryUtilities::putRequestVariable('form[action][cancel]', 1);
143
$results = $this->handleRequest();
144
$this->assertEquals(array('redirect' => array('view' => 'core.SiteAdmin',
145
'subView' => 'core.AdminPlugins'),
151
function testSaveTestErrorPath() {
152
/* Use valid inputs */
153
GalleryUtilities::putRequestVariable('form[action][save]', 1);
154
GalleryUtilities::putRequestVariable('form[path]', '/validPathBadBinary/ffmpeg');
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'),
161
'error' => array('form[error][path][testError]')),
165
function testSaveBadPath() {
166
/* Use valid inputs */
167
GalleryUtilities::putRequestVariable('form[action][save]', 1);
168
GalleryUtilities::putRequestVariable('form[path]', '/invalidPath/ffmpeg');
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'),
175
'error' => array('form[error][path][badPath]')),
179
function testNotExecutablePath() {
180
/* Use valid inputs */
181
GalleryUtilities::putRequestVariable('form[action][save]', 1);
182
GalleryUtilities::putRequestVariable('form[path]', '/notExecutablePath/ffmpeg');
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'),
189
'error' => array('form[error][path][notExecutable]')),
193
function testSaveMissingPath() {
194
/* Use valid inputs */
195
GalleryUtilities::putRequestVariable('form[action][save]', 1);
196
GalleryUtilities::putRequestVariable('form[path]', '');
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'),
203
'error' => array('form[error][path][missing]')),
207
function testAddRemoveWatermark() {
209
$gallery->setPlatform($this->_savePlatform);
211
$ret = $this->_saveThumbnailOps();
213
return $this->failWithStatus($ret);
216
list ($ret, $path) = GalleryCoreApi::getPluginParameter('module', 'ffmpeg', 'path');
218
return $this->failWithStatus($ret);
221
GalleryUtilities::putRequestVariable('form[path]', $path);
222
GalleryUtilities::putRequestVariable('form[action][save]', 1);
223
GalleryUtilities::putRequestVariable('form[addWatermark]', 1);
225
$results = $this->handleRequest();
226
$this->assertEquals(array('redirect' => array('view' => 'core.SiteAdmin',
227
'subView' => 'ffmpeg.AdminFfmpeg'),
228
'status' => array('added' => 1, 'saved' => 1),
232
list ($ret, $thumbnail) = $this->_thumbnail->refresh();
234
$this->failWithStatus($ret);
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');
242
GalleryUtilities::putRequestVariable('form[addWatermark]', 0);
243
GalleryUtilities::putRequestVariable('form[removeWatermark]', 1);
245
$results = $this->handleRequest();
246
$this->assertEquals(array('redirect' => array('view' => 'core.SiteAdmin',
247
'subView' => 'ffmpeg.AdminFfmpeg'),
248
'status' => array('removed' => 1, 'saved' => 1),
252
list ($ret, $thumbnail) = $this->_thumbnail->refresh();
254
$this->failWithStatus($ret);
257
$this->assertEquals('convert-to-image/jpeg;thumbnail|150',
258
$thumbnail->getDerivativeOperations(), 'remove watermark');
260
$ret = $this->_restoreThumbnailOps();
262
return $this->failWithStatus($ret);
266
function _saveThumbnailOps() {
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);
278
$this->_thumbnailOps = array();
279
while ($result = $searchResults->nextResult()) {
280
$this->_thumbnailOps[(int)$result[0]] = $result[1];
285
function _restoreThumbnailOps() {
286
if (empty($this->_thumbnailOps)) {
289
list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock(array_keys($this->_thumbnailOps));
293
list ($ret, $thumbnails) =
294
GalleryCoreApi::loadEntitiesById(array_keys($this->_thumbnailOps));
296
GalleryCoreApi::releaseLocks($lockId);
299
foreach ($thumbnails as $thumbnail) {
300
$thumbnail->setDerivativeOperations($this->_thumbnailOps[$thumbnail->getId()]);
301
$ret = $thumbnail->save();
303
GalleryCoreApi::releaseLocks($lockId);
307
$ret = GalleryCoreApi::releaseLocks($lockId);
316
* Test platform for this test
319
* @subpackage PHPUnit
321
class AdminFfmpegControllerTestPlatform {
322
function getDirectorySeparator() {
326
function file_exists($path) {
328
case '/validPath/ffmpeg':
329
case '/validPathBadBinary/ffmpeg':
330
case '/notExecutablePath/ffmpeg':
331
case '/incompletePath/':
332
case '/incompletePath/ffmpeg':
339
function is_dir($dir) {
342
case '/validPathBadBinary/':
343
case '/incompletePath/':
350
function is_file($path) {
352
case '/validPath/ffmpeg':
353
case '/validPathBadBinary/ffmpeg':
354
case '/notExecutablePath/ffmpeg':
355
case '/incompletePath/ffmpeg':
362
function is_executable($path) {
364
case '/validPath/ffmpeg':
365
case '/validPathBadBinary/ffmpeg':
366
case '/incompletePath/ffmpeg':
373
function unlink($args) {
377
function isRestrictedByOpenBaseDir($path) {
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'));
388
return array(0, array());