Refactored out of CRM_Core_PseudoConstant: IMProvider(), pcm(), preferredCommunicatio...
[civicrm-core.git] / tests / phpunit / CRM / Core / PseudoConstantTest.php
CommitLineData
887a4028
A
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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
28require_once 'CiviTest/CiviUnitTestCase.php';
29
30/**
31 * Tests for linking to resource files
32 */
33class CRM_Core_PseudoConstantTest extends CiviUnitTestCase {
34 function get_info() {
35 return array(
36 'name' => 'PseudoConstant',
37 'description' => 'Tests for pseudoconstant option values',
38 'group' => 'Core',
39 );
40 }
41
42 function setUp() {
43 parent::setUp();
44 }
45
398f49ab
AS
46 function testOptionValues() {
47 // We'll test these daoName/field combinations.
48 // array[DAO Name] = properties, where properties can be:
49 // - fieldName: the SQL column name within the DAO table.
50 // - sample: Any one value which is expected in the list of option values.
51 // - max: integer (default = 10) maximum number of option values expected.
52 $fields = array(
cbf48754
AS
53 'CRM_Project_DAO_Task' => array(
54 array(
55 'fieldName' => 'priority_id',
56 'sample' => 'Urgent',
57 ),
58 ),
59 'CRM_Activity_DAO_Activity' => array(
60 array(
61 'fieldName' => 'priority_id',
62 'sample' => 'Urgent',
63 ),
64 ),
65 'CRM_Core_DAO_MailSettings' => array(
66 array(
67 'fieldName' => 'protocol',
68 'sample' => 'Localdir',
69 ),
70 ),
71 'CRM_Core_DAO_Mapping' => array(
72 array(
73 'fieldName' => 'mapping_type_id',
74 'sample' => 'Search Builder',
75 'max' => 15,
76 ),
77 ),
78 'CRM_Pledge_DAO_Pledge' => array(
79 array(
80 'fieldName' => 'honor_type_id',
81 'sample' => 'In Honor of',
82 ),
83 ),
84 'CRM_Contribute_DAO_Contribution' => array(
85 array(
86 'fieldName' => 'honor_type_id',
87 'sample' => 'In Honor of',
88 ),
89 ),
e7e657f0
AS
90 'CRM_Core_DAO_Phone' => array(
91 array(
92 'fieldName' => 'phone_type_id',
93 'sample' => 'Phone',
94 ),
95 array(
96 'fieldName' => 'location_type_id',
97 'sample' => 'Home',
98 ),
99 ),
100 'CRM_Core_DAO_Email' => array(
101 array(
102 'fieldName' => 'location_type_id',
103 'sample' => 'Home',
104 ),
105 ),
106 'CRM_Core_DAO_Address' => array(
107 array(
108 'fieldName' => 'location_type_id',
109 'sample' => 'Home',
110 ),
111 ),
cbf48754
AS
112 'CRM_Core_DAO_Website' => array(
113 array(
114 'fieldName' => 'website_type_id',
115 'sample' => 'Facebook',
116 ),
117 ),
118 'CRM_Core_DAO_MappingField' => array(
119 array(
120 'fieldName' => 'website_type_id',
121 'sample' => 'Facebook',
122 ),
e7e657f0
AS
123 array(
124 'fieldName' => 'im_provider_id',
125 'sample' => 'Yahoo',
126 ),
cbf48754 127 ),
398f49ab
AS
128 'CRM_Contact_DAO_Contact' => array(
129 array(
130 'fieldName' => 'prefix_id',
131 'sample' => 'Mr.',
132 ),
133 array(
134 'fieldName' => 'suffix_id',
135 'sample' => 'Sr.',
136 ),
137 array(
138 'fieldName' => 'gender_id',
139 'sample' => 'Male',
140 ),
398f49ab 141 array(
e7e657f0
AS
142 'fieldName' => 'preferred_communication_method',
143 'sample' => 'Postal Mail',
398f49ab
AS
144 ),
145 ),
e7e657f0 146 'CRM_Batch_DAO_Batch' => array(
398f49ab 147 array(
e7e657f0
AS
148 'fieldName' => 'type_id',
149 'sample' => 'Membership',
398f49ab 150 ),
398f49ab 151 array(
e7e657f0
AS
152 'fieldName' => 'status_id',
153 'sample' => 'Reopened',
398f49ab 154 ),
cbf48754 155 array(
e7e657f0
AS
156 'fieldName' => 'mode_id',
157 'sample' => 'Automatic Batch',
cbf48754
AS
158 ),
159 ),
e7e657f0 160 'CRM_Core_DAO_IM' => array(
cbf48754 161 array(
e7e657f0
AS
162 'fieldName' => 'provider_id',
163 'sample' => 'Yahoo',
cbf48754
AS
164 ),
165 ),
887a4028 166 );
398f49ab
AS
167
168 foreach ($fields as $daoName => $daoFields) {
169 foreach ($daoFields as $field) {
a42ef93c 170 $message = "DAO name: '{$daoName}', field: '{$field['fieldName']}'";
398f49ab
AS
171
172 // Ensure sample value is contained in the returned optionValues.
173 $optionValues = CRM_Core_PseudoConstant::get($daoName, $field['fieldName']);
174 $this->assertContains($field['sample'], $optionValues, $message);
175
176 // Ensure count of optionValues is not extraordinarily high.
177 $max = CRM_Utils_Array::value('max', $field, 10);
178 $this->assertLessThanOrEqual($max, count($optionValues), $message);
179 }
180 }
887a4028
A
181 }
182}