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
37 class api_v3_CustomGroupTest
extends CiviUnitTestCase
{
38 protected $_apiversion = 3;
42 public $DBResetRequired = TRUE;
44 public function setUp() {
45 $this->_entity
= 'CustomGroup';
46 $this->_params
= array(
47 'title' => 'Test_Group_1',
48 'name' => 'test_group_1',
49 'extends' => 'Individual',
51 'collapse_display' => 1,
53 'help_pre' => 'This is Pre Help For Test Group 1',
54 'help_post' => 'This is Post Help For Test Group 1',
60 public function tearDown() {
61 $tablesToTruncate = array('civicrm_custom_group', 'civicrm_custom_field');
62 // true tells quickCleanup to drop any tables that might have been created in the test
63 $this->quickCleanup($tablesToTruncate, TRUE);
66 ///////////////// civicrm_custom_group_create methods
69 * Check with empty array
70 * note that these tests are of marginal value so should not be included in copy & paste
71 * code. The SyntaxConformance is capable of testing this for all entities on create
72 * & delete (& it would be easy to add if not there)
74 public function testCustomGroupCreateNoParam() {
75 $customGroup = $this->callAPIFailure('custom_group', 'create', array(),
76 'Mandatory key(s) missing from params array: title, extends'
81 * Check with empty array
83 public function testCustomGroupCreateNoExtends() {
86 'title' => 'Test_Group_1',
87 'name' => 'test_group_1',
89 'collapse_display' => 1,
91 'help_pre' => 'This is Pre Help For Test Group 1',
92 'help_post' => 'This is Post Help For Test Group 1',
96 $customGroup = $this->callAPIFailure('custom_group', 'create', $params);
97 $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: extends', 'In line ' . __LINE__
);
98 $this->assertAPIFailure($customGroup, 'In line ' . __LINE__
);
102 * Check with empty array
104 public function testCustomGroupCreateInvalidExtends() {
107 'title' => 'Test_Group_1',
108 'name' => 'test_group_1',
110 'collapse_display' => 1,
112 'help_pre' => 'This is Pre Help For Test Group 1',
113 'help_post' => 'This is Post Help For Test Group 1',
115 'extends' => array(),
118 $customGroup = $this->callAPIFailure('custom_group', 'create', $params);
119 $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: extends', 'In line ' . __LINE__
);
123 * Check with a string instead of array for extends
125 public function testCustomGroupCreateExtendsString() {
128 'title' => 'Test_Group_1',
129 'name' => 'test_group_1',
131 'collapse_display' => 1,
133 'help_pre' => 'This is Pre Help For Test Group 1',
134 'help_post' => 'This is Post Help For Test Group 1',
136 'extends' => 'Individual',
139 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
143 * Check with valid array
145 public function testCustomGroupCreate() {
147 'title' => 'Test_Group_1',
148 'name' => 'test_group_1',
149 'extends' => array('Individual'),
151 'collapse_display' => 1,
153 'help_pre' => 'This is Pre Help For Test Group 1',
154 'help_post' => 'This is Post Help For Test Group 1',
158 $result = $this->callAPIAndDocument('custom_group', 'create', $params, __FUNCTION__
, __FILE__
);
159 $this->assertNotNull($result['id'], 'In line ' . __LINE__
);
160 $this->assertEquals($result['values'][$result['id']]['extends'], 'Individual', 'In line ' . __LINE__
);
164 * Check with valid array
166 public function testCustomGroupGetFields() {
168 'options' => array('get_options' => 'style'),
171 $result = $this->callAPISuccess('custom_group', 'getfields', $params);
174 'Inline' => 'Inline',
175 'Tab with table' => 'Tab with table',
177 $this->assertEquals($expected, $result['values']['style']['options']);
181 * Check with extends array length greater than 1
183 public function testCustomGroupExtendsMultipleCreate() {
185 'title' => 'Test_Group_1',
186 'name' => 'test_group_1',
187 'extends' => array('Individual', 'Household'),
189 'collapse_display' => 1,
191 'help_pre' => 'This is Pre Help For Test Group 1',
192 'help_post' => 'This is Post Help For Test Group 1',
196 $result = $this->callAPIFailure('custom_group', 'create', $params,
197 'implode(): Invalid arguments passed');
201 * Check with style missing from params array
203 public function testCustomGroupCreateNoStyle() {
205 'title' => 'Test_Group_1',
206 'name' => 'test_group_1',
207 'extends' => array('Individual'),
209 'collapse_display' => 1,
210 'help_pre' => 'This is Pre Help For Test Group 1',
211 'help_post' => 'This is Post Help For Test Group 1',
215 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
216 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
217 $this->assertEquals($customGroup['values'][$customGroup['id']]['style'], 'Inline', 'In line ' . __LINE__
);
221 * Check with not array
223 public function testCustomGroupCreateNotArray() {
225 $customGroup = $this->callAPIFailure('custom_group', 'create', $params);
226 $this->assertEquals($customGroup['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__
);
230 * Check without title
232 public function testCustomGroupCreateNoTitle() {
234 'extends' => array('Contact'),
236 'collapse_display' => 1,
238 'help_pre' => 'This is Pre Help For Test Group 2',
239 'help_post' => 'This is Post Help For Test Group 2',
242 $customGroup = $this->callAPIFailure('custom_group', 'create', $params,
243 'Mandatory key(s) missing from params array: title');
247 * Check for household without weight
249 public function testCustomGroupCreateHouseholdNoWeight() {
251 'title' => 'Test_Group_3',
252 'name' => 'test_group_3',
253 'extends' => array('Household'),
254 'collapse_display' => 1,
256 'help_pre' => 'This is Pre Help For Test Group 3',
257 'help_post' => 'This is Post Help For Test Group 3',
261 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
262 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
263 $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Household', 'In line ' . __LINE__
);
264 $this->assertEquals($customGroup['values'][$customGroup['id']]['style'], 'Tab', 'In line ' . __LINE__
);
268 * Check for Contribution Donation
270 public function testCustomGroupCreateContributionDonation() {
272 'title' => 'Test_Group_6',
273 'name' => 'test_group_6',
274 'extends' => array('Contribution', array(1)),
276 'collapse_display' => 1,
278 'help_pre' => 'This is Pre Help For Test Group 6',
279 'help_post' => 'This is Post Help For Test Group 6',
283 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
284 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
285 $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Contribution', 'In line ' . __LINE__
);
289 * Check with valid array
291 public function testCustomGroupCreateGroup() {
294 'title' => 'Test_Group_8',
295 'name' => 'test_group_8',
296 'extends' => array('Group'),
298 'collapse_display' => 1,
301 'help_pre' => 'This is Pre Help For Test Group 8',
302 'help_post' => 'This is Post Help For Test Group 8',
305 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
306 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
307 $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Group', 'In line ' . __LINE__
);
311 * Check with Activity - Meeting Type
313 public function testCustomGroupCreateActivityMeeting() {
315 'title' => 'Test_Group_10',
316 'name' => 'test_group_10',
317 'extends' => array('Activity', array(1)),
319 'collapse_display' => 1,
321 'help_pre' => 'This is Pre Help For Test Group 10',
322 'help_post' => 'This is Post Help For Test Group 10',
325 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
326 $this->assertNotNull($customGroup['id'], 'In line ' . __LINE__
);
327 $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Activity', 'In line ' . __LINE__
);
330 ///////////////// civicrm_custom_group_delete methods
333 * Check without GroupID
335 public function testCustomGroupDeleteWithoutGroupID() {
336 $customGroup = $this->callAPIFailure('custom_group', 'delete', array());
337 $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: id', 'In line ' . __LINE__
);
341 * Check with no array
343 public function testCustomGroupDeleteNoArray() {
345 $customGroup = $this->callAPIFailure('custom_group', 'delete', $params);
346 $this->assertEquals($customGroup['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__
);
350 * Check with valid custom group id
352 public function testCustomGroupDelete() {
353 $customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'test_group'));
355 'id' => $customGroup['id'],
357 $result = $this->callAPIAndDocument('custom_group', 'delete', $params, __FUNCTION__
, __FILE__
);
358 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
362 * Main success get function
364 public function testGetCustomGroupSuccess() {
366 $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
368 $result = $this->callAPIAndDocument($this->_entity
, 'get', $params, __FUNCTION__
, __FILE__
);
369 $values = $result['values'][$result['id']];
370 foreach ($this->_params
as $key => $value) {
371 if ($key == 'weight') {
374 $this->assertEquals($value, $values[$key], $key . " doesn't match " . print_r($values, TRUE) . 'in line' . __LINE__
);