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

« back to all changes in this revision

Viewing changes to modules/core/test/phpunit/ItemEditControllerTest.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
 
 * ItemEdit controller tests
23
 
 * @package GalleryCore
24
 
 * @subpackage PHPUnit
25
 
 * @author Bharat Mediratta <bharat@menalto.com>
26
 
 * @version $Revision: 15513 $
27
 
 */
28
 
class ItemEditControllerTest extends GalleryControllerTestCase {
29
 
 
30
 
    function ItemEditControllerTest($methodName) {
31
 
        $this->GalleryControllerTestCase($methodName, 'core.ItemEdit');
32
 
    }
33
 
 
34
 
    function setUp() {
35
 
        parent::setUp();
36
 
 
37
 
        list ($ret, $this->_album) = $this->_createRandomAlbum($this->_getRootId());
38
 
        if ($ret) {
39
 
            return $this->failWithStatus($ret);
40
 
        }
41
 
 
42
 
        $this->_markForCleanup($this->_album);
43
 
 
44
 
        list ($ret, $this->_item) =
45
 
            $this->_createRandomDataItem($this->_album->getId(), 'test/file');
46
 
        if ($ret) {
47
 
            return $this->failWithStatus($ret);
48
 
        }
49
 
 
50
 
        $path = 'modules/core/test/phpunit/ItemEditControllerTest.class';
51
 
        $ret = GalleryCoreApi::registerFactoryImplementation(
52
 
            'ItemEditPlugin', 'ItemEditControllerTestPluginSuccess',
53
 
            'ItemEditControllerTestPluginSuccess', $path, 'coreTest', null);
54
 
        if ($ret) {
55
 
            print $ret->getAsHtml();
56
 
            return $this->failWithStatus($ret);
57
 
        }
58
 
 
59
 
        $ret = GalleryCoreApi::registerFactoryImplementation(
60
 
            'ItemEditPlugin', 'ItemEditControllerTestPluginFailAndWarn',
61
 
            'ItemEditControllerTestPluginFailAndWarn', $path, 'coreTest', null);
62
 
        if ($ret) {
63
 
            print $ret->getAsHtml();
64
 
            return $this->failWithStatus($ret);
65
 
        }
66
 
 
67
 
        $ret = GalleryCoreApi::registerFactoryImplementation(
68
 
            'ItemEditOption', 'ItemEditControllerTestOption', 'ItemEditControllerTestOption',
69
 
            $path, 'coreTest', array('ItemEditControllerTestPluginFailAndWarn'));
70
 
        if ($ret) {
71
 
            print $ret->getAsHtml();
72
 
            return $this->failWithStatus($ret);
73
 
        }
74
 
        $this->_markFactoryModuleForCleanup('coreTest');
75
 
    }
76
 
 
77
 
    function testHandleRequestWithPreferred() {
78
 
        list ($ret, $this->_preferred) =
79
 
            $this->_createDerivative($this->_item, $this->_item->getId(),
80
 
                                     DERIVATIVE_TYPE_IMAGE_PREFERRED, 'rotate|90');
81
 
        if ($ret) {
82
 
            return $this->failWithStatus($ret);
83
 
        }
84
 
 
85
 
        GalleryUtilities::putRequestVariable('itemId', $this->_item->getId());
86
 
        GalleryUtilities::putRequestVariable('form[serialNumber]', $this->_item->getSerialNumber());
87
 
        GalleryUtilities::putRequestVariable('editPlugin', 'ItemEditControllerTestPluginSuccess');
88
 
 
89
 
        $results = $this->handleRequest();
90
 
        $this->assertEquals(
91
 
            array('redirect' => array('view' => 'core.ItemAdmin',
92
 
                                      'subView' => 'core.ItemEdit',
93
 
                                      'editPlugin' => 'ItemEditControllerTestPluginSuccess',
94
 
                                      'itemId' => $this->_item->getId()),
95
 
                  'status' => array('editMessage' => 'success',
96
 
                                    'warning' => array()),
97
 
                  'error' => array()),
98
 
            $results);
99
 
    }
100
 
 
101
 
    function testHandleRequestWithoutPreferred() {
102
 
        GalleryUtilities::putRequestVariable('itemId', $this->_item->getId());
103
 
        GalleryUtilities::putRequestVariable('form[serialNumber]', $this->_item->getSerialNumber());
104
 
        GalleryUtilities::putRequestVariable('editPlugin', 'ItemEditControllerTestPluginSuccess');
105
 
 
106
 
        $results = $this->handleRequest();
107
 
        $this->assertEquals(
108
 
            array('redirect' => array('view' => 'core.ItemAdmin',
109
 
                                      'subView' => 'core.ItemEdit',
110
 
                                      'editPlugin' => 'ItemEditControllerTestPluginSuccess',
111
 
                                      'itemId' => $this->_item->getId()),
112
 
                  'status' => array('editMessage' => 'success',
113
 
                                    'warning' => array()),
114
 
                  'error' => array()),
115
 
            $results);
116
 
    }
117
 
 
118
 
    function testHandleRequestDelegate() {
119
 
        GalleryUtilities::putRequestVariable('itemId', $this->_item->getId());
120
 
        GalleryUtilities::putRequestVariable('form[serialNumber]', $this->_item->getSerialNumber());
121
 
        GalleryUtilities::putRequestVariable(
122
 
            'editPlugin', 'ItemEditControllerTestPluginFailAndWarn');
123
 
        GalleryUtilities::putRequestVariable('form[action][save]', 1);
124
 
 
125
 
        $results = $this->handleRequest();
126
 
        $this->assertEquals(
127
 
            array('delegate' => array('view' => 'core.ItemAdmin',
128
 
                                      'subView' => 'core.ItemEdit',
129
 
                                      'editPlugin' => 'ItemEditControllerTestPluginFailAndWarn'),
130
 
                  'status' => array('editMessage' => null,
131
 
                                    'warning' => array('a warning')),   /* from its option */
132
 
                  'error' => array('failed',   /* from the plugin */
133
 
                                   'an error') /* from its option */
134
 
                  ),
135
 
            $results);
136
 
    }
137
 
}
138
 
 
139
 
/**
140
 
 * Test plugin that returns success
141
 
 *
142
 
 * @package GalleryCore
143
 
 * @subpackage PHPUnit
144
 
 */
145
 
class ItemEditControllerTestPluginSuccess {
146
 
    function handleRequest($form, &$item, &$preferred) {
147
 
        /* TODO: We should verify the item is legit here */
148
 
 
149
 
        /* Check to see if we have a preferred source */
150
 
        list ($ret, $preferredTable) =
151
 
            GalleryCoreApi::fetchPreferredsByItemIds(array($item->getId()));
152
 
        if ($ret) {
153
 
            return array($ret, null, null, null);
154
 
        }
155
 
 
156
 
        if ($preferred != null &&
157
 
            (empty($preferredTable) ||
158
 
             !is_object($preferredTable[$item->getId()]) ||
159
 
             $preferredTable[$item->getId()]->getId() != $preferred->getId())) {
160
 
            return array(GalleryCoreApi::error(ERROR_UNKNOWN),
161
 
                         array('PREFERRED MISMATCH'), null, null);
162
 
        }
163
 
 
164
 
        return array(null, array(), 'success', false);
165
 
    }
166
 
}
167
 
 
168
 
/**
169
 
 * Test plugin that fails
170
 
 *
171
 
 * @package GalleryCore
172
 
 * @subpackage PHPUnit
173
 
 */
174
 
class ItemEditControllerTestPluginFailAndWarn extends ItemEditPlugin {
175
 
    function handleRequest($form, &$item, &$preferred) {
176
 
        return array(null, array('failed'), null, false);
177
 
    }
178
 
}
179
 
 
180
 
/**
181
 
 * Test ItemEditOption that returns warnings and errors
182
 
 *
183
 
 * @package GalleryCore
184
 
 * @subpackage PHPUnit
185
 
 */
186
 
class ItemEditControllerTestOption extends ItemEditOption {
187
 
    function isAppropriate($item, $thumbnail) {
188
 
        return array(null, true);
189
 
    }
190
 
 
191
 
    function handleRequestAfterEdit($form, &$item, &$preferred) {
192
 
        return array(null,
193
 
                     array('an error'),
194
 
                     array('a warning'));
195
 
    }
196
 
}
197
 
 
198
 
?>