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
* ItemEditTheme controller tests
23
* @package GalleryCore
25
* @author Bharat Mediratta <bharat@menalto.com>
26
* @version $Revision: 15513 $
28
class ItemEditThemePluginTest extends ItemEditPluginTestCase {
30
function ItemEditThemePluginTest($methodName) {
31
$this->ItemEditPluginTestCase($methodName, 'core', 'ItemEditTheme');
39
/* Create a random album */
40
list ($ret, $this->_album) = $this->_createRandomAlbum(
41
$this->_getRootId(), array('theme' => 'ItemEditThemeControllerTest'));
43
return $this->failWithStatus($ret);
46
/* Create child album here, since test theme is too rudimentary */
47
list ($ret, $this->_childAlbum) = $this->_createRandomAlbum($this->_album->getId());
49
print $ret->getAsHtml();
50
return $this->failWithStatus($ret);
54
* Also check the grandchild album - to make sure that descendents don't
55
* just return children
57
list ($ret, $this->_grandchildAlbum) = $this->_createRandomAlbum(
58
$this->_childAlbum->getId());
60
print $ret->getAsHtml();
61
return $this->failWithStatus($ret);
64
$this->_markForCleanup($this->_album);
66
$gallery->setPlatform(new ItemEditThemeTestPlatform($gallery->getPlatform()));
68
$this->_preferred = null;
70
/* Reset test theme */
71
ItemEditThemeControllerTestTheme::reset();
74
function _setTheme(&$item, $themeId) {
75
list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($item->getId());
77
return $this->failWithStatus($ret);
80
$item->setTheme($themeId);
83
return $this->failWithStatus($ret);
86
$ret = GalleryCoreApi::releaseLocks($lockId);
88
return $this->failWithStatus($ret);
93
/* Use valid inputs */
94
GalleryUtilities::putRequestVariable('form[action][undo]', 1);
96
/* Perform the request and verify that we succeeded */
97
$results = $this->handleRequest($this->_album, $this->_preferred);
98
$this->assertEquals(array(array(), null), $results);
101
function testSave() {
102
GalleryUtilities::putRequestVariable('form[key][rows]', 3);
103
GalleryUtilities::putRequestVariable('form[key][columns]', 4);
104
GalleryUtilities::putRequestVariable('form[action][save]', 1);
106
/* Perform the request and verify that we succeeded */
107
$results = $this->handleRequest($this->_album, $this->_preferred);
108
$this->assertEquals(array(array(), $this->_translate('Successfully saved theme settings')),
112
$this->assertEquals(array('setParameter(rows, 3)',
113
'setParameter(columns, 4)'),
114
ItemEditThemeControllerTestTheme::getMap());
117
function testInvalidSave() {
118
GalleryUtilities::putRequestVariable('form[key][rows]', '3x');
119
GalleryUtilities::putRequestVariable('form[key][columns]', 4);
120
GalleryUtilities::putRequestVariable('form[action][save]', 1);
122
/* Perform the request and verify that we succeeded */
123
$results = $this->handleRequest($this->_album, $this->_preferred);
124
$this->assertEquals(array(array('form[error][key][rows][invalid]'), null),
127
/* Verify that we have a detailed error message */
128
$this->assert(GalleryUtilities::hasRequestVariable('form[errorMessage]'));
130
$errorMessage = GalleryUtilities::getRequestVariables('form[errorMessage]');
131
$this->assertEquals('You must enter a number greater than 0', $errorMessage['rows']);
134
function testSaveWithGlobal() {
135
GalleryUtilities::putRequestVariable('form[key][rows]', 3);
136
GalleryUtilities::putRequestVariable('form[key][columns]', 4);
137
GalleryUtilities::putRequestVariable('form[useGlobal][columns]', 'on');
138
GalleryUtilities::putRequestVariable('form[action][save]', 1);
140
/* Perform the request and verify that we succeeded */
141
$results = $this->handleRequest($this->_album, $this->_preferred);
142
$this->assertEquals(array(array(), $this->_translate('Successfully saved theme settings')),
146
$this->assertEquals(array('setParameter(rows, 3)',
147
sprintf('removeParameter(columns, %d)', $this->_album->getId())),
148
ItemEditThemeControllerTestTheme::getMap());
152
* Test applying options from 'Theme' tab to sub-albums
154
function testChangeInDescendents() {
155
GalleryUtilities::putRequestVariable('form[key][rows]', 3);
156
GalleryUtilities::putRequestVariable('form[key][columns]', 4);
157
GalleryUtilities::putRequestVariable('form[action][save]', 1);
158
GalleryUtilities::putRequestVariable('form[changeInDescendents][theme]', 1);
160
/* Perform the request and verify that we succeeded */
161
$results = $this->handleRequest($this->_album, $this->_preferred);
162
$this->assertEquals(array(array(), $this->_translate('Successfully saved theme settings')),
164
/* Verify - 3 albums should be set */
165
$this->assertEquals(array('setParameter(rows, 3)',
166
'setParameter(rows, 3)',
167
'setParameter(rows, 3)',
168
'setParameter(columns, 4)',
169
'setParameter(columns, 4)',
170
'setParameter(columns, 4)'),
171
ItemEditThemeControllerTestTheme::getMap());
175
* Test applying options from 'Theme' tab to sub-albums with no subalbum
177
function testChangeInDescendentsLeaf() {
178
GalleryUtilities::putRequestVariable('form[key][rows]', 3);
179
GalleryUtilities::putRequestVariable('form[key][columns]', 4);
180
GalleryUtilities::putRequestVariable('form[action][save]', 1);
181
GalleryUtilities::putRequestVariable('form[changeInDescendents][theme]', 1);
183
$this->_setTheme($this->_grandchildAlbum, 'ItemEditThemeControllerTest');
185
/* Perform the request and verify that we succeeded */
186
$results = $this->handleRequest($this->_grandchildAlbum, $this->_preferred);
187
$this->assertEquals(array(array(), $this->_translate('Successfully saved theme settings')),
189
$this->assertEquals(array('setParameter(rows, 3)',
190
'setParameter(columns, 4)'),
191
ItemEditThemeControllerTestTheme::getMap());
194
function testChooseTheme() {
195
$this->_setTheme($this->_album, null);
197
GalleryUtilities::putRequestVariable('form[theme]', 'ItemEditThemeControllerTest');
198
GalleryUtilities::putRequestVariable('form[action][chooseTheme]', 1);
199
GalleryUtilities::putRequestVariable(
200
'form[serialNumber]', $this->_album->getSerialNumber());
202
/* Perform the request and verify that we succeeded */
203
$results = $this->handleRequest($this->_album, $this->_preferred);
204
$this->assertEquals(array(array(), $this->_translate('Successfully changed theme')),
207
list ($ret, $this->_album) = $this->_album->refresh();
209
$this->failWithStatus($ret);
211
$this->assertEquals('ItemEditThemeControllerTest', $this->_album->getTheme());
214
function testChooseDefaultTheme() {
215
$this->_setTheme($this->_album, 'ItemEditThemeControllerTest');
217
GalleryUtilities::putRequestVariable('form[action][chooseTheme]', 1);
218
GalleryUtilities::putRequestVariable(
219
'form[serialNumber]', $this->_album->getSerialNumber());
221
/* Perform the request and verify that we succeeded */
222
$results = $this->handleRequest($this->_album, $this->_preferred);
223
$this->assertEquals(array(array(), $this->_translate('Successfully changed theme')),
226
list ($ret, $this->_album) = $this->_album->refresh();
228
$this->failWithStatus($ret);
230
$themeId = $this->_album->getTheme();
231
$this->assert(empty($themeId));
234
function testChooseBogusTheme() {
235
GalleryUtilities::putRequestVariable('form[theme]', 'BogusBogus!');
236
GalleryUtilities::putRequestVariable('form[action][chooseTheme]', 1);
238
$results = $this->handleRequest($this->_album, $this->_preferred, ERROR_BAD_PARAMETER);
241
function testChooseThemeInvalidSerialNumber() {
242
GalleryUtilities::putRequestVariable('form[theme]', 'ItemEditThemeControllerTest');
243
GalleryUtilities::putRequestVariable('form[action][chooseTheme]', 1);
244
GalleryUtilities::putRequestVariable('form[serialNumber]', -1);
246
$results = $this->handleRequest($this->_album, $this->_preferred, ERROR_OBSOLETE_DATA);
249
function testChooseThemeInDescendents() {
250
$this->_setTheme($this->_album, null);
251
$this->_setTheme($this->_childAlbum, null);
252
$this->_setTheme($this->_grandchildAlbum, null);
254
GalleryUtilities::putRequestVariable('form[theme]', 'ItemEditThemeControllerTest');
255
GalleryUtilities::putRequestVariable('form[changeInDescendents][theme]', 1);
256
GalleryUtilities::putRequestVariable('form[action][chooseTheme]', 1);
257
GalleryUtilities::putRequestVariable(
258
'form[serialNumber]', $this->_album->getSerialNumber());
260
/* Perform the request and verify that we succeeded */
261
$results = $this->handleRequest($this->_album, $this->_preferred);
262
$this->assertEquals(array(array(), $this->_translate('Successfully changed theme')),
265
list ($ret, $album) = $this->_album->refresh();
267
$this->failWithStatus($ret);
269
list ($ret, $childAlbum) = $this->_childAlbum->refresh();
271
$this->failWithStatus($ret);
273
list ($ret, $grandchildAlbum) = $this->_grandchildAlbum->refresh();
275
$this->failWithStatus($ret);
278
$this->assertEquals('ItemEditThemeControllerTest', $album->getTheme(), 'album');
279
$this->assertEquals('ItemEditThemeControllerTest', $childAlbum->getTheme(), 'child');
280
$this->assertEquals('ItemEditThemeControllerTest',
281
$grandchildAlbum->getTheme(), 'grandchild');
288
class ItemEditThemeControllerTestTheme {
290
return 'ItemEditThemeControllerTest';
294
* @see GalleryTheme::getSettings
296
function getSettings($itemId=0) {
298
$settings[] = array('key' => 'rows',
299
'name' => 'Rows per album page',
300
'type' => 'text-field',
301
'typeParams' => array('size' => 2),
303
$settings[] = array('key' => 'columns',
304
'name' => 'Columns per album page',
305
'type' => 'text-field',
306
'typeParams' => array('size' => 2),
308
return array(null, $settings);
312
* @see GalleryTheme::validateSettings
314
function validateSettings($settings) {
316
if (empty($settings['rows']) || !is_numeric($settings['rows'])) {
317
$error['rows'] = $this->translate('You must enter a number greater than 0');
320
if (empty($settings['columns']) || !is_numeric($settings['columns'])) {
321
$error['columns'] = $this->translate('You must enter a number greater than 0');
328
* @see GalleryTheme::isAdvancedSettings
330
function isAdvancedSettings() {
334
function isActive() {
335
return array(null, true);
338
function translate($text) {
342
function removeParameter($key, $itemIds) {
343
$map =& $this->getMap();
344
foreach ($itemIds as $id) {
345
$map[] = "removeParameter($key, $id)";
350
function setParameter($key, $value, $itemIds) {
351
$map =& $this->getMap();
352
foreach ($itemIds as $id) {
353
$map[] = "setParameter($key, $value)";
371
$map =& ItemEditThemeControllerTestTheme::getMap();
376
return 'ItemEditThemeControllerTest';
383
class ItemEditThemeTestPlatform {
385
function ItemEditThemeTestPlatform($originalPlatform) {
386
$this->_savedPlatform = $originalPlatform;
389
function opendir($path) {
390
if ($path == dirname(__FILE__) . '/../../../../themes/') {
391
return 'TEST_VALID_RESOURCE';
397
function readdir($path) {
399
if (!isset($paths)) {
400
$paths = array('.', '..', 'ItemEditThemeControllerTest');
403
if ($path == 'TEST_VALID_RESOURCE') {
408
return array_shift($paths);
413
function fopen($filename, $modes) {
414
/* Pass lock requests */
415
if (preg_match("|\blocks\b|", $filename)) {
416
return fopen($filename, $modes);
419
print "Unexpected fopen($filename, $modes)";
423
function fclose($handle) {
424
return fclose($handle); /* needed to release locks */
427
function getDirectorySeparator() {
428
return DIRECTORY_SEPARATOR;
431
function unlink($path) {
432
return unlink($path); /* needed to release locks */
435
function closedir($path) {
438
function realpath($path) {
439
return realpath($path);
442
function file_exists($path) {
443
$base = dirname(__FILE__) . '/../../../../themes/';
445
case $base . 'ItemEditThemeControllerTest/theme.inc':
453
function is_dir($path) {
454
$base = dirname(__FILE__) . '/../../../../themes/';
456
case $base . 'ItemEditThemeControllerTest':
464
function flock($fd, $lockType, $flag) {
465
return $this->_savedPlatform->flock($fd, $lockType, $flag);