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
* AdminNetPbm controller tests
25
* @author Bharat Mediratta <bharat@menalto.com>
26
* @version $Revision: 15513 $
28
class AdminNetPbmControllerTest extends GalleryControllerTestCase {
30
function AdminNetPbmControllerTest($methodName) {
31
$this->GalleryControllerTestCase($methodName, 'netpbm.AdminNetPbm');
38
$ret = $this->_markPluginParametersForCleanup('module', 'netpbm');
40
print $ret->getAsHtml();
41
return $this->failWithStatus($ret);
44
foreach (array('jpegQuality' => 75, 'pnmcomp' => 'pamcomp') as $key => $value) {
45
$ret = GalleryCoreApi::setPluginParameter('module', 'netpbm', $key, $value);
47
print $ret->getAsHtml();
48
return $this->failWithStatus($ret);
52
$gallery->setPlatform(new AdminNetPbmControllerTestPlatform($gallery->getPlatform()));
55
function testSaveGoodNetPbmPathNoJheadPath() {
56
GalleryUtilities::putRequestVariable('form[action][save]', 1);
57
GalleryUtilities::putRequestVariable('form[path]', '/validPath/');
58
GalleryUtilities::putRequestVariable('form[jpegQuality]', '12');
60
/* Perform the request and verify that we succeeded */
61
$results = $this->handleRequest();
62
$this->assertEquals(array('redirect' => array('view' => 'core.SiteAdmin',
63
'subView' => 'netpbm.AdminNetPbm'),
64
'status' => array('saved' => 1),
68
/* Verify the settings went in properly */
69
$this->assertEquals(array(null, '/validPath/'),
70
GalleryCoreApi::getPluginParameter('module', 'netpbm', 'path'));
71
$this->assertEquals(array(null, '12'),
72
GalleryCoreApi::getPluginParameter('module', 'netpbm', 'jpegQuality'));
75
function testSaveGoodPaths() {
76
GalleryUtilities::putRequestVariable('form[action][save]', 1);
77
GalleryUtilities::putRequestVariable('form[path]', '/validPath/');
78
GalleryUtilities::putRequestVariable('form[jheadPath]', '/validPath/');
79
GalleryUtilities::putRequestVariable('form[jpegQuality]', '12');
81
/* Perform the request and verify that we succeeded */
82
$results = $this->handleRequest();
83
$this->assertEquals(array('redirect' => array('view' => 'core.SiteAdmin',
84
'subView' => 'netpbm.AdminNetPbm'),
85
'status' => array('saved' => 1),
89
/* Verify the settings went in properly */
90
$this->assertEquals(array(null, '/validPath/'),
91
GalleryCoreApi::getPluginParameter('module', 'netpbm', 'path'));
92
$this->assertEquals(array(null, '/validPath/'),
93
GalleryCoreApi::getPluginParameter('module', 'netpbm', 'jheadPath'));
94
$this->assertEquals(array(null, '12'),
95
GalleryCoreApi::getPluginParameter('module', 'netpbm', 'jpegQuality'));
96
/* Verify we detected which binaries to use: */
97
$this->assertEquals(array(null, 'pnmcomp'),
98
GalleryCoreApi::getPluginParameter('module', 'netpbm', 'pnmcomp'));
101
function testReset() {
102
GalleryUtilities::putRequestVariable('form[action][reset]', 1);
104
$results = $this->handleRequest();
105
$this->assertEquals(array('redirect' => array('view' => 'core.SiteAdmin',
106
'subView' => 'netpbm.AdminNetPbm'),
112
function testCancel() {
113
GalleryUtilities::putRequestVariable('form[action][cancel]', 1);
115
$results = $this->handleRequest();
116
$this->assertEquals(array('redirect' => array('view' => 'core.SiteAdmin',
117
'subView' => 'core.AdminPlugins'),
123
function testSaveTestErrorPath() {
124
GalleryUtilities::putRequestVariable('form[action][save]', 1);
125
GalleryUtilities::putRequestVariable('form[path]', '/validPathBadBinaries/');
126
GalleryUtilities::putRequestVariable('form[jpegQuality]', '12');
128
/* Perform the request and verify that we failed */
129
$results = $this->handleRequest();
130
$this->assertEquals(array('delegate' => array('view' => 'core.SiteAdmin',
131
'subView' => 'netpbm.AdminNetPbm'),
133
'error' => array('form[error][path][testError]')),
137
function testSaveBadPath() {
138
GalleryUtilities::putRequestVariable('form[action][save]', 1);
139
GalleryUtilities::putRequestVariable('form[path]', '/invalidPath/');
140
GalleryUtilities::putRequestVariable('form[jpegQuality]', '12');
142
/* Perform the request and verify that we failed */
143
$results = $this->handleRequest();
144
$this->assertEquals(array('delegate' => array('view' => 'core.SiteAdmin',
145
'subView' => 'netpbm.AdminNetPbm'),
147
'error' => array('form[error][path][badPath]')),
151
function testSaveMissingPath() {
152
GalleryUtilities::putRequestVariable('form[action][save]', 1);
153
GalleryUtilities::putRequestVariable('form[path]', '');
154
GalleryUtilities::putRequestVariable('form[jpegQuality]', '12');
156
/* Perform the request and verify that we failed */
157
$results = $this->handleRequest();
158
$this->assertEquals(array('delegate' => array('view' => 'core.SiteAdmin',
159
'subView' => 'netpbm.AdminNetPbm'),
161
'error' => array('form[error][path][missing]')),
165
function testSaveGoodNetPbmBadJheadPath() {
166
GalleryUtilities::putRequestVariable('form[action][save]', 1);
167
GalleryUtilities::putRequestVariable('form[path]', '/validPath/');
168
GalleryUtilities::putRequestVariable('form[jheadPath]', '/invalid/');
169
GalleryUtilities::putRequestVariable('form[jpegQuality]', '12');
171
/* Perform the request and verify that we failed */
172
$results = $this->handleRequest();
173
$this->assertEquals(array('delegate' => array('view' => 'core.SiteAdmin',
174
'subView' => 'netpbm.AdminNetPbm'),
176
'error' => array('form[error][jheadPath][badPath]')),
182
* Test platform for this test
185
* @subpackage PHPUnit
187
class AdminNetPbmControllerTestPlatform {
188
function AdminNetPbmControllerTestPlatform($originalPlatform) {
189
$this->_platform = $originalPlatform;
192
function getDirectorySeparator() {
196
function file_exists($path) {
199
case '/validPath/pnmscale':
200
case '/validPath/pnmcut':
201
case '/validPath/pnmfile':
202
case '/validPath/pnmcomp':
203
case '/validPath/pnmflip':
204
case '/validPath/pnmquant':
205
case '/validPath/giftopnm':
206
case '/validPath/ppmtogif':
207
case '/validPath/jpegtopnm':
208
case '/validPath/ppmtojpeg':
209
case '/validPath/pnmtojpeg':
210
case '/validPath/pngtopnm':
211
case '/validPath/pnmtopng':
212
case '/validPath/tifftopnm':
213
case '/validPath/pnmtotiff':
214
case '/validPath/jhead':
215
case '/validPathBadBinaries/':
222
function is_dir($dir) {
225
case '/validPathBadBinaries/':
232
function unlink($args) {
236
function isRestrictedByOpenBaseDir($path) {
240
function exec($args) {
241
switch ($args[0][0]) {
242
case '/validPath/pnmscale':
243
case '/validPath/pnmcut':
244
case '/validPath/pnmfile':
245
case '/validPath/pnmcomp':
246
case '/validPath/giftopnm':
247
case '/validPath/ppmtogif':
248
case '/validPath/jpegtopnm':
249
case '/validPath/ppmtojpeg':
250
case '/validPath/pngtopnm':
251
case '/validPath/pnmtopng':
252
case '/validPath/tifftopnm':
253
case '/validPath/pnmtotiff':
254
case '/validPath/jhead':
255
return array(1, array());
258
return array(0, null);
262
function realpath($file) {
263
return $this->_platform->realpath($file);