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

« back to all changes in this revision

Viewing changes to modules/core/test/phpunit/ItemDeleteSingleControllerTest.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
 
 * ItemDeleteSingle controller tests
23
 
 * @package GalleryCore
24
 
 * @subpackage PHPUnit
25
 
 * @author Bharat Mediratta <bharat@menalto.com>
26
 
 * @version $Revision: 15513 $
27
 
 */
28
 
class ItemDeleteSingleControllerTest extends GalleryControllerTestCase {
29
 
 
30
 
    function ItemDeleteSingleControllerTest($methodName) {
31
 
        $this->GalleryControllerTestCase($methodName, 'core.ItemDeleteSingle');
32
 
    }
33
 
 
34
 
    function setUp() {
35
 
        parent::setUp();
36
 
 
37
 
        /* create an album to hold all of the test items */
38
 
        list ($ret, $this->_album) = $this->_createRandomAlbum($this->_getRootId());
39
 
        if ($ret) {
40
 
            $this->failWithStatus($ret);
41
 
        }
42
 
 
43
 
        $this->_markForCleanup($this->_album);
44
 
    }
45
 
 
46
 
    /**
47
 
     * Create a random album and verify that we can delete it.
48
 
     */
49
 
    function testDeleteItem() {
50
 
        global $gallery;
51
 
 
52
 
        /* Create a random sub album */
53
 
        list ($ret, $album) = $this->_createRandomAlbum($this->_album->getId());
54
 
        if ($ret) {
55
 
            return $this->failWithStatus($ret);
56
 
        }
57
 
 
58
 
        /* Use valid inputs */
59
 
        GalleryUtilities::putRequestVariable('itemId', $album->getId());
60
 
        GalleryUtilities::putRequestVariable('form[action][delete]', 1);
61
 
 
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),
68
 
                                  'error' => array()),
69
 
                            $results);
70
 
 
71
 
        /* Make sure the album is actually gone */
72
 
        $this->_verifyMissing($album->getId());
73
 
        if ($ret) {
74
 
            return $this->failWithStatus($ret);
75
 
        }
76
 
    }
77
 
 
78
 
    /**
79
 
     * Verify that we can't delete items without the right permissions
80
 
     */
81
 
    function testDeleteItemWithoutPermission() {
82
 
        global $gallery;
83
 
 
84
 
        list ($ret, $item) = $this->_createRandomDataItem($this->_album->getId());
85
 
        if ($ret) {
86
 
            return $this->failWithStatus($ret);
87
 
        }
88
 
 
89
 
        $ret = GalleryCoreApi::removeItemPermissions($item->getId());
90
 
        if ($ret) {
91
 
            return $this->failWithStatus($ret);
92
 
        }
93
 
 
94
 
        GalleryUtilities::putRequestVariable('itemId', $item->getId());
95
 
        GalleryUtilities::putRequestVariable('form[action][delete]', 1);
96
 
 
97
 
        /* Perform the request and verify that we failed */
98
 
        $results = $this->handleRequest(ERROR_PERMISSION_DENIED);
99
 
 
100
 
        /* make sure it's still there */
101
 
        list ($ret, $item) = $item->refresh();
102
 
        if ($ret) {
103
 
            return $this->failWithStatus($ret);
104
 
        }
105
 
    }
106
 
 
107
 
    /**
108
 
     * Test deleting the root album We should get a bad parameter error
109
 
     */
110
 
    function testDeleteRootAlbum() {
111
 
        global $gallery;
112
 
 
113
 
        /* Use invalid inputs */
114
 
        GalleryUtilities::putRequestVariable('itemId', $this->_getRootId());
115
 
        GalleryUtilities::putRequestVariable('form[action][delete]', 1);
116
 
 
117
 
        /* Perform the request and verify that we failed */
118
 
        $results = $this->handleRequest(ERROR_BAD_PARAMETER);
119
 
    }
120
 
 
121
 
    /**
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)
125
 
     */
126
 
    function testDeleteBogusItem() {
127
 
        /* Use invalid inputs */
128
 
        GalleryUtilities::putRequestVariable('itemId', 1234567890);
129
 
        GalleryUtilities::putRequestVariable('form[action][delete]', 1);
130
 
 
131
 
        /* Perform the request and verify that we failed */
132
 
        $results = $this->handleRequest(ERROR_PERMISSION_DENIED);
133
 
    }
134
 
 
135
 
}
136
 
?>