Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
0eea664b | 2 | |
aba1cd8b EM |
3 | /** |
4 | * Class CRM_Core_BAO_CustomFieldTest | |
8392a043 | 5 | * |
acb109b7 | 6 | * @group headless |
aba1cd8b | 7 | */ |
6a488035 | 8 | class CRM_Core_BAO_CustomFieldTest extends CiviUnitTestCase { |
6a488035 | 9 | |
8392a043 | 10 | use CRMTraits_Custom_CustomDataTrait; |
11 | ||
c6b559da | 12 | protected $customFieldID; |
13 | ||
00be9182 | 14 | public function setUp() { |
6a488035 TO |
15 | parent::setUp(); |
16 | } | |
17 | ||
cef2e96c | 18 | /** |
19 | * Clean up after test. | |
20 | * | |
21 | * @throws \Exception | |
22 | */ | |
23 | public function tearDown() { | |
24 | $this->quickCleanup([], TRUE); | |
25 | parent::tearDown(); | |
26 | } | |
27 | ||
08e37a2a | 28 | public function testCreateCustomField() { |
c6b559da | 29 | $customGroup = $this->createCustomField(); |
08e37a2a | 30 | $customFieldID = $this->assertDBNotNull('CRM_Core_DAO_CustomField', $customGroup['id'], 'id', 'custom_group_id', |
6a488035 TO |
31 | 'Database check for created CustomField.' |
32 | ); | |
cef2e96c | 33 | $fields = array( |
6a488035 TO |
34 | 'id' => $customFieldID, |
35 | 'label' => 'editTestFld', | |
36 | 'is_active' => 1, | |
37 | 'data_type' => 'String', | |
38 | 'html_type' => 'Text', | |
08e37a2a | 39 | 'custom_group_id' => $customGroup['id'], |
cef2e96c | 40 | ); |
6a488035 | 41 | |
08e37a2a | 42 | CRM_Core_BAO_CustomField::create($fields); |
6a488035 TO |
43 | $this->assertDBNotNull('CRM_Core_DAO_CustomField', 1, 'id', 'is_active', 'Database check for edited CustomField.'); |
44 | $this->assertDBNotNull('CRM_Core_DAO_CustomField', $fields['label'], 'id', 'label', 'Database check for edited CustomField.'); | |
45 | ||
8b3b9a2e ARW |
46 | $dbFieldName = $this->assertDBNotNull('CRM_Core_DAO_CustomField', $customFieldID, 'name', 'id', 'Database check for edited CustomField.'); |
47 | $dbColumnName = $this->assertDBNotNull('CRM_Core_DAO_CustomField', $customFieldID, 'column_name', 'id', 'Database check for edited CustomField.'); | |
48 | $this->assertEquals(strtolower("{$dbFieldName}_{$customFieldID}"), $dbColumnName, | |
92915c55 | 49 | "Column name ends in ID"); |
8b3b9a2e | 50 | |
08e37a2a | 51 | $this->customGroupDelete($customGroup['id']); |
8b3b9a2e | 52 | } |
b2042573 | 53 | |
08e37a2a | 54 | public function testCreateCustomFieldColumnName() { |
cef2e96c | 55 | $customGroup = $this->customGroupCreate(array('extends' => 'Individual')); |
56 | $fields = array( | |
8b3b9a2e ARW |
57 | 'label' => 'testFld 2', |
58 | 'column_name' => 'special_colname', | |
59 | 'data_type' => 'String', | |
60 | 'html_type' => 'Text', | |
08e37a2a | 61 | 'custom_group_id' => $customGroup['id'], |
cef2e96c | 62 | ); |
08e37a2a | 63 | CRM_Core_BAO_CustomField::create($fields); |
64 | $customFieldID = $this->assertDBNotNull('CRM_Core_DAO_CustomField', $customGroup['id'], 'id', 'custom_group_id', | |
8b3b9a2e ARW |
65 | 'Database check for created CustomField.' |
66 | ); | |
67 | $dbColumnName = $this->assertDBNotNull('CRM_Core_DAO_CustomField', $customFieldID, 'column_name', 'id', 'Database check for edited CustomField.'); | |
68 | $this->assertEquals($fields['column_name'], $dbColumnName, | |
92915c55 | 69 | "Column name set as specified"); |
8b3b9a2e | 70 | |
08e37a2a | 71 | $this->customGroupDelete($customGroup['id']); |
6a488035 TO |
72 | } |
73 | ||
08e37a2a | 74 | public function testCreateCustomFieldName() { |
cef2e96c | 75 | $customGroup = $this->customGroupCreate(array('extends' => 'Individual')); |
76 | $fields = array( | |
43ff3196 TO |
77 | 'label' => 'testFld 2', |
78 | 'name' => 'special_fldlname', | |
79 | 'data_type' => 'String', | |
80 | 'html_type' => 'Text', | |
08e37a2a | 81 | 'custom_group_id' => $customGroup['id'], |
cef2e96c | 82 | ); |
08e37a2a | 83 | CRM_Core_BAO_CustomField::create($fields); |
84 | $customFieldID = $this->assertDBNotNull('CRM_Core_DAO_CustomField', $customGroup['id'], 'id', 'custom_group_id', | |
43ff3196 TO |
85 | 'Database check for created CustomField.' |
86 | ); | |
87 | $dbFieldName = $this->assertDBNotNull('CRM_Core_DAO_CustomField', $customFieldID, 'name', 'id', 'Database check for edited CustomField.'); | |
88 | $this->assertEquals($fields['name'], $dbFieldName, | |
89 | "Column name set as specified"); | |
90 | ||
08e37a2a | 91 | $this->customGroupDelete($customGroup['id']); |
43ff3196 TO |
92 | } |
93 | ||
00be9182 | 94 | public function testGetFields() { |
cef2e96c | 95 | $customGroup = $this->customGroupCreate(array('extends' => 'Individual')); |
96 | $fields = array( | |
6a488035 TO |
97 | 'label' => 'testFld1', |
98 | 'data_type' => 'String', | |
99 | 'html_type' => 'Text', | |
100 | 'is_active' => 1, | |
08e37a2a | 101 | 'custom_group_id' => $customGroup['id'], |
cef2e96c | 102 | ); |
08e37a2a | 103 | CRM_Core_BAO_CustomField::create($fields); |
104 | $this->assertDBNotNull('CRM_Core_DAO_CustomField', $customGroup['id'], 'id', 'custom_group_id', | |
6a488035 TO |
105 | 'Database check for created CustomField.' |
106 | ); | |
cef2e96c | 107 | $fields = array( |
6a488035 TO |
108 | 'label' => 'testFld2', |
109 | 'data_type' => 'String', | |
110 | 'html_type' => 'Text', | |
111 | 'is_active' => 1, | |
08e37a2a | 112 | 'custom_group_id' => $customGroup['id'], |
cef2e96c | 113 | ); |
08e37a2a | 114 | CRM_Core_BAO_CustomField::create($fields); |
115 | $this->assertDBNotNull('CRM_Core_DAO_CustomField', $customGroup['id'], 'id', 'custom_group_id', | |
6a488035 TO |
116 | 'Database check for created CustomField.' |
117 | ); | |
6a488035 | 118 | |
08e37a2a | 119 | $this->customGroupDelete($customGroup['id']); |
6a488035 TO |
120 | } |
121 | ||
00be9182 | 122 | public function testGetDisplayedValues() { |
cef2e96c | 123 | $customGroup = $this->customGroupCreate(array('extends' => 'Individual')); |
124 | $fieldsToCreate = array( | |
125 | array( | |
d5c86914 CW |
126 | 'data_type' => 'Country', |
127 | 'html_type' => 'Select Country', | |
cef2e96c | 128 | 'tests' => array( |
602b60e0 | 129 | 'United States' => 1228, |
d5c86914 | 130 | '' => NULL, |
cef2e96c | 131 | ), |
132 | ), | |
133 | array( | |
d5c86914 CW |
134 | 'data_type' => 'StateProvince', |
135 | 'html_type' => 'Multi-Select State/Province', | |
cef2e96c | 136 | 'tests' => array( |
d5c86914 CW |
137 | '' => 0, |
138 | 'Alabama' => 1000, | |
cef2e96c | 139 | 'Alabama, Alaska' => array(1000, 1001), |
140 | ), | |
141 | ), | |
142 | array( | |
d5c86914 CW |
143 | 'data_type' => 'String', |
144 | 'html_type' => 'Radio', | |
cef2e96c | 145 | 'option_values' => array( |
d5c86914 | 146 | 'key' => 'KeyLabel', |
cef2e96c | 147 | ), |
148 | 'tests' => array( | |
d5c86914 | 149 | 'KeyLabel' => 'key', |
cef2e96c | 150 | ), |
151 | ), | |
152 | array( | |
d5c86914 CW |
153 | 'data_type' => 'String', |
154 | 'html_type' => 'CheckBox', | |
cef2e96c | 155 | 'option_values' => array( |
d5c86914 CW |
156 | 'key1' => 'Label1', |
157 | 'key2' => 'Label2', | |
158 | 'key3' => 'Label3', | |
159 | 'key4' => 'Label4', | |
cef2e96c | 160 | ), |
161 | 'tests' => array( | |
162 | 'Label1' => array('key1'), | |
d5c86914 | 163 | 'Label2' => 'key2', |
cef2e96c | 164 | 'Label2, Label3' => array('key2', 'key3'), |
165 | 'Label3, Label4' => CRM_Utils_Array::implodePadded(array('key3', 'key4')), | |
166 | 'Label1, Label4' => array('key1' => 1, 'key4' => 1), | |
167 | ), | |
168 | ), | |
169 | array( | |
d5c86914 CW |
170 | 'data_type' => 'Date', |
171 | 'html_type' => 'Select Date', | |
172 | 'date_format' => 'd M yy', | |
173 | 'time_format' => 1, | |
cef2e96c | 174 | 'tests' => array( |
d5c86914 CW |
175 | '1 Jun 1999 1:30PM' => '1999-06-01 13:30', |
176 | '' => '', | |
cef2e96c | 177 | ), |
178 | ), | |
179 | ); | |
d5c86914 | 180 | foreach ($fieldsToCreate as $num => $field) { |
cef2e96c | 181 | $params = $field + array( |
182 | 'label' => 'test field ' . $num, | |
183 | 'custom_group_id' => $customGroup['id'], | |
184 | ); | |
d5c86914 CW |
185 | unset($params['tests']); |
186 | $createdField = $this->callAPISuccess('customField', 'create', $params); | |
187 | foreach ($field['tests'] as $expected => $input) { | |
188 | $this->assertEquals($expected, CRM_Core_BAO_CustomField::displayValue($input, $createdField['id'])); | |
189 | } | |
190 | } | |
6a488035 | 191 | |
08e37a2a | 192 | $this->customGroupDelete($customGroup['id']); |
6a488035 TO |
193 | } |
194 | ||
17369736 AS |
195 | public function testGetDisplayedValuesContactRef() { |
196 | $customGroup = $this->customGroupCreate(['extends' => 'Individual']); | |
197 | $params = [ | |
198 | 'data_type' => 'ContactReference', | |
199 | 'html_type' => 'Autocomplete-Select', | |
200 | 'label' => 'test ref', | |
201 | 'custom_group_id' => $customGroup['id'], | |
202 | ]; | |
203 | $createdField = $this->callAPISuccess('customField', 'create', $params); | |
204 | $contact1 = $this->individualCreate(); | |
205 | $contact2 = $this->individualCreate(['custom_' . $createdField['id'] => $contact1['id']]); | |
206 | ||
207 | $this->assertEquals($contact1['display_name'], CRM_Core_BAO_CustomField::displayValue($contact2['id'], $createdField['id'])); | |
208 | $this->assertEquals("Bob", CRM_Core_BAO_CustomField::displayValue("Bob", $createdField['id'])); | |
209 | ||
210 | $this->contactDelete($contact2['id']); | |
211 | $this->contactDelete($contact1['id']); | |
212 | $this->customGroupDelete($customGroup['id']); | |
213 | } | |
214 | ||
08e37a2a | 215 | public function testDeleteCustomField() { |
cef2e96c | 216 | $customGroup = $this->customGroupCreate(array('extends' => 'Individual')); |
217 | $fields = array( | |
08e37a2a | 218 | 'custom_group_id' => $customGroup['id'], |
8b3b9a2e | 219 | 'label' => 'Throwaway Field', |
d9136461 | 220 | 'dataType' => 'Memo', |
221 | 'htmlType' => 'TextArea', | |
cef2e96c | 222 | ); |
6a488035 | 223 | |
08e37a2a | 224 | $customField = $this->customFieldCreate($fields); |
225 | $fieldObject = new CRM_Core_BAO_CustomField(); | |
226 | $fieldObject->id = $customField['id']; | |
227 | $fieldObject->find(TRUE); | |
228 | CRM_Core_BAO_CustomField::deleteField($fieldObject); | |
229 | $this->assertDBNull('CRM_Core_DAO_CustomField', $customGroup['id'], 'id', | |
6a488035 TO |
230 | 'custom_group_id', 'Database check for deleted Custom Field.' |
231 | ); | |
08e37a2a | 232 | $this->customGroupDelete($customGroup['id']); |
6a488035 TO |
233 | } |
234 | ||
235 | /** | |
08e37a2a | 236 | * Move a custom field from $groupA to $groupB. |
237 | * | |
238 | * Make sure that data records are correctly matched and created. | |
6a488035 | 239 | */ |
00be9182 | 240 | public function testMoveField() { |
6a488035 | 241 | $countriesByName = array_flip(CRM_Core_PseudoConstant::country(FALSE, FALSE)); |
602b60e0 | 242 | $this->assertTrue($countriesByName['Andorra'] > 0); |
cef2e96c | 243 | $groups = array( |
244 | 'A' => $this->customGroupCreate(array( | |
92915c55 TO |
245 | 'title' => 'Test_Group A', |
246 | 'name' => 'test_group_a', | |
cef2e96c | 247 | 'extends' => array('Individual'), |
92915c55 TO |
248 | 'style' => 'Inline', |
249 | 'is_multiple' => 0, | |
250 | 'is_active' => 1, | |
251 | 'version' => 3, | |
cef2e96c | 252 | )), |
253 | 'B' => $this->customGroupCreate(array( | |
92915c55 TO |
254 | 'title' => 'Test_Group B', |
255 | 'name' => 'test_group_b', | |
cef2e96c | 256 | 'extends' => array('Individual'), |
92915c55 TO |
257 | 'style' => 'Inline', |
258 | 'is_multiple' => 0, | |
259 | 'is_active' => 1, | |
260 | 'version' => 3, | |
cef2e96c | 261 | )), |
262 | ); | |
08e37a2a | 263 | $groupA = $groups['A']['values'][$groups['A']['id']]; |
264 | $groupB = $groups['B']['values'][$groups['B']['id']]; | |
cef2e96c | 265 | $countryA = $this->customFieldCreate(array( |
08e37a2a | 266 | 'custom_group_id' => $groups['A']['id'], |
267 | 'label' => 'Country A', | |
268 | 'dataType' => 'Country', | |
269 | 'htmlType' => 'Select Country', | |
270 | 'default_value' => NULL, | |
cef2e96c | 271 | )); |
272 | $countryB = $this->customFieldCreate(array( | |
08e37a2a | 273 | 'custom_group_id' => $groups['A']['id'], |
274 | 'label' => 'Country B', | |
275 | 'dataType' => 'Country', | |
276 | 'htmlType' => 'Select Country', | |
277 | 'default_value' => NULL, | |
cef2e96c | 278 | )); |
279 | $countryC = $this->customFieldCreate(array( | |
08e37a2a | 280 | 'custom_group_id' => $groups['B']['id'], |
281 | 'label' => 'Country C', | |
282 | 'dataType' => 'Country', | |
283 | 'htmlType' => 'Select Country', | |
284 | 'default_value' => NULL, | |
cef2e96c | 285 | )); |
08e37a2a | 286 | |
cef2e96c | 287 | $fields = array( |
08e37a2a | 288 | 'countryA' => $countryA['values'][$countryA['id']], |
289 | 'countryB' => $countryB['values'][$countryB['id']], | |
290 | 'countryC' => $countryC['values'][$countryC['id']], | |
cef2e96c | 291 | ); |
292 | $contacts = array( | |
293 | 'alice' => $this->individualCreate(array( | |
92915c55 TO |
294 | 'first_name' => 'Alice', |
295 | 'last_name' => 'Albertson', | |
602b60e0 SL |
296 | 'custom_' . $fields['countryA']['id'] => $countriesByName['Andorra'], |
297 | 'custom_' . $fields['countryB']['id'] => $countriesByName['Barbados'], | |
cef2e96c | 298 | )), |
299 | 'bob' => $this->individualCreate(array( | |
92915c55 TO |
300 | 'first_name' => 'Bob', |
301 | 'last_name' => 'Roberts', | |
602b60e0 SL |
302 | 'custom_' . $fields['countryA']['id'] => $countriesByName['Austria'], |
303 | 'custom_' . $fields['countryB']['id'] => $countriesByName['Bermuda'], | |
304 | 'custom_' . $fields['countryC']['id'] => $countriesByName['Chad'], | |
cef2e96c | 305 | )), |
306 | 'carol' => $this->individualCreate(array( | |
92915c55 TO |
307 | 'first_name' => 'Carol', |
308 | 'last_name' => 'Carolson', | |
602b60e0 | 309 | 'custom_' . $fields['countryC']['id'] => $countriesByName['Cambodia'], |
cef2e96c | 310 | )), |
311 | ); | |
6a488035 TO |
312 | |
313 | // Move! | |
08e37a2a | 314 | CRM_Core_BAO_CustomField::moveField($fields['countryB']['id'], $groupB['id']); |
6a488035 TO |
315 | |
316 | // Group[A] no longer has fields[countryB] | |
317 | $errorScope = CRM_Core_TemporaryErrorScope::useException(); | |
318 | try { | |
08e37a2a | 319 | $this->assertDBQuery(1, "SELECT {$fields['countryB']['column_name']} FROM " . $groupA['table_name']); |
6a488035 TO |
320 | $this->fail('Expected exception when querying column on wrong table'); |
321 | } | |
92915c55 TO |
322 | catch (PEAR_Exception$e) { |
323 | } | |
6a488035 TO |
324 | $errorScope = NULL; |
325 | ||
326 | // Alice: Group[B] has fields[countryB], but fields[countryC] did not exist before | |
327 | $this->assertDBQuery(1, | |
08e37a2a | 328 | "SELECT count(*) FROM {$groupB['table_name']} |
b2042573 | 329 | WHERE entity_id = %1 |
08e37a2a | 330 | AND {$fields['countryB']['column_name']} = %3 |
331 | AND {$fields['countryC']['column_name']} is null", | |
cef2e96c | 332 | array( |
333 | 1 => array($contacts['alice'], 'Integer'), | |
334 | 3 => array($countriesByName['Barbados'], 'Integer'), | |
335 | ) | |
6a488035 TO |
336 | ); |
337 | ||
338 | // Bob: Group[B] has merged fields[countryB] and fields[countryC] on the same record | |
339 | $this->assertDBQuery(1, | |
08e37a2a | 340 | "SELECT count(*) FROM {$groupB['table_name']} |
b2042573 | 341 | WHERE entity_id = %1 |
08e37a2a | 342 | AND {$fields['countryB']['column_name']} = %3 |
343 | AND {$fields['countryC']['column_name']} = %4", | |
cef2e96c | 344 | array( |
345 | 1 => array($contacts['bob'], 'Integer'), | |
346 | 3 => array($countriesByName['Bermuda'], 'Integer'), | |
347 | 4 => array($countriesByName['Chad'], 'Integer'), | |
348 | ) | |
6a488035 TO |
349 | ); |
350 | ||
351 | // Carol: Group[B] still has fields[countryC] but did not get fields[countryB] | |
352 | $this->assertDBQuery(1, | |
08e37a2a | 353 | "SELECT count(*) FROM {$groupB['table_name']} |
b2042573 | 354 | WHERE entity_id = %1 |
08e37a2a | 355 | AND {$fields['countryB']['column_name']} is null |
356 | AND {$fields['countryC']['column_name']} = %4", | |
cef2e96c | 357 | array( |
358 | 1 => array($contacts['carol'], 'Integer'), | |
359 | 4 => array($countriesByName['Cambodia'], 'Integer'), | |
360 | ) | |
6a488035 TO |
361 | ); |
362 | ||
08e37a2a | 363 | $this->customGroupDelete($groups['A']['id']); |
364 | $this->customGroupDelete($groupB['id']); | |
6a488035 | 365 | } |
96025800 | 366 | |
c6b559da | 367 | /** |
368 | * Test get custom field id function. | |
cef2e96c | 369 | * |
370 | * @throws \CiviCRM_API3_Exception | |
c6b559da | 371 | */ |
372 | public function testGetCustomFieldID() { | |
373 | $this->createCustomField(); | |
374 | $fieldID = CRM_Core_BAO_CustomField::getCustomFieldID('testFld'); | |
375 | $this->assertEquals($this->customFieldID, $fieldID); | |
376 | ||
377 | $fieldID = CRM_Core_BAO_CustomField::getCustomFieldID('testFld', 'new custom group'); | |
378 | $this->assertEquals($this->customFieldID, $fieldID); | |
30b6e002 PF |
379 | |
380 | $fieldID = CRM_Core_BAO_CustomField::getCustomFieldID('testFld', 'new custom group', TRUE); | |
381 | $this->assertEquals('custom_' . $this->customFieldID, $fieldID); | |
382 | ||
383 | // create field with same name in a different group | |
384 | $this->createCustomField('other custom group'); | |
385 | $otherFieldID = CRM_Core_BAO_CustomField::getCustomFieldID('testFld', 'other custom group'); | |
386 | // make sure it does not return the field ID of the first field | |
387 | $this->assertNotEquals($fieldID, $otherFieldID); | |
c6b559da | 388 | } |
389 | ||
390 | /** | |
30b6e002 PF |
391 | * Create a custom field |
392 | * | |
393 | * @param string $groupTitle | |
394 | * | |
c6b559da | 395 | * @return array |
396 | */ | |
30b6e002 PF |
397 | protected function createCustomField($groupTitle = 'new custom group') { |
398 | $customGroup = $this->customGroupCreate([ | |
399 | 'extends' => 'Individual', | |
8392a043 | 400 | 'title' => $groupTitle, |
30b6e002 | 401 | ]); |
8392a043 | 402 | $fields = [ |
c6b559da | 403 | 'label' => 'testFld', |
404 | 'data_type' => 'String', | |
405 | 'html_type' => 'Text', | |
406 | 'custom_group_id' => $customGroup['id'], | |
8392a043 | 407 | ]; |
c6b559da | 408 | $field = CRM_Core_BAO_CustomField::create($fields); |
409 | $this->customFieldID = $field->id; | |
410 | return $customGroup; | |
411 | } | |
412 | ||
8392a043 | 413 | /** |
cef2e96c | 414 | * Test the getFieldsForImport function. |
415 | * | |
416 | * @throws \Exception | |
8392a043 | 417 | */ |
418 | public function testGetFieldsForImport() { | |
419 | $this->entity = 'Contact'; | |
420 | $this->createCustomGroupWithFieldsOfAllTypes(); | |
cef2e96c | 421 | $customGroupID = $this->ids['CustomGroup']['Custom Group']; |
8392a043 | 422 | $expected = [ |
423 | $this->getCustomFieldName('country') => [ | |
cef2e96c | 424 | 'name' => $this->getCustomFieldName('country'), |
8392a043 | 425 | 'type' => 1, |
426 | 'title' => 'Country', | |
427 | 'headerPattern' => '//', | |
428 | 'import' => 1, | |
429 | 'custom_field_id' => $this->getCustomFieldID('country'), | |
430 | 'options_per_line' => NULL, | |
431 | 'text_length' => NULL, | |
432 | 'data_type' => 'Int', | |
433 | 'html_type' => 'Select Country', | |
434 | 'is_search_range' => '0', | |
cef2e96c | 435 | 'id' => $this->getCustomFieldID('country'), |
436 | 'label' => 'Country', | |
437 | 'groupTitle' => 'Custom Group', | |
438 | 'default_value' => NULL, | |
439 | 'custom_group_id' => $customGroupID, | |
440 | 'extends' => 'Contact', | |
441 | 'extends_entity_column_value' => NULL, | |
442 | 'extends_entity_column_id' => NULL, | |
443 | 'is_view' => '0', | |
444 | 'is_multiple' => '0', | |
445 | 'option_group_id' => NULL, | |
446 | 'date_format' => NULL, | |
447 | 'time_format' => NULL, | |
448 | 'is_required' => '0', | |
449 | 'table_name' => 'civicrm_value_custom_group_' . $customGroupID, | |
450 | 'column_name' => 'country_' . $this->getCustomFieldID('country'), | |
451 | 'where' => 'civicrm_value_custom_group_' . $customGroupID . '.country_' . $this->getCustomFieldID('country'), | |
452 | 'extends_table' => 'civicrm_contact', | |
453 | 'search_table' => 'contact_a', | |
8392a043 | 454 | ], |
cef2e96c | 455 | $this->getCustomFieldName('file') => [ |
8392a043 | 456 | 'name' => $this->getCustomFieldName('file'), |
457 | 'type' => 2, | |
458 | 'title' => 'Custom Field', | |
459 | 'headerPattern' => '//', | |
460 | 'import' => 1, | |
461 | 'custom_field_id' => $this->getCustomFieldID('file'), | |
462 | 'options_per_line' => NULL, | |
463 | 'text_length' => NULL, | |
464 | 'data_type' => 'File', | |
465 | 'html_type' => 'File', | |
466 | 'is_search_range' => '0', | |
cef2e96c | 467 | 'id' => $this->getCustomFieldID('file'), |
468 | 'label' => 'Custom Field', | |
469 | 'groupTitle' => 'Custom Group', | |
470 | 'default_value' => NULL, | |
471 | 'custom_group_id' => $customGroupID, | |
472 | 'extends' => 'Contact', | |
473 | 'extends_entity_column_value' => NULL, | |
474 | 'extends_entity_column_id' => NULL, | |
475 | 'is_view' => '0', | |
476 | 'is_multiple' => '0', | |
477 | 'option_group_id' => NULL, | |
478 | 'date_format' => NULL, | |
479 | 'time_format' => NULL, | |
480 | 'is_required' => '0', | |
481 | 'table_name' => 'civicrm_value_custom_group_' . $customGroupID, | |
482 | 'column_name' => 'custom_field_' . $this->getCustomFieldID('file'), | |
483 | 'where' => 'civicrm_value_custom_group_' . $customGroupID . '.custom_field_' . $this->getCustomFieldID('file'), | |
484 | 'extends_table' => 'civicrm_contact', | |
485 | 'search_table' => 'contact_a', | |
8392a043 | 486 | ], |
487 | $this->getCustomFieldName('text') => [ | |
488 | 'name' => $this->getCustomFieldName('text'), | |
489 | 'type' => 2, | |
490 | 'title' => 'Enter text here', | |
491 | 'headerPattern' => '//', | |
492 | 'import' => 1, | |
493 | 'custom_field_id' => $this->getCustomFieldID('text'), | |
494 | 'options_per_line' => NULL, | |
495 | 'text_length' => NULL, | |
496 | 'data_type' => 'String', | |
497 | 'html_type' => 'Text', | |
498 | 'is_search_range' => '0', | |
cef2e96c | 499 | 'id' => $this->getCustomFieldID('text'), |
500 | 'label' => 'Enter text here', | |
501 | 'groupTitle' => 'Custom Group', | |
502 | 'default_value' => 'xyz', | |
503 | 'custom_group_id' => '1', | |
504 | 'extends' => 'Contact', | |
505 | 'extends_entity_column_value' => NULL, | |
506 | 'extends_entity_column_id' => NULL, | |
507 | 'is_view' => '0', | |
508 | 'is_multiple' => '0', | |
509 | 'option_group_id' => NULL, | |
510 | 'date_format' => NULL, | |
511 | 'time_format' => NULL, | |
512 | 'is_required' => '1', | |
513 | 'table_name' => 'civicrm_value_custom_group_' . $customGroupID, | |
514 | 'column_name' => 'enter_text_here_' . $this->getCustomFieldID('text'), | |
515 | 'where' => 'civicrm_value_custom_group_' . $customGroupID . '.enter_text_here_' . $this->getCustomFieldID('text'), | |
516 | 'extends_table' => 'civicrm_contact', | |
517 | 'search_table' => 'contact_a', | |
8392a043 | 518 | ], |
519 | $this->getCustomFieldName('select_string') => [ | |
cef2e96c | 520 | 'name' => $this->getCustomFieldName('select_string'), |
8392a043 | 521 | 'type' => 2, |
522 | 'title' => 'Pick Color', | |
523 | 'headerPattern' => '//', | |
524 | 'import' => 1, | |
525 | 'custom_field_id' => $this->getCustomFieldID('select_string'), | |
526 | 'options_per_line' => NULL, | |
527 | 'text_length' => NULL, | |
528 | 'data_type' => 'String', | |
529 | 'html_type' => 'Select', | |
530 | 'is_search_range' => '0', | |
cef2e96c | 531 | 'id' => $this->getCustomFieldID('select_string'), |
532 | 'label' => 'Pick Color', | |
533 | 'groupTitle' => 'Custom Group', | |
534 | 'default_value' => NULL, | |
535 | 'custom_group_id' => $customGroupID, | |
536 | 'extends' => 'Contact', | |
537 | 'extends_entity_column_value' => NULL, | |
538 | 'extends_entity_column_id' => NULL, | |
539 | 'is_view' => '0', | |
540 | 'is_multiple' => '0', | |
541 | 'option_group_id' => $this->callAPISuccessGetValue('CustomField', ['id' => $this->getCustomFieldID('select_string'), 'return' => 'option_group_id']), | |
542 | 'date_format' => NULL, | |
543 | 'time_format' => NULL, | |
544 | 'is_required' => '1', | |
545 | 'table_name' => 'civicrm_value_custom_group_' . $customGroupID, | |
546 | 'column_name' => 'pick_color_' . $this->getCustomFieldID('select_string'), | |
547 | 'where' => 'civicrm_value_custom_group_' . $customGroupID . '.pick_color_' . $this->getCustomFieldID('select_string'), | |
548 | 'extends_table' => 'civicrm_contact', | |
549 | 'search_table' => 'contact_a', | |
550 | 'pseudoconstant' => [ | |
551 | 'optionGroupName' => $this->callAPISuccessGetValue('CustomField', ['id' => $this->getCustomFieldID('select_string'), 'return' => 'option_group_id.name']), | |
552 | 'optionEditPath' => 'civicrm/admin/options/' . $this->callAPISuccessGetValue('CustomField', ['id' => $this->getCustomFieldID('select_string'), 'return' => 'option_group_id.name']), | |
553 | ], | |
8392a043 | 554 | ], |
555 | $this->getCustomFieldName('select_date') => [ | |
556 | 'name' => $this->getCustomFieldName('select_date'), | |
557 | 'type' => 4, | |
558 | 'title' => 'test_date', | |
559 | 'headerPattern' => '//', | |
560 | 'import' => 1, | |
561 | 'custom_field_id' => $this->getCustomFieldID('select_date'), | |
562 | 'options_per_line' => NULL, | |
563 | 'text_length' => NULL, | |
564 | 'data_type' => 'Date', | |
565 | 'html_type' => 'Select Date', | |
566 | 'is_search_range' => '0', | |
567 | 'date_format' => 'mm/dd/yy', | |
568 | 'time_format' => '1', | |
cef2e96c | 569 | 'id' => $this->getCustomFieldID('select_date'), |
570 | 'label' => 'test_date', | |
571 | 'groupTitle' => 'Custom Group', | |
572 | 'default_value' => '20090711', | |
573 | 'custom_group_id' => $customGroupID, | |
574 | 'extends' => 'Contact', | |
575 | 'extends_entity_column_value' => NULL, | |
576 | 'extends_entity_column_id' => NULL, | |
577 | 'is_view' => '0', | |
578 | 'is_multiple' => '0', | |
579 | 'option_group_id' => NULL, | |
580 | 'is_required' => '0', | |
581 | 'table_name' => 'civicrm_value_custom_group_' . $customGroupID, | |
582 | 'column_name' => 'test_date_' . $this->getCustomFieldID('select_date'), | |
583 | 'where' => 'civicrm_value_custom_group_' . $customGroupID . '.test_date_' . $this->getCustomFieldID('select_date'), | |
584 | 'extends_table' => 'civicrm_contact', | |
585 | 'search_table' => 'contact_a', | |
8392a043 | 586 | ], |
587 | $this->getCustomFieldName('link') => [ | |
588 | 'name' => $this->getCustomFieldName('link'), | |
589 | 'type' => 2, | |
590 | 'title' => 'test_link', | |
591 | 'headerPattern' => '//', | |
592 | 'import' => 1, | |
593 | 'custom_field_id' => $this->getCustomFieldID('link'), | |
594 | 'options_per_line' => NULL, | |
595 | 'text_length' => NULL, | |
596 | 'data_type' => 'Link', | |
597 | 'html_type' => 'Link', | |
598 | 'is_search_range' => '0', | |
cef2e96c | 599 | 'id' => $this->getCustomFieldID('link'), |
600 | 'label' => 'test_link', | |
601 | 'groupTitle' => 'Custom Group', | |
602 | 'default_value' => 'http://civicrm.org', | |
603 | 'custom_group_id' => $customGroupID, | |
604 | 'extends' => 'Contact', | |
605 | 'extends_entity_column_value' => NULL, | |
606 | 'extends_entity_column_id' => NULL, | |
607 | 'is_view' => '0', | |
608 | 'is_multiple' => '0', | |
609 | 'option_group_id' => NULL, | |
610 | 'date_format' => NULL, | |
611 | 'time_format' => NULL, | |
612 | 'is_required' => '1', | |
613 | 'table_name' => 'civicrm_value_custom_group_' . $customGroupID, | |
614 | 'column_name' => 'test_link_' . $this->getCustomFieldID('link'), | |
615 | 'where' => 'civicrm_value_custom_group_' . $customGroupID . '.test_link_' . $this->getCustomFieldID('link'), | |
616 | 'extends_table' => 'civicrm_contact', | |
617 | 'search_table' => 'contact_a', | |
8392a043 | 618 | ], |
619 | ]; | |
620 | $this->assertEquals($expected, CRM_Core_BAO_CustomField::getFieldsForImport()); | |
621 | } | |
622 | ||
6a488035 | 623 | } |