Test fixes
[civicrm-core.git] / tests / phpunit / CiviTest / Custom.php
CommitLineData
6a488035
TO
1<?php
2class Custom extends CiviUnitTestCase {
3 /**
4 * Helper function to create Custom Group
5 *
fbd1b89e 6 * @deprecated - use functions on test case parent class
6a488035
TO
7 * @return object of created group
8 */
9 static function createGroup($group, $extends = NULL, $isMultiple = FALSE) {
10 if (empty($group)) {
11 if (isset($extends) &&
12 !is_array($extends)
13 ) {
14 $extends = array($extends);
15 }
16 $group = array(
17 'title' => 'Test_Group',
18 'name' => 'test_group',
19 'extends' => $extends,
20 'style' => 'Inline',
21 'is_multiple' => $isMultiple,
22 'is_active' => 1,
23 'version' => 3,
24 );
25 }
26 else {
27 // this is done for backward compatibility
28 // with tests older than 3.2.3
29 if (isset($group['extends']) &&
30 !is_array($group['extends'])
31 ) {
32 $group['extends'] = array($group['extends']);
33 }
34 }
35
36 $result = civicrm_api('custom_group', 'create', $group);
37
38 if ($result['is_error']) {
39 return NULL;
40 }
41
42 // this is done for backward compatibility
43 // with tests older than 3.2.3
44 require_once 'CRM/Core/BAO/CustomGroup.php';
45 $group = new CRM_Core_BAO_CustomGroup();
46 $group->id = $result['id'];
47 $group->find(TRUE);
48
49 return $group;
50 }
51
52 /**
53 * Helper function to create Custom Field
fbd1b89e 54 * @deprecated use parent object create fn
6a488035
TO
55 * @return object of created field
56 */
57 static function createField($params, $fields = NULL) {
58 if (empty($params)) {
59 $params = array(
60 'custom_group_id' => $fields['groupId'],
fbd1b89e
E
61 'label' => empty($fields['label']) ? 'test_' . CRM_Utils_Array::value('dataType', $fields) : $fields['label'],
62 'html_type' => CRM_Utils_Array::value('htmlType', $fields),
63 'data_type' => CRM_Utils_Array::value('dataType', $fields),
6a488035
TO
64 'weight' => 4,
65 'is_required' => 1,
66 'is_searchable' => 0,
67 'is_active' => 1,
68 'version' => 3,
69 );
70 }
71
72 $result = civicrm_api('custom_field', 'create', $params);
73
74 if ($result['is_error']) {
75 print_r($result);
76 return NULL;
77 }
78
79 // this is done for backward compatibility
80 // with tests older than 3.2.3
81 $customField = new CRM_Core_DAO_CustomField();
82 $customField->id = $result['id'];
83 $customField->find(TRUE);
84
85 return $customField;
86 }
87
88 /**
89 * Helper function to delete custom field
fbd1b89e 90 * @deprecated use function on parent class
6a488035
TO
91 * @param object of Custom Field to delete
92 */
93 static function deleteField($params) {
94 require_once 'CRM/Core/BAO/CustomField.php';
95 CRM_Core_BAO_CustomField::deleteField($params);
96 }
97
98 /**
99 * Helper function to delete custom group
fbd1b89e 100 * @deprecated use function on parent class
6a488035
TO
101 * @param object Custom Group to delete
102 * @return boolean true if Group deleted, false otherwise
103 */
104 static function deleteGroup($params) {
105 require_once 'CRM/Core/BAO/CustomGroup.php';
106 $deleteCustomGroup = CRM_Core_BAO_CustomGroup::deleteGroup($params, TRUE);
107 return $deleteCustomGroup;
108 }
109}
110
111