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