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.
21
GalleryCoreApi::requireOnce('modules/customfield/classes/CustomFieldHelper.class');
24
* Test CustomFieldInterface functionality
25
* @package CustomField
27
* @author Alan Harder <alan.harder@sun.com>
28
* @version $Revision: 15513 $
30
class CustomFieldInterfaceTest extends GalleryTestCase {
32
function CustomFieldInterfaceTest($methodName) {
33
$this->GalleryTestCase($methodName);
40
list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'customfield');
42
print $ret->getAsHtml();
43
$this->failWithStatus($ret);
45
list ($ret, $this->_interface) =
46
GalleryCoreApi::newFactoryInstance('CustomFieldInterface_1_0', 'CustomFieldHelper');
47
if ($ret || !isset($this->_interface)) {
48
print $ret->getAsHtml();
49
$this->failWithStatus($ret);
52
list ($ret, $this->_album) = $this->_createRandomAlbum($this->_getRootId());
54
print $ret->getAsHtml();
55
return $this->failWithStatus($ret);
58
$this->_markForCleanup($this->_album);
60
list ($ret, $this->_item) = $this->_createRandomDataItem($this->_album->getId(),
61
'image/test', array(), __FILE__, 'GalleryPhotoItem');
63
print $ret->getAsHtml();
64
return $this->failWithStatus($ret);
67
$ret = $this->_markPluginParametersForCleanup('module', 'customfield');
69
print $ret->getAsHtml();
73
foreach (array('common' => '', 'album' => '', 'photo' => 'Test`0`1') as $key => $value) {
74
$ret = GalleryCoreApi::setPluginParameter('module', 'customfield', $key, $value);
76
print $ret->getAsHtml();
77
return $this->failWithStatus($ret);
82
function testInterface() {
84
// Create global fields..
85
list ($ret, $duplicates) = $this->_interface->createCustomFields(array('One', 'Two'));
87
return $this->failWithStatus($ret);
89
$this->assertEquals(array(), $duplicates, 'Add global 1');
91
list ($ret, $params) = GalleryCoreApi::fetchAllPluginParameters('module', 'customfield');
93
return $this->failWithStatus($ret);
95
foreach ($params as $key => $value) {
101
$this->assertEquals(array('album' => '',
102
'common' => 'One`0`1|Two`0`1',
103
'photo' => 'Test`0`1'),
104
$params, 'Check Data 1');
106
// Create global fields, with duplicate..
107
list ($ret, $duplicates) =
108
$this->_interface->createCustomFields(array('Test', 'Three', 'Two'));
110
return $this->failWithStatus($ret);
112
$this->assertEquals(array('Test', 'Two'), $duplicates, 'Add global 2');
114
list ($ret, $params) = GalleryCoreApi::fetchAllPluginParameters('module', 'customfield');
116
return $this->failWithStatus($ret);
118
foreach ($params as $key => $value) {
119
if ($key[0] == '_') {
120
unset($params[$key]);
124
$this->assertEquals(array('album' => '',
125
'common' => 'One`0`1|Two`0`1|Three`0`1',
126
'photo' => 'Test`0`1'),
127
$params, 'Check Data 2');
129
// Create album-specific fields..
130
list ($ret, $duplicates) =
131
$this->_interface->createCustomFields(array('Photographer', 'Location', 'One'),
132
$this->_album->getId());
134
return $this->failWithStatus($ret);
136
$this->assertEquals(array(), $duplicates, 'Add album');
138
list ($ret, $params) = GalleryCoreApi::fetchAllPluginParameters('module', 'customfield',
139
$this->_album->getId());
141
return $this->failWithStatus($ret);
144
$this->assertEquals(array('common' => 'Photographer`0`1|Location`0`1|One`0`1'),
145
$params, 'Check Data 3');
147
// Set field values..
148
$ret = $this->_interface->setCustomFieldValues($this->_item->getId(),
149
array('Photographer' => 'Me', 'Location' => 'Here'));
151
return $this->failWithStatus($ret);
154
list ($ret, $data, $tmp, $isContainer) =
155
CustomFieldHelper::fetchFieldValues(array($this->_item));
157
return $this->failWithStatus($ret);
159
$this->assertEquals(array('Photographer' => 'Me', 'Location' => 'Here'),
160
$data[$this->_item->getId()], 'Field values');
161
$this->assertEquals(true, $isContainer[$this->_item->getId()], 'Album-specific settings');