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