5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
33 require_once 'CiviTest/CiviUnitTestCase.php';
36 * Test class for UFGroup API - civicrm_uf_*
37 * @todo Split UFGroup and UFJoin tests
41 class api_v3_UFJoinTest
extends CiviUnitTestCase
{
42 // ids from the uf_group_test.xml fixture
43 protected $_ufGroupId = 11;
44 protected $_ufFieldId;
45 protected $_contactId = 69;
46 protected $_apiversion;
47 public $_eNoticeCompliant = TRUE;
48 protected function setUp() {
50 // Truncate the tables
60 $this->_apiversion
= 3;
61 $op = new PHPUnit_Extensions_Database_Operation_Insert
;
64 new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__
) . '/dataset/uf_group_test.xml')
67 // FIXME: something NULLs $GLOBALS['_HTML_QuickForm_registered_rules'] when the tests are ran all together
68 $GLOBALS['_HTML_QuickForm_registered_rules'] = array(
69 'required' => array('html_quickform_rule_required', 'HTML/QuickForm/Rule/Required.php'),
70 'maxlength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'),
71 'minlength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'),
72 'rangelength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'),
73 'email' => array('html_quickform_rule_email', 'HTML/QuickForm/Rule/Email.php'),
74 'regex' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
75 'lettersonly' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
76 'alphanumeric' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
77 'numeric' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
78 'nopunctuation' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
79 'nonzero' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
80 'callback' => array('html_quickform_rule_callback', 'HTML/QuickForm/Rule/Callback.php'),
81 'compare' => array('html_quickform_rule_compare', 'HTML/QuickForm/Rule/Compare.php'),
83 // FIXME: …ditto for $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES']
84 $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'] = array(
85 'group' => array('HTML/QuickForm/group.php', 'HTML_QuickForm_group'),
86 'hidden' => array('HTML/QuickForm/hidden.php', 'HTML_QuickForm_hidden'),
87 'reset' => array('HTML/QuickForm/reset.php', 'HTML_QuickForm_reset'),
88 'checkbox' => array('HTML/QuickForm/checkbox.php', 'HTML_QuickForm_checkbox'),
89 'file' => array('HTML/QuickForm/file.php', 'HTML_QuickForm_file'),
90 'image' => array('HTML/QuickForm/image.php', 'HTML_QuickForm_image'),
91 'password' => array('HTML/QuickForm/password.php', 'HTML_QuickForm_password'),
92 'radio' => array('HTML/QuickForm/radio.php', 'HTML_QuickForm_radio'),
93 'button' => array('HTML/QuickForm/button.php', 'HTML_QuickForm_button'),
94 'submit' => array('HTML/QuickForm/submit.php', 'HTML_QuickForm_submit'),
95 'select' => array('HTML/QuickForm/select.php', 'HTML_QuickForm_select'),
96 'hiddenselect' => array('HTML/QuickForm/hiddenselect.php', 'HTML_QuickForm_hiddenselect'),
97 'text' => array('HTML/QuickForm/text.php', 'HTML_QuickForm_text'),
98 'textarea' => array('HTML/QuickForm/textarea.php', 'HTML_QuickForm_textarea'),
99 'fckeditor' => array('HTML/QuickForm/fckeditor.php', 'HTML_QuickForm_FCKEditor'),
100 'tinymce' => array('HTML/QuickForm/tinymce.php', 'HTML_QuickForm_TinyMCE'),
101 'dojoeditor' => array('HTML/QuickForm/dojoeditor.php', 'HTML_QuickForm_dojoeditor'),
102 'link' => array('HTML/QuickForm/link.php', 'HTML_QuickForm_link'),
103 'advcheckbox' => array('HTML/QuickForm/advcheckbox.php', 'HTML_QuickForm_advcheckbox'),
104 'date' => array('HTML/QuickForm/date.php', 'HTML_QuickForm_date'),
105 'static' => array('HTML/QuickForm/static.php', 'HTML_QuickForm_static'),
106 'header' => array('HTML/QuickForm/header.php', 'HTML_QuickForm_header'),
107 'html' => array('HTML/QuickForm/html.php', 'HTML_QuickForm_html'),
108 'hierselect' => array('HTML/QuickForm/hierselect.php', 'HTML_QuickForm_hierselect'),
109 'autocomplete' => array('HTML/QuickForm/autocomplete.php', 'HTML_QuickForm_autocomplete'),
110 'xbutton' => array('HTML/QuickForm/xbutton.php', 'HTML_QuickForm_xbutton'),
111 'advmultiselect' => array('HTML/QuickForm/advmultiselect.php', 'HTML_QuickForm_advmultiselect'),
115 function tearDown() {
116 // Truncate the tables
129 * find uf join group id
131 public function testFindUFGroupId() {
133 'module' => 'CiviContribute',
134 'entity_table' => 'civicrm_contribution_page',
137 'uf_group_id' => $this->_ufGroupId
,
139 'version' => $this->_apiversion
,
141 $ufJoin = civicrm_api('uf_join', 'create', $params);
143 $searchParams = array(
144 'entity_table' => 'civicrm_contribution_page',
146 'version' => $this->_apiversion
,
148 $result = civicrm_api('uf_join', 'get', $searchParams);
150 foreach ($result['values'] as $key => $value) {
151 $this->assertEquals($value['uf_group_id'], $this->_ufGroupId
, 'In line ' . __LINE__
);
156 public function testUFJoinEditWrongParamsType() {
157 $params = 'a string';
158 $result = civicrm_api('uf_join', 'create', $params);
160 $this->assertEquals($result['is_error'], 1, 'In line ' . __LINE__
);
161 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__
);
164 public function testUFJoinEditEmptyParams() {
166 $result = civicrm_api('uf_join', 'create', $params);
168 $this->assertEquals($result['is_error'], 1, 'In line ' . __LINE__
);
169 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, module, weight, uf_group_id', 'In line ' . __LINE__
);
172 public function testUFJoinEditWithoutUFGroupId() {
174 'module' => 'CiviContribute',
175 'entity_table' => 'civicrm_contribution_page',
179 'version' => $this->_apiversion
,
181 $result = civicrm_api('uf_join', 'create', $params);
182 $this->assertEquals($result['is_error'], 1, 'In line ' . __LINE__
);
183 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: uf_group_id', 'In line ' . __LINE__
);
187 * create/update uf join
189 public function testCreateUFJoin() {
191 'module' => 'CiviContribute',
192 'entity_table' => 'civicrm_contribution_page',
195 'uf_group_id' => $this->_ufGroupId
,
197 'version' => $this->_apiversion
,
200 $ufJoin = civicrm_api('uf_join', 'create', $params);
201 $this->documentMe($params, $ufJoin, __FUNCTION__
, __FILE__
);
202 $this->assertEquals($ufJoin['values'][0]['module'], $params['module'], 'In line ' . __LINE__
);
203 $this->assertEquals($ufJoin['values'][0]['uf_group_id'], $params['uf_group_id'], 'In line ' . __LINE__
);
204 $this->assertEquals($ufJoin['values'][0]['is_active'], $params['is_active'], 'In line ' . __LINE__
);
207 'id' => $ufJoin['id'],
208 'module' => 'CiviContribute',
209 'entity_table' => 'civicrm_contribution_page',
212 'uf_group_id' => $this->_ufGroupId
,
214 'version' => $this->_apiversion
,
217 $ufJoinUpdated = civicrm_api('uf_join', 'create', $params);
218 $this->assertEquals($ufJoinUpdated['values'][0]['module'], $params['module'], 'In line ' . __LINE__
);
219 $this->assertEquals($ufJoinUpdated['values'][0]['uf_group_id'], $params['uf_group_id'], 'In line ' . __LINE__
);
220 $this->assertEquals($ufJoinUpdated['values'][0]['is_active'], $params['is_active'], 'In line ' . __LINE__
);
224 public function testFindUFJoinWrongParamsType() {
225 $params = 'a string';
226 $result = civicrm_api('uf_join', 'create', $params);
228 $this->assertEquals($result['is_error'], 1);
229 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__
);
232 public function testFindUFJoinEmptyParams() {
234 $result = civicrm_api('uf_join', 'create', $params);
236 $this->assertEquals($result['is_error'], 1, 'In line ' . __LINE__
);
237 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, module, weight, uf_group_id', 'In line ' . __LINE__
);
240 public function testFindUFJoinWithoutUFGroupId() {
242 'module' => 'CiviContribute',
243 'entity_table' => 'civicrm_contribution_page',
247 'version' => $this->_apiversion
,
249 $result = civicrm_api('uf_join', 'create', $params);
251 $this->assertEquals($result['is_error'], 1);
252 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: uf_group_id', 'In line ' . __LINE__
);
258 public function testGetUFJoinId() {
260 'module' => 'CiviContribute',
261 'entity_table' => 'civicrm_contribution_page',
264 'uf_group_id' => $this->_ufGroupId
,
266 'version' => $this->_apiversion
,
269 $ufJoin = civicrm_api('uf_join', 'create', $params);
270 $searchParams = array(
271 'entity_table' => 'civicrm_contribution_page',
273 'version' => $this->_apiversion
,
277 $result = civicrm_api('uf_join', 'get', $searchParams);
278 $this->documentMe($searchParams, $result, __FUNCTION__
, __FILE__
);
279 $this->assertEquals($result['values'][0]['module'], $params['module'], 'In line ' . __LINE__
);
280 $this->assertEquals($result['values'][0]['uf_group_id'], $params['uf_group_id'], 'In line ' . __LINE__
);
281 $this->assertEquals($result['values'][0]['entity_id'], $params['entity_id'], 'In line ' . __LINE__
);
285 * Test civicrm_activity_create() using example code
287 function testUFJoinCreateExample() {
288 require_once 'api/v3/examples/UFJoinCreate.php';
289 $result = UF_join_create_example();
290 $expectedResult = UF_join_create_expectedresult();
291 $this->assertEquals($result, $expectedResult);