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
* ItemEdit controller tests
23
* @package GalleryCore
25
* @author Bharat Mediratta <bharat@menalto.com>
26
* @version $Revision: 15513 $
28
class ItemEditControllerTest extends GalleryControllerTestCase {
30
function ItemEditControllerTest($methodName) {
31
$this->GalleryControllerTestCase($methodName, 'core.ItemEdit');
37
list ($ret, $this->_album) = $this->_createRandomAlbum($this->_getRootId());
39
return $this->failWithStatus($ret);
42
$this->_markForCleanup($this->_album);
44
list ($ret, $this->_item) =
45
$this->_createRandomDataItem($this->_album->getId(), 'test/file');
47
return $this->failWithStatus($ret);
50
$path = 'modules/core/test/phpunit/ItemEditControllerTest.class';
51
$ret = GalleryCoreApi::registerFactoryImplementation(
52
'ItemEditPlugin', 'ItemEditControllerTestPluginSuccess',
53
'ItemEditControllerTestPluginSuccess', $path, 'coreTest', null);
55
print $ret->getAsHtml();
56
return $this->failWithStatus($ret);
59
$ret = GalleryCoreApi::registerFactoryImplementation(
60
'ItemEditPlugin', 'ItemEditControllerTestPluginFailAndWarn',
61
'ItemEditControllerTestPluginFailAndWarn', $path, 'coreTest', null);
63
print $ret->getAsHtml();
64
return $this->failWithStatus($ret);
67
$ret = GalleryCoreApi::registerFactoryImplementation(
68
'ItemEditOption', 'ItemEditControllerTestOption', 'ItemEditControllerTestOption',
69
$path, 'coreTest', array('ItemEditControllerTestPluginFailAndWarn'));
71
print $ret->getAsHtml();
72
return $this->failWithStatus($ret);
74
$this->_markFactoryModuleForCleanup('coreTest');
77
function testHandleRequestWithPreferred() {
78
list ($ret, $this->_preferred) =
79
$this->_createDerivative($this->_item, $this->_item->getId(),
80
DERIVATIVE_TYPE_IMAGE_PREFERRED, 'rotate|90');
82
return $this->failWithStatus($ret);
85
GalleryUtilities::putRequestVariable('itemId', $this->_item->getId());
86
GalleryUtilities::putRequestVariable('form[serialNumber]', $this->_item->getSerialNumber());
87
GalleryUtilities::putRequestVariable('editPlugin', 'ItemEditControllerTestPluginSuccess');
89
$results = $this->handleRequest();
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()),
101
function testHandleRequestWithoutPreferred() {
102
GalleryUtilities::putRequestVariable('itemId', $this->_item->getId());
103
GalleryUtilities::putRequestVariable('form[serialNumber]', $this->_item->getSerialNumber());
104
GalleryUtilities::putRequestVariable('editPlugin', 'ItemEditControllerTestPluginSuccess');
106
$results = $this->handleRequest();
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()),
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);
125
$results = $this->handleRequest();
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 */
140
* Test plugin that returns success
142
* @package GalleryCore
143
* @subpackage PHPUnit
145
class ItemEditControllerTestPluginSuccess {
146
function handleRequest($form, &$item, &$preferred) {
147
/* TODO: We should verify the item is legit here */
149
/* Check to see if we have a preferred source */
150
list ($ret, $preferredTable) =
151
GalleryCoreApi::fetchPreferredsByItemIds(array($item->getId()));
153
return array($ret, null, null, null);
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);
164
return array(null, array(), 'success', false);
169
* Test plugin that fails
171
* @package GalleryCore
172
* @subpackage PHPUnit
174
class ItemEditControllerTestPluginFailAndWarn extends ItemEditPlugin {
175
function handleRequest($form, &$item, &$preferred) {
176
return array(null, array('failed'), null, false);
181
* Test ItemEditOption that returns warnings and errors
183
* @package GalleryCore
184
* @subpackage PHPUnit
186
class ItemEditControllerTestOption extends ItemEditOption {
187
function isAppropriate($item, $thumbnail) {
188
return array(null, true);
191
function handleRequestAfterEdit($form, &$item, &$preferred) {