Merge pull request #4897 from totten/master-cleanup2
[civicrm-core.git] / tests / phpunit / CiviTest / Custom.php
CommitLineData
6a488035 1<?php
aba1cd8b
EM
2
3/**
4 * Class Custom
5 */
6a488035
TO
6class Custom extends CiviUnitTestCase {
7 /**
8 * Helper function to create Custom Group
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 /**
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 /**
102 * Helper function to delete custom field
fbd1b89e 103 * @deprecated use function on parent class
e16033b4 104 * @param object of Custom Field to delete
6a488035 105 */
00be9182 106 public static function deleteField($params) {
6a488035
TO
107 require_once 'CRM/Core/BAO/CustomField.php';
108 CRM_Core_BAO_CustomField::deleteField($params);
109 }
110
111 /**
112 * Helper function to delete custom group
fbd1b89e 113 * @deprecated use function on parent class
e16033b4 114 * @param object Custom Group to delete
a6c01b45
CW
115 * @return boolean
116 * true if Group deleted, false otherwise
6a488035 117 */
00be9182 118 public static function deleteGroup($params) {
6a488035
TO
119 require_once 'CRM/Core/BAO/CustomGroup.php';
120 $deleteCustomGroup = CRM_Core_BAO_CustomGroup::deleteGroup($params, TRUE);
121 return $deleteCustomGroup;
122 }
123}