3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
31 * Tests for linking to resource files
33 class CRM_Core_PseudoConstantTest
extends CiviUnitTestCase
{
36 'name' => 'PseudoConstant',
37 'description' => 'Tests for pseudoconstant option values',
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.
53 'CRM_Project_DAO_Task' => array(
55 'fieldName' => 'priority_id',
59 'CRM_Activity_DAO_Activity' => array(
61 'fieldName' => 'priority_id',
65 'CRM_Core_DAO_MailSettings' => array(
67 'fieldName' => 'protocol',
68 'sample' => 'Localdir',
71 'CRM_Core_DAO_Mapping' => array(
73 'fieldName' => 'mapping_type_id',
74 'sample' => 'Search Builder',
78 'CRM_Pledge_DAO_Pledge' => array(
80 'fieldName' => 'honor_type_id',
81 'sample' => 'In Honor of',
84 'CRM_Contribute_DAO_Contribution' => array(
86 'fieldName' => 'honor_type_id',
87 'sample' => 'In Honor of',
90 'CRM_Core_DAO_Phone' => array(
92 'fieldName' => 'phone_type_id',
96 'fieldName' => 'location_type_id',
100 'CRM_Core_DAO_Email' => array(
102 'fieldName' => 'location_type_id',
106 'CRM_Core_DAO_Address' => array(
108 'fieldName' => 'location_type_id',
112 'CRM_Core_DAO_Website' => array(
114 'fieldName' => 'website_type_id',
115 'sample' => 'Facebook',
118 'CRM_Core_DAO_MappingField' => array(
120 'fieldName' => 'website_type_id',
121 'sample' => 'Facebook',
124 'fieldName' => 'im_provider_id',
128 'CRM_Contact_DAO_Contact' => array(
130 'fieldName' => 'prefix_id',
134 'fieldName' => 'suffix_id',
138 'fieldName' => 'gender_id',
142 'fieldName' => 'preferred_communication_method',
143 'sample' => 'Postal Mail',
146 'CRM_Batch_DAO_Batch' => array(
148 'fieldName' => 'type_id',
149 'sample' => 'Membership',
152 'fieldName' => 'status_id',
153 'sample' => 'Reopened',
156 'fieldName' => 'mode_id',
157 'sample' => 'Automatic Batch',
160 'CRM_Core_DAO_IM' => array(
162 'fieldName' => 'provider_id',
168 foreach ($fields as $daoName => $daoFields) {
169 foreach ($daoFields as $field) {
170 $message = "DAO name: '{$daoName}', field: '{$field['fieldName']}'";
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);
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);