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

« back to all changes in this revision

Viewing changes to lib/tools/phpunit/ItemEditOptionTestCase.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
 
require_once(dirname(__FILE__) . '/../../../modules/core/classes/GalleryView.class');
22
 
require_once(dirname(__FILE__) . '/../../../modules/core/classes/GalleryController.class');
23
 
require_once(dirname(__FILE__) . '/../../../modules/core/ItemEdit.inc');
24
 
 
25
 
/**
26
 
 * An ItemEditOption specific version of GalleryTestCase
27
 
 * @package Gallery
28
 
 * @subpackage PHPUnit
29
 
 * @author Alan Harder <alan.harder@sun.com>
30
 
 * @version $Revision: 15513 $
31
 
 */
32
 
class ItemEditOptionTestCase extends GalleryTestCase {
33
 
 
34
 
    /**
35
 
     * The option instance
36
 
     * @access protected
37
 
     */
38
 
    var $_option;
39
 
 
40
 
    /**
41
 
     * immediate status view
42
 
     * @access private
43
 
     */
44
 
    var $_statusMonitor;
45
 
 
46
 
    function ItemEditOptionTestCase($methodName, $moduleName, $optionName) {
47
 
        $this->GalleryTestCase($methodName);
48
 
 
49
 
        list ($ret, $this->_option) =
50
 
            GalleryCoreApi::newFactoryInstanceById('ItemEditOption', $optionName);
51
 
        if ($ret) {
52
 
            return $this->failWithStatus($ret);
53
 
        }
54
 
        if (!isset($this->_option)) {
55
 
            return $this->failWithStatus(
56
 
                          GalleryCoreApi::error(ERROR_MISSING_OBJECT));
57
 
        }
58
 
 
59
 
        list ($ret, $this->_module) = GalleryCoreApi::loadPlugin('module', $moduleName);
60
 
        if ($ret) {
61
 
            return $this->failWithStatus($ret);
62
 
        }
63
 
        $this->_statusMonitor = new ItemEditOptionTestImmediateStatusView();
64
 
    }
65
 
 
66
 
    function _handleRequestAfterEdit($form, &$item, $errorCode=null) {
67
 
        list ($ret, $preferred) = GalleryCoreApi::fetchPreferredsByItemIds(array($item->getId()));
68
 
        if ($ret) {
69
 
            return array($ret, null);
70
 
        }
71
 
        $preferred = empty($preferred) ? null : array_shift($preferred);
72
 
 
73
 
        list ($ret, $error, $warning) = $this->_option->handleRequestAfterEdit(
74
 
                $form, $item, $preferred, $this->_statusMonitor);
75
 
        if (isset($errorCode)) {
76
 
            if (($ret->getErrorCode() & $errorCode) != $errorCode) {
77
 
                $this->assert(false,
78
 
                        sprintf('Expected error code (%s) but received (%s)',
79
 
                            implode(' | ', GalleryStatus::getErrorCodeConstants($errorCode)),
80
 
                            implode(' | ', GalleryStatus::getErrorCodeConstants(
81
 
                                                          $ret->getErrorCode()))));
82
 
            }
83
 
        } else if ($ret) {
84
 
            $this->failWithStatus($ret);
85
 
        } else {
86
 
            /* Check to make sure we got back everything we want */
87
 
            $this->assert(isset($error) && is_array($error), 'option error results missing');
88
 
 
89
 
            /* Check to make sure we got back everything we want */
90
 
            $this->assert(isset($warning) && is_array($warning), 'option warning results missing');
91
 
        }
92
 
 
93
 
        return array($error, $warning);
94
 
    }
95
 
 
96
 
    function _translate($message) {
97
 
        return $this->_module->translate($message);
98
 
    }
99
 
}
100
 
 
101
 
/**
102
 
 * Test ImmediateStatusView implementation
103
 
 */
104
 
class ItemEditOptionTestImmediateStatusView extends GalleryView {
105
 
    function doLoadImmediateTemplate() {
106
 
        $this->_l10Domain = 'test';
107
 
        $this->_template = 'test';
108
 
        return null;
109
 
    }
110
 
 
111
 
    function renderHeader() {
112
 
        return null;
113
 
    }
114
 
 
115
 
    function renderStatusMessage($statusMessage) {
116
 
        return null;
117
 
    }
118
 
 
119
 
    function renderRedirect($redirectUrl) {
120
 
        return null;
121
 
    }
122
 
 
123
 
    function renderFooter() {
124
 
        return null;
125
 
    }
126
 
 
127
 
    function setMain($main) {
128
 
        return null;
129
 
    }
130
 
}
131
 
?>