3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
29 * Test APIv3 civicrm_custom_group* functions
31 * @package CiviCRM_APIv3
32 * @subpackage API_CustomGroup
34 class api_v3_CustomGroupTest
extends CiviUnitTestCase
{
35 protected $_apiversion = 3;
39 public $DBResetRequired = TRUE;
41 public function setUp() {
42 $this->_entity
= 'CustomGroup';
43 $this->_params
= array(
44 'title' => 'Test_Group_1',
45 'name' => 'test_group_1',
46 'extends' => 'Individual',
48 'collapse_display' => 1,
50 'help_pre' => 'This is Pre Help For Test Group 1',
51 'help_post' => 'This is Post Help For Test Group 1',
57 public function tearDown() {
58 $tablesToTruncate = array('civicrm_custom_group', 'civicrm_custom_field');
59 // true tells quickCleanup to drop any tables that might have been created in the test
60 $this->quickCleanup($tablesToTruncate, TRUE);
63 ///////////////// civicrm_custom_group_create methods
66 * Check with empty array.
67 * note that these tests are of marginal value so should not be included in copy & paste
68 * code. The SyntaxConformance is capable of testing this for all entities on create
69 * & delete (& it would be easy to add if not there)
71 public function testCustomGroupCreateNoParam() {
72 $customGroup = $this->callAPIFailure('custom_group', 'create', array(),
73 'Mandatory key(s) missing from params array: title, extends'
78 * Check with empty array.
80 public function testCustomGroupCreateNoExtends() {
83 'title' => 'Test_Group_1',
84 'name' => 'test_group_1',
86 'collapse_display' => 1,
88 'help_pre' => 'This is Pre Help For Test Group 1',
89 'help_post' => 'This is Post Help For Test Group 1',
93 $customGroup = $this->callAPIFailure('custom_group', 'create', $params);
94 $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: extends');
95 $this->assertAPIFailure($customGroup);
99 * Check with empty array.
101 public function testCustomGroupCreateInvalidExtends() {
104 'title' => 'Test_Group_1',
105 'name' => 'test_group_1',
107 'collapse_display' => 1,
109 'help_pre' => 'This is Pre Help For Test Group 1',
110 'help_post' => 'This is Post Help For Test Group 1',
112 'extends' => array(),
115 $customGroup = $this->callAPIFailure('custom_group', 'create', $params);
116 $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: extends');
120 * Check with a string instead of array for extends.
122 public function testCustomGroupCreateExtendsString() {
125 'title' => 'Test_Group_1',
126 'name' => 'test_group_1',
128 'collapse_display' => 1,
130 'help_pre' => 'This is Pre Help For Test Group 1',
131 'help_post' => 'This is Post Help For Test Group 1',
133 'extends' => 'Individual',
136 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
140 * Check with valid array.
142 public function testCustomGroupCreate() {
144 'title' => 'Test_Group_1',
145 'name' => 'test_group_1',
146 'extends' => array('Individual'),
148 'collapse_display' => 1,
150 'help_pre' => 'This is Pre Help For Test Group 1',
151 'help_post' => 'This is Post Help For Test Group 1',
155 $result = $this->callAPIAndDocument('custom_group', 'create', $params, __FUNCTION__
, __FILE__
);
156 $this->assertNotNull($result['id']);
157 $this->assertEquals($result['values'][$result['id']]['extends'], 'Individual');
161 * Check with valid array.
163 public function testCustomGroupGetFields() {
165 'options' => array('get_options' => 'style'),
168 $result = $this->callAPISuccess('custom_group', 'getfields', $params);
171 'Inline' => 'Inline',
172 'Tab with table' => 'Tab with table',
174 $this->assertEquals($expected, $result['values']['style']['options']);
178 * Check with extends array length greater than 1
180 public function testCustomGroupExtendsMultipleCreate() {
182 'title' => 'Test_Group_1',
183 'name' => 'test_group_1',
184 'extends' => array('Individual', 'Household'),
186 'collapse_display' => 1,
188 'help_pre' => 'This is Pre Help For Test Group 1',
189 'help_post' => 'This is Post Help For Test Group 1',
193 $result = $this->callAPIFailure('custom_group', 'create', $params,
194 'implode(): Invalid arguments passed');
198 * Check with style missing from params array.
200 public function testCustomGroupCreateNoStyle() {
202 'title' => 'Test_Group_1',
203 'name' => 'test_group_1',
204 'extends' => array('Individual'),
206 'collapse_display' => 1,
207 'help_pre' => 'This is Pre Help For Test Group 1',
208 'help_post' => 'This is Post Help For Test Group 1',
212 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
213 $this->assertNotNull($customGroup['id']);
214 $this->assertEquals($customGroup['values'][$customGroup['id']]['style'], 'Inline');
218 * Check with not array.
220 public function testCustomGroupCreateNotArray() {
222 $customGroup = $this->callAPIFailure('custom_group', 'create', $params);
223 $this->assertEquals($customGroup['error_message'], 'Input variable `params` is not an array');
227 * Check without title.
229 public function testCustomGroupCreateNoTitle() {
231 'extends' => array('Contact'),
233 'collapse_display' => 1,
235 'help_pre' => 'This is Pre Help For Test Group 2',
236 'help_post' => 'This is Post Help For Test Group 2',
239 $customGroup = $this->callAPIFailure('custom_group', 'create', $params,
240 'Mandatory key(s) missing from params array: title');
244 * Check for household without weight.
246 public function testCustomGroupCreateHouseholdNoWeight() {
248 'title' => 'Test_Group_3',
249 'name' => 'test_group_3',
250 'extends' => array('Household'),
251 'collapse_display' => 1,
253 'help_pre' => 'This is Pre Help For Test Group 3',
254 'help_post' => 'This is Post Help For Test Group 3',
258 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
259 $this->assertNotNull($customGroup['id']);
260 $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Household');
261 $this->assertEquals($customGroup['values'][$customGroup['id']]['style'], 'Tab');
265 * Check for Contribution Donation.
267 public function testCustomGroupCreateContributionDonation() {
269 'title' => 'Test_Group_6',
270 'name' => 'test_group_6',
271 'extends' => array('Contribution', array(1)),
273 'collapse_display' => 1,
275 'help_pre' => 'This is Pre Help For Test Group 6',
276 'help_post' => 'This is Post Help For Test Group 6',
280 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
281 $this->assertNotNull($customGroup['id']);
282 $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Contribution');
286 * Check with valid array.
288 public function testCustomGroupCreateGroup() {
291 'title' => 'Test_Group_8',
292 'name' => 'test_group_8',
293 'extends' => array('Group'),
295 'collapse_display' => 1,
298 'help_pre' => 'This is Pre Help For Test Group 8',
299 'help_post' => 'This is Post Help For Test Group 8',
302 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
303 $this->assertNotNull($customGroup['id']);
304 $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Group');
308 * Check with Activity - Meeting Type
310 public function testCustomGroupCreateActivityMeeting() {
312 'title' => 'Test_Group_10',
313 'name' => 'test_group_10',
314 'extends' => array('Activity', array(1)),
316 'collapse_display' => 1,
318 'help_pre' => 'This is Pre Help For Test Group 10',
319 'help_post' => 'This is Post Help For Test Group 10',
322 $customGroup = $this->callAPISuccess('custom_group', 'create', $params);
323 $this->assertNotNull($customGroup['id']);
324 $this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Activity');
327 ///////////////// civicrm_custom_group_delete methods
330 * Check without GroupID.
332 public function testCustomGroupDeleteWithoutGroupID() {
333 $customGroup = $this->callAPIFailure('custom_group', 'delete', array());
334 $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: id');
338 * Check with no array.
340 public function testCustomGroupDeleteNoArray() {
342 $customGroup = $this->callAPIFailure('custom_group', 'delete', $params);
343 $this->assertEquals($customGroup['error_message'], 'Input variable `params` is not an array');
347 * Check with valid custom group id.
349 public function testCustomGroupDelete() {
350 $customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'test_group'));
352 'id' => $customGroup['id'],
354 $result = $this->callAPIAndDocument('custom_group', 'delete', $params, __FUNCTION__
, __FILE__
);
355 $this->assertAPISuccess($result);
359 * Main success get function.
361 public function testGetCustomGroupSuccess() {
363 $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
365 $result = $this->callAPIAndDocument($this->_entity
, 'get', $params, __FUNCTION__
, __FILE__
);
366 $values = $result['values'][$result['id']];
367 foreach ($this->_params
as $key => $value) {
368 if ($key == 'weight') {
371 $this->assertEquals($value, $values[$key], $key . " doesn't match " . print_r($values, TRUE) . 'in line' . __LINE__
);