~ubuntu-branches/ubuntu/maverick/gallery2/maverick

« back to all changes in this revision

Viewing changes to modules/netpbm/test/phpunit/AdminNetPbmControllerTest.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
 
 * AdminNetPbm controller tests
23
 
 * @package NetPbm
24
 
 * @subpackage PHPUnit
25
 
 * @author Bharat Mediratta <bharat@menalto.com>
26
 
 * @version $Revision: 15513 $
27
 
 */
28
 
class AdminNetPbmControllerTest extends GalleryControllerTestCase {
29
 
 
30
 
    function AdminNetPbmControllerTest($methodName) {
31
 
        $this->GalleryControllerTestCase($methodName, 'netpbm.AdminNetPbm');
32
 
    }
33
 
 
34
 
    function setUp() {
35
 
        global $gallery;
36
 
        parent::setUp();
37
 
 
38
 
        $ret = $this->_markPluginParametersForCleanup('module', 'netpbm');
39
 
        if ($ret) {
40
 
            print $ret->getAsHtml();
41
 
            return $this->failWithStatus($ret);
42
 
        }
43
 
 
44
 
        foreach (array('jpegQuality' => 75, 'pnmcomp' => 'pamcomp') as $key => $value) {
45
 
            $ret = GalleryCoreApi::setPluginParameter('module', 'netpbm', $key, $value);
46
 
            if ($ret) {
47
 
                print $ret->getAsHtml();
48
 
                return $this->failWithStatus($ret);
49
 
            }
50
 
        }
51
 
 
52
 
        $gallery->setPlatform(new AdminNetPbmControllerTestPlatform($gallery->getPlatform()));
53
 
    }
54
 
 
55
 
    function testSaveGoodNetPbmPathNoJheadPath() {
56
 
        GalleryUtilities::putRequestVariable('form[action][save]', 1);
57
 
        GalleryUtilities::putRequestVariable('form[path]', '/validPath/');
58
 
        GalleryUtilities::putRequestVariable('form[jpegQuality]', '12');
59
 
 
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),
65
 
                                  'error' => array()),
66
 
                            $results);
67
 
 
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'));
73
 
    }
74
 
 
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');
80
 
 
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),
86
 
                                  'error' => array()),
87
 
                            $results);
88
 
 
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'));
99
 
    }
100
 
 
101
 
    function testReset() {
102
 
        GalleryUtilities::putRequestVariable('form[action][reset]', 1);
103
 
 
104
 
        $results = $this->handleRequest();
105
 
        $this->assertEquals(array('redirect' => array('view' => 'core.SiteAdmin',
106
 
                                                      'subView' => 'netpbm.AdminNetPbm'),
107
 
                                  'status' => array(),
108
 
                                  'error' => array()),
109
 
                            $results);
110
 
    }
111
 
 
112
 
    function testCancel() {
113
 
        GalleryUtilities::putRequestVariable('form[action][cancel]', 1);
114
 
 
115
 
        $results = $this->handleRequest();
116
 
        $this->assertEquals(array('redirect' => array('view' => 'core.SiteAdmin',
117
 
                                                      'subView' => 'core.AdminPlugins'),
118
 
                                  'status' => array(),
119
 
                                  'error' => array()),
120
 
                            $results);
121
 
    }
122
 
 
123
 
    function testSaveTestErrorPath() {
124
 
        GalleryUtilities::putRequestVariable('form[action][save]', 1);
125
 
        GalleryUtilities::putRequestVariable('form[path]', '/validPathBadBinaries/');
126
 
        GalleryUtilities::putRequestVariable('form[jpegQuality]', '12');
127
 
 
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'),
132
 
                                  'status' => array(),
133
 
                                  'error' => array('form[error][path][testError]')),
134
 
                                  $results);
135
 
    }
136
 
 
137
 
    function testSaveBadPath() {
138
 
        GalleryUtilities::putRequestVariable('form[action][save]', 1);
139
 
        GalleryUtilities::putRequestVariable('form[path]', '/invalidPath/');
140
 
        GalleryUtilities::putRequestVariable('form[jpegQuality]', '12');
141
 
 
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'),
146
 
                                  'status' => array(),
147
 
                                  'error' => array('form[error][path][badPath]')),
148
 
                            $results);
149
 
    }
150
 
 
151
 
    function testSaveMissingPath() {
152
 
        GalleryUtilities::putRequestVariable('form[action][save]', 1);
153
 
        GalleryUtilities::putRequestVariable('form[path]', '');
154
 
        GalleryUtilities::putRequestVariable('form[jpegQuality]', '12');
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' => 'netpbm.AdminNetPbm'),
160
 
                                  'status' => array(),
161
 
                                  'error' => array('form[error][path][missing]')),
162
 
                            $results);
163
 
    }
164
 
 
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');
170
 
 
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'),
175
 
                                  'status' => array(),
176
 
                                  'error' => array('form[error][jheadPath][badPath]')),
177
 
                            $results);
178
 
    }
179
 
}
180
 
 
181
 
/**
182
 
 * Test platform for this test
183
 
 *
184
 
 * @package NetPbm
185
 
 * @subpackage PHPUnit
186
 
 */
187
 
class AdminNetPbmControllerTestPlatform {
188
 
    function AdminNetPbmControllerTestPlatform($originalPlatform) {
189
 
        $this->_platform = $originalPlatform;
190
 
    }
191
 
 
192
 
    function getDirectorySeparator() {
193
 
        return '/';
194
 
    }
195
 
 
196
 
    function file_exists($path) {
197
 
        switch ($path) {
198
 
        case '/validPath/':
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/':
216
 
            return true;
217
 
        }
218
 
 
219
 
        return false;
220
 
    }
221
 
 
222
 
    function is_dir($dir) {
223
 
        switch ($dir) {
224
 
        case '/validPath/':
225
 
        case '/validPathBadBinaries/':
226
 
            return true;
227
 
        }
228
 
 
229
 
        return false;
230
 
    }
231
 
 
232
 
    function unlink($args) {
233
 
        /* do nothing */
234
 
    }
235
 
 
236
 
    function isRestrictedByOpenBaseDir($path) {
237
 
        return false;
238
 
    }
239
 
 
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());
256
 
 
257
 
        default:
258
 
            return array(0, null);
259
 
        }
260
 
    }
261
 
 
262
 
    function realpath($file) {
263
 
        return $this->_platform->realpath($file);
264
 
    }
265
 
}
266
 
?>