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

« back to all changes in this revision

Viewing changes to modules/watermark/test/phpunit/WatermarkSiteAdminControllerTest.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: WatermarkSiteAdminControllerTest.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.16 $ $Date: 2005/08/23 03:49:57 $
 
23
 * @version $Revision: 1.18 $ $Date: 2006/01/10 04:43:34 $
24
24
 * @package Watermark
25
25
 * @subpackage PHPUnit
26
26
 * @author Alan Harder <alan.harder@sun.com>
29
29
/**
30
30
 * Load required classes
31
31
 */
32
 
GalleryCoreApi::relativeRequireOnce('modules/watermark/classes/WatermarkHelper.class');
 
32
GalleryCoreApi::requireOnce('modules/watermark/classes/WatermarkHelper.class');
33
33
 
34
34
/**
35
35
 * WatermarkSiteAdmin controller tests
48
48
        parent::setUp();
49
49
 
50
50
        $ret = $this->_markPluginParametersForCleanup('module', 'watermark');
51
 
        if ($ret->isError()) {
 
51
        if ($ret) {
52
52
            print $ret->getAsHtml();
53
53
            return $ret->wrap(__FILE__, __LINE__);
54
54
        }
59
59
 
60
60
        /* Get the list of watermarks before, then after delete any that we created */
61
61
        list ($ret, $this->_beforeWatermarks) = WatermarkHelper::fetchWatermarks();
62
 
        if ($ret->isError()) {
 
62
        if ($ret) {
63
63
            print $ret->getAsHtml();
64
64
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
65
65
        }
68
68
    function tearDown() {
69
69
        /* Get the list of watermarks before, then after delete any that we created */
70
70
        list ($ret, $this->_afterWatermarks) = WatermarkHelper::fetchWatermarks();
71
 
        if ($ret->isError()) {
 
71
        if ($ret) {
72
72
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
73
73
        }
74
74
 
75
75
        foreach (array_keys($this->_afterWatermarks) as $id) {
76
76
            if (!isset($this->_beforeWatermarks[$id])) {
77
77
                $ret = GalleryCoreApi::deleteEntityById($id);
78
 
                if ($ret->isError()) {
 
78
                if ($ret) {
79
79
                    return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
80
80
                }
81
81
            }
102
102
        GalleryUtilities::putRequestVariable('form[name][1]', $this->_randomName);
103
103
        GalleryUtilities::putRequestVariable('form[type][1]', 'image/jpeg');
104
104
        GalleryUtilities::putRequestVariable('form[tmp_name][1]',
105
 
            dirname(__FILE__) . '/../../../core/test/data/test1.jpg');
 
105
            GalleryCoreApi::getPluginBaseDir('module', 'core')
 
106
                . 'modules/core/test/data/test1.jpg');
106
107
 
107
108
        $results = $this->handleRequest();
108
109
        $counter =& GalleryTestCase::getEntityCounter();
117
118
 
118
119
        /* Verify */
119
120
        list ($ret, $map) = $this->_fetchWatermarkMapByFilename();
120
 
        if ($ret->isError()) {
 
121
        if ($ret) {
121
122
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
122
123
        }
123
124
 
131
132
            GalleryUtilities::putRequestVariable('form[name][1]', $this->_randomName);
132
133
            GalleryUtilities::putRequestVariable('form[type][1]', 'image/jpeg');
133
134
            GalleryUtilities::putRequestVariable('form[tmp_name][1]',
134
 
                dirname(__FILE__) . '/../../../core/test/data/test1.jpg');
 
135
                GalleryCoreApi::getPluginBaseDir('module', 'core')
 
136
                    . 'modules/core/test/data/test1.jpg');
135
137
 
136
138
            $results = $this->handleRequest();
137
139
            $counter =& GalleryTestCase::getEntityCounter();
147
149
 
148
150
        /* Verify */
149
151
        list ($ret, $map) = $this->_fetchWatermarkMapByFilename();
150
 
        if ($ret->isError()) {
 
152
        if ($ret) {
151
153
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
152
154
        }
153
155
 
162
164
        GalleryUtilities::putRequestVariable('form[type][1]', 'image/jpeg');
163
165
        GalleryUtilities::putRequestVariable('form[type][1]', 'application/octet-stream');
164
166
        GalleryUtilities::putRequestVariable('form[tmp_name][1]',
165
 
            dirname(__FILE__) . '/../../../core/test/data/test1.jpg');
 
167
            GalleryCoreApi::getPluginBaseDir('module', 'core')
 
168
                . 'modules/core/test/data/test1.jpg');
166
169
 
167
170
        $results = $this->handleRequest();
168
171
        $counter =& GalleryTestCase::getEntityCounter();
176
179
                            $results, 'Add same name, bad mime');
177
180
 
178
181
        list ($ret, $map) = $this->_fetchWatermarkMapByFilename();
179
 
        if ($ret->isError()) {
 
182
        if ($ret) {
180
183
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
181
184
        }
182
185
 
194
197
        GalleryUtilities::putRequestVariable('form[name][1]', $this->_randomName);
195
198
        GalleryUtilities::putRequestVariable('form[type][1]', 'image/jpeg');
196
199
        GalleryUtilities::putRequestVariable('form[tmp_name][1]',
197
 
            dirname(__FILE__) . '/../../../core/test/data/test1.jpg');
 
200
            GalleryCoreApi::getPluginBaseDir('module', 'core')
 
201
                . 'modules/core/test/data/test1.jpg');
198
202
 
199
203
        $results = $this->handleRequest();
200
204
        $counter =& GalleryTestCase::getEntityCounter();
208
212
                            $results, 'Add');
209
213
 
210
214
        list ($ret, $map) = $this->_fetchWatermarkMapByFilename();
211
 
        if ($ret->isError()) {
 
215
        if ($ret) {
212
216
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
213
217
        }
214
218
 
229
233
 
230
234
            /* Verify that it's gone */
231
235
            $ret = $this->_verifyMissing($map[$this->_expectedName]->getId());
232
 
            if ($ret->isError()) {
 
236
            if ($ret) {
233
237
                return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
234
238
            }
235
239
        } else {
243
247
        GalleryUtilities::putRequestVariable('form[name][1]', $this->_randomName);
244
248
        GalleryUtilities::putRequestVariable('form[type][1]', 'image/jpeg');
245
249
        GalleryUtilities::putRequestVariable('form[tmp_name][1]',
246
 
            dirname(__FILE__) . '/../../../core/test/data/test1.jpg');
 
250
            GalleryCoreApi::getPluginBaseDir('module', 'core')
 
251
                . 'modules/core/test/data/test1.jpg');
247
252
 
248
253
        $results = $this->handleRequest();
249
254
        $counter =& GalleryTestCase::getEntityCounter();
257
262
            $results, 'Add');
258
263
 
259
264
        list ($ret, $map) = $this->_fetchWatermarkMapByFilename();
260
 
        if ($ret->isError()) {
 
265
        if ($ret) {
261
266
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
262
267
        }
263
268
        $watermark = $map[$this->_expectedName];
264
269
 
265
270
        /* Use this watermark */
266
271
        list ($ret, $item) = $this->_createRandomDataItem($this->_getRootId());
267
 
        if ($ret->isError()) {
 
272
        if ($ret) {
268
273
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
269
274
        }
270
275
        $this->_markForCleanup($item);
271
276
        list ($ret, $derivative) = $this->_createDerivative(
272
277
            $item, $item->getId(), DERIVATIVE_TYPE_IMAGE_THUMBNAIL, '', 'test/file',
273
 
            array('postfilterOperations' =>
 
278
            array('postFilterOperations' =>
274
279
                      'composite|plugins_data/modules/watermark/' . $this->_expectedName . ',...'));
275
 
        if ($ret->isError()) {
 
280
        if ($ret) {
276
281
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
277
282
        }
278
283
 
294
299
 
295
300
            /* Verify that it's NOT gone */
296
301
            $ret = $this->_verifyEntity($watermark);
297
 
            if ($ret->isError()) {
 
302
            if ($ret) {
298
303
                return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
299
304
            }
300
305
        } else {
338
343
                            $results, 'Add');
339
344
 
340
345
        list ($ret, $map) = $this->_fetchWatermarkMapByFilename();
341
 
        if ($ret->isError()) {
 
346
        if ($ret) {
342
347
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
343
348
        }
344
349
        $this->assert(isset($map[$expectedName]), 'Watermark is missing');
348
353
                                'Watermark mime type incorrect');
349
354
 
350
355
            list ($ret, $path) = $map[$expectedName]->fetchPath();
351
 
            if ($ret->isError()) {
 
356
            if ($ret) {
352
357
                return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
353
358
            }
354
359
 
361
366
 
362
367
    function _fetchWatermarkMapByFilename() {
363
368
        list ($ret, $watermarks) = WatermarkHelper::fetchWatermarks();
364
 
        if ($ret->isError()) {
 
369
        if ($ret) {
365
370
            return array($this->wrap(__FILE__, __LINE__), null);
366
371
        }
367
372
        $results = array();
368
373
        foreach ($watermarks as $id => $watermark) {
369
374
            $results[$watermark->getFileName()] = $watermark;
370
375
        }
371
 
        return array(GalleryStatus::success(), $results);
 
376
        return array(null, $results);
372
377
    }
373
378
 
374
379
    function testSaveMissingId() {