~ubuntu-branches/ubuntu/quantal/gallery2/quantal

« back to all changes in this revision

Viewing changes to modules/nokiaupload/test/phpunit/NokiaUploadUploadControllerTest.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
 
 * Upload controller tests
23
 
 *
24
 
 * @package NokiaUpload
25
 
 * @subpackage PHPUnit
26
 
 * @author Alan Harder <alan.harder@sun.com>
27
 
 * @version $Revision: 15759 $
28
 
 */
29
 
class NokiaUploadUploadControllerTest extends GalleryControllerTestCase {
30
 
 
31
 
    function NokiaUploadUploadControllerTest($methodName) {
32
 
        $this->GalleryControllerTestCase($methodName, 'nokiaupload.Upload');
33
 
    }
34
 
 
35
 
    function setUp() {
36
 
        parent::setUp();
37
 
        global $gallery;
38
 
 
39
 
        list ($ret, $this->_album) = $this->_createRandomAlbum($this->_getRootId());
40
 
        if ($ret) {
41
 
            print $ret->getAsHtml();
42
 
            return $this->failWithStatus($ret);
43
 
        }
44
 
 
45
 
        $this->_markForCleanup($this->_album);
46
 
 
47
 
        list ($ret, $this->_subAlbum) = $this->_createRandomAlbum($this->_album->getId());
48
 
        if ($ret) {
49
 
            print $ret->getAsHtml();
50
 
            return $this->failWithStatus($ret);
51
 
        }
52
 
        list ($ret, $this->_group) = $this->_createRandomGroup();
53
 
        if ($ret) {
54
 
            print $ret->getAsHtml();
55
 
            return $this->failWithStatus($ret);
56
 
        }
57
 
 
58
 
        $this->_markForCleanup($this->_group);
59
 
 
60
 
        $ret = GalleryCoreApi::addGroupPermission(
61
 
                          $this->_album->getId(), $this->_group->getId(), 'core.addDataItem');
62
 
        if ($ret) {
63
 
            print $ret->getAsHtml();
64
 
            return $this->failWithStatus($ret);
65
 
        }
66
 
        list ($ret, $this->_user) = $this->_createRandomUser();
67
 
        if ($ret) {
68
 
            print $ret->getAsHtml();
69
 
            return $this->failWithStatus($ret);
70
 
        }
71
 
        $this->_markForCleanup($this->_user);
72
 
 
73
 
        $ret = GalleryCoreApi::addUserToGroup($this->_user->getId(), $this->_group->getId());
74
 
        if ($ret) {
75
 
            print $ret->getAsHtml();
76
 
            return $this->failWithStatus($ret);
77
 
        }
78
 
 
79
 
        $ret = $this->_markPluginParametersForCleanup('module', 'nokiaupload');
80
 
        if ($ret) {
81
 
            print $ret->getAsHtml();
82
 
            return $ret;
83
 
        }
84
 
 
85
 
        $ret = GalleryCoreApi::setPluginParameter(
86
 
                          'module', 'nokiaupload', 'id.mobileGroup', $this->_group->getId());
87
 
        if ($ret) {
88
 
            print $ret->getAsHtml();
89
 
            return $this->failWithStatus($ret);
90
 
        }
91
 
        $ret = GalleryCoreApi::setPluginParameter(
92
 
                          'module', 'nokiaupload', 'id.uploadAlbum', $this->_album->getId());
93
 
        if ($ret) {
94
 
            print $ret->getAsHtml();
95
 
            return $this->failWithStatus($ret);
96
 
        }
97
 
        $_SERVER['HTTP_USER_AGENT'] = 'Nokia6630/1.0 (2.39.129) Series60/2.6 Profile/MIDP-2.0';
98
 
    }
99
 
 
100
 
    function testUploadController() {
101
 
        global $gallery;
102
 
 
103
 
        /* Login our test user */
104
 
        $gallery->setActiveUser($this->_user);
105
 
 
106
 
        $session =& $gallery->getSession();
107
 
        $session->remove('permissionCache');
108
 
        $ret = GalleryCoreApi::assertHasItemPermission($this->_getRootId(), 'core.addAlbumItem');
109
 
        if (!$ret) {
110
 
            return $this->assert(false, 'expected test user to not have addAlbum access in root');
111
 
        }
112
 
 
113
 
        /* Missing file */
114
 
        GalleryUtilities::putRequestVariable('Filename', 'uploadTest.jpg', false);
115
 
        GalleryUtilities::putRequestVariable('MimeType', 'image/jpeg', false);
116
 
        GalleryUtilities::putRequestVariable('DirId', $this->_album->getId(), false);
117
 
        $results = $this->handleRequest();
118
 
        $this->assertEquals(array('delegate' => array('view' => 'nokiaupload.Upload'),
119
 
                                  'status' => array('success' => NOKIAUPLOAD_ERR_UNKNOWN,
120
 
                                                    'spaceleft' => 10000000),
121
 
                                  'error' => array()),
122
 
                            $results, 'missing parameter');
123
 
 
124
 
        /* Empty file */
125
 
        $_FILES['ImageData'] = array('size' => 0, 'tmp_name' => '');
126
 
        $results = $this->handleRequest();
127
 
        $this->assertEquals(array('delegate' => array('view' => 'nokiaupload.Upload'),
128
 
                                  'status' => array('success' => NOKIAUPLOAD_ERR_TOOBIG,
129
 
                                                    'spaceleft' => 10000000),
130
 
                                  'error' => array()),
131
 
                            $results, 'file size');
132
 
 
133
 
        /* Bad parent */
134
 
        $_FILES['ImageData'] = array('size' => 1966,
135
 
            'tmp_name' => GalleryCoreApi::getPluginBaseDir('module', 'core')
136
 
                                . 'modules/core/test/data/test1.jpg');
137
 
        GalleryUtilities::putRequestVariable('DirId', 'badId', false);
138
 
        $results = $this->handleRequest();
139
 
        $this->assertEquals(array('delegate' => array('view' => 'nokiaupload.Upload'),
140
 
                                  'status' => array('success' => NOKIAUPLOAD_ERR_UNKNOWN,
141
 
                                                    'spaceleft' => 10000000),
142
 
                                  'error' => array()),
143
 
                            $results, 'bad parent');
144
 
 
145
 
        /* No permission */
146
 
        GalleryUtilities::putRequestVariable('DirId', $this->_subAlbum->getId(), false);
147
 
        $results = $this->handleRequest();
148
 
        $this->assertEquals(array('delegate' => array('view' => 'nokiaupload.Upload'),
149
 
                                  'status' => array('success' => NOKIAUPLOAD_ERR_UNKNOWN,
150
 
                                                    'spaceleft' => 10000000),
151
 
                                  'error' => array()),
152
 
                            $results, 'permission');
153
 
 
154
 
        /* Valid request */
155
 
        GalleryUtilities::putRequestVariable('DirId', $this->_album->getId(), false);
156
 
        GalleryUtilities::putRequestVariable('Desc', 'this is the description', false);
157
 
        $results = $this->handleRequest();
158
 
        $this->assertEquals(array('delegate' => array('view' => 'nokiaupload.Upload'),
159
 
                                  'status' => array('success' => NOKIAUPLOAD_ERR_NOERR,
160
 
                                                    'spaceleft' => 10000000),
161
 
                                  'error' => array()),
162
 
                            $results, 'valid request');
163
 
 
164
 
        list ($ret, $itemIds) = GalleryCoreApi::fetchChildItemIdsWithPermission(
165
 
                                                $this->_album->getId(), 'core.all');
166
 
        if ($ret) {
167
 
            return $this->failWithStatus($ret);
168
 
        }
169
 
        $this->assertEquals(1, count($itemIds), 'one item with core.all permission');
170
 
 
171
 
        list ($ret, $item) = GalleryCoreApi::loadEntitiesById(array_shift($itemIds));
172
 
        if ($ret) {
173
 
            return $this->failWithStatus($ret);
174
 
        }
175
 
        $this->assert(GalleryUtilities::isA($item, 'GalleryPhotoItem'), 'item type');
176
 
        $this->assertEquals('this is the description', $item->getDescription(), 'description');
177
 
    }
178
 
}
179
 
?>