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