8ba5884d |
1 | <?php |
2 | /* |
3 | +--------------------------------------------------------------------+ |
4 | | CiviCRM version 5 | |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | |
9 | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | |
11 | | under the terms of the GNU Affero General Public License | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | |
13 | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
17 | | See the GNU Affero General Public License for more details. | |
18 | | | |
19 | | You should have received a copy of the GNU Affero General Public | |
20 | | License and the CiviCRM Licensing Exception along | |
21 | | with this program; if not, contact CiviCRM LLC | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | |
25 | +--------------------------------------------------------------------+ |
26 | */ |
27 | |
28 | /** |
29 | * Trait Custom Data trait. |
30 | * |
31 | * Trait for setting up custom data in tests. |
32 | */ |
33 | trait CRMTraits_Custom_CustomDataTrait { |
34 | |
35 | /** |
36 | * Create a custom group. |
37 | * |
38 | * @param array $params |
39 | * |
40 | * @return int |
41 | */ |
42 | public function createCustomGroup($params = []) { |
43 | $params = array_merge([ |
44 | 'title' => 'Custom Group', |
45 | 'extends' => [$this->entity], |
46 | 'weight' => 5, |
47 | 'style' => 'Inline', |
48 | 'max_multiple' => 0, |
49 | ], $params); |
50 | $this->ids['CustomGroup'][$params['title']] = $this->callAPISuccess('CustomGroup', 'create', $params)['id']; |
51 | return $this->ids['CustomGroup'][$params['title']]; |
52 | } |
53 | |
54 | /** |
55 | * @return array |
56 | */ |
57 | public function createCustomFieldsOfAllTypes() { |
58 | $customGroupID = $this->ids['CustomGroup']['Custom Group']; |
59 | $ids = []; |
60 | $params = [ |
61 | 'custom_group_id' => $customGroupID, |
62 | 'label' => 'Enter text here', |
63 | 'html_type' => 'Text', |
64 | 'data_type' => 'String', |
65 | 'default_value' => 'xyz', |
66 | 'weight' => 1, |
67 | 'is_required' => 1, |
68 | ]; |
69 | |
70 | $customField = $this->callAPISuccess('CustomField', 'create', $params); |
71 | $ids[] = $customField['id']; |
72 | |
73 | $optionValue[] = [ |
74 | 'label' => 'Red', |
75 | 'value' => 'R', |
76 | 'weight' => 1, |
77 | 'is_active' => 1, |
78 | ]; |
79 | $optionValue[] = [ |
80 | 'label' => 'Yellow', |
81 | 'value' => 'Y', |
82 | 'weight' => 2, |
83 | 'is_active' => 1, |
84 | ]; |
85 | $optionValue[] = [ |
86 | 'label' => 'Green', |
87 | 'value' => 'G', |
88 | 'weight' => 3, |
89 | 'is_active' => 1, |
90 | ]; |
91 | |
92 | $params = [ |
93 | 'label' => 'Pick Color', |
94 | 'html_type' => 'Select', |
95 | 'data_type' => 'String', |
96 | 'weight' => 2, |
97 | 'is_required' => 1, |
98 | 'is_searchable' => 0, |
99 | 'is_active' => 1, |
100 | 'option_values' => $optionValue, |
101 | 'custom_group_id' => $customGroupID, |
102 | ]; |
103 | |
104 | $customField = $this->callAPISuccess('custom_field', 'create', $params); |
105 | $ids[] = $customField['id']; |
106 | |
107 | $params = [ |
108 | 'custom_group_id' => $customGroupID, |
109 | 'name' => 'test_date', |
110 | 'label' => 'test_date', |
111 | 'html_type' => 'Select Date', |
112 | 'data_type' => 'Date', |
113 | 'default_value' => '20090711', |
114 | 'weight' => 3, |
115 | 'is_required' => 1, |
116 | 'is_searchable' => 0, |
117 | 'is_active' => 1, |
118 | ]; |
119 | |
120 | $customField = $this->callAPISuccess('custom_field', 'create', $params); |
121 | |
122 | $ids[] = $customField['id']; |
123 | $params = [ |
124 | 'custom_group_id' => $customGroupID, |
125 | 'name' => 'test_link', |
126 | 'label' => 'test_link', |
127 | 'html_type' => 'Link', |
128 | 'data_type' => 'Link', |
129 | 'default_value' => 'http://civicrm.org', |
130 | 'weight' => 4, |
131 | 'is_required' => 1, |
132 | 'is_searchable' => 0, |
133 | 'is_active' => 1, |
134 | ]; |
135 | |
136 | $customField = $this->callAPISuccess('custom_field', 'create', $params); |
137 | $ids[] = $customField['id']; |
138 | return $ids; |
139 | } |
140 | |
141 | } |