4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
32 require_once 'CiviTest/CiviUnitTestCase.php';
35 * Test class for UFGroup API - civicrm_uf_*
36 * @todo Split UFGroup and UFJoin tests
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;
47 public $_eNoticeCompliant = TRUE;
49 protected function setUp() {
51 $this->_apiversion
= 3;
52 // Truncate the tables
63 $op = new PHPUnit_Extensions_Database_Operation_Insert
;
66 new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__
) . '/dataset/uf_group_test.xml')
69 // FIXME: something NULLs $GLOBALS['_HTML_QuickForm_registered_rules'] when the tests are ran all together
70 $GLOBALS['_HTML_QuickForm_registered_rules'] = array(
71 'required' => array('html_quickform_rule_required', 'HTML/QuickForm/Rule/Required.php'),
72 'maxlength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'),
73 'minlength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'),
74 'rangelength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'),
75 'email' => array('html_quickform_rule_email', 'HTML/QuickForm/Rule/Email.php'),
76 'regex' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
77 'lettersonly' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
78 'alphanumeric' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
79 'numeric' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
80 'nopunctuation' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
81 'nonzero' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
82 'callback' => array('html_quickform_rule_callback', 'HTML/QuickForm/Rule/Callback.php'),
83 'compare' => array('html_quickform_rule_compare', 'HTML/QuickForm/Rule/Compare.php'),
85 // FIXME: …ditto for $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES']
86 $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'] = array(
87 'group' => array('HTML/QuickForm/group.php', 'HTML_QuickForm_group'),
88 'hidden' => array('HTML/QuickForm/hidden.php', 'HTML_QuickForm_hidden'),
89 'reset' => array('HTML/QuickForm/reset.php', 'HTML_QuickForm_reset'),
90 'checkbox' => array('HTML/QuickForm/checkbox.php', 'HTML_QuickForm_checkbox'),
91 'file' => array('HTML/QuickForm/file.php', 'HTML_QuickForm_file'),
92 'image' => array('HTML/QuickForm/image.php', 'HTML_QuickForm_image'),
93 'password' => array('HTML/QuickForm/password.php', 'HTML_QuickForm_password'),
94 'radio' => array('HTML/QuickForm/radio.php', 'HTML_QuickForm_radio'),
95 'button' => array('HTML/QuickForm/button.php', 'HTML_QuickForm_button'),
96 'submit' => array('HTML/QuickForm/submit.php', 'HTML_QuickForm_submit'),
97 'select' => array('HTML/QuickForm/select.php', 'HTML_QuickForm_select'),
98 'hiddenselect' => array('HTML/QuickForm/hiddenselect.php', 'HTML_QuickForm_hiddenselect'),
99 'text' => array('HTML/QuickForm/text.php', 'HTML_QuickForm_text'),
100 'textarea' => array('HTML/QuickForm/textarea.php', 'HTML_QuickForm_textarea'),
101 'fckeditor' => array('HTML/QuickForm/fckeditor.php', 'HTML_QuickForm_FCKEditor'),
102 'tinymce' => array('HTML/QuickForm/tinymce.php', 'HTML_QuickForm_TinyMCE'),
103 'dojoeditor' => array('HTML/QuickForm/dojoeditor.php', 'HTML_QuickForm_dojoeditor'),
104 'link' => array('HTML/QuickForm/link.php', 'HTML_QuickForm_link'),
105 'advcheckbox' => array('HTML/QuickForm/advcheckbox.php', 'HTML_QuickForm_advcheckbox'),
106 'date' => array('HTML/QuickForm/date.php', 'HTML_QuickForm_date'),
107 'static' => array('HTML/QuickForm/static.php', 'HTML_QuickForm_static'),
108 'header' => array('HTML/QuickForm/header.php', 'HTML_QuickForm_header'),
109 'html' => array('HTML/QuickForm/html.php', 'HTML_QuickForm_html'),
110 'hierselect' => array('HTML/QuickForm/hierselect.php', 'HTML_QuickForm_hierselect'),
111 'autocomplete' => array('HTML/QuickForm/autocomplete.php', 'HTML_QuickForm_autocomplete'),
112 'xbutton' => array('HTML/QuickForm/xbutton.php', 'HTML_QuickForm_xbutton'),
113 'advmultiselect' => array('HTML/QuickForm/advmultiselect.php', 'HTML_QuickForm_advmultiselect'),
115 $this->params
= array(
117 'add_contact_to_group' => 2,
118 'cancel_URL' => 'http://example.org/cancel',
119 'created_date' => '2009-06-27 00:00:00',
122 'group_type' => 'Individual,Contact',
123 'help_post' => 'help post',
124 'help_pre' => 'help pre',
131 'is_update_dupe' => 1,
132 'name' => 'Test_Group',
133 'notify' => 'admin@example.org',
134 'post_URL' => 'http://example.org/post',
135 'title' => 'Test Group',
136 'version' => $this->_apiversion
,
140 function tearDown() {
142 // Truncate the tables
157 public function testUpdateUFGroup() {
159 'title' => 'Edited Test Profile',
160 'help_post' => 'Profile Pro help text.',
162 'id' => $this->_ufGroupId
,
163 'version' => $this->_apiversion
,
166 $result = civicrm_api('uf_group', 'create', $params);
167 unset($params['version']);
168 foreach ($params as $key => $value) {
169 $this->assertEquals($result['values'][$result['id']][$key], $value);
173 function testUFGroupCreate() {
175 $result = civicrm_api('uf_group', 'create', $this->params
);
176 $this->documentMe($this->params
, $result, __FUNCTION__
, __FILE__
);
177 $this->assertAPISuccess($result);
178 $this->assertEquals($result['values'][$result['id']]['add_to_group_id'], $this->params
['add_contact_to_group'], 'in line ' . __LINE__
);
179 $this->assertEquals($result['values'][$result['id']]['limit_listings_group_id'], $this->params
['group'], 'in line ' . __LINE__
);
180 $this->params
['created_date'] = date('YmdHis', strtotime($this->params
['created_date']));
181 foreach ($this->params
as $key => $value) {
182 if ($key == 'add_contact_to_group' or $key == 'group' or $key == 'version') {
185 $expected = $this->params
[$key];
186 $received = $result['values'][$result['id']][$key];
187 // group names are renamed to name_id by BAO
188 if ($key == 'name') {
189 $expected = $this->params
[$key] . '_' . $result['id'];
191 $this->assertEquals($expected, $received, "The string '$received' does not equal '$expected' for key '$key' in line " . __LINE__
);
195 function testUFGroupCreateWithWrongParams() {
196 $result = civicrm_api('uf_group', 'create', 'a string');
197 $this->assertAPIFailure($result);
198 $result = civicrm_api('uf_group', 'create', array('name' => 'A title-less group'));
199 $this->assertAPIFailure($result);
202 function testUFGroupUpdate() {
204 'id' => $this->_ufGroupId
,
206 'add_contact_to_group' => 2,
207 'cancel_URL' => 'http://example.org/cancel',
208 'created_date' => '2009-06-27',
211 'group_type' => 'Individual,Contact',
212 'help_post' => 'help post',
213 'help_pre' => 'help pre',
220 'is_update_dupe' => 1,
221 'name' => 'test_group',
222 'notify' => 'admin@example.org',
223 'post_URL' => 'http://example.org/post',
224 'title' => 'Test Group',
225 'version' => $this->_apiversion
,
227 $result = civicrm_api('uf_group', 'create', $params);
228 unset($params['version']);
229 $params['created_date'] = date('YmdHis', strtotime($params['created_date']));
230 foreach ($params as $key => $value) {
231 if ($key == 'add_contact_to_group' or $key == 'group') {
234 $this->assertEquals($result['values'][$result['id']][$key], $params[$key], $key . " doesn't match " . $value);
237 $this->assertEquals($result['values'][$this->_ufGroupId
]['add_to_group_id'], $params['add_contact_to_group'], 'in line ' . __LINE__
);
238 $this->assertEquals($result['values'][$result['id']]['limit_listings_group_id'], $params['group'], 'in line ' . __LINE__
);
241 function testUFGroupGet() {
243 $result = civicrm_api('uf_group', 'create', $this->params
);
244 $this->assertEquals(0, $result['is_error'], 'in line ' . __LINE__
);
246 $params = array('version' => 3, 'id' => $result['id']);
247 $result = civicrm_api('uf_group', 'get', $params);
248 $this->assertEquals(0, $result['is_error'], 'in line ' . __LINE__
);
249 $this->documentMe($this->params
, $result, __FUNCTION__
, __FILE__
);
250 $this->assertEquals($result['values'][$result['id']]['add_to_group_id'], $this->params
['add_contact_to_group'], 'in line ' . __LINE__
);
251 $this->assertEquals($result['values'][$result['id']]['limit_listings_group_id'], $this->params
['group'], 'in line ' . __LINE__
);
252 foreach ($this->params
as $key => $value) {
253 // skip created date because it doesn't seem to be working properly & fixing date handling is for another day
254 if ($key == 'add_contact_to_group' or $key == 'group' or $key == 'version' or $key == 'created_date') {
257 $expected = $this->params
[$key];
258 $received = $result['values'][$result['id']][$key];
259 // group names are renamed to name_id by BAO
260 if ($key == 'name') {
261 $expected = $this->params
[$key] . '_' . $result['id'];
263 $this->assertEquals($expected, $received, "The string '$received' does not equal '$expected' for key '$key' in line " . __LINE__
);
267 function testUFGroupUpdateWithEmptyParams() {
268 $result = civicrm_api('uf_group', 'create', array(), $this->_ufGroupId
);
269 $this->assertAPIFailure($result);
272 function testUFGroupUpdateWithWrongParams() {
273 $result = civicrm_api('uf_group', 'create', 'a string', $this->_ufGroupId
);
274 $this->assertAPIFailure($result);
275 $result = civicrm_api('uf_group', 'create', array('title' => 'Title'), 'a string');
276 $this->assertAPIFailure($result);
279 function testUFGroupDelete() {
281 $ufGroup = civicrm_api('uf_group', 'create', $this->params
);
282 $this->assertAPISuccess($ufGroup);
283 $params = array('version' => $this->_apiversion
, 'id' => $ufGroup['id']);
284 $this->assertEquals(1, civicrm_api('uf_group', 'getcount', $params), "in line " . __LINE__
);
285 $result = civicrm_api('uf_group', 'delete', $params, "in line " . __LINE__
);
286 $this->documentMe($this->params
, $result, __FUNCTION__
, __FILE__
);
287 $this->assertEquals(0, civicrm_api('uf_group', 'getcount', $params), "in line " . __LINE__
);
288 $this->assertAPISuccess($result, "in line " . __LINE__
);