3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 field options
33 class CRM_Core_FieldOptionsTest
extends CiviUnitTestCase
{
39 'name' => 'FieldOptions',
40 'description' => 'Tests for field-specific option values',
50 * Assure CRM_Core_PseudoConstant::get() is working properly for a range of
51 * DAO fields having a <pseudoconstant> tag in the XML schema.
53 function testOptionValues() {
55 * baoName/field combinations to test
56 * Format: array[BAO Name] = $properties, where properties is an array whose
57 * named members can be:
58 * - fieldName: the SQL column name within the DAO table.
59 * - sample: Any one value which is expected in the list of option values.
60 * - context: Context to pass
61 * - props: Object properties to pass
62 * - exclude: Any one value which should not be in the list.
63 * - max: integer (default = 10) maximum number of option values expected.
66 'CRM_Core_BAO_Address' => array(
68 'fieldName' => 'state_province_id',
69 'sample' => 'California',
71 'props' => array('country_id' => 1228),
74 'CRM_Contact_BAO_Contact' => array(
76 'fieldName' => 'contact_sub_type',
78 'exclude' => 'Organization',
79 'props' => array('contact_type' => 'Organization'),
84 foreach ($fields as $baoName => $baoFields) {
85 foreach ($baoFields as $field) {
86 $message = "BAO name: '{$baoName}', field: '{$field['fieldName']}'";
88 $props = CRM_Utils_Array
::value('props', $field, array());
89 $optionValues = $baoName::buildOptions($field['fieldName'], 'create', $props);
90 $this->assertNotEmpty($optionValues, $message);
92 // Ensure sample value is contained in the returned optionValues.
93 $this->assertContains($field['sample'], $optionValues, $message);
96 if (!empty($field['exclude'])) {
97 $this->assertNotContains($field['exclude'], $optionValues, $message);
100 // Ensure count of optionValues is not extraordinarily high.
101 $max = CRM_Utils_Array
::value('max', $field, 10);
102 $this->assertLessThanOrEqual($max, count($optionValues), $message);