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
* ItemDeleteSingle controller tests
23
* @package GalleryCore
25
* @author Bharat Mediratta <bharat@menalto.com>
26
* @version $Revision: 15513 $
28
class ItemDeleteSingleControllerTest extends GalleryControllerTestCase {
30
function ItemDeleteSingleControllerTest($methodName) {
31
$this->GalleryControllerTestCase($methodName, 'core.ItemDeleteSingle');
37
/* create an album to hold all of the test items */
38
list ($ret, $this->_album) = $this->_createRandomAlbum($this->_getRootId());
40
$this->failWithStatus($ret);
43
$this->_markForCleanup($this->_album);
47
* Create a random album and verify that we can delete it.
49
function testDeleteItem() {
52
/* Create a random sub album */
53
list ($ret, $album) = $this->_createRandomAlbum($this->_album->getId());
55
return $this->failWithStatus($ret);
58
/* Use valid inputs */
59
GalleryUtilities::putRequestVariable('itemId', $album->getId());
60
GalleryUtilities::putRequestVariable('form[action][delete]', 1);
62
/* Perform the request and verify that we succeeded */
63
$results = $this->handleRequest();
64
$this->assertEquals(array('redirect' => array('view' => 'core.ItemAdmin',
65
'subView' => 'core.ItemDeleteConfirmation',
66
'itemId' => $this->_album->getId()),
67
'status' => array('deleted' => 1),
71
/* Make sure the album is actually gone */
72
$this->_verifyMissing($album->getId());
74
return $this->failWithStatus($ret);
79
* Verify that we can't delete items without the right permissions
81
function testDeleteItemWithoutPermission() {
84
list ($ret, $item) = $this->_createRandomDataItem($this->_album->getId());
86
return $this->failWithStatus($ret);
89
$ret = GalleryCoreApi::removeItemPermissions($item->getId());
91
return $this->failWithStatus($ret);
94
GalleryUtilities::putRequestVariable('itemId', $item->getId());
95
GalleryUtilities::putRequestVariable('form[action][delete]', 1);
97
/* Perform the request and verify that we failed */
98
$results = $this->handleRequest(ERROR_PERMISSION_DENIED);
100
/* make sure it's still there */
101
list ($ret, $item) = $item->refresh();
103
return $this->failWithStatus($ret);
108
* Test deleting the root album We should get a bad parameter error
110
function testDeleteRootAlbum() {
113
/* Use invalid inputs */
114
GalleryUtilities::putRequestVariable('itemId', $this->_getRootId());
115
GalleryUtilities::putRequestVariable('form[action][delete]', 1);
117
/* Perform the request and verify that we failed */
118
$results = $this->handleRequest(ERROR_BAD_PARAMETER);
122
* Test deleting a random item that doesn't exist. We should get a
123
* permission denied (since the permission check happens before we even
124
* verify that it's a valid item to prevent information leakage)
126
function testDeleteBogusItem() {
127
/* Use invalid inputs */
128
GalleryUtilities::putRequestVariable('itemId', 1234567890);
129
GalleryUtilities::putRequestVariable('form[action][delete]', 1);
131
/* Perform the request and verify that we failed */
132
$results = $this->handleRequest(ERROR_PERMISSION_DENIED);