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
* Upload controller tests
24
* @package NokiaUpload
26
* @author Alan Harder <alan.harder@sun.com>
27
* @version $Revision: 15759 $
29
class NokiaUploadUploadControllerTest extends GalleryControllerTestCase {
31
function NokiaUploadUploadControllerTest($methodName) {
32
$this->GalleryControllerTestCase($methodName, 'nokiaupload.Upload');
39
list ($ret, $this->_album) = $this->_createRandomAlbum($this->_getRootId());
41
print $ret->getAsHtml();
42
return $this->failWithStatus($ret);
45
$this->_markForCleanup($this->_album);
47
list ($ret, $this->_subAlbum) = $this->_createRandomAlbum($this->_album->getId());
49
print $ret->getAsHtml();
50
return $this->failWithStatus($ret);
52
list ($ret, $this->_group) = $this->_createRandomGroup();
54
print $ret->getAsHtml();
55
return $this->failWithStatus($ret);
58
$this->_markForCleanup($this->_group);
60
$ret = GalleryCoreApi::addGroupPermission(
61
$this->_album->getId(), $this->_group->getId(), 'core.addDataItem');
63
print $ret->getAsHtml();
64
return $this->failWithStatus($ret);
66
list ($ret, $this->_user) = $this->_createRandomUser();
68
print $ret->getAsHtml();
69
return $this->failWithStatus($ret);
71
$this->_markForCleanup($this->_user);
73
$ret = GalleryCoreApi::addUserToGroup($this->_user->getId(), $this->_group->getId());
75
print $ret->getAsHtml();
76
return $this->failWithStatus($ret);
79
$ret = $this->_markPluginParametersForCleanup('module', 'nokiaupload');
81
print $ret->getAsHtml();
85
$ret = GalleryCoreApi::setPluginParameter(
86
'module', 'nokiaupload', 'id.mobileGroup', $this->_group->getId());
88
print $ret->getAsHtml();
89
return $this->failWithStatus($ret);
91
$ret = GalleryCoreApi::setPluginParameter(
92
'module', 'nokiaupload', 'id.uploadAlbum', $this->_album->getId());
94
print $ret->getAsHtml();
95
return $this->failWithStatus($ret);
97
$_SERVER['HTTP_USER_AGENT'] = 'Nokia6630/1.0 (2.39.129) Series60/2.6 Profile/MIDP-2.0';
100
function testUploadController() {
103
/* Login our test user */
104
$gallery->setActiveUser($this->_user);
106
$session =& $gallery->getSession();
107
$session->remove('permissionCache');
108
$ret = GalleryCoreApi::assertHasItemPermission($this->_getRootId(), 'core.addAlbumItem');
110
return $this->assert(false, 'expected test user to not have addAlbum access in root');
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),
122
$results, 'missing parameter');
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),
131
$results, 'file size');
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),
143
$results, 'bad parent');
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),
152
$results, 'permission');
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),
162
$results, 'valid request');
164
list ($ret, $itemIds) = GalleryCoreApi::fetchChildItemIdsWithPermission(
165
$this->_album->getId(), 'core.all');
167
return $this->failWithStatus($ret);
169
$this->assertEquals(1, count($itemIds), 'one item with core.all permission');
171
list ($ret, $item) = GalleryCoreApi::loadEntitiesById(array_shift($itemIds));
173
return $this->failWithStatus($ret);
175
$this->assert(GalleryUtilities::isA($item, 'GalleryPhotoItem'), 'item type');
176
$this->assertEquals('this is the description', $item->getDescription(), 'description');