~ubuntu-branches/ubuntu/quantal/gallery2/quantal

« back to all changes in this revision

Viewing changes to modules/customfield/test/phpunit/CustomFieldInterfaceTest.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
 
GalleryCoreApi::requireOnce('modules/customfield/classes/CustomFieldHelper.class');
22
 
 
23
 
/**
24
 
 * Test CustomFieldInterface functionality
25
 
 * @package CustomField
26
 
 * @subpackage PHPUnit
27
 
 * @author Alan Harder <alan.harder@sun.com>
28
 
 * @version $Revision: 15513 $
29
 
 */
30
 
class CustomFieldInterfaceTest extends GalleryTestCase {
31
 
 
32
 
    function CustomFieldInterfaceTest($methodName) {
33
 
        $this->GalleryTestCase($methodName);
34
 
    }
35
 
 
36
 
    function setUp() {
37
 
        parent::setUp();
38
 
        global $gallery;
39
 
 
40
 
        list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'customfield');
41
 
        if ($ret) {
42
 
            print $ret->getAsHtml();
43
 
            $this->failWithStatus($ret);
44
 
        }
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);
50
 
        }
51
 
 
52
 
        list ($ret, $this->_album) = $this->_createRandomAlbum($this->_getRootId());
53
 
        if ($ret) {
54
 
            print $ret->getAsHtml();
55
 
            return $this->failWithStatus($ret);
56
 
        }
57
 
 
58
 
        $this->_markForCleanup($this->_album);
59
 
 
60
 
        list ($ret, $this->_item) = $this->_createRandomDataItem($this->_album->getId(),
61
 
                'image/test', array(), __FILE__, 'GalleryPhotoItem');
62
 
        if ($ret) {
63
 
            print $ret->getAsHtml();
64
 
            return $this->failWithStatus($ret);
65
 
        }
66
 
 
67
 
        $ret = $this->_markPluginParametersForCleanup('module', 'customfield');
68
 
        if ($ret) {
69
 
            print $ret->getAsHtml();
70
 
            return $ret;
71
 
        }
72
 
 
73
 
        foreach (array('common' => '', 'album' => '', 'photo' => 'Test`0`1') as $key => $value) {
74
 
            $ret = GalleryCoreApi::setPluginParameter('module', 'customfield', $key, $value);
75
 
            if ($ret) {
76
 
                print $ret->getAsHtml();
77
 
                return $this->failWithStatus($ret);
78
 
            }
79
 
        }
80
 
    }
81
 
 
82
 
    function testInterface() {
83
 
 
84
 
        // Create global fields..
85
 
        list ($ret, $duplicates) = $this->_interface->createCustomFields(array('One', 'Two'));
86
 
        if ($ret) {
87
 
            return $this->failWithStatus($ret);
88
 
        }
89
 
        $this->assertEquals(array(), $duplicates, 'Add global 1');
90
 
 
91
 
        list ($ret, $params) = GalleryCoreApi::fetchAllPluginParameters('module', 'customfield');
92
 
        if ($ret) {
93
 
            return $this->failWithStatus($ret);
94
 
        }
95
 
        foreach ($params as $key => $value) {
96
 
            if ($key[0] == '_') {
97
 
                unset($params[$key]);
98
 
            }
99
 
        }
100
 
        ksort($params);
101
 
        $this->assertEquals(array('album' => '',
102
 
                                  'common' => 'One`0`1|Two`0`1',
103
 
                                  'photo' => 'Test`0`1'),
104
 
                            $params, 'Check Data 1');
105
 
 
106
 
        // Create global fields, with duplicate..
107
 
        list ($ret, $duplicates) =
108
 
            $this->_interface->createCustomFields(array('Test', 'Three', 'Two'));
109
 
        if ($ret) {
110
 
            return $this->failWithStatus($ret);
111
 
        }
112
 
        $this->assertEquals(array('Test', 'Two'), $duplicates, 'Add global 2');
113
 
 
114
 
        list ($ret, $params) = GalleryCoreApi::fetchAllPluginParameters('module', 'customfield');
115
 
        if ($ret) {
116
 
            return $this->failWithStatus($ret);
117
 
        }
118
 
        foreach ($params as $key => $value) {
119
 
            if ($key[0] == '_') {
120
 
                unset($params[$key]);
121
 
            }
122
 
        }
123
 
        ksort($params);
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');
128
 
 
129
 
        // Create album-specific fields..
130
 
        list ($ret, $duplicates) =
131
 
            $this->_interface->createCustomFields(array('Photographer', 'Location', 'One'),
132
 
                                                  $this->_album->getId());
133
 
        if ($ret) {
134
 
            return $this->failWithStatus($ret);
135
 
        }
136
 
        $this->assertEquals(array(), $duplicates, 'Add album');
137
 
 
138
 
        list ($ret, $params) = GalleryCoreApi::fetchAllPluginParameters('module', 'customfield',
139
 
                                                                        $this->_album->getId());
140
 
        if ($ret) {
141
 
            return $this->failWithStatus($ret);
142
 
        }
143
 
        ksort($params);
144
 
        $this->assertEquals(array('common' => 'Photographer`0`1|Location`0`1|One`0`1'),
145
 
                            $params, 'Check Data 3');
146
 
 
147
 
        // Set field values..
148
 
        $ret = $this->_interface->setCustomFieldValues($this->_item->getId(),
149
 
                array('Photographer' => 'Me', 'Location' => 'Here'));
150
 
        if ($ret) {
151
 
            return $this->failWithStatus($ret);
152
 
        }
153
 
 
154
 
        list ($ret, $data, $tmp, $isContainer) =
155
 
                CustomFieldHelper::fetchFieldValues(array($this->_item));
156
 
        if ($ret) {
157
 
            return $this->failWithStatus($ret);
158
 
        }
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');
162
 
    }
163
 
}
164
 
?>