2 class Custom
extends CiviUnitTestCase
{
4 * Helper function to create Custom Group
6 * @return object of created group
8 static function createGroup($group, $extends = NULL, $isMultiple = FALSE) {
10 if (isset($extends) &&
13 $extends = array($extends);
16 'title' => 'Test_Group',
17 'name' => 'test_group',
18 'extends' => $extends,
20 'is_multiple' => $isMultiple,
26 // this is done for backward compatibility
27 // with tests older than 3.2.3
28 if (isset($group['extends']) &&
29 !is_array($group['extends'])
31 $group['extends'] = array($group['extends']);
35 $result = civicrm_api('custom_group', 'create', $group);
37 if ($result['is_error']) {
41 // this is done for backward compatibility
42 // with tests older than 3.2.3
43 require_once 'CRM/Core/BAO/CustomGroup.php';
44 $group = new CRM_Core_BAO_CustomGroup();
45 $group->id
= $result['id'];
52 * Helper function to create Custom Field
54 * @return object of created field
56 static function createField($params, $fields = NULL) {
59 'custom_group_id' => $fields['groupId'],
60 'label' => empty($fields['label']) ?
'test_' . $fields['dataType'] : $fields['label'],
61 'html_type' => $fields['htmlType'],
62 'data_type' => $fields['dataType'],
71 $result = civicrm_api('custom_field', 'create', $params);
73 if ($result['is_error']) {
78 // this is done for backward compatibility
79 // with tests older than 3.2.3
80 $customField = new CRM_Core_DAO_CustomField();
81 $customField->id
= $result['id'];
82 $customField->find(TRUE);
88 * Helper function to delete custom field
90 * @param object of Custom Field to delete
92 static function deleteField($params) {
93 require_once 'CRM/Core/BAO/CustomField.php';
94 CRM_Core_BAO_CustomField
::deleteField($params);
98 * Helper function to delete custom group
100 * @param object Custom Group to delete
101 * @return boolean true if Group deleted, false otherwise
103 static function deleteGroup($params) {
104 require_once 'CRM/Core/BAO/CustomGroup.php';
105 $deleteCustomGroup = CRM_Core_BAO_CustomGroup
::deleteGroup($params, TRUE);
106 return $deleteCustomGroup;