Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | |
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
5 | | CiviCRM version 4.3 | | |
6 | +--------------------------------------------------------------------+ | |
7 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
8 | +--------------------------------------------------------------------+ | |
9 | | This file is a part of CiviCRM. | | |
10 | | | | |
11 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
12 | | under the terms of the GNU Affero General Public License | | |
13 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
14 | | | | |
15 | | CiviCRM is distributed in the hope that it will be useful, but | | |
16 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
17 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
18 | | See the GNU Affero General Public License for more details. | | |
19 | | | | |
20 | | You should have received a copy of the GNU Affero General Public | | |
21 | | License and the CiviCRM Licensing Exception along | | |
22 | | with this program; if not, contact CiviCRM LLC | | |
23 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
24 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
25 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
26 | +--------------------------------------------------------------------+ | |
27 | */ | |
28 | ||
29 | ||
30 | ||
31 | ||
32 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
33 | ||
34 | /** | |
35 | * Test class for UFGroup API - civicrm_uf_* | |
36 | * @todo Split UFGroup and UFJoin tests | |
37 | * | |
38 | * @package CiviCRM | |
39 | */ | |
40 | class api_v3_UFGroupTest extends CiviUnitTestCase { | |
41 | // ids from the uf_group_test.xml fixture | |
42 | protected $_ufGroupId = 11; | |
43 | protected $_ufFieldId; | |
44 | protected $_contactId = 69; | |
45 | protected $_apiversion; | |
46 | protected $params; | |
47 | ||
48 | protected function setUp() { | |
49 | parent::setUp(); | |
50 | $this->_apiversion = 3; | |
51 | // Truncate the tables | |
52 | $this->quickCleanup( | |
53 | array( | |
54 | 'civicrm_group', | |
55 | 'civicrm_contact', | |
56 | 'civicrm_uf_group', | |
57 | 'civicrm_uf_join', | |
58 | 'civicrm_uf_match', | |
59 | ) | |
60 | ); | |
61 | ||
62 | $op = new PHPUnit_Extensions_Database_Operation_Insert; | |
63 | $op->execute( | |
64 | $this->_dbconn, | |
65 | new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml') | |
66 | ); | |
67 | ||
68 | // FIXME: something NULLs $GLOBALS['_HTML_QuickForm_registered_rules'] when the tests are ran all together | |
69 | $GLOBALS['_HTML_QuickForm_registered_rules'] = array( | |
70 | 'required' => array('html_quickform_rule_required', 'HTML/QuickForm/Rule/Required.php'), | |
71 | 'maxlength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'), | |
72 | 'minlength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'), | |
73 | 'rangelength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'), | |
74 | 'email' => array('html_quickform_rule_email', 'HTML/QuickForm/Rule/Email.php'), | |
75 | 'regex' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), | |
76 | 'lettersonly' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), | |
77 | 'alphanumeric' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), | |
78 | 'numeric' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), | |
79 | 'nopunctuation' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), | |
80 | 'nonzero' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), | |
81 | 'callback' => array('html_quickform_rule_callback', 'HTML/QuickForm/Rule/Callback.php'), | |
82 | 'compare' => array('html_quickform_rule_compare', 'HTML/QuickForm/Rule/Compare.php'), | |
83 | ); | |
84 | // FIXME: …ditto for $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'] | |
85 | $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'] = array( | |
86 | 'group' => array('HTML/QuickForm/group.php', 'HTML_QuickForm_group'), | |
87 | 'hidden' => array('HTML/QuickForm/hidden.php', 'HTML_QuickForm_hidden'), | |
88 | 'reset' => array('HTML/QuickForm/reset.php', 'HTML_QuickForm_reset'), | |
89 | 'checkbox' => array('HTML/QuickForm/checkbox.php', 'HTML_QuickForm_checkbox'), | |
90 | 'file' => array('HTML/QuickForm/file.php', 'HTML_QuickForm_file'), | |
91 | 'image' => array('HTML/QuickForm/image.php', 'HTML_QuickForm_image'), | |
92 | 'password' => array('HTML/QuickForm/password.php', 'HTML_QuickForm_password'), | |
93 | 'radio' => array('HTML/QuickForm/radio.php', 'HTML_QuickForm_radio'), | |
94 | 'button' => array('HTML/QuickForm/button.php', 'HTML_QuickForm_button'), | |
95 | 'submit' => array('HTML/QuickForm/submit.php', 'HTML_QuickForm_submit'), | |
96 | 'select' => array('HTML/QuickForm/select.php', 'HTML_QuickForm_select'), | |
97 | 'hiddenselect' => array('HTML/QuickForm/hiddenselect.php', 'HTML_QuickForm_hiddenselect'), | |
98 | 'text' => array('HTML/QuickForm/text.php', 'HTML_QuickForm_text'), | |
99 | 'textarea' => array('HTML/QuickForm/textarea.php', 'HTML_QuickForm_textarea'), | |
100 | 'fckeditor' => array('HTML/QuickForm/fckeditor.php', 'HTML_QuickForm_FCKEditor'), | |
101 | 'tinymce' => array('HTML/QuickForm/tinymce.php', 'HTML_QuickForm_TinyMCE'), | |
102 | 'dojoeditor' => array('HTML/QuickForm/dojoeditor.php', 'HTML_QuickForm_dojoeditor'), | |
103 | 'link' => array('HTML/QuickForm/link.php', 'HTML_QuickForm_link'), | |
104 | 'advcheckbox' => array('HTML/QuickForm/advcheckbox.php', 'HTML_QuickForm_advcheckbox'), | |
105 | 'date' => array('HTML/QuickForm/date.php', 'HTML_QuickForm_date'), | |
106 | 'static' => array('HTML/QuickForm/static.php', 'HTML_QuickForm_static'), | |
107 | 'header' => array('HTML/QuickForm/header.php', 'HTML_QuickForm_header'), | |
108 | 'html' => array('HTML/QuickForm/html.php', 'HTML_QuickForm_html'), | |
109 | 'hierselect' => array('HTML/QuickForm/hierselect.php', 'HTML_QuickForm_hierselect'), | |
110 | 'autocomplete' => array('HTML/QuickForm/autocomplete.php', 'HTML_QuickForm_autocomplete'), | |
111 | 'xbutton' => array('HTML/QuickForm/xbutton.php', 'HTML_QuickForm_xbutton'), | |
112 | 'advmultiselect' => array('HTML/QuickForm/advmultiselect.php', 'HTML_QuickForm_advmultiselect'), | |
113 | ); | |
114 | $this->params = array( | |
115 | 'add_captcha' => 1, | |
116 | 'add_contact_to_group' => 2, | |
117 | 'cancel_URL' => 'http://example.org/cancel', | |
118 | 'created_date' => '2009-06-27 00:00:00', | |
119 | 'created_id' => 69, | |
120 | 'group' => 2, | |
121 | 'group_type' => 'Individual,Contact', | |
122 | 'help_post' => 'help post', | |
123 | 'help_pre' => 'help pre', | |
124 | 'is_active' => 0, | |
125 | 'is_cms_user' => 1, | |
126 | 'is_edit_link' => 1, | |
127 | 'is_map' => 1, | |
128 | 'is_reserved' => 1, | |
129 | 'is_uf_link' => 1, | |
130 | 'is_update_dupe' => 1, | |
131 | 'name' => 'Test_Group', | |
132 | 'notify' => 'admin@example.org', | |
133 | 'post_URL' => 'http://example.org/post', | |
134 | 'title' => 'Test Group', | |
135 | 'version' => $this->_apiversion, | |
136 | ); | |
137 | } | |
138 | ||
139 | function tearDown() { | |
140 | ||
141 | // Truncate the tables | |
142 | $this->quickCleanup( | |
143 | array( | |
144 | 'civicrm_group', | |
145 | 'civicrm_contact', | |
146 | 'civicrm_uf_group', | |
147 | 'civicrm_uf_join', | |
148 | 'civicrm_uf_match', | |
149 | ) | |
150 | ); | |
151 | } | |
152 | ||
153 | /** | |
154 | * updating group | |
155 | */ | |
156 | public function testUpdateUFGroup() { | |
157 | $params = array( | |
158 | 'title' => 'Edited Test Profile', | |
159 | 'help_post' => 'Profile Pro help text.', | |
160 | 'is_active' => 1, | |
161 | 'id' => $this->_ufGroupId, | |
162 | 'version' => $this->_apiversion, | |
163 | ); | |
164 | ||
165 | $result = civicrm_api('uf_group', 'create', $params); | |
166 | unset($params['version']); | |
167 | foreach ($params as $key => $value) { | |
168 | $this->assertEquals($result['values'][$result['id']][$key], $value); | |
169 | } | |
170 | } | |
171 | ||
172 | function testUFGroupCreate() { | |
173 | ||
174 | $result = civicrm_api('uf_group', 'create', $this->params); | |
175 | $this->documentMe($this->params, $result, __FUNCTION__, __FILE__); | |
176 | ||
177 | $this->assertEquals($result['values'][$result['id']]['add_to_group_id'], $this->params['add_contact_to_group'], 'in line ' . __LINE__); | |
178 | $this->assertEquals($result['values'][$result['id']]['limit_listings_group_id'], $this->params['group'], 'in line ' . __LINE__); | |
179 | $this->params['created_date'] = date('YmdHis', strtotime($this->params['created_date'])); | |
180 | foreach ($this->params as $key => $value) { | |
181 | if ($key == 'add_contact_to_group' or $key == 'group' or $key == 'version') { | |
182 | continue; | |
183 | } | |
184 | $expected = $this->params[$key]; | |
185 | $received = $result['values'][$result['id']][$key]; | |
186 | // group names are renamed to name_id by BAO | |
187 | if ($key == 'name') { | |
188 | $expected = $this->params[$key] . '_' . $result['id']; | |
189 | } | |
190 | $this->assertEquals($expected, $received, "The string '$received' does not equal '$expected' for key '$key' in line " . __LINE__); | |
191 | } | |
192 | } | |
193 | ||
194 | function testUFGroupCreateWithWrongParams() { | |
195 | $result = civicrm_api('uf_group', 'create', 'a string'); | |
196 | $this->assertEquals($result['is_error'], 1); | |
197 | $result = civicrm_api('uf_group', 'create', array('name' => 'A title-less group')); | |
198 | $this->assertEquals($result['is_error'], 1); | |
199 | } | |
200 | ||
201 | function testUFGroupUpdate() { | |
202 | $params = array( | |
203 | 'id' => $this->_ufGroupId, | |
204 | 'add_captcha' => 1, | |
205 | 'add_contact_to_group' => 2, | |
206 | 'cancel_URL' => 'http://example.org/cancel', | |
207 | 'created_date' => '2009-06-27', | |
208 | 'created_id' => 69, | |
209 | 'group' => 2, | |
210 | 'group_type' => 'Individual,Contact', | |
211 | 'help_post' => 'help post', | |
212 | 'help_pre' => 'help pre', | |
213 | 'is_active' => 0, | |
214 | 'is_cms_user' => 1, | |
215 | 'is_edit_link' => 1, | |
216 | 'is_map' => 1, | |
217 | 'is_reserved' => 1, | |
218 | 'is_uf_link' => 1, | |
219 | 'is_update_dupe' => 1, | |
220 | 'name' => 'test_group', | |
221 | 'notify' => 'admin@example.org', | |
222 | 'post_URL' => 'http://example.org/post', | |
223 | 'title' => 'Test Group', | |
224 | 'version' => $this->_apiversion, | |
225 | ); | |
226 | $result = civicrm_api('uf_group', 'create', $params); | |
227 | unset($params['version']); | |
228 | $params['created_date'] = date('YmdHis', strtotime($params['created_date'])); | |
229 | foreach ($params as $key => $value) { | |
230 | if ($key == 'add_contact_to_group' or $key == 'group') { | |
231 | continue; | |
232 | } | |
233 | $this->assertEquals($result['values'][$result['id']][$key], $params[$key], $key . " doesn't match " . $value); | |
234 | } | |
235 | ||
236 | $this->assertEquals($result['values'][$this->_ufGroupId]['add_to_group_id'], $params['add_contact_to_group'], 'in line ' . __LINE__); | |
237 | $this->assertEquals($result['values'][$result['id']]['limit_listings_group_id'], $params['group'], 'in line ' . __LINE__); | |
238 | } | |
239 | ||
240 | function testUFGroupGet() { | |
241 | ||
242 | $result = civicrm_api('uf_group', 'create', $this->params); | |
243 | $this->assertEquals(0, $result['is_error'], 'in line ' . __LINE__); | |
244 | ||
245 | $params = array('version' => 3, 'id' => $result['id']); | |
246 | $result = civicrm_api('uf_group', 'get', $params); | |
247 | $this->assertEquals(0, $result['is_error'], 'in line ' . __LINE__); | |
248 | $this->documentMe($this->params, $result, __FUNCTION__, __FILE__); | |
249 | $this->assertEquals($result['values'][$result['id']]['add_to_group_id'], $this->params['add_contact_to_group'], 'in line ' . __LINE__); | |
250 | $this->assertEquals($result['values'][$result['id']]['limit_listings_group_id'], $this->params['group'], 'in line ' . __LINE__); | |
251 | foreach ($this->params as $key => $value) { | |
252 | // skip created date because it doesn't seem to be working properly & fixing date handling is for another day | |
253 | if ($key == 'add_contact_to_group' or $key == 'group' or $key == 'version' or $key == 'created_date') { | |
254 | continue; | |
255 | } | |
256 | $expected = $this->params[$key]; | |
257 | $received = $result['values'][$result['id']][$key]; | |
258 | // group names are renamed to name_id by BAO | |
259 | if ($key == 'name') { | |
260 | $expected = $this->params[$key] . '_' . $result['id']; | |
261 | } | |
262 | $this->assertEquals($expected, $received, "The string '$received' does not equal '$expected' for key '$key' in line " . __LINE__); | |
263 | } | |
264 | } | |
265 | ||
266 | function testUFGroupUpdateWithEmptyParams() { | |
267 | $result = civicrm_api('uf_group', 'create', array(), $this->_ufGroupId); | |
268 | $this->assertEquals($result['is_error'], 1); | |
269 | } | |
270 | ||
271 | function testUFGroupUpdateWithWrongParams() { | |
272 | $result = civicrm_api('uf_group', 'create', 'a string', $this->_ufGroupId); | |
273 | $this->assertEquals($result['is_error'], 1); | |
274 | $result = civicrm_api('uf_group', 'create', array('title' => 'Title'), 'a string'); | |
275 | $this->assertEquals($result['is_error'], 1); | |
276 | } | |
277 | ||
278 | function testUFGroupDelete() { | |
279 | ||
280 | $ufGroup = civicrm_api('uf_group', 'create', $this->params); | |
281 | $params = array('version' => $this->_apiversion, 'id' => $ufGroup['id']); | |
282 | $this->assertEquals(1, civicrm_api('uf_group', 'getcount', $params), "in line " . __LINE__); | |
283 | $result = civicrm_api('uf_group', 'delete', $params, "in line " . __LINE__); | |
284 | $this->documentMe($this->params, $result, __FUNCTION__, __FILE__); | |
285 | $this->assertEquals(0, civicrm_api('uf_group', 'getcount', $params), "in line " . __LINE__); | |
286 | $this->assertAPISuccess($result, "in line " . __LINE__); | |
287 | } | |
288 | } | |
289 |