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;
45 public function setUp() {
46 $this->_entity
= 'CustomGroup';
47 $this->_params
= array(
48 'title' => 'Test_Group_1',
49 'name' => 'test_group_1',
50 'extends' => 'Individual',
52 'collapse_display' => 1,
54 'help_pre' => 'This is Pre Help For Test Group 1',
55 'help_post' => 'This is Post Help For Test Group 1',
61 public function tearDown() {
62 $tablesToTruncate = array('civicrm_custom_group', 'civicrm_custom_field');
63 // true tells quickCleanup to drop any tables that might have been created in the test
64 $this->quickCleanup($tablesToTruncate, TRUE);
67 ///////////////// civicrm_custom_group_create methods
70 * Check with empty array
71 * note that these tests are of marginal value so should not be included in copy & paste
72 * code. The SyntaxConformance is capable of testing this for all entities on create
73 * & delete (& it would be easy to add if not there)
75 public function testCustomGroupCreateNoParam() {
76 $customGroup = $this->callAPIFailure('custom_group', 'create', array(),
77 'Mandatory key(s) missing from params array: title, extends'
82 * Check with empty array
84 public function testCustomGroupCreateNoExtends() {
87 'title' => 'Test_Group_1',
88 'name' => 'test_group_1',
90 'collapse_display' => 1,
92 'help_pre' => 'This is Pre Help For Test Group 1',
93 'help_post' => 'This is Post Help For Test Group 1',
97 $customGroup = $this->callAPIFailure('custom_group', 'create', $params);
98 $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: extends', 'In line ' . __LINE__
);
99 $this->assertAPIFailure($customGroup, 'In line ' . __LINE__
);
103 * Check with empty array
105 public function testCustomGroupCreateInvalidExtends() {
108 'title' => 'Test_Group_1',
109 'name' => 'test_group_1',
111 'collapse_display' => 1,
113 'help_pre' => 'This is Pre Help For Test Group 1',
114 'help_post' => 'This is Post Help For Test Group 1',
116 'extends' => array(),
119 $customGroup = $this->callAPIFailure('custom_group', 'create', $params);
120 $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: extends', 'In line ' . __LINE__
);
124 * Check with a string instead of array for extends
126 public function testCustomGroupCreateExtendsString() {
129 'title' => 'Test_Group_1',
130 'name' => 'test_group_1',
132 'collapse_display' => 1,
134 'help_pre' => 'This is Pre Help For Test Group 1',
135 'help_post' => 'This is Post Help For Test Group 1',
137 'extends' => 'Individual',
140 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
144 * Check with valid array
146 public function testCustomGroupCreate() {
148 'title' => 'Test_Group_1',
149 'name' => 'test_group_1',
150 'extends' => array('Individual'),
152 'collapse_display' => 1,
154 'help_pre' => 'This is Pre Help For Test Group 1',
155 'help_post' => 'This is Post Help For Test Group 1',
159 $result = $this->callAPIAndDocument('custom_group', 'create', $params, __FUNCTION__
, __FILE__
);
160 $this->assertNotNull($result['id'], 'In line ' . __LINE__
);
161 $this->assertEquals($result['values'][$result['id']]['extends'], 'Individual', 'In line ' . __LINE__
);
165 * Check with valid array
167 public function testCustomGroupGetFields() {
169 'options' => array('get_options' => 'style'),
172 $result = $this->callAPISuccess('custom_group', 'getfields', $params);
175 'Inline' => 'Inline',
176 'Tab with table' => 'Tab with table',
178 $this->assertEquals($expected, $result['values']['style']['options']);
182 * Check with extends array length greater than 1
184 public function testCustomGroupExtendsMultipleCreate() {
186 'title' => 'Test_Group_1',
187 'name' => 'test_group_1',
188 'extends' => array('Individual', 'Household'),
190 'collapse_display' => 1,
192 'help_pre' => 'This is Pre Help For Test Group 1',
193 'help_post' => 'This is Post Help For Test Group 1',
197 $result = $this->callAPIFailure('custom_group', 'create', $params,
198 'implode(): Invalid arguments passed');
202 * Check with style missing from params array
204 public function testCustomGroupCreateNoStyle() {
206 'title' => 'Test_Group_1',
207 'name' => 'test_group_1',
208 'extends' => array('Individual'),
210 'collapse_display' => 1,
211 'help_pre' => 'This is Pre Help For Test Group 1',
212 'help_post' => 'This is Post Help For Test Group 1',
216 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
217 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
218 $this->assertEquals($customGroup['values'][$customGroup['id']]['style'], 'Inline', 'In line ' . __LINE__
);
222 * Check with not array
224 public function testCustomGroupCreateNotArray() {
226 $customGroup = $this->callAPIFailure('custom_group', 'create', $params);
227 $this->assertEquals($customGroup['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__
);
231 * Check without title
233 public function testCustomGroupCreateNoTitle() {
235 'extends' => array('Contact'),
237 'collapse_display' => 1,
239 'help_pre' => 'This is Pre Help For Test Group 2',
240 'help_post' => 'This is Post Help For Test Group 2',
243 $customGroup = $this->callAPIFailure('custom_group', 'create', $params,
244 'Mandatory key(s) missing from params array: title');
248 * Check for household without weight
250 public function testCustomGroupCreateHouseholdNoWeight() {
252 'title' => 'Test_Group_3',
253 'name' => 'test_group_3',
254 'extends' => array('Household'),
255 'collapse_display' => 1,
257 'help_pre' => 'This is Pre Help For Test Group 3',
258 'help_post' => 'This is Post Help For Test Group 3',
262 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
263 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
264 $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Household', 'In line ' . __LINE__
);
265 $this->assertEquals($customGroup['values'][$customGroup['id']]['style'], 'Tab', 'In line ' . __LINE__
);
269 * Check for Contribution Donation
271 public function testCustomGroupCreateContributionDonation() {
273 'title' => 'Test_Group_6',
274 'name' => 'test_group_6',
275 'extends' => array('Contribution', array(1)),
277 'collapse_display' => 1,
279 'help_pre' => 'This is Pre Help For Test Group 6',
280 'help_post' => 'This is Post Help For Test Group 6',
284 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
285 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
286 $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Contribution', 'In line ' . __LINE__
);
290 * Check with valid array
292 public function testCustomGroupCreateGroup() {
295 'title' => 'Test_Group_8',
296 'name' => 'test_group_8',
297 'extends' => array('Group'),
299 'collapse_display' => 1,
302 'help_pre' => 'This is Pre Help For Test Group 8',
303 'help_post' => 'This is Post Help For Test Group 8',
306 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
307 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
308 $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Group', 'In line ' . __LINE__
);
312 * Check with Activity - Meeting Type
314 public function testCustomGroupCreateActivityMeeting() {
316 'title' => 'Test_Group_10',
317 'name' => 'test_group_10',
318 'extends' => array('Activity', array(1)),
320 'collapse_display' => 1,
322 'help_pre' => 'This is Pre Help For Test Group 10',
323 'help_post' => 'This is Post Help For Test Group 10',
326 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
327 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
328 $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Activity', 'In line ' . __LINE__
);
331 ///////////////// civicrm_custom_group_delete methods
334 * Check without GroupID
336 public function testCustomGroupDeleteWithoutGroupID() {
337 $customGroup = $this->callAPIFailure('custom_group', 'delete', array());
338 $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: id', 'In line ' . __LINE__
);
342 * Check with no array
344 public function testCustomGroupDeleteNoArray() {
346 $customGroup = $this->callAPIFailure('custom_group', 'delete', $params);
347 $this->assertEquals($customGroup['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__
);
351 * Check with valid custom group id
353 public function testCustomGroupDelete() {
354 $customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'test_group'));
356 'id' => $customGroup['id'],
358 $result = $this->callAPIAndDocument('custom_group', 'delete', $params, __FUNCTION__
, __FILE__
);
359 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
363 * Main success get function
365 public function testGetCustomGroupSuccess() {
367 $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
369 $result = $this->callAPIAndDocument($this->_entity
, 'get', $params, __FUNCTION__
, __FILE__
);
370 $values = $result['values'][$result['id']];
371 foreach ($this->_params
as $key => $value) {
372 if ($key == 'weight') {
375 $this->assertEquals($value, $values[$key], $key . " doesn't match " . print_r($values, TRUE) . 'in line' . __LINE__
);