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