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