CRM-12133 - api/v3/ReportTemplate - Fix option_group_id and component_id errors
[civicrm-core.git] / tests / phpunit / api / v3 / UFJoinTest.php
1 <?php
2 // $Id$
3
4 /*
5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
11 | |
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. |
15 | |
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. |
20 | |
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 +--------------------------------------------------------------------+
28 */
29
30
31
32
33 require_once 'CiviTest/CiviUnitTestCase.php';
34
35 /**
36 * Test class for UFGroup API - civicrm_uf_*
37 * @todo Split UFGroup and UFJoin tests
38 *
39 * @package CiviCRM
40 */
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() {
49 parent::setUp();
50 // Truncate the tables
51 $this->quickCleanup(
52 array(
53 'civicrm_group',
54 'civicrm_contact',
55 'civicrm_uf_group',
56 'civicrm_uf_join',
57 'civicrm_uf_match',
58 )
59 );
60 $this->_apiversion = 3;
61 $op = new PHPUnit_Extensions_Database_Operation_Insert;
62 $op->execute(
63 $this->_dbconn,
64 new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml')
65 );
66
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'),
82 );
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'),
112 );
113 }
114
115 function tearDown() {
116 // Truncate the tables
117 $this->quickCleanup(
118 array(
119 'civicrm_group',
120 'civicrm_contact',
121 'civicrm_uf_group',
122 'civicrm_uf_join',
123 'civicrm_uf_match',
124 )
125 );
126 }
127
128 /**
129 * find uf join group id
130 */
131 public function testFindUFGroupId() {
132 $params = array(
133 'module' => 'CiviContribute',
134 'entity_table' => 'civicrm_contribution_page',
135 'entity_id' => 1,
136 'weight' => 1,
137 'uf_group_id' => $this->_ufGroupId,
138 'is_active' => 1,
139 'version' => $this->_apiversion,
140 );
141 $ufJoin = civicrm_api('uf_join', 'create', $params);
142
143 $searchParams = array(
144 'entity_table' => 'civicrm_contribution_page',
145 'entity_id' => 1,
146 'version' => $this->_apiversion,
147 );
148 $result = civicrm_api('uf_join', 'get', $searchParams);
149
150 foreach ($result['values'] as $key => $value) {
151 $this->assertEquals($value['uf_group_id'], $this->_ufGroupId, 'In line ' . __LINE__);
152 }
153 }
154
155
156 public function testUFJoinEditWrongParamsType() {
157 $params = 'a string';
158 $result = civicrm_api('uf_join', 'create', $params);
159
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__);
162 }
163
164 public function testUFJoinEditEmptyParams() {
165 $params = array();
166 $result = civicrm_api('uf_join', 'create', $params);
167
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__);
170 }
171
172 public function testUFJoinEditWithoutUFGroupId() {
173 $params = array(
174 'module' => 'CiviContribute',
175 'entity_table' => 'civicrm_contribution_page',
176 'entity_id' => 1,
177 'weight' => 1,
178 'is_active' => 1,
179 'version' => $this->_apiversion,
180 );
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__);
184 }
185
186 /**
187 * create/update uf join
188 */
189 public function testCreateUFJoin() {
190 $params = array(
191 'module' => 'CiviContribute',
192 'entity_table' => 'civicrm_contribution_page',
193 'entity_id' => 1,
194 'weight' => 1,
195 'uf_group_id' => $this->_ufGroupId,
196 'is_active' => 1,
197 'version' => $this->_apiversion,
198 'sequential' => 1,
199 );
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__);
205
206 $params = array(
207 'id' => $ufJoin['id'],
208 'module' => 'CiviContribute',
209 'entity_table' => 'civicrm_contribution_page',
210 'entity_id' => 1,
211 'weight' => 1,
212 'uf_group_id' => $this->_ufGroupId,
213 'is_active' => 0,
214 'version' => $this->_apiversion,
215 'sequential' => 1,
216 );
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__);
221 }
222
223
224 public function testFindUFJoinWrongParamsType() {
225 $params = 'a string';
226 $result = civicrm_api('uf_join', 'create', $params);
227
228 $this->assertEquals($result['is_error'], 1);
229 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__);
230 }
231
232 public function testFindUFJoinEmptyParams() {
233 $params = array();
234 $result = civicrm_api('uf_join', 'create', $params);
235
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__);
238 }
239
240 public function testFindUFJoinWithoutUFGroupId() {
241 $params = array(
242 'module' => 'CiviContribute',
243 'entity_table' => 'civicrm_contribution_page',
244 'entity_id' => 1,
245 'weight' => 1,
246 'is_active' => 1,
247 'version' => $this->_apiversion,
248 );
249 $result = civicrm_api('uf_join', 'create', $params);
250
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__);
253 }
254
255 /**
256 * find uf join id
257 */
258 public function testGetUFJoinId() {
259 $params = array(
260 'module' => 'CiviContribute',
261 'entity_table' => 'civicrm_contribution_page',
262 'entity_id' => 1,
263 'weight' => 1,
264 'uf_group_id' => $this->_ufGroupId,
265 'is_active' => 1,
266 'version' => $this->_apiversion,
267 );
268
269 $ufJoin = civicrm_api('uf_join', 'create', $params);
270 $searchParams = array(
271 'entity_table' => 'civicrm_contribution_page',
272 'entity_id' => 1,
273 'version' => $this->_apiversion,
274 'sequential' => 1,
275 );
276
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__);
282 }
283
284 /**
285 * Test civicrm_activity_create() using example code
286 */
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);
292 }
293 }
294