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;
48 protected function setUp() {
50 $this->_apiversion
= 3;
51 // Truncate the tables
62 $op = new PHPUnit_Extensions_Database_Operation_Insert
;
65 new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__
) . '/dataset/uf_group_test.xml')
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'),
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'),
114 $this->params
= array(
116 'add_contact_to_group' => 2,
117 'cancel_URL' => 'http://example.org/cancel',
118 'created_date' => '2009-06-27 00:00:00',
121 'group_type' => 'Individual,Contact',
122 'help_post' => 'help post',
123 'help_pre' => 'help pre',
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
,
139 function tearDown() {
141 // Truncate the tables
156 public function testUpdateUFGroup() {
158 'title' => 'Edited Test Profile',
159 'help_post' => 'Profile Pro help text.',
161 'id' => $this->_ufGroupId
,
162 'version' => $this->_apiversion
,
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);
172 function testUFGroupCreate() {
174 $result = civicrm_api('uf_group', 'create', $this->params
);
175 $this->documentMe($this->params
, $result, __FUNCTION__
, __FILE__
);
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') {
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'];
190 $this->assertEquals($expected, $received, "The string '$received' does not equal '$expected' for key '$key' in line " . __LINE__
);
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);
201 function testUFGroupUpdate() {
203 'id' => $this->_ufGroupId
,
205 'add_contact_to_group' => 2,
206 'cancel_URL' => 'http://example.org/cancel',
207 'created_date' => '2009-06-27',
210 'group_type' => 'Individual,Contact',
211 'help_post' => 'help post',
212 'help_pre' => 'help pre',
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
,
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') {
233 $this->assertEquals($result['values'][$result['id']][$key], $params[$key], $key . " doesn't match " . $value);
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__
);
240 function testUFGroupGet() {
242 $result = civicrm_api('uf_group', 'create', $this->params
);
243 $this->assertEquals(0, $result['is_error'], 'in line ' . __LINE__
);
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') {
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'];
262 $this->assertEquals($expected, $received, "The string '$received' does not equal '$expected' for key '$key' in line " . __LINE__
);
266 function testUFGroupUpdateWithEmptyParams() {
267 $result = civicrm_api('uf_group', 'create', array(), $this->_ufGroupId
);
268 $this->assertEquals($result['is_error'], 1);
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);
278 function testUFGroupDelete() {
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__
);