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