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_UFJoinTest
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 public $_eNoticeCompliant = TRUE;
47 protected function setUp() {
49 // Truncate the tables
59 $this->_apiversion
= 3;
60 $op = new PHPUnit_Extensions_Database_Operation_Insert
;
63 new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__
) . '/dataset/uf_group_test.xml')
66 // FIXME: something NULLs $GLOBALS['_HTML_QuickForm_registered_rules'] when the tests are ran all together
67 $GLOBALS['_HTML_QuickForm_registered_rules'] = array(
68 'required' => array('html_quickform_rule_required', 'HTML/QuickForm/Rule/Required.php'),
69 'maxlength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'),
70 'minlength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'),
71 'rangelength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'),
72 'email' => array('html_quickform_rule_email', 'HTML/QuickForm/Rule/Email.php'),
73 'regex' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
74 'lettersonly' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
75 'alphanumeric' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
76 'numeric' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
77 'nopunctuation' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
78 'nonzero' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
79 'callback' => array('html_quickform_rule_callback', 'HTML/QuickForm/Rule/Callback.php'),
80 'compare' => array('html_quickform_rule_compare', 'HTML/QuickForm/Rule/Compare.php'),
82 // FIXME: …ditto for $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES']
83 $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'] = array(
84 'group' => array('HTML/QuickForm/group.php', 'HTML_QuickForm_group'),
85 'hidden' => array('HTML/QuickForm/hidden.php', 'HTML_QuickForm_hidden'),
86 'reset' => array('HTML/QuickForm/reset.php', 'HTML_QuickForm_reset'),
87 'checkbox' => array('HTML/QuickForm/checkbox.php', 'HTML_QuickForm_checkbox'),
88 'file' => array('HTML/QuickForm/file.php', 'HTML_QuickForm_file'),
89 'image' => array('HTML/QuickForm/image.php', 'HTML_QuickForm_image'),
90 'password' => array('HTML/QuickForm/password.php', 'HTML_QuickForm_password'),
91 'radio' => array('HTML/QuickForm/radio.php', 'HTML_QuickForm_radio'),
92 'button' => array('HTML/QuickForm/button.php', 'HTML_QuickForm_button'),
93 'submit' => array('HTML/QuickForm/submit.php', 'HTML_QuickForm_submit'),
94 'select' => array('HTML/QuickForm/select.php', 'HTML_QuickForm_select'),
95 'hiddenselect' => array('HTML/QuickForm/hiddenselect.php', 'HTML_QuickForm_hiddenselect'),
96 'text' => array('HTML/QuickForm/text.php', 'HTML_QuickForm_text'),
97 'textarea' => array('HTML/QuickForm/textarea.php', 'HTML_QuickForm_textarea'),
98 'fckeditor' => array('HTML/QuickForm/fckeditor.php', 'HTML_QuickForm_FCKEditor'),
99 'tinymce' => array('HTML/QuickForm/tinymce.php', 'HTML_QuickForm_TinyMCE'),
100 'dojoeditor' => array('HTML/QuickForm/dojoeditor.php', 'HTML_QuickForm_dojoeditor'),
101 'link' => array('HTML/QuickForm/link.php', 'HTML_QuickForm_link'),
102 'advcheckbox' => array('HTML/QuickForm/advcheckbox.php', 'HTML_QuickForm_advcheckbox'),
103 'date' => array('HTML/QuickForm/date.php', 'HTML_QuickForm_date'),
104 'static' => array('HTML/QuickForm/static.php', 'HTML_QuickForm_static'),
105 'header' => array('HTML/QuickForm/header.php', 'HTML_QuickForm_header'),
106 'html' => array('HTML/QuickForm/html.php', 'HTML_QuickForm_html'),
107 'hierselect' => array('HTML/QuickForm/hierselect.php', 'HTML_QuickForm_hierselect'),
108 'autocomplete' => array('HTML/QuickForm/autocomplete.php', 'HTML_QuickForm_autocomplete'),
109 'xbutton' => array('HTML/QuickForm/xbutton.php', 'HTML_QuickForm_xbutton'),
110 'advmultiselect' => array('HTML/QuickForm/advmultiselect.php', 'HTML_QuickForm_advmultiselect'),
114 function tearDown() {
115 // Truncate the tables
128 * find uf join group id
130 public function testFindUFGroupId() {
132 'module' => 'CiviContribute',
133 'entity_table' => 'civicrm_contribution_page',
136 'uf_group_id' => $this->_ufGroupId
,
138 'version' => $this->_apiversion
,
140 $ufJoin = civicrm_api('uf_join', 'create', $params);
142 $searchParams = array(
143 'entity_table' => 'civicrm_contribution_page',
145 'version' => $this->_apiversion
,
147 $result = civicrm_api('uf_join', 'get', $searchParams);
149 foreach ($result['values'] as $key => $value) {
150 $this->assertEquals($value['uf_group_id'], $this->_ufGroupId
, 'In line ' . __LINE__
);
155 public function testUFJoinEditWrongParamsType() {
156 $params = 'a string';
157 $result = civicrm_api('uf_join', 'create', $params);
159 $this->assertAPIFailure($result, 'In line ' . __LINE__
);
160 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__
);
163 public function testUFJoinEditEmptyParams() {
165 $result = civicrm_api('uf_join', 'create', $params);
167 $this->assertAPIFailure($result, 'In line ' . __LINE__
);
168 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, module, weight, uf_group_id', 'In line ' . __LINE__
);
171 public function testUFJoinEditWithoutUFGroupId() {
173 'module' => 'CiviContribute',
174 'entity_table' => 'civicrm_contribution_page',
178 'version' => $this->_apiversion
,
180 $result = civicrm_api('uf_join', 'create', $params);
181 $this->assertAPIFailure($result, 'In line ' . __LINE__
);
182 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: uf_group_id', 'In line ' . __LINE__
);
186 * create/update uf join
188 public function testCreateUFJoin() {
190 'module' => 'CiviContribute',
191 'entity_table' => 'civicrm_contribution_page',
194 'uf_group_id' => $this->_ufGroupId
,
196 'version' => $this->_apiversion
,
199 $ufJoin = civicrm_api('uf_join', 'create', $params);
200 $this->documentMe($params, $ufJoin, __FUNCTION__
, __FILE__
);
201 $this->assertEquals($ufJoin['values'][0]['module'], $params['module'], 'In line ' . __LINE__
);
202 $this->assertEquals($ufJoin['values'][0]['uf_group_id'], $params['uf_group_id'], 'In line ' . __LINE__
);
203 $this->assertEquals($ufJoin['values'][0]['is_active'], $params['is_active'], 'In line ' . __LINE__
);
206 'id' => $ufJoin['id'],
207 'module' => 'CiviContribute',
208 'entity_table' => 'civicrm_contribution_page',
211 'uf_group_id' => $this->_ufGroupId
,
213 'version' => $this->_apiversion
,
216 $ufJoinUpdated = civicrm_api('uf_join', 'create', $params);
217 $this->assertEquals($ufJoinUpdated['values'][0]['module'], $params['module'], 'In line ' . __LINE__
);
218 $this->assertEquals($ufJoinUpdated['values'][0]['uf_group_id'], $params['uf_group_id'], 'In line ' . __LINE__
);
219 $this->assertEquals($ufJoinUpdated['values'][0]['is_active'], $params['is_active'], 'In line ' . __LINE__
);
223 public function testFindUFJoinWrongParamsType() {
224 $params = 'a string';
225 $result = civicrm_api('uf_join', 'create', $params);
227 $this->assertAPIFailure($result);
228 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__
);
231 public function testFindUFJoinEmptyParams() {
233 $result = civicrm_api('uf_join', 'create', $params);
235 $this->assertAPIFailure($result, 'In line ' . __LINE__
);
236 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, module, weight, uf_group_id', 'In line ' . __LINE__
);
239 public function testFindUFJoinWithoutUFGroupId() {
241 'module' => 'CiviContribute',
242 'entity_table' => 'civicrm_contribution_page',
246 'version' => $this->_apiversion
,
248 $result = civicrm_api('uf_join', 'create', $params);
250 $this->assertAPIFailure($result);
251 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: uf_group_id', 'In line ' . __LINE__
);
257 public function testGetUFJoinId() {
259 'module' => 'CiviContribute',
260 'entity_table' => 'civicrm_contribution_page',
263 'uf_group_id' => $this->_ufGroupId
,
265 'version' => $this->_apiversion
,
268 $ufJoin = civicrm_api('uf_join', 'create', $params);
269 $searchParams = array(
270 'entity_table' => 'civicrm_contribution_page',
272 'version' => $this->_apiversion
,
276 $result = civicrm_api('uf_join', 'get', $searchParams);
277 $this->documentMe($searchParams, $result, __FUNCTION__
, __FILE__
);
278 $this->assertEquals($result['values'][0]['module'], $params['module'], 'In line ' . __LINE__
);
279 $this->assertEquals($result['values'][0]['uf_group_id'], $params['uf_group_id'], 'In line ' . __LINE__
);
280 $this->assertEquals($result['values'][0]['entity_id'], $params['entity_id'], 'In line ' . __LINE__
);
284 * Test civicrm_activity_create() using example code
286 function testUFJoinCreateExample() {
287 require_once 'api/v3/examples/UFJoinCreate.php';
288 $result = UF_join_create_example();
289 $expectedResult = UF_join_create_expectedresult();
290 $this->assertEquals($result, $expectedResult);