3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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;
42 public $_eNoticeCompliant = TRUE;
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',
185 $this->assertEquals($expected, $result['values']['style']['options']);
189 * check with extends array length greater than 1
191 function testCustomGroupExtendsMultipleCreate() {
193 'title' => 'Test_Group_1',
194 'name' => 'test_group_1',
195 'extends' => array('Individual', 'Household'),
197 'collapse_display' => 1,
199 'help_pre' => 'This is Pre Help For Test Group 1',
200 'help_post' => 'This is Post Help For Test Group 1',
204 $result = $this->callAPIFailure('custom_group', 'create', $params,
205 'implode(): Invalid arguments passed');
209 * check with style missing from params array
211 function testCustomGroupCreateNoStyle() {
213 'title' => 'Test_Group_1',
214 'name' => 'test_group_1',
215 'extends' => array('Individual'),
217 'collapse_display' => 1,
218 'help_pre' => 'This is Pre Help For Test Group 1',
219 'help_post' => 'This is Post Help For Test Group 1',
223 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
224 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
225 $this->assertEquals($customGroup['values'][$customGroup['id']]['style'], 'Inline', 'In line ' . __LINE__
);
229 * check with not array
231 function testCustomGroupCreateNotArray() {
233 $customGroup = $this->callAPIFailure('custom_group', 'create', $params);
234 $this->assertEquals($customGroup['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__
);
238 * check without title
240 function testCustomGroupCreateNoTitle() {
241 $params = array('extends' => array('Contact'),
243 'collapse_display' => 1,
245 'help_pre' => 'This is Pre Help For Test Group 2',
246 'help_post' => 'This is Post Help For Test Group 2',
249 $customGroup = $this->callAPIFailure('custom_group', 'create', $params,
250 'Mandatory key(s) missing from params array: title');
254 * check for household without weight
256 function testCustomGroupCreateHouseholdNoWeight() {
258 'title' => 'Test_Group_3',
259 'name' => 'test_group_3',
260 'extends' => array('Household'),
261 'collapse_display' => 1,
263 'help_pre' => 'This is Pre Help For Test Group 3',
264 'help_post' => 'This is Post Help For Test Group 3',
268 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
269 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
270 $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Household', 'In line ' . __LINE__
);
271 $this->assertEquals($customGroup['values'][$customGroup['id']]['style'], 'Tab', 'In line ' . __LINE__
);
275 * check for Contribution Donation
277 function testCustomGroupCreateContributionDonation() {
279 'title' => 'Test_Group_6',
280 'name' => 'test_group_6',
281 'extends' => array('Contribution', array(1)),
283 'collapse_display' => 1,
285 'help_pre' => 'This is Pre Help For Test Group 6',
286 'help_post' => 'This is Post Help For Test Group 6',
290 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
291 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
292 $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Contribution', 'In line ' . __LINE__
);
296 * check with valid array
298 function testCustomGroupCreateGroup() {
301 'title' => 'Test_Group_8',
302 'name' => 'test_group_8',
303 'extends' => array('Group'),
305 'collapse_display' => 1,
308 'help_pre' => 'This is Pre Help For Test Group 8',
309 'help_post' => 'This is Post Help For Test Group 8',
312 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
313 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
314 $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Group', 'In line ' . __LINE__
);
318 * check with Activity - Meeting Type
320 function testCustomGroupCreateActivityMeeting() {
322 'title' => 'Test_Group_10',
323 'name' => 'test_group_10',
324 'extends' => array('Activity', array(1)),
326 'collapse_display' => 1,
328 'help_pre' => 'This is Pre Help For Test Group 10',
329 'help_post' => 'This is Post Help For Test Group 10',
332 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
333 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
334 $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Activity', 'In line ' . __LINE__
);
337 ///////////////// civicrm_custom_group_delete methods
340 * check without GroupID
342 function testCustomGroupDeleteWithoutGroupID() {
343 $customGroup = $this->callAPIFailure('custom_group', 'delete', array());
344 $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: id', 'In line ' . __LINE__
);
348 * check with no array
350 function testCustomGroupDeleteNoArray() {
352 $customGroup = $this->callAPIFailure('custom_group', 'delete', $params);
353 $this->assertEquals($customGroup['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__
);
357 * check with valid custom group id
359 function testCustomGroupDelete() {
360 $customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'test_group'));
362 'id' => $customGroup['id'],
364 $result = $this->callAPIAndDocument('custom_group', 'delete', $params, __FUNCTION__
, __FILE__
);
365 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
368 * main success get function
373 public function testGetCustomGroupSuccess() {
375 $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
377 $result = $this->callAPIAndDocument($this->_entity
, 'get', $params, __FUNCTION__
, __FILE__
);
378 $values = $result['values'][$result['id']];
379 foreach ($this->_params
as $key => $value) {
380 if ($key == 'weight') {
383 $this->assertEquals($value, $values[$key], $key . " doesn't match " . print_r($values, TRUE) . 'in line' . __LINE__
);