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