Commit | Line | Data |
---|---|---|
dc86f881 CW |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
dc86f881 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
dc86f881 CW |
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 | */ |
dc86f881 CW |
27 | |
28 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
29 | ||
30 | /** | |
2158332a | 31 | * Tests for field options |
dc86f881 CW |
32 | */ |
33 | class CRM_Core_FieldOptionsTest extends CiviUnitTestCase { | |
00be9182 | 34 | public function setUp() { |
dc86f881 CW |
35 | parent::setUp(); |
36 | } | |
37 | ||
38 | /** | |
39 | * Assure CRM_Core_PseudoConstant::get() is working properly for a range of | |
40 | * DAO fields having a <pseudoconstant> tag in the XML schema. | |
41 | */ | |
00be9182 | 42 | public function testOptionValues() { |
dc86f881 CW |
43 | /** |
44 | * baoName/field combinations to test | |
45 | * Format: array[BAO Name] = $properties, where properties is an array whose | |
46 | * named members can be: | |
47 | * - fieldName: the SQL column name within the DAO table. | |
48 | * - sample: Any one value which is expected in the list of option values. | |
49 | * - context: Context to pass | |
50 | * - props: Object properties to pass | |
51 | * - exclude: Any one value which should not be in the list. | |
52 | * - max: integer (default = 10) maximum number of option values expected. | |
53 | */ | |
54 | $fields = array( | |
55 | 'CRM_Core_BAO_Address' => array( | |
56 | array( | |
57 | 'fieldName' => 'state_province_id', | |
58 | 'sample' => 'California', | |
59 | 'max' => 60, | |
60 | 'props' => array('country_id' => 1228), | |
61 | ), | |
62 | ), | |
63 | 'CRM_Contact_BAO_Contact' => array( | |
64 | array( | |
65 | 'fieldName' => 'contact_sub_type', | |
66 | 'sample' => 'Team', | |
67 | 'exclude' => 'Organization', | |
68 | 'props' => array('contact_type' => 'Organization'), | |
69 | ), | |
70 | ), | |
71 | ); | |
72 | ||
73 | foreach ($fields as $baoName => $baoFields) { | |
74 | foreach ($baoFields as $field) { | |
75 | $message = "BAO name: '{$baoName}', field: '{$field['fieldName']}'"; | |
76 | ||
77 | $props = CRM_Utils_Array::value('props', $field, array()); | |
262f0ecc | 78 | $optionValues = $baoName::buildOptions($field['fieldName'], 'create', $props); |
dc86f881 CW |
79 | $this->assertNotEmpty($optionValues, $message); |
80 | ||
81 | // Ensure sample value is contained in the returned optionValues. | |
82 | $this->assertContains($field['sample'], $optionValues, $message); | |
83 | ||
84 | // Exclude test | |
85 | if (!empty($field['exclude'])) { | |
86 | $this->assertNotContains($field['exclude'], $optionValues, $message); | |
87 | } | |
88 | ||
89 | // Ensure count of optionValues is not extraordinarily high. | |
90 | $max = CRM_Utils_Array::value('max', $field, 10); | |
91 | $this->assertLessThanOrEqual($max, count($optionValues), $message); | |
92 | } | |
93 | } | |
94 | } | |
96025800 | 95 | |
dc86f881 | 96 | } |