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