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

« back to all changes in this revision

Viewing changes to modules/rss/test/phpunit/RssEditFeedTest.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
 
GalleryCoreApi::requireOnce('modules/rss/classes/RssMapHelper.class');
22
 
 
23
 
/**
24
 
 * EditFeed controller tests
25
 
 *
26
 
 * @package Rss
27
 
 * @subpackage PHPUnit
28
 
 * @author Jonatan Heyman <http://heyman.info>
29
 
 * @author Pierre-Luc Paour
30
 
 * @author Daniel Grund <http://www.photogrund.nl>
31
 
 * @version $Revision: 15513 $
32
 
 */
33
 
class RssEditFeedTest extends GalleryControllerTestCase {
34
 
 
35
 
    var $_feedsToDelete;
36
 
 
37
 
    function RssEditFeedTest($methodName) {
38
 
        $this->GalleryControllerTestCase($methodName, 'rss.EditFeed');
39
 
    }
40
 
 
41
 
    function setUp() {
42
 
        parent::setUp();
43
 
 
44
 
        $ret = $this->_markPluginParametersForCleanup('module', 'rss');
45
 
        if ($ret) {
46
 
            print $ret->getAsHtml();
47
 
            return $this->failWithStatus($ret);
48
 
        }
49
 
 
50
 
        $ret = GalleryCoreApi::setPluginParameter('module', 'rss', 'allowConfigurableFeed', 1);
51
 
        if ($ret) {
52
 
            return $this->failWithStatus($ret);
53
 
        }
54
 
        $ret = GalleryCoreApi::setPluginParameter('module', 'rss', 'allowAlbums', 1);
55
 
        if ($ret) {
56
 
            return $this->failWithStatus($ret);
57
 
        }
58
 
    }
59
 
 
60
 
    function tearDown() {
61
 
        if (!empty($this->_feedsToDelete)) {
62
 
            foreach ($this->_feedsToDelete as $name) {
63
 
                $ret = RssMapHelper::deleteFeed($name);
64
 
                if ($ret) {
65
 
                    return $this->failWithStatus($ret);
66
 
                }
67
 
            }
68
 
        }
69
 
 
70
 
        parent::tearDown();
71
 
    }
72
 
 
73
 
    function testRssEditFeedCancel() {
74
 
        GalleryUtilities::putRequestVariable('form[action][cancel]', '1');
75
 
        GalleryUtilities::putRequestVariable('form[itemId]', $this->_getRootId());
76
 
        GalleryUtilities::putRequestVariable('form[mode]', 'edit');
77
 
 
78
 
        $results = $this->handleRequest();
79
 
        $this->assertEquals(array(
80
 
            'status' => array(),
81
 
            'error' => array(),
82
 
            'redirect' => array(
83
 
                'view' => 'core.ItemAdmin',
84
 
                'subView' => 'rss.EditFeed',
85
 
                'itemId' => $this->_getRootId(),
86
 
                'mode' => 'list',
87
 
                'form' => array(
88
 
                    'action' => array('cancel' => '1'),
89
 
                    'mode' => 'edit',
90
 
                    'itemId' => (string) $this->_getRootId()))),
91
 
            $results);
92
 
    }
93
 
 
94
 
    function testRssEditFeed() {
95
 
        $name = 'feed' .rand();
96
 
        GalleryUtilities::putRequestVariable('form[action][create]', '1');
97
 
        GalleryUtilities::putRequestVariable('form[action][save]', '1');
98
 
        GalleryUtilities::putRequestVariable('form[mode]', 'new');
99
 
 
100
 
        $values = array(
101
 
            'itemId' => (string) $this->_getRootId(),
102
 
            'mode' => 'edit',
103
 
            'feedType' => 'photosRecurse',
104
 
            'photosRecurseLimit'=> '0',
105
 
            'feedName' => $name,
106
 
            'version' => '2.0',
107
 
            'count' => '10',
108
 
            'copyright' => 'me',
109
 
            'description' => 'description',
110
 
            'useImage' => '1',
111
 
            'usePubDate' => '1',
112
 
            'useEnclosure' => '1',
113
 
            'useCategory' => '1',
114
 
            'useCloud' => '1',
115
 
            'cloudDomain' => 'Gallery',
116
 
            'cloudPort' => '202',
117
 
            'cloudPath' => 'rss',
118
 
            'cloudRegisterProcedure' => 'register',
119
 
            'cloudProtocol' => 'tcp',
120
 
            'useTtl' => '1',
121
 
            'ttl' => '60',
122
 
            'category' => 'photo',
123
 
            'useItemCategory' => '1',
124
 
            'language' => 'en-us',
125
 
            'feedDate' => 'updated');
126
 
 
127
 
        foreach ($values as $key => $value) {
128
 
            GalleryUtilities::putRequestVariable('form['.$key.']', $value);
129
 
        }
130
 
 
131
 
        $results = $this->handleRequest();
132
 
 
133
 
        $this->assertEquals(array(
134
 
            'status' => array('saved' => 1),
135
 
            'error' => array(),
136
 
            'redirect' => array(
137
 
                'view' => 'core.ItemAdmin',
138
 
                'subView' => 'rss.EditFeed',
139
 
                'itemId' => $this->_getRootId(),
140
 
                'mode' => 'edit',
141
 
                'form' => array_merge(array(
142
 
                    'action' => array('save' => '1', 'create' => '1'),
143
 
                    'mode' => 'new',
144
 
                    ), $values))),
145
 
            $results);
146
 
 
147
 
        /* remember to delete this new feed */
148
 
        $this->_feedsToDelete[] = $name;
149
 
 
150
 
        /* check the feed values */
151
 
        list ($ret, $feed) = RssMapHelper::fetchFeed($name);
152
 
        if ($ret) {
153
 
            return $this->failWithStatus($ret);
154
 
        }
155
 
    }
156
 
 
157
 
    function testRssUpdateFeed() {
158
 
        $name = 'feed' .rand();
159
 
 
160
 
        /* create feed we're going to edit */
161
 
        $params = array('itemId' => $this->_getRootId());
162
 
        $ret = RssMapHelper::createFeed($name, $params);
163
 
        if ($ret) {
164
 
            return $this->failWithStatus($ret);
165
 
        }
166
 
 
167
 
        /* remember to delete this new feed */
168
 
        $this->_feedsToDelete[] = $name;
169
 
 
170
 
        GalleryUtilities::putRequestVariable('form[action][update]', '1');
171
 
        GalleryUtilities::putRequestVariable('form[action][save]', '1');
172
 
        GalleryUtilities::putRequestVariable('form[mode]', 'edit');
173
 
 
174
 
        $values = array(
175
 
            'itemId' => (string) $this->_getRootId(),
176
 
            'mode' => 'edit',
177
 
            'feedType' => 'photosRecurse',
178
 
            'photosRecurseLimit'=> '0',
179
 
            'feedName' => $name,
180
 
            'version' => '2.0',
181
 
            'count' => '10',
182
 
            'copyright' => 'me',
183
 
            'description' => 'description',
184
 
            'useImage' => '1',
185
 
            'usePubDate' => '1',
186
 
            'useEnclosure' => '1',
187
 
            'useCategory' => '1',
188
 
            'useCloud' => '1',
189
 
            'cloudDomain' => 'Gallery',
190
 
            'cloudPort' => '202',
191
 
            'cloudPath' => 'rss',
192
 
            'cloudRegisterProcedure' => 'register',
193
 
            'cloudProtocol' => 'tcp',
194
 
            'useTtl' => '1',
195
 
            'ttl' => '60',
196
 
            'category' => 'photo',
197
 
            'useItemCategory' => '1',
198
 
            'language' => 'en-us',
199
 
            'feedDate' => 'updated');
200
 
 
201
 
        foreach ($values as $key => $value) {
202
 
            GalleryUtilities::putRequestVariable('form['.$key.']', $value);
203
 
        }
204
 
 
205
 
        $results = $this->handleRequest();
206
 
 
207
 
        $this->assertEquals(array(
208
 
            'status' => array('saved' => 1),
209
 
            'error' => array(),
210
 
            'redirect' => array(
211
 
                'view' => 'core.ItemAdmin',
212
 
                'subView' => 'rss.EditFeed',
213
 
                'itemId' => $this->_getRootId(),
214
 
                'mode' => 'edit',
215
 
                'form' => array_merge(array(
216
 
                    'action' => array('save' => '1', 'update' => '1'),
217
 
                    'mode' => 'edit',
218
 
                    ), $values))),
219
 
            $results);
220
 
 
221
 
        /* check the feed values */
222
 
        list ($ret, $feed) = RssMapHelper::fetchFeed($name);
223
 
        if ($ret) {
224
 
            return $this->failWithStatus($ret);
225
 
        }
226
 
    }
227
 
 
228
 
    function testRssUpdateFeedNew() {
229
 
        $name = 'feed' .rand();
230
 
 
231
 
        GalleryUtilities::putRequestVariable('form[action][update]', '1');
232
 
        GalleryUtilities::putRequestVariable('form[action][save]', '1');
233
 
        GalleryUtilities::putRequestVariable('form[mode]', 'edit');
234
 
 
235
 
        $values = array(
236
 
            'itemId' => (string) $this->_getRootId(),
237
 
            'mode' => 'edit',
238
 
            'feedType' => 'photosRecurse',
239
 
            'photosRecurseLimit'=> '0',
240
 
            'feedName' => $name,
241
 
            'version' => '2.0',
242
 
            'count' => '10',
243
 
            'copyright' => 'me',
244
 
            'description' => 'description',
245
 
            'useImage' => '1',
246
 
            'usePubDate' => '1',
247
 
            'useEnclosure' => '1',
248
 
            'useCategory' => '1',
249
 
            'useCloud' => '1',
250
 
            'cloudDomain' => 'Gallery',
251
 
            'cloudPort' => '202',
252
 
            'cloudPath' => 'rss',
253
 
            'cloudRegisterProcedure' => 'register',
254
 
            'cloudProtocol' => 'tcp',
255
 
            'useTtl' => '1',
256
 
            'ttl' => '60',
257
 
            'category' => 'photo',
258
 
            'useItemCategory' => '1',
259
 
            'language' => 'en-us',
260
 
            'feedDate' => 'updated');
261
 
 
262
 
        foreach ($values as $key => $value) {
263
 
            GalleryUtilities::putRequestVariable('form['.$key.']', $value);
264
 
        }
265
 
 
266
 
        $results = $this->handleRequest();
267
 
 
268
 
        $this->assertEquals(array(
269
 
            'status' => array('saved' => 1),
270
 
            'error' => array(),
271
 
            'redirect' => array(
272
 
                'view' => 'core.ItemAdmin',
273
 
                'subView' => 'rss.EditFeed',
274
 
                'itemId' => $this->_getRootId(),
275
 
                'mode' => 'edit',
276
 
                'form' => array_merge(array(
277
 
                    'action' => array('save' => '1', 'update' => '1'),
278
 
                    'mode' => 'edit',
279
 
                    ), $values))),
280
 
            $results);
281
 
    }
282
 
 
283
 
    function testDeleteFeed() {
284
 
        $name = 'feed' .rand();
285
 
 
286
 
        /* Create feed that we're going to delete */
287
 
        $params = array('itemId' => $this->_getRootId());
288
 
        $ret = RssMapHelper::createFeed($name, $params);
289
 
        if ($ret) {
290
 
            return $this->failWithStatus($ret);
291
 
        }
292
 
        /* Cleanup if things go wrong */
293
 
        $this->_feedsToDelete[] = $name;
294
 
        
295
 
        GalleryUtilities::putRequestVariable('form[action][delete]', $name);
296
 
        GalleryUtilities::putRequestVariable('itemId', $this->_getRootId());
297
 
        GalleryUtilities::putRequestVariable('controller', 'rss.EditFeed');
298
 
        
299
 
        $results = $this->handleRequest();
300
 
 
301
 
        $this->assertEquals(array(
302
 
            'status' => array('deleted' => 1),
303
 
            'error' => array(),
304
 
            'redirect' => array(
305
 
                'view' => 'core.ItemAdmin',
306
 
                'subView' => 'rss.EditFeed',
307
 
                'itemId' => $this->_getRootId(),
308
 
                'mode' => 'list',
309
 
                'form' => array('action' => array('delete' => $name))
310
 
                )),
311
 
            $results);
312
 
    }
313
 
}
314
 
?>