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

« back to all changes in this revision

Viewing changes to modules/quotas/test/phpunit/AdminDeleteGroupQuotaControllerTest.class

  • Committer: Bazaar Package Importer
  • Author(s): Michael C. Schultheiss
  • Date: 2005-11-29 15:50:12 UTC
  • Revision ID: james.westby@ubuntu.com-20051129155012-wtophp03lu01kdgl
Tags: upstream-2.0.2
ImportĀ upstreamĀ versionĀ 2.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*
 
3
 * $RCSfile: AdminDeleteGroupQuotaControllerTest.class,v $
 
4
 *
 
5
 * Gallery - a web based photo album viewer and editor
 
6
 * Copyright (C) 2000-2005 Bharat Mediratta
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2 of the License, or (at
 
11
 * your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful, but
 
14
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 * General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program; if not, write to the Free Software
 
20
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
 
21
 */
 
22
/**
 
23
 * @version $Revision: 1.5 $ $Date: 2005/08/23 03:49:50 $
 
24
 * @package Quotas
 
25
 * @subpackage PHPUnit
 
26
 * @author Robert Balousek <volksport@users.sf.net>
 
27
 */
 
28
 
 
29
GalleryCoreApi::relativeRequireOnce('modules/quotas/classes/GalleryQuotasHelper.class');
 
30
GalleryCoreApi::relativeRequireOnce('modules/quotas/classes/QuotasMap.class');
 
31
 
 
32
/**
 
33
 * AdminDeleteGroupQuota controller tests
 
34
 * @package Quotas
 
35
 * @subpackage PHPUnit
 
36
 */
 
37
class AdminDeleteGroupQuotaControllerTest extends GalleryControllerTestCase {
 
38
 
 
39
    function AdminDeleteGroupQuotaControllerTest($methodName) {
 
40
        $this->GalleryControllerTestCase($methodName, 'quotas.AdminDeleteGroupQuota');
 
41
    }
 
42
 
 
43
    function setUp() {
 
44
        parent::setUp();
 
45
 
 
46
        /* Create a group for quota testing */
 
47
        list ($ret, $this->_group) = $this->_createRandomGroup();
 
48
        if ($ret->isError()) {
 
49
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
50
        }
 
51
        $this->_markForCleanup($this->_group);
 
52
    }
 
53
 
 
54
    function testCancel() {
 
55
        GalleryUtilities::putRequestVariable('form[action][cancel]', 1);
 
56
        GalleryUtilities::putRequestVariable('groupId', $this->_group->getId());
 
57
 
 
58
        $results = $this->handleRequest();
 
59
        $this->assertEquals(array('redirect' => array('view' => 'core.SiteAdmin',
 
60
                                                      'subView' => 'quotas.AdminQuotas'),
 
61
                                  'status' => array(),
 
62
                                  'error' => array()),
 
63
                            $results);
 
64
    }
 
65
 
 
66
    /**
 
67
     * Create and delete a group quota
 
68
     */
 
69
    function testDeleteGroupQuota() {
 
70
        $this->_createUserOrGroupQuota($this->_group->getId(), 2048);
 
71
 
 
72
        GalleryUtilities::putRequestVariable('groupId', $this->_group->getId());
 
73
        GalleryUtilities::putRequestVariable('form[action][delete]', 1);
 
74
 
 
75
        $results = $this->handleRequest();
 
76
        $this->assertEquals(
 
77
            array('redirect' => array('view' => 'core.SiteAdmin',
 
78
                                                'subView' => 'quotas.AdminQuotas'),
 
79
                  'status' => array('deletedGroup' => $this->_group->getGroupName()),
 
80
                  'error' => array()),
 
81
            $results, 'Failed to delete group quota');
 
82
 
 
83
        /* Verify the group quota is gone */
 
84
        list ($ret, $quotaExists, $quota) =
 
85
            GalleryQuotasHelper::fetchGroupQuota($this->_group->getId());
 
86
        if ($quotaExists) {
 
87
            $this->assert(false, 'The group quota was not actually deleted');
 
88
        } else {
 
89
            $this->_deleteUserOrGroupQuota($this->_group->getId());
 
90
        }
 
91
    }
 
92
 
 
93
    function testDeleteGroupQuotaGroupIdMissing() {
 
94
        GalleryUtilities::putRequestVariable('form[action][save]', 1);
 
95
        $results = $this->handleRequest(ERROR_BAD_PARAMETER);
 
96
    }
 
97
 
 
98
    /**
 
99
     * Delete a non-existant group quota
 
100
     */
 
101
    function testDeleteNonExistantGroupQuota() {
 
102
        GalleryUtilities::putRequestVariable('groupId', $this->_group->getId());
 
103
        GalleryUtilities::putRequestVariable('form[action][delete]', 1);
 
104
 
 
105
        $results = $this->handleRequest();
 
106
 
 
107
        $this->assertEquals(array('delegate' => array('view' => 'core.SiteAdmin',
 
108
                                                      'subView' => 'quotas.AdminDeleteGroupQuota'),
 
109
                                  'status' => array(),
 
110
                                  'error' => array()),
 
111
                            $results);
 
112
    }
 
113
 
 
114
    function _createUserOrGroupQuota($userOrGroupId, $quota) {
 
115
        $ret = QuotasMap::addMapEntry(array('userOrGroupId' => $userOrGroupId,
 
116
                                            'quotaSize' => $quota));
 
117
        if ($ret->isError()) {
 
118
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
119
        }
 
120
    }
 
121
 
 
122
    function _deleteUserOrGroupQuota($userOrGroupId) {
 
123
        $ret = QuotasMap::removeMapEntry(array('userOrGroupId' => $userOrGroupId));
 
124
        if ($ret->isError()) {
 
125
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
126
        }
 
127
    }
 
128
}
 
129
?>