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
* Test DownloadItem functionality
23
* @package GalleryCore
25
* @author Alan Harder <alan.harder@sun.com>
26
* @version $Revision: 15513 $
28
class DownloadItemTest extends GalleryTestCase {
30
function DownloadItemTest($methodName) {
31
$this->GalleryTestCase($methodName);
38
list ($ret, $this->_item) = $this->_createRandomDataItem($this->_getRootId());
40
print $ret->getAsHtml();
41
return $this->failWithStatus($ret);
43
$ret = GalleryCoreApi::removeItemPermissions($this->_item->getId());
45
print $ret->getAsHtml();
46
return $this->failWithStatus($ret);
48
$this->_markForCleanup($this->_item);
50
list ($ret, $this->_view) = GalleryView::loadView('core.DownloadItem');
52
print $ret->getAsHtml();
53
return $this->failWithStatus($ret);
55
$this->_userId = $gallery->getActiveUserId();
56
$gallery->_phpVm = new DownloadItemTestPhpVm();
59
function _download() {
61
$ret = $this->_view->renderImmediate(array(), array());
62
$output = ob_get_contents();
64
return array($ret, $output);
67
function testNoItemId() {
68
list ($ret, $output) = $this->_download();
69
$this->assert($ret && $ret->getErrorCode() & ERROR_BAD_PARAMETER, 'expected error');
72
function testMaliciousFilename() {
73
GalleryUtilities::putRequestVariable('itemId', $this->_item->getId());
74
GalleryUtilities::putRequestVariable('fileName', 'voodoo');
75
list ($ret, $output) = $this->_download();
76
$this->assert($ret && $ret->getErrorCode(), 'expected error');
79
function testItemPermission() {
80
/* Item needs core.viewSource */
81
$ret = GalleryCoreApi::addUserPermission($this->_item->getId(), $this->_userId,
84
return $this->failWithStatus($ret);
86
$ret = GalleryCoreApi::addUserPermission($this->_item->getId(), $this->_userId,
89
return $this->failWithStatus($ret);
92
GalleryUtilities::putRequestVariable('itemId', $this->_item->getId());
93
list ($ret, $output) = $this->_download();
94
$this->assert($ret && $ret->getErrorCode() & ERROR_PERMISSION_DENIED, 'expected error');
96
$ret = GalleryCoreApi::addUserPermission($this->_item->getId(), $this->_userId,
99
return $this->failWithStatus($ret);
102
list ($ret, $output) = $this->_download();
103
$this->assert(!$ret, 'expected success');
106
function testPreferredPermission() {
107
/* Preferred needs core.viewSource */
108
list ($ret, $derivative) = $this->_createDerivative($this->_item, $this->_item->getId(),
109
DERIVATIVE_TYPE_IMAGE_PREFERRED);
111
return $this->failWithStatus($ret);
113
$ret = GalleryCoreApi::addUserPermission($this->_item->getId(), $this->_userId,
116
return $this->failWithStatus($ret);
118
$ret = GalleryCoreApi::addUserPermission($this->_item->getId(), $this->_userId,
121
return $this->failWithStatus($ret);
124
GalleryUtilities::putRequestVariable('itemId', $derivative->getId());
125
list ($ret, $output) = $this->_download();
126
$this->assert($ret && $ret->getErrorCode() & ERROR_PERMISSION_DENIED, 'expected error');
128
$ret = GalleryCoreApi::addUserPermission($this->_item->getId(), $this->_userId,
131
return $this->failWithStatus($ret);
134
list ($ret, $output) = $this->_download();
135
$this->assert(!$ret, 'expected success');
138
function testResizePermission() {
139
/* Resize needs core.viewResizes */
140
list ($ret, $derivative) = $this->_createDerivative($this->_item, $this->_item->getId(),
141
DERIVATIVE_TYPE_IMAGE_RESIZE);
143
return $this->failWithStatus($ret);
145
$ret = GalleryCoreApi::addUserPermission($this->_item->getId(), $this->_userId,
148
return $this->failWithStatus($ret);
150
$ret = GalleryCoreApi::addUserPermission($this->_item->getId(), $this->_userId,
153
return $this->failWithStatus($ret);
156
GalleryUtilities::putRequestVariable('itemId', $derivative->getId());
157
list ($ret, $output) = $this->_download();
158
$this->assert($ret && $ret->getErrorCode() & ERROR_PERMISSION_DENIED, 'expected error');
160
$ret = GalleryCoreApi::addUserPermission($this->_item->getId(), $this->_userId,
163
return $this->failWithStatus($ret);
166
list ($ret, $output) = $this->_download();
167
$this->assert(!$ret, 'expected success');
170
function testThumbnailPermission() {
171
/* Thumbnail needs core.view */
172
list ($ret, $derivative) = $this->_createDerivative($this->_item, $this->_item->getId(),
173
DERIVATIVE_TYPE_IMAGE_THUMBNAIL);
175
return $this->failWithStatus($ret);
177
$ret = GalleryCoreApi::addUserPermission($this->_item->getId(), $this->_userId,
180
return $this->failWithStatus($ret);
182
$ret = GalleryCoreApi::addUserPermission($this->_item->getId(), $this->_userId,
185
return $this->failWithStatus($ret);
188
GalleryUtilities::putRequestVariable('itemId', $derivative->getId());
189
list ($ret, $output) = $this->_download();
190
$this->assert($ret && $ret->getErrorCode() & ERROR_PERMISSION_DENIED, 'expected error');
192
$ret = GalleryCoreApi::addUserPermission($this->_item->getId(), $this->_userId,
195
return $this->failWithStatus($ret);
198
list ($ret, $output) = $this->_download();
199
$this->assert(!$ret, 'expected success');
202
function testPrintService() {
203
/* Flag in session allows print service to bypass viewResizes/viewSource for set of ids */
205
$session =& $gallery->getSession();
206
$session->put('core.isPrintService', array(2, $this->_item->getId()));
208
/* Still need core.view */
209
GalleryUtilities::putRequestVariable('itemId', $this->_item->getId());
210
list ($ret, $output) = $this->_download();
211
$this->assert($ret && $ret->getErrorCode() & ERROR_PERMISSION_DENIED, 'expected error 1');
213
$ret = GalleryCoreApi::addUserPermission($this->_item->getId(), $this->_userId,
216
return $this->failWithStatus($ret);
219
$session->put('core.isPrintService', array(2, 5));
220
list ($ret, $output) = $this->_download();
221
$this->assert($ret && $ret->getErrorCode() & ERROR_PERMISSION_DENIED, 'expected error 2');
223
$session->put('core.isPrintService', array(2, $this->_item->getId(), 5));
224
list ($ret, $output) = $this->_download();
225
$this->assert(!$ret, 'expected success');
230
* Test PhpVm to ignore header() calls
232
class DownloadItemTestPhpVm extends GalleryPhpVm {
233
function header($string, $replace=null) {