3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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;
50 'name' => 'Custom Group Create',
51 'description' => 'Test all Custom Group Create API methods.',
52 'group' => 'CiviCRM API Tests',
57 $this->_entity
= 'CustomGroup';
58 $this->_params
= array(
59 'title' => 'Test_Group_1',
60 'name' => 'test_group_1',
61 'extends' => 'Individual',
63 'collapse_display' => 1,
65 'help_pre' => 'This is Pre Help For Test Group 1',
66 'help_post' => 'This is Post Help For Test Group 1',
73 $tablesToTruncate = array('civicrm_custom_group', 'civicrm_custom_field');
74 // true tells quickCleanup to drop any tables that might have been created in the test
75 $this->quickCleanup($tablesToTruncate, TRUE);
78 ///////////////// civicrm_custom_group_create methods
81 * Check with empty array
82 * note that these tests are of marginal value so should not be included in copy & paste
83 * code. The SyntaxConformance is capable of testing this for all entities on create
84 * & delete (& it would be easy to add if not there)
86 function testCustomGroupCreateNoParam() {
87 $customGroup = $this->callAPIFailure('custom_group', 'create', array(),
88 'Mandatory key(s) missing from params array: title, extends'
93 * Check with empty array
95 function testCustomGroupCreateNoExtends() {
98 'title' => 'Test_Group_1',
99 'name' => 'test_group_1',
101 'collapse_display' => 1,
103 'help_pre' => 'This is Pre Help For Test Group 1',
104 'help_post' => 'This is Post Help For Test Group 1',
108 $customGroup = $this->callAPIFailure('custom_group', 'create', $params);
109 $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: extends', 'In line ' . __LINE__
);
110 $this->assertAPIFailure($customGroup, 'In line ' . __LINE__
);
114 * Check with empty array
116 function testCustomGroupCreateInvalidExtends() {
119 'title' => 'Test_Group_1',
120 'name' => 'test_group_1',
122 'collapse_display' => 1,
124 'help_pre' => 'This is Pre Help For Test Group 1',
125 'help_post' => 'This is Post Help For Test Group 1',
127 'extends' => array(),
130 $customGroup = $this->callAPIFailure('custom_group', 'create', $params);
131 $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: extends', 'In line ' . __LINE__
);
135 * Check with a string instead of array for extends
137 function testCustomGroupCreateExtendsString() {
140 'title' => 'Test_Group_1',
141 'name' => 'test_group_1',
143 'collapse_display' => 1,
145 'help_pre' => 'This is Pre Help For Test Group 1',
146 'help_post' => 'This is Post Help For Test Group 1',
148 'extends' => 'Individual',
151 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
155 * Check with valid array
157 function testCustomGroupCreate() {
159 'title' => 'Test_Group_1',
160 'name' => 'test_group_1',
161 'extends' => array('Individual'),
163 'collapse_display' => 1,
165 'help_pre' => 'This is Pre Help For Test Group 1',
166 'help_post' => 'This is Post Help For Test Group 1',
170 $result = $this->callAPIAndDocument('custom_group', 'create', $params, __FUNCTION__
, __FILE__
);
171 $this->assertNotNull($result['id'], 'In line ' . __LINE__
);
172 $this->assertEquals($result['values'][$result['id']]['extends'], 'Individual', 'In line ' . __LINE__
);
176 * Check with valid array
178 function testCustomGroupGetFields() {
180 'options' => array('get_options' => 'style'),
183 $result = $this->callAPISuccess('custom_group', 'getfields', $params);
186 'Inline' => 'Inline',
187 'Tab with table' => 'Tab with table',
189 $this->assertEquals($expected, $result['values']['style']['options']);
193 * Check with extends array length greater than 1
195 function testCustomGroupExtendsMultipleCreate() {
197 'title' => 'Test_Group_1',
198 'name' => 'test_group_1',
199 'extends' => array('Individual', 'Household'),
201 'collapse_display' => 1,
203 'help_pre' => 'This is Pre Help For Test Group 1',
204 'help_post' => 'This is Post Help For Test Group 1',
208 $result = $this->callAPIFailure('custom_group', 'create', $params,
209 'implode(): Invalid arguments passed');
213 * Check with style missing from params array
215 function testCustomGroupCreateNoStyle() {
217 'title' => 'Test_Group_1',
218 'name' => 'test_group_1',
219 'extends' => array('Individual'),
221 'collapse_display' => 1,
222 'help_pre' => 'This is Pre Help For Test Group 1',
223 'help_post' => 'This is Post Help For Test Group 1',
227 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
228 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
229 $this->assertEquals($customGroup['values'][$customGroup['id']]['style'], 'Inline', 'In line ' . __LINE__
);
233 * Check with not array
235 function testCustomGroupCreateNotArray() {
237 $customGroup = $this->callAPIFailure('custom_group', 'create', $params);
238 $this->assertEquals($customGroup['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__
);
242 * Check without title
244 function testCustomGroupCreateNoTitle() {
245 $params = array('extends' => array('Contact'),
247 'collapse_display' => 1,
249 'help_pre' => 'This is Pre Help For Test Group 2',
250 'help_post' => 'This is Post Help For Test Group 2',
253 $customGroup = $this->callAPIFailure('custom_group', 'create', $params,
254 'Mandatory key(s) missing from params array: title');
258 * Check for household without weight
260 function testCustomGroupCreateHouseholdNoWeight() {
262 'title' => 'Test_Group_3',
263 'name' => 'test_group_3',
264 'extends' => array('Household'),
265 'collapse_display' => 1,
267 'help_pre' => 'This is Pre Help For Test Group 3',
268 'help_post' => 'This is Post Help For Test Group 3',
272 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
273 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
274 $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Household', 'In line ' . __LINE__
);
275 $this->assertEquals($customGroup['values'][$customGroup['id']]['style'], 'Tab', 'In line ' . __LINE__
);
279 * Check for Contribution Donation
281 function testCustomGroupCreateContributionDonation() {
283 'title' => 'Test_Group_6',
284 'name' => 'test_group_6',
285 'extends' => array('Contribution', array(1)),
287 'collapse_display' => 1,
289 'help_pre' => 'This is Pre Help For Test Group 6',
290 'help_post' => 'This is Post Help For Test Group 6',
294 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
295 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
296 $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Contribution', 'In line ' . __LINE__
);
300 * Check with valid array
302 function testCustomGroupCreateGroup() {
305 'title' => 'Test_Group_8',
306 'name' => 'test_group_8',
307 'extends' => array('Group'),
309 'collapse_display' => 1,
312 'help_pre' => 'This is Pre Help For Test Group 8',
313 'help_post' => 'This is Post Help For Test Group 8',
316 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
317 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
318 $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Group', 'In line ' . __LINE__
);
322 * Check with Activity - Meeting Type
324 function testCustomGroupCreateActivityMeeting() {
326 'title' => 'Test_Group_10',
327 'name' => 'test_group_10',
328 'extends' => array('Activity', array(1)),
330 'collapse_display' => 1,
332 'help_pre' => 'This is Pre Help For Test Group 10',
333 'help_post' => 'This is Post Help For Test Group 10',
336 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
337 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
338 $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Activity', 'In line ' . __LINE__
);
341 ///////////////// civicrm_custom_group_delete methods
344 * Check without GroupID
346 function testCustomGroupDeleteWithoutGroupID() {
347 $customGroup = $this->callAPIFailure('custom_group', 'delete', array());
348 $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: id', 'In line ' . __LINE__
);
352 * Check with no array
354 function testCustomGroupDeleteNoArray() {
356 $customGroup = $this->callAPIFailure('custom_group', 'delete', $params);
357 $this->assertEquals($customGroup['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__
);
361 * Check with valid custom group id
363 function testCustomGroupDelete() {
364 $customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'test_group'));
366 'id' => $customGroup['id'],
368 $result = $this->callAPIAndDocument('custom_group', 'delete', $params, __FUNCTION__
, __FILE__
);
369 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
373 * Main success get function
375 public function testGetCustomGroupSuccess() {
377 $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
379 $result = $this->callAPIAndDocument($this->_entity
, 'get', $params, __FUNCTION__
, __FILE__
);
380 $values = $result['values'][$result['id']];
381 foreach ($this->_params
as $key => $value) {
382 if ($key == 'weight') {
385 $this->assertEquals($value, $values[$key], $key . " doesn't match " . print_r($values, TRUE) . 'in line' . __LINE__
);