Merge pull request #17282 from agh1/calendar-icons
[civicrm-core.git] / tests / phpunit / CRM / Core / PseudoConstantTest.php
CommitLineData
887a4028
A
1<?php
2/*
3 +--------------------------------------------------------------------+
7d61e75f 4 | Copyright CiviCRM LLC. All rights reserved. |
887a4028 5 | |
7d61e75f
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
887a4028 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
887a4028 11
887a4028 12/**
2158332a 13 * Tests for pseudoconstant retrieval
acb109b7 14 * @group headless
887a4028
A
15 */
16class CRM_Core_PseudoConstantTest extends CiviUnitTestCase {
887a4028 17
00be9182 18 public function setUp() {
887a4028 19 parent::setUp();
68fd48d9
CW
20
21 $this->loadAllFixtures();
22
23 CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase');
874bbfa9 24 CRM_Core_BAO_ConfigSetting::enableComponent('CiviCampaign');
887a4028
A
25 }
26
cd43c5e3
AS
27 /**
28 * Assure CRM_Core_PseudoConstant::get() is working properly for a range of
29 * DAO fields having a <pseudoconstant> tag in the XML schema.
30 */
00be9182 31 public function testOptionValues() {
bd44e0df 32
29494eef 33 // Create a custom field group for testing.
bd44e0df 34 $custom_group_name = md5(microtime());
9099cab3 35 $api_params = [
bd44e0df
AS
36 'title' => $custom_group_name,
37 'extends' => 'Individual',
38 'is_active' => TRUE,
9099cab3 39 ];
874bbfa9 40 $result = civicrm_api3('customGroup', 'create', $api_params);
cd43c5e3 41
deceed83 42 // Add a custom field to the above field group.
9099cab3 43 $api_params = [
deceed83
CW
44 'debug' => 1,
45 'custom_group_id' => $result['id'],
46 'label' => $custom_group_name,
47 'html_type' => 'Select',
48 'data_type' => 'String',
49 'is_active' => TRUE,
9099cab3
CW
50 'option_values' => [
51 [
92915c55
TO
52 'label' => 'Foo',
53 'value' => 'foo',
54 'is_active' => 1,
55 'weight' => 0,
9099cab3
CW
56 ],
57 ],
58 ];
874bbfa9 59 $result = civicrm_api3('custom_field', 'create', $api_params);
deceed83
CW
60 $customFieldId = $result['id'];
61
62 // Create a Contact Group for testing.
29494eef 63 $group_name = md5(microtime());
9099cab3 64 $api_params = [
29494eef
AS
65 'title' => $group_name,
66 'is_active' => TRUE,
9099cab3 67 ];
874bbfa9 68 $result = civicrm_api3('group', 'create', $api_params);
6d68a4cb
CW
69
70 // Create a PaymentProcessor for testing.
71 $pp_name = md5(microtime());
9099cab3 72 $api_params = [
6d68a4cb 73 'domain_id' => 1,
97502bac 74 'payment_processor_type_id' => 'Dummy',
6d68a4cb
CW
75 'name' => $pp_name,
76 'user_name' => $pp_name,
77 'class_name' => 'Payment_Dummy',
78 'url_site' => 'https://test.com/',
79 'url_recur' => 'https://test.com/',
80 'is_active' => 1,
9099cab3 81 ];
874bbfa9
CW
82 $result = civicrm_api3('payment_processor', 'create', $api_params);
83
84 // Create a Campaign for testing.
85 $campaign_name = md5(microtime());
9099cab3 86 $api_params = [
874bbfa9
CW
87 'title' => $campaign_name,
88 'is_active' => TRUE,
89 'status_id' => 2,
9099cab3 90 ];
874bbfa9
CW
91 $result = civicrm_api3('campaign', 'create', $api_params);
92
93 // Create a membership type for testing.
94 $membership_type = md5(microtime());
9099cab3 95 $api_params = [
874bbfa9
CW
96 'name' => $membership_type,
97 'is_active' => TRUE,
98 'financial_type_id' => 1,
99 'domain_id' => 1,
100 'member_of_contact_id' => 1,
101 'duration_unit' => 'day',
102 'duration_interval' => 1,
5b1b8db2 103 'period_type' => 'rolling',
9099cab3 104 ];
874bbfa9 105 $result = civicrm_api3('membership_type', 'create', $api_params);
48b420d7 106
874bbfa9
CW
107 // Create a contribution page for testing.
108 $contribution_page = md5(microtime());
9099cab3 109 $api_params = [
874bbfa9
CW
110 'title' => $contribution_page,
111 'is_active' => TRUE,
112 'financial_type_id' => 1,
9099cab3 113 ];
874bbfa9 114 $result = civicrm_api3('contribution_page', 'create', $api_params);
29494eef 115
cd43c5e3 116 /**
091fe2a8 117 * daoName/field combinations to test
cd43c5e3
AS
118 * Format: array[DAO Name] = $properties, where properties is an array whose
119 * named members can be:
091fe2a8
CW
120 * - fieldName: the SQL column name within the DAO table.
121 * - sample: Any one value which is expected in the list of option values.
122 * - exclude: Any one value which should not be in the list.
874bbfa9 123 * - max: integer (default = 20) maximum number of option values expected.
091fe2a8 124 */
9099cab3
CW
125 $fields = [
126 'CRM_ACL_DAO_ACL' => [
127 [
874bbfa9
CW
128 'fieldName' => 'operation',
129 'sample' => 'View',
9099cab3
CW
130 ],
131 ],
132 'CRM_Contact_DAO_Group' => [
133 [
874bbfa9
CW
134 'fieldName' => 'visibility',
135 'sample' => 'Public Pages',
9099cab3
CW
136 ],
137 ],
138 'CRM_Contact_DAO_GroupContact' => [
139 [
29494eef
AS
140 'fieldName' => 'group_id',
141 'sample' => $group_name,
9099cab3
CW
142 ],
143 [
874bbfa9
CW
144 'fieldName' => 'status',
145 'sample' => 'Added',
9099cab3
CW
146 ],
147 ],
148 'CRM_Contact_DAO_GroupContactCache' => [
149 [
29494eef
AS
150 'fieldName' => 'group_id',
151 'sample' => $group_name,
9099cab3
CW
152 ],
153 ],
154 'CRM_Contact_DAO_GroupOrganization' => [
155 [
29494eef
AS
156 'fieldName' => 'group_id',
157 'sample' => $group_name,
9099cab3
CW
158 ],
159 ],
160 'CRM_Contact_DAO_SubscriptionHistory' => [
161 [
29494eef
AS
162 'fieldName' => 'group_id',
163 'sample' => $group_name,
9099cab3
CW
164 ],
165 [
874bbfa9
CW
166 'fieldName' => 'method',
167 'sample' => 'Web',
9099cab3
CW
168 ],
169 [
874bbfa9
CW
170 'fieldName' => 'status',
171 'sample' => 'Added',
9099cab3
CW
172 ],
173 ],
174 'CRM_Core_DAO_Cache' => [
175 [
874bbfa9
CW
176 'fieldName' => 'component_id',
177 'sample' => 'CiviMail',
9099cab3
CW
178 ],
179 ],
180 'CRM_Contact_DAO_ACLContactCache' => [
181 [
874bbfa9
CW
182 'fieldName' => 'operation',
183 'sample' => 'All',
9099cab3
CW
184 ],
185 ],
186 'CRM_Core_DAO_Setting' => [
187 [
874bbfa9
CW
188 'fieldName' => 'component_id',
189 'sample' => 'CiviMail',
9099cab3
CW
190 ],
191 ],
192 'CRM_Core_DAO_ActionSchedule' => [
193 [
29494eef
AS
194 'fieldName' => 'group_id',
195 'sample' => $group_name,
9099cab3
CW
196 ],
197 [
874bbfa9
CW
198 'fieldName' => 'start_action_unit',
199 'sample' => 'hour',
9099cab3
CW
200 ],
201 [
874bbfa9
CW
202 'fieldName' => 'repetition_frequency_unit',
203 'sample' => 'hour',
9099cab3
CW
204 ],
205 [
874bbfa9
CW
206 'fieldName' => 'end_frequency_unit',
207 'sample' => 'hour',
9099cab3
CW
208 ],
209 [
874bbfa9
CW
210 'fieldName' => 'mode',
211 'sample' => 'Email',
9099cab3
CW
212 ],
213 ],
214 'CRM_Dedupe_DAO_RuleGroup' => [
215 [
874bbfa9
CW
216 'fieldName' => 'contact_type',
217 'sample' => 'Individual',
9099cab3
CW
218 ],
219 [
874bbfa9
CW
220 'fieldName' => 'used',
221 'sample' => 'Unsupervised',
9099cab3
CW
222 ],
223 ],
224 'CRM_Activity_DAO_Activity' => [
225 [
4080e473 226 'fieldName' => 'activity_type_id',
a38a89fc 227 'sample' => 'Email',
68fd48d9 228 'max' => 100,
9099cab3
CW
229 ],
230 [
4080e473
AS
231 'fieldName' => 'status_id',
232 'sample' => 'Scheduled',
9099cab3
CW
233 ],
234 [
6d68a4cb
CW
235 'fieldName' => 'priority_id',
236 'sample' => 'Urgent',
9099cab3
CW
237 ],
238 [
3f3a3ba0
CW
239 'fieldName' => 'engagement_level',
240 'sample' => '1',
9099cab3
CW
241 ],
242 [
3f3a3ba0
CW
243 'fieldName' => 'medium_id',
244 'sample' => 'Phone',
9099cab3
CW
245 ],
246 [
874bbfa9
CW
247 'fieldName' => 'campaign_id',
248 'sample' => $campaign_name,
9099cab3
CW
249 ],
250 ],
251 'CRM_Campaign_DAO_Campaign' => [
252 [
874bbfa9
CW
253 'fieldName' => 'campaign_type_id',
254 'sample' => 'Constituent Engagement',
255 'max' => 50,
9099cab3
CW
256 ],
257 [
3f3a3ba0
CW
258 'fieldName' => 'status_id',
259 'sample' => 'Completed',
260 'max' => 50,
9099cab3
CW
261 ],
262 ],
263 'CRM_Campaign_DAO_Survey' => [
264 [
874bbfa9
CW
265 'fieldName' => 'campaign_id',
266 'sample' => $campaign_name,
9099cab3
CW
267 ],
268 [
4080e473 269 'fieldName' => 'activity_type_id',
a38a89fc 270 'sample' => 'Phone Call',
68fd48d9 271 'max' => 100,
9099cab3
CW
272 ],
273 ],
274 'CRM_Campaign_DAO_CampaignGroup' => [
275 [
874bbfa9
CW
276 'fieldName' => 'campaign_id',
277 'sample' => $campaign_name,
9099cab3
CW
278 ],
279 [
874bbfa9
CW
280 'fieldName' => 'group_type',
281 'sample' => 'Include',
9099cab3
CW
282 ],
283 ],
284 'CRM_Contact_DAO_RelationshipType' => [
285 [
874bbfa9
CW
286 'fieldName' => 'contact_type_a',
287 'sample' => 'Individual',
9099cab3
CW
288 ],
289 [
874bbfa9
CW
290 'fieldName' => 'contact_type_b',
291 'sample' => 'Organization',
9099cab3
CW
292 ],
293 ],
294 'CRM_Event_DAO_ParticipantStatusType' => [
295 [
874bbfa9
CW
296 'fieldName' => 'class',
297 'sample' => 'Waiting',
9099cab3
CW
298 ],
299 [
4080e473
AS
300 'fieldName' => 'visibility_id',
301 'sample' => 'Public',
9099cab3
CW
302 ],
303 ],
304 'CRM_Price_DAO_LineItem' => [
305 [
874bbfa9
CW
306 'fieldName' => 'financial_type_id',
307 'sample' => 'Donation',
9099cab3
CW
308 ],
309 ],
310 'CRM_Price_DAO_PriceField' => [
311 [
874bbfa9
CW
312 'fieldName' => 'html_type',
313 'sample' => 'Select',
9099cab3
CW
314 ],
315 [
4080e473
AS
316 'fieldName' => 'visibility_id',
317 'sample' => 'Public',
9099cab3
CW
318 ],
319 ],
320 'CRM_Price_DAO_PriceFieldValue' => [
321 [
874bbfa9
CW
322 'fieldName' => 'financial_type_id',
323 'sample' => 'Donation',
9099cab3
CW
324 ],
325 ],
326 'CRM_Price_DAO_PriceSet' => [
327 [
874bbfa9
CW
328 'fieldName' => 'domain_id',
329 'sample' => 'Default Domain Name',
9099cab3
CW
330 ],
331 [
874bbfa9
CW
332 'fieldName' => 'extends',
333 'sample' => 'CiviEvent',
9099cab3
CW
334 ],
335 [
874bbfa9
CW
336 'fieldName' => 'financial_type_id',
337 'sample' => 'Donation',
9099cab3
CW
338 ],
339 ],
340 'CRM_Financial_DAO_EntityFinancialAccount' => [
341 [
7611ae71
AS
342 'fieldName' => 'financial_account_id',
343 'sample' => 'Member Dues',
9099cab3
CW
344 ],
345 [
7611ae71
AS
346 'fieldName' => 'account_relationship',
347 'sample' => 'Income Account is',
9099cab3
CW
348 ],
349 ],
350 'CRM_Financial_DAO_FinancialItem' => [
351 [
7611ae71
AS
352 'fieldName' => 'status_id',
353 'sample' => 'Partially paid',
9099cab3
CW
354 ],
355 [
7611ae71
AS
356 'fieldName' => 'financial_account_id',
357 'sample' => 'Accounts Receivable',
9099cab3
CW
358 ],
359 [
6d68a4cb 360 'fieldName' => 'currency',
9099cab3 361 'sample' => ['USD' => 'US Dollar'],
6d68a4cb 362 'max' => 200,
9099cab3
CW
363 ],
364 ],
365 'CRM_Financial_DAO_FinancialTrxn' => [
366 [
7611ae71
AS
367 'fieldName' => 'from_financial_account_id',
368 'sample' => 'Accounts Receivable',
9099cab3
CW
369 ],
370 [
7611ae71
AS
371 'fieldName' => 'to_financial_account_id',
372 'sample' => 'Accounts Receivable',
9099cab3
CW
373 ],
374 [
6d68a4cb 375 'fieldName' => 'currency',
9099cab3 376 'sample' => ['USD' => 'US Dollar'],
6d68a4cb 377 'max' => 200,
9099cab3
CW
378 ],
379 [
874bbfa9
CW
380 'fieldName' => 'payment_instrument_id',
381 'sample' => 'Check',
9099cab3
CW
382 ],
383 ],
384 'CRM_Financial_DAO_FinancialAccount' => [
385 [
7611ae71
AS
386 'fieldName' => 'financial_account_type_id',
387 'sample' => 'Cost of Sales',
9099cab3
CW
388 ],
389 ],
390 'CRM_Financial_DAO_PaymentProcessor' => [
391 [
874bbfa9
CW
392 'fieldName' => 'domain_id',
393 'sample' => 'Default Domain Name',
9099cab3
CW
394 ],
395 ],
396 'CRM_Financial_BAO_PaymentProcessorType' => [
397 [
874bbfa9
CW
398 'fieldName' => 'billing_mode',
399 'sample' => 'form',
9099cab3
CW
400 ],
401 ],
402 'CRM_Core_DAO_UFField' => [
403 [
bd44e0df
AS
404 'fieldName' => 'uf_group_id',
405 'sample' => 'Name and Address',
9099cab3
CW
406 ],
407 [
874bbfa9 408 'fieldName' => 'visibility',
cd5e5125 409 'sample' => 'Expose Publicly',
9099cab3
CW
410 ],
411 ],
412 'CRM_Core_DAO_UFJoin' => [
413 [
bd44e0df
AS
414 'fieldName' => 'uf_group_id',
415 'sample' => 'Name and Address',
9099cab3
CW
416 ],
417 ],
418 'CRM_Core_DAO_UFMatch' => [
419 [
874bbfa9
CW
420 'fieldName' => 'domain_id',
421 'sample' => 'Default Domain Name',
9099cab3
CW
422 ],
423 ],
424 'CRM_Core_DAO_Job' => [
425 [
874bbfa9
CW
426 'fieldName' => 'domain_id',
427 'sample' => 'Default Domain Name',
9099cab3
CW
428 ],
429 [
874bbfa9
CW
430 'fieldName' => 'run_frequency',
431 'sample' => 'Daily',
9099cab3
CW
432 ],
433 ],
434 'CRM_Core_DAO_JobLog' => [
435 [
874bbfa9
CW
436 'fieldName' => 'domain_id',
437 'sample' => 'Default Domain Name',
9099cab3
CW
438 ],
439 ],
440 'CRM_Contribute_DAO_ContributionSoft' => [
441 [
bd44e0df 442 'fieldName' => 'currency',
9099cab3 443 'sample' => ['USD' => 'US Dollar'],
bd44e0df 444 'max' => 200,
9099cab3
CW
445 ],
446 [
d9136461 447 'fieldName' => 'soft_credit_type_id',
448 'sample' => 'In Honor of',
9099cab3
CW
449 ],
450 ],
451 'CRM_Contribute_DAO_Product' => [
452 [
bd44e0df 453 'fieldName' => 'currency',
9099cab3 454 'sample' => ['USD' => 'US Dollar'],
bd44e0df 455 'max' => 200,
9099cab3
CW
456 ],
457 [
874bbfa9
CW
458 'fieldName' => 'financial_type_id',
459 'sample' => 'Donation',
9099cab3
CW
460 ],
461 [
874bbfa9
CW
462 'fieldName' => 'period_type',
463 'sample' => 'Rolling',
9099cab3
CW
464 ],
465 [
874bbfa9
CW
466 'fieldName' => 'duration_unit',
467 'sample' => 'Day',
9099cab3
CW
468 ],
469 [
874bbfa9
CW
470 'fieldName' => 'frequency_unit',
471 'sample' => 'Day',
9099cab3
CW
472 ],
473 ],
474 'CRM_Contribute_DAO_ContributionProduct' => [
475 [
874bbfa9
CW
476 'fieldName' => 'financial_type_id',
477 'sample' => 'Donation',
9099cab3
CW
478 ],
479 ],
480 'CRM_Contribute_DAO_ContributionRecur' => [
481 [
bd44e0df 482 'fieldName' => 'currency',
9099cab3 483 'sample' => ['USD' => 'US Dollar'],
bd44e0df 484 'max' => 200,
9099cab3
CW
485 ],
486 [
874bbfa9
CW
487 'fieldName' => 'frequency_unit',
488 'sample' => 'month',
9099cab3
CW
489 ],
490 [
874bbfa9
CW
491 'fieldName' => 'contribution_status_id',
492 'sample' => 'Completed',
9099cab3
CW
493 ],
494 [
874bbfa9
CW
495 'fieldName' => 'financial_type_id',
496 'sample' => 'Donation',
9099cab3
CW
497 ],
498 [
874bbfa9
CW
499 'fieldName' => 'payment_instrument_id',
500 'sample' => 'Check',
9099cab3
CW
501 ],
502 [
874bbfa9
CW
503 'fieldName' => 'campaign_id',
504 'sample' => $campaign_name,
9099cab3
CW
505 ],
506 ],
507 'CRM_Pledge_DAO_PledgePayment' => [
508 [
bd44e0df 509 'fieldName' => 'currency',
9099cab3 510 'sample' => ['USD' => 'US Dollar'],
bd44e0df 511 'max' => 200,
9099cab3
CW
512 ],
513 ],
514 'CRM_Pledge_DAO_Pledge' => [
515 [
bd44e0df 516 'fieldName' => 'currency',
9099cab3 517 'sample' => ['USD' => 'US Dollar'],
bd44e0df 518 'max' => 200,
9099cab3
CW
519 ],
520 [
874bbfa9
CW
521 'fieldName' => 'financial_type_id',
522 'sample' => 'Donation',
9099cab3
CW
523 ],
524 [
874bbfa9
CW
525 'fieldName' => 'frequency_unit',
526 'sample' => 'month',
9099cab3
CW
527 ],
528 [
874bbfa9
CW
529 'fieldName' => 'campaign_id',
530 'sample' => $campaign_name,
9099cab3
CW
531 ],
532 ],
533 'CRM_PCP_DAO_PCP' => [
534 [
bd44e0df 535 'fieldName' => 'currency',
9099cab3 536 'sample' => ['USD' => 'US Dollar'],
bd44e0df 537 'max' => 200,
9099cab3
CW
538 ],
539 [
6d68a4cb
CW
540 'fieldName' => 'status_id',
541 'sample' => 'Approved',
9099cab3
CW
542 ],
543 ],
544 'CRM_Core_DAO_CustomField' => [
545 [
cd43c5e3
AS
546 'fieldName' => 'custom_group_id',
547 'sample' => $custom_group_name,
9099cab3
CW
548 ],
549 [
874bbfa9
CW
550 'fieldName' => 'data_type',
551 'sample' => 'Alphanumeric',
9099cab3
CW
552 ],
553 [
874bbfa9
CW
554 'fieldName' => 'html_type',
555 'sample' => 'Select Date',
9099cab3
CW
556 ],
557 ],
558 'CRM_Core_DAO_CustomGroup' => [
559 [
874bbfa9
CW
560 'fieldName' => 'style',
561 'sample' => 'Inline',
9099cab3
CW
562 ],
563 ],
564 'CRM_Core_DAO_Dashboard' => [
565 [
874bbfa9
CW
566 'fieldName' => 'domain_id',
567 'sample' => 'Default Domain Name',
9099cab3
CW
568 ],
569 ],
570 'CRM_Core_DAO_Tag' => [
571 [
874bbfa9
CW
572 'fieldName' => 'used_for',
573 'sample' => 'Contacts',
9099cab3
CW
574 ],
575 ],
576 'CRM_Core_DAO_EntityTag' => [
577 [
cd43c5e3
AS
578 'fieldName' => 'tag_id',
579 'sample' => 'Government Entity',
9099cab3
CW
580 ],
581 ],
582 'CRM_Core_DAO_Extension' => [
583 [
874bbfa9
CW
584 'fieldName' => 'type',
585 'sample' => 'Module',
9099cab3
CW
586 ],
587 ],
588 'CRM_Core_DAO_OptionValue' => [
589 [
874bbfa9 590 'fieldName' => 'option_group_id',
17f78bae 591 'sample' => 'Gender',
874bbfa9 592 'max' => 200,
9099cab3
CW
593 ],
594 [
8f785c9e
AS
595 'fieldName' => 'component_id',
596 'sample' => 'CiviContribute',
9099cab3
CW
597 ],
598 [
874bbfa9
CW
599 'fieldName' => 'domain_id',
600 'sample' => 'Default Domain Name',
9099cab3
CW
601 ],
602 ],
603 'CRM_Core_DAO_MailSettings' => [
604 [
874bbfa9
CW
605 'fieldName' => 'domain_id',
606 'sample' => 'Default Domain Name',
9099cab3
CW
607 ],
608 [
cbf48754
AS
609 'fieldName' => 'protocol',
610 'sample' => 'Localdir',
9099cab3
CW
611 ],
612 ],
613 'CRM_Core_DAO_Managed' => [
614 [
874bbfa9
CW
615 'fieldName' => 'cleanup',
616 'sample' => 'Always',
9099cab3
CW
617 ],
618 ],
619 'CRM_Core_DAO_Mapping' => [
620 [
cbf48754
AS
621 'fieldName' => 'mapping_type_id',
622 'sample' => 'Search Builder',
9099cab3
CW
623 ],
624 ],
625 'CRM_Core_DAO_Navigation' => [
626 [
874bbfa9
CW
627 'fieldName' => 'domain_id',
628 'sample' => 'Default Domain Name',
9099cab3
CW
629 ],
630 ],
631 'CRM_Core_DAO_Phone' => [
632 [
e7e657f0
AS
633 'fieldName' => 'phone_type_id',
634 'sample' => 'Phone',
9099cab3
CW
635 ],
636 [
e7e657f0
AS
637 'fieldName' => 'location_type_id',
638 'sample' => 'Home',
9099cab3
CW
639 ],
640 ],
641 'CRM_Core_DAO_PrintLabel' => [
642 [
874bbfa9
CW
643 'fieldName' => 'label_format_name',
644 'sample' => 'Avery 5395',
9099cab3
CW
645 ],
646 [
874bbfa9
CW
647 'fieldName' => 'label_type_id',
648 'sample' => 'Event Badge',
9099cab3
CW
649 ],
650 ],
651 'CRM_Core_DAO_Email' => [
652 [
e7e657f0
AS
653 'fieldName' => 'location_type_id',
654 'sample' => 'Home',
9099cab3
CW
655 ],
656 ],
657 'CRM_Core_DAO_Address' => [
658 [
e7e657f0
AS
659 'fieldName' => 'location_type_id',
660 'sample' => 'Home',
9099cab3
CW
661 ],
662 ],
663 'CRM_Core_DAO_Website' => [
664 [
cbf48754
AS
665 'fieldName' => 'website_type_id',
666 'sample' => 'Facebook',
9099cab3
CW
667 ],
668 ],
669 'CRM_Core_DAO_WordReplacement' => [
670 [
874bbfa9
CW
671 'fieldName' => 'match_type',
672 'sample' => 'Exact Match',
9099cab3
CW
673 ],
674 [
874bbfa9
CW
675 'fieldName' => 'domain_id',
676 'sample' => 'Default Domain Name',
9099cab3
CW
677 ],
678 ],
679 'CRM_Core_DAO_MappingField' => [
680 [
cbf48754
AS
681 'fieldName' => 'website_type_id',
682 'sample' => 'Facebook',
9099cab3
CW
683 ],
684 [
e7e657f0
AS
685 'fieldName' => 'im_provider_id',
686 'sample' => 'Yahoo',
9099cab3
CW
687 ],
688 [
874bbfa9
CW
689 'fieldName' => 'operator',
690 'sample' => '=',
9099cab3
CW
691 ],
692 ],
693 'CRM_Contact_DAO_Contact' => [
694 [
398f49ab
AS
695 'fieldName' => 'prefix_id',
696 'sample' => 'Mr.',
9099cab3
CW
697 ],
698 [
398f49ab
AS
699 'fieldName' => 'suffix_id',
700 'sample' => 'Sr.',
9099cab3
CW
701 ],
702 [
398f49ab
AS
703 'fieldName' => 'gender_id',
704 'sample' => 'Male',
9099cab3
CW
705 ],
706 [
e7e657f0
AS
707 'fieldName' => 'preferred_communication_method',
708 'sample' => 'Postal Mail',
9099cab3
CW
709 ],
710 [
091fe2a8
CW
711 'fieldName' => 'contact_type',
712 'sample' => 'Individual',
713 'exclude' => 'Team',
9099cab3
CW
714 ],
715 [
091fe2a8
CW
716 'fieldName' => 'contact_sub_type',
717 'sample' => 'Team',
718 'exclude' => 'Individual',
9099cab3
CW
719 ],
720 [
c0c9cd82 721 'fieldName' => 'preferred_language',
9099cab3 722 'sample' => ['en_US' => 'English (United States)'],
c0c9cd82 723 'max' => 250,
9099cab3
CW
724 ],
725 [
874bbfa9
CW
726 'fieldName' => 'preferred_mail_format',
727 'sample' => 'Text',
9099cab3
CW
728 ],
729 [
874bbfa9
CW
730 'fieldName' => 'communication_style_id',
731 'sample' => 'Formal',
9099cab3
CW
732 ],
733 [
deceed83 734 'fieldName' => "custom_$customFieldId",
9099cab3 735 'sample' => ['foo' => 'Foo'],
deceed83 736 'max' => 1,
9099cab3
CW
737 ],
738 ],
739 'CRM_Batch_DAO_Batch' => [
740 [
e7e657f0
AS
741 'fieldName' => 'type_id',
742 'sample' => 'Membership',
9099cab3
CW
743 ],
744 [
e7e657f0
AS
745 'fieldName' => 'status_id',
746 'sample' => 'Reopened',
9099cab3
CW
747 ],
748 [
e7e657f0
AS
749 'fieldName' => 'mode_id',
750 'sample' => 'Automatic Batch',
9099cab3
CW
751 ],
752 [
874bbfa9
CW
753 'fieldName' => 'payment_instrument_id',
754 'sample' => 'Check',
9099cab3
CW
755 ],
756 ],
757 'CRM_Core_DAO_IM' => [
758 [
e7e657f0
AS
759 'fieldName' => 'provider_id',
760 'sample' => 'Yahoo',
9099cab3
CW
761 ],
762 [
874bbfa9
CW
763 'fieldName' => 'location_type_id',
764 'sample' => 'Home',
9099cab3
CW
765 ],
766 ],
767 'CRM_Event_DAO_Participant' => [
768 [
2158332a
CW
769 'fieldName' => 'status_id',
770 'sample' => 'Registered',
9099cab3
CW
771 ],
772 [
2158332a
CW
773 'fieldName' => 'role_id',
774 'sample' => 'Speaker',
9099cab3
CW
775 ],
776 [
6d68a4cb 777 'fieldName' => 'fee_currency',
9099cab3 778 'sample' => ['USD' => 'US Dollar'],
6d68a4cb 779 'max' => 200,
9099cab3
CW
780 ],
781 [
874bbfa9
CW
782 'fieldName' => 'campaign_id',
783 'sample' => $campaign_name,
9099cab3
CW
784 ],
785 ],
786 'CRM_Event_DAO_Event' => [
787 [
2158332a
CW
788 'fieldName' => 'event_type_id',
789 'sample' => 'Fundraiser',
9099cab3
CW
790 ],
791 [
874bbfa9
CW
792 'fieldName' => 'participant_listing_id',
793 'sample' => 'Name and Email',
9099cab3
CW
794 ],
795 [
6d68a4cb
CW
796 'fieldName' => 'payment_processor',
797 'sample' => $pp_name,
9099cab3
CW
798 ],
799 [
6d68a4cb
CW
800 'fieldName' => 'financial_type_id',
801 'sample' => 'Donation',
9099cab3
CW
802 ],
803 [
874bbfa9
CW
804 'fieldName' => 'default_role_id',
805 'sample' => 'Attendee',
9099cab3
CW
806 ],
807 [
6d68a4cb 808 'fieldName' => 'currency',
9099cab3 809 'sample' => ['USD' => 'US Dollar'],
6d68a4cb 810 'max' => 200,
9099cab3
CW
811 ],
812 [
874bbfa9
CW
813 'fieldName' => 'campaign_id',
814 'sample' => $campaign_name,
9099cab3
CW
815 ],
816 ],
817 'CRM_Core_DAO_Menu' => [
818 [
874bbfa9
CW
819 'fieldName' => 'domain_id',
820 'sample' => 'Default Domain Name',
9099cab3
CW
821 ],
822 [
874bbfa9
CW
823 'fieldName' => 'component_id',
824 'sample' => 'CiviMember',
9099cab3
CW
825 ],
826 ],
827 'CRM_Member_DAO_Membership' => [
828 [
874bbfa9
CW
829 'fieldName' => 'membership_type_id',
830 'sample' => $membership_type,
9099cab3
CW
831 ],
832 [
f899561e
CW
833 'fieldName' => 'status_id',
834 'sample' => 'New',
9099cab3
CW
835 ],
836 [
874bbfa9
CW
837 'fieldName' => 'campaign_id',
838 'sample' => $campaign_name,
9099cab3
CW
839 ],
840 ],
841 'CRM_Member_DAO_MembershipStatus' => [
842 [
874bbfa9
CW
843 'fieldName' => 'start_event',
844 'sample' => 'start date',
9099cab3
CW
845 ],
846 [
874bbfa9
CW
847 'fieldName' => 'end_event',
848 'sample' => 'member since',
9099cab3
CW
849 ],
850 [
874bbfa9
CW
851 'fieldName' => 'start_event_adjust_unit',
852 'sample' => 'month',
9099cab3
CW
853 ],
854 [
874bbfa9
CW
855 'fieldName' => 'end_event_adjust_unit',
856 'sample' => 'year',
9099cab3
CW
857 ],
858 ],
859 'CRM_Member_DAO_MembershipType' => [
860 [
874bbfa9
CW
861 'fieldName' => 'visibility',
862 'sample' => 'Public',
9099cab3
CW
863 ],
864 [
874bbfa9
CW
865 'fieldName' => 'domain_id',
866 'sample' => 'Default Domain Name',
9099cab3
CW
867 ],
868 [
874bbfa9
CW
869 'fieldName' => 'financial_type_id',
870 'sample' => 'Donation',
9099cab3
CW
871 ],
872 [
874bbfa9
CW
873 'fieldName' => 'duration_unit',
874 'sample' => 'lifetime',
9099cab3
CW
875 ],
876 [
874bbfa9
CW
877 'fieldName' => 'period_type',
878 'sample' => 'Rolling',
9099cab3
CW
879 ],
880 ],
881 'CRM_Mailing_DAO_Mailing' => [
882 [
6ce01b02
CW
883 'fieldName' => 'approval_status_id',
884 'sample' => 'Approved',
9099cab3
CW
885 ],
886 [
874bbfa9
CW
887 'fieldName' => 'domain_id',
888 'sample' => 'Default Domain Name',
9099cab3
CW
889 ],
890 [
874bbfa9
CW
891 'fieldName' => 'visibility',
892 'sample' => 'Public Pages',
9099cab3
CW
893 ],
894 [
874bbfa9
CW
895 'fieldName' => 'campaign_id',
896 'sample' => $campaign_name,
9099cab3
CW
897 ],
898 ],
899 'CRM_Mailing_DAO_MailingComponent' => [
900 [
874bbfa9
CW
901 'fieldName' => 'component_type',
902 'sample' => 'Header',
9099cab3
CW
903 ],
904 ],
905 'CRM_Mailing_DAO_MailingGroup' => [
906 [
874bbfa9
CW
907 'fieldName' => 'group_type',
908 'sample' => 'Include',
9099cab3
CW
909 ],
910 ],
911 'CRM_Mailing_DAO_MailingJob' => [
912 [
874bbfa9
CW
913 'fieldName' => 'status',
914 'sample' => 'Scheduled',
9099cab3
CW
915 ],
916 ],
917 'CRM_Mailing_Event_DAO_Bounce' => [
918 [
874bbfa9
CW
919 'fieldName' => 'bounce_type_id',
920 'sample' => 'Invalid',
9099cab3
CW
921 ],
922 ],
923 'CRM_Mailing_Event_DAO_Subscribe' => [
924 [
874bbfa9
CW
925 'fieldName' => 'group_id',
926 'sample' => $group_name,
9099cab3
CW
927 ],
928 ],
929 'CRM_Grant_DAO_Grant' => [
930 [
fb1fd730 931 'fieldName' => 'status_id',
d7867ce7 932 'sample' => 'Approved for Payment',
9099cab3
CW
933 ],
934 [
fb1fd730
CW
935 'fieldName' => 'grant_type_id',
936 'sample' => 'Emergency',
9099cab3
CW
937 ],
938 [
6d68a4cb 939 'fieldName' => 'currency',
9099cab3 940 'sample' => ['USD' => 'US Dollar'],
6d68a4cb 941 'max' => 200,
9099cab3
CW
942 ],
943 [
874bbfa9
CW
944 'fieldName' => 'financial_type_id',
945 'sample' => 'Donation',
9099cab3
CW
946 ],
947 ],
948 'CRM_Contribute_DAO_Contribution' => [
949 [
6d68a4cb
CW
950 'fieldName' => 'payment_instrument_id',
951 'sample' => 'Credit Card',
9099cab3
CW
952 ],
953 [
6d68a4cb
CW
954 'fieldName' => 'financial_type_id',
955 'sample' => 'Donation',
9099cab3
CW
956 ],
957 [
6d68a4cb 958 'fieldName' => 'currency',
9099cab3 959 'sample' => ['USD' => 'US Dollar'],
6d68a4cb 960 'max' => 200,
9099cab3
CW
961 ],
962 [
6d68a4cb
CW
963 'fieldName' => 'contribution_status_id',
964 'sample' => 'Completed',
9099cab3
CW
965 ],
966 [
874bbfa9
CW
967 'fieldName' => 'contribution_page_id',
968 'sample' => $contribution_page,
9099cab3
CW
969 ],
970 [
874bbfa9
CW
971 'fieldName' => 'campaign_id',
972 'sample' => $campaign_name,
9099cab3
CW
973 ],
974 ],
975 'CRM_Contribute_DAO_PremiumsProduct' => [
976 [
874bbfa9
CW
977 'fieldName' => 'financial_type_id',
978 'sample' => 'Donation',
9099cab3
CW
979 ],
980 ],
981 'CRM_Contribute_DAO_ContributionPage' => [
982 [
6d68a4cb
CW
983 'fieldName' => 'payment_processor',
984 'sample' => $pp_name,
9099cab3
CW
985 ],
986 [
6d68a4cb
CW
987 'fieldName' => 'financial_type_id',
988 'sample' => 'Donation',
9099cab3
CW
989 ],
990 [
6d68a4cb 991 'fieldName' => 'currency',
9099cab3 992 'sample' => ['USD' => 'US Dollar'],
6d68a4cb 993 'max' => 200,
9099cab3
CW
994 ],
995 [
874bbfa9
CW
996 'fieldName' => 'campaign_id',
997 'sample' => $campaign_name,
9099cab3
CW
998 ],
999 ],
1000 'CRM_Case_DAO_Case' => [
1001 [
3f3a3ba0
CW
1002 'fieldName' => 'status_id',
1003 'sample' => 'Ongoing',
9099cab3
CW
1004 ],
1005 [
68fd48d9
CW
1006 'fieldName' => 'case_type_id',
1007 'sample' => 'Housing Support',
9099cab3
CW
1008 ],
1009 ],
1010 'CRM_Report_DAO_ReportInstance' => [
1011 [
874bbfa9
CW
1012 'fieldName' => 'domain_id',
1013 'sample' => 'Default Domain Name',
9099cab3
CW
1014 ],
1015 ],
1016 ];
398f49ab
AS
1017
1018 foreach ($fields as $daoName => $daoFields) {
1019 foreach ($daoFields as $field) {
a42ef93c 1020 $message = "DAO name: '{$daoName}', field: '{$field['fieldName']}'";
398f49ab 1021
6d68a4cb 1022 $optionValues = $daoName::buildOptions($field['fieldName']);
091fe2a8
CW
1023 $this->assertNotEmpty($optionValues, $message);
1024
1025 // Ensure sample value is contained in the returned optionValues.
c0c9cd82
CW
1026 if (!is_array($field['sample'])) {
1027 $this->assertContains($field['sample'], $optionValues, $message);
1028 }
1029 // If sample is an array, we check keys and values
1030 else {
1031 foreach ($field['sample'] as $key => $value) {
1032 $this->assertArrayHasKey($key, $optionValues, $message);
1033 $this->assertEquals(CRM_Utils_Array::value($key, $optionValues), $value, $message);
1034 }
1035 }
398f49ab 1036
6ce01b02 1037 // Ensure exclude value is not contained in the optionValues
091fe2a8
CW
1038 if (!empty($field['exclude'])) {
1039 $this->assertNotContains($field['exclude'], $optionValues, $message);
1040 }
1041
398f49ab 1042 // Ensure count of optionValues is not extraordinarily high.
874bbfa9 1043 $max = CRM_Utils_Array::value('max', $field, 20);
398f49ab
AS
1044 $this->assertLessThanOrEqual($max, count($optionValues), $message);
1045 }
1046 }
887a4028 1047 }
091fe2a8 1048
00be9182 1049 public function testContactTypes() {
9099cab3 1050 $byName = [
091fe2a8
CW
1051 'Individual' => 'Individual',
1052 'Household' => 'Household',
1053 'Organization' => 'Organization',
9099cab3
CW
1054 ];
1055 $byId = [
091fe2a8
CW
1056 1 => 'Individual',
1057 2 => 'Household',
1058 3 => 'Organization',
9099cab3 1059 ];
a1ef51e2 1060 // By default this should return an array keyed by name
c0c9cd82 1061 $result = CRM_Contact_DAO_Contact::buildOptions('contact_type');
091fe2a8
CW
1062 $this->assertEquals($byName, $result);
1063 // But we can also fetch by ID
9099cab3 1064 $result = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'contact_type', [
39b959db
SL
1065 'keyColumn' => 'id',
1066 'labelColumn' => 'name',
9099cab3 1067 ]);
091fe2a8
CW
1068 $this->assertEquals($byId, $result);
1069 // Make sure flip param works
9099cab3 1070 $result = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'contact_type', [
39b959db
SL
1071 'keyColumn' => 'id',
1072 'labelColumn' => 'name',
1073 'flip' => TRUE,
9099cab3 1074 ]);
091fe2a8
CW
1075 $this->assertEquals(array_flip($byId), $result);
1076 }
96025800 1077
56a7794d
SL
1078 public function testGetTaxRates() {
1079 $contact = $this->createLoggedInUser();
9099cab3 1080 $financialType = $this->callAPISuccess('financial_type', 'create', [
56a7794d
SL
1081 'name' => 'Test taxable financial Type',
1082 'is_reserved' => 0,
1083 'is_active' => 1,
9099cab3
CW
1084 ]);
1085 $financialAccount = $this->callAPISuccess('financial_account', 'create', [
39b959db
SL
1086 'name' => 'Test Tax financial account ',
1087 'contact_id' => $contact,
1088 'financial_account_type_id' => 2,
1089 'is_tax' => 1,
1090 'tax_rate' => 5.00,
1091 'is_reserved' => 0,
1092 'is_active' => 1,
1093 'is_default' => 0,
9099cab3 1094 ]);
56a7794d
SL
1095 $financialTypeId = $financialType['id'];
1096 $financialAccountId = $financialAccount['id'];
9099cab3 1097 $financialAccountParams = [
56a7794d
SL
1098 'entity_table' => 'civicrm_financial_type',
1099 'entity_id' => $financialTypeId,
1100 'account_relationship' => 10,
1101 'financial_account_id' => $financialAccountId,
9099cab3 1102 ];
56a7794d
SL
1103 CRM_Financial_BAO_FinancialTypeAccount::add($financialAccountParams);
1104 $taxRates = CRM_Core_PseudoConstant::getTaxRates();
1105 $this->assertEquals('5.00', $taxRates[$financialType['id']]);
1106 }
1107
887a4028 1108}