3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
32 * Test APIv3 civicrm_custom_group* functions
34 * @package CiviCRM_APIv3
35 * @subpackage API_CustomGroup
38 class api_v3_CustomGroupTest
extends CiviUnitTestCase
{
39 protected $_apiversion = 3;
43 public $DBResetRequired = TRUE;
47 'name' => 'Custom Group Create',
48 'description' => 'Test all Custom Group Create API methods.',
49 'group' => 'CiviCRM API Tests',
54 $this->_entity
= 'CustomGroup';
55 $this->_params
= array(
56 'title' => 'Test_Group_1',
57 'name' => 'test_group_1',
58 'extends' => 'Individual',
60 'collapse_display' => 1,
62 'help_pre' => 'This is Pre Help For Test Group 1',
63 'help_post' => 'This is Post Help For Test Group 1',
70 $tablesToTruncate = array('civicrm_custom_group', 'civicrm_custom_field');
71 // true tells quickCleanup to drop any tables that might have been created in the test
72 $this->quickCleanup($tablesToTruncate, TRUE);
75 ///////////////// civicrm_custom_group_create methods
78 * check with empty array
79 * note that these tests are of marginal value so should not be included in copy & paste
80 * code. The SyntaxConformance is capable of testing this for all entities on create
81 * & delete (& it would be easy to add if not there)
83 function testCustomGroupCreateNoParam() {
84 $customGroup = $this->callAPIFailure('custom_group', 'create', array(),
85 'Mandatory key(s) missing from params array: title, extends'
90 * check with empty array
92 function testCustomGroupCreateNoExtends() {
95 'title' => 'Test_Group_1',
96 'name' => 'test_group_1',
98 'collapse_display' => 1,
100 'help_pre' => 'This is Pre Help For Test Group 1',
101 'help_post' => 'This is Post Help For Test Group 1',
105 $customGroup = $this->callAPIFailure('custom_group', 'create', $params);
106 $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: extends', 'In line ' . __LINE__
);
107 $this->assertAPIFailure($customGroup, 'In line ' . __LINE__
);
111 * check with empty array
113 function testCustomGroupCreateInvalidExtends() {
116 'title' => 'Test_Group_1',
117 'name' => 'test_group_1',
119 'collapse_display' => 1,
121 'help_pre' => 'This is Pre Help For Test Group 1',
122 'help_post' => 'This is Post Help For Test Group 1',
124 'extends' => array(),
127 $customGroup = $this->callAPIFailure('custom_group', 'create', $params);
128 $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: extends', 'In line ' . __LINE__
);
132 * check with a string instead of array for extends
134 function testCustomGroupCreateExtendsString() {
137 'title' => 'Test_Group_1',
138 'name' => 'test_group_1',
140 'collapse_display' => 1,
142 'help_pre' => 'This is Pre Help For Test Group 1',
143 'help_post' => 'This is Post Help For Test Group 1',
145 'extends' => 'Individual',
148 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
152 * check with valid array
154 function testCustomGroupCreate() {
156 'title' => 'Test_Group_1',
157 'name' => 'test_group_1',
158 'extends' => array('Individual'),
160 'collapse_display' => 1,
162 'help_pre' => 'This is Pre Help For Test Group 1',
163 'help_post' => 'This is Post Help For Test Group 1',
167 $result = $this->callAPIAndDocument('custom_group', 'create', $params, __FUNCTION__
, __FILE__
);
168 $this->assertNotNull($result['id'], 'In line ' . __LINE__
);
169 $this->assertEquals($result['values'][$result['id']]['extends'], 'Individual', 'In line ' . __LINE__
);
173 * check with valid array
175 function testCustomGroupGetFields() {
177 'options' => array('get_options' => 'style'),
180 $result = $this->callAPISuccess('custom_group', 'getfields', $params);
183 'Inline' => 'Inline',
184 'Tab with table' => 'Tab with table',
186 $this->assertEquals($expected, $result['values']['style']['options']);
190 * check with extends array length greater than 1
192 function testCustomGroupExtendsMultipleCreate() {
194 'title' => 'Test_Group_1',
195 'name' => 'test_group_1',
196 'extends' => array('Individual', 'Household'),
198 'collapse_display' => 1,
200 'help_pre' => 'This is Pre Help For Test Group 1',
201 'help_post' => 'This is Post Help For Test Group 1',
205 $result = $this->callAPIFailure('custom_group', 'create', $params,
206 'implode(): Invalid arguments passed');
210 * check with style missing from params array
212 function testCustomGroupCreateNoStyle() {
214 'title' => 'Test_Group_1',
215 'name' => 'test_group_1',
216 'extends' => array('Individual'),
218 'collapse_display' => 1,
219 'help_pre' => 'This is Pre Help For Test Group 1',
220 'help_post' => 'This is Post Help For Test Group 1',
224 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
225 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
226 $this->assertEquals($customGroup['values'][$customGroup['id']]['style'], 'Inline', 'In line ' . __LINE__
);
230 * check with not array
232 function testCustomGroupCreateNotArray() {
234 $customGroup = $this->callAPIFailure('custom_group', 'create', $params);
235 $this->assertEquals($customGroup['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__
);
239 * check without title
241 function testCustomGroupCreateNoTitle() {
242 $params = array('extends' => array('Contact'),
244 'collapse_display' => 1,
246 'help_pre' => 'This is Pre Help For Test Group 2',
247 'help_post' => 'This is Post Help For Test Group 2',
250 $customGroup = $this->callAPIFailure('custom_group', 'create', $params,
251 'Mandatory key(s) missing from params array: title');
255 * check for household without weight
257 function testCustomGroupCreateHouseholdNoWeight() {
259 'title' => 'Test_Group_3',
260 'name' => 'test_group_3',
261 'extends' => array('Household'),
262 'collapse_display' => 1,
264 'help_pre' => 'This is Pre Help For Test Group 3',
265 'help_post' => 'This is Post Help For Test Group 3',
269 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
270 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
271 $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Household', 'In line ' . __LINE__
);
272 $this->assertEquals($customGroup['values'][$customGroup['id']]['style'], 'Tab', 'In line ' . __LINE__
);
276 * check for Contribution Donation
278 function testCustomGroupCreateContributionDonation() {
280 'title' => 'Test_Group_6',
281 'name' => 'test_group_6',
282 'extends' => array('Contribution', array(1)),
284 'collapse_display' => 1,
286 'help_pre' => 'This is Pre Help For Test Group 6',
287 'help_post' => 'This is Post Help For Test Group 6',
291 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
292 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
293 $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Contribution', 'In line ' . __LINE__
);
297 * check with valid array
299 function testCustomGroupCreateGroup() {
302 'title' => 'Test_Group_8',
303 'name' => 'test_group_8',
304 'extends' => array('Group'),
306 'collapse_display' => 1,
309 'help_pre' => 'This is Pre Help For Test Group 8',
310 'help_post' => 'This is Post Help For Test Group 8',
313 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
314 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
315 $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Group', 'In line ' . __LINE__
);
319 * check with Activity - Meeting Type
321 function testCustomGroupCreateActivityMeeting() {
323 'title' => 'Test_Group_10',
324 'name' => 'test_group_10',
325 'extends' => array('Activity', array(1)),
327 'collapse_display' => 1,
329 'help_pre' => 'This is Pre Help For Test Group 10',
330 'help_post' => 'This is Post Help For Test Group 10',
333 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
334 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
335 $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Activity', 'In line ' . __LINE__
);
338 ///////////////// civicrm_custom_group_delete methods
341 * check without GroupID
343 function testCustomGroupDeleteWithoutGroupID() {
344 $customGroup = $this->callAPIFailure('custom_group', 'delete', array());
345 $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: id', 'In line ' . __LINE__
);
349 * check with no array
351 function testCustomGroupDeleteNoArray() {
353 $customGroup = $this->callAPIFailure('custom_group', 'delete', $params);
354 $this->assertEquals($customGroup['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__
);
358 * check with valid custom group id
360 function testCustomGroupDelete() {
361 $customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'test_group'));
363 'id' => $customGroup['id'],
365 $result = $this->callAPIAndDocument('custom_group', 'delete', $params, __FUNCTION__
, __FILE__
);
366 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
369 * main success get function
374 public function testGetCustomGroupSuccess() {
376 $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
378 $result = $this->callAPIAndDocument($this->_entity
, 'get', $params, __FUNCTION__
, __FILE__
);
379 $values = $result['values'][$result['id']];
380 foreach ($this->_params
as $key => $value) {
381 if ($key == 'weight') {
384 $this->assertEquals($value, $values[$key], $key . " doesn't match " . print_r($values, TRUE) . 'in line' . __LINE__
);