Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
3 | require_once 'CiviTest/Contact.php'; | |
4 | require_once 'CiviTest/Custom.php'; | |
5 | class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase { | |
6 | function get_info() { | |
7 | return array( | |
8 | 'name' => 'Custom Value Table BAOs', | |
9 | 'description' => 'Test all Core_BAO_CustomValueTable methods.', | |
10 | 'group' => 'CiviCRM BAO Tests', | |
11 | ); | |
12 | } | |
13 | ||
14 | function setUp() { | |
15 | parent::setUp(); | |
16 | } | |
17 | ||
18 | ||
19 | /* | |
20 | * function to test store function for country | |
21 | * | |
22 | */ | |
23 | function testStoreCountry() { | |
24 | $params = array(); | |
25 | $contactID = Contact::createIndividual(); | |
26 | $customGroup = Custom::createGroup($params, 'Individual'); | |
27 | $fields = array( | |
28 | 'groupId' => $customGroup->id, | |
29 | 'dataType' => 'Country', | |
30 | 'htmlType' => 'Select Country', | |
31 | ); | |
32 | ||
33 | $customField = Custom::createField($params, $fields); | |
34 | ||
35 | $params[] = array( | |
36 | $customField->id => array( | |
37 | 'value' => 1228, | |
38 | 'type' => 'Country', | |
39 | 'custom_field_id' => $customField->id, | |
40 | 'custom_group_id' => $customGroup->id, | |
41 | 'table_name' => 'civicrm_value_test_group_' . $customGroup->id, | |
42 | 'column_name' => 'test_Country_' . $customField->id, | |
43 | 'file_id' => '', | |
44 | )); | |
45 | ||
46 | CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID); | |
47 | // $this->assertDBCompareValue('CRM_Custom_DAO_CustomValue', ) | |
48 | ||
49 | Custom::deleteField($customField); | |
50 | Custom::deleteGroup($customGroup); | |
51 | Contact::delete($contactID); | |
52 | } | |
53 | ||
54 | /* | |
55 | * function to test store function for file | |
56 | * | |
57 | */ | |
58 | function atestStoreFile() { | |
59 | $params = array(); | |
60 | $contactID = Contact::createIndividual(); | |
61 | $customGroup = Custom::createGroup($params, 'Individual'); | |
62 | $fields = array( | |
63 | 'groupId' => $customGroup->id, | |
64 | 'dataType' => 'File', | |
65 | 'htmlType' => 'File', | |
66 | ); | |
67 | ||
68 | $customField = Custom::createField($params, $fields); | |
69 | ||
70 | $params[] = array( | |
71 | $customField->id => array( | |
72 | 'value' => 'i/contact_house.png', | |
73 | 'type' => 'File', | |
74 | 'custom_field_id' => $customField->id, | |
75 | 'custom_group_id' => $customGroup->id, | |
76 | 'table_name' => 'civicrm_value_test_group_' . $customGroup->id, | |
77 | 'column_name' => 'test_File_' . $customField->id, | |
78 | 'file_id' => 1, | |
79 | )); | |
80 | ||
81 | CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID); | |
82 | // $this->assertDBCompareValue('CRM_Custom_DAO_CustomValue', ) | |
83 | ||
84 | Custom::deleteField($customField); | |
85 | Custom::deleteGroup($customGroup); | |
86 | Contact::delete($contactID); | |
87 | } | |
88 | ||
89 | /* | |
90 | * function to test store function for state province | |
91 | * | |
92 | */ | |
93 | function testStoreStateProvince() { | |
94 | $params = array(); | |
95 | $contactID = Contact::createIndividual(); | |
96 | $customGroup = Custom::createGroup($params, 'Individual'); | |
97 | $fields = array( | |
98 | 'groupId' => $customGroup->id, | |
99 | 'dataType' => 'StateProvince', | |
100 | 'htmlType' => 'Select State/Province', | |
101 | ); | |
102 | ||
103 | $customField = Custom::createField($params, $fields); | |
104 | ||
105 | $params[] = array( | |
106 | $customField->id => array( | |
107 | 'value' => 1029, | |
108 | 'type' => 'StateProvince', | |
109 | 'custom_field_id' => $customField->id, | |
110 | 'custom_group_id' => $customGroup->id, | |
111 | 'table_name' => 'civicrm_value_test_group_' . $customGroup->id, | |
112 | 'column_name' => 'test_StateProvince_' . $customField->id, | |
113 | 'file_id' => 1, | |
114 | )); | |
115 | ||
116 | CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID); | |
117 | // $this->assertDBCompareValue('CRM_Custom_DAO_CustomValue', ) | |
118 | ||
119 | Custom::deleteField($customField); | |
120 | Custom::deleteGroup($customGroup); | |
121 | Contact::delete($contactID); | |
122 | } | |
123 | ||
124 | /* | |
125 | * function to test store function for date | |
126 | * | |
127 | */ | |
128 | function testStoreDate() { | |
129 | $params = array(); | |
130 | $contactID = Contact::createIndividual(); | |
131 | $customGroup = Custom::createGroup($params, 'Individual'); | |
132 | $fields = array( | |
133 | 'groupId' => $customGroup->id, | |
134 | 'dataType' => 'Date', | |
135 | 'htmlType' => 'Select Date', | |
136 | ); | |
137 | ||
138 | $customField = Custom::createField($params, $fields); | |
139 | ||
140 | $params[] = array( | |
141 | $customField->id => array( | |
142 | 'value' => '20080608000000', | |
143 | 'type' => 'Date', | |
144 | 'custom_field_id' => $customField->id, | |
145 | 'custom_group_id' => $customGroup->id, | |
146 | 'table_name' => 'civicrm_value_test_group_' . $customGroup->id, | |
147 | 'column_name' => 'test_Date_' . $customField->id, | |
148 | 'file_id' => '', | |
149 | )); | |
150 | ||
151 | CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID); | |
152 | // $this->assertDBCompareValue('CRM_Custom_DAO_CustomValue', ) | |
153 | ||
154 | Custom::deleteField($customField); | |
155 | Custom::deleteGroup($customGroup); | |
156 | Contact::delete($contactID); | |
157 | } | |
158 | ||
159 | /* | |
160 | * function to test store function for rich text editor | |
161 | * | |
162 | */ | |
163 | function testStoreRichTextEditor() { | |
164 | $params = array(); | |
165 | $contactID = Contact::createIndividual(); | |
166 | $customGroup = Custom::createGroup($params, 'Individual'); | |
167 | $fields = array( | |
168 | 'groupId' => $customGroup->id, | |
169 | 'htmlType' => 'RichTextEditor', | |
170 | 'dataType' => 'Memo', | |
171 | ); | |
172 | ||
173 | $customField = Custom::createField($params, $fields); | |
174 | ||
175 | $params[] = array( | |
176 | $customField->id => array( | |
177 | 'value' => '<p><strong>This is a <u>test</u></p>', | |
178 | 'type' => 'Memo', | |
179 | 'custom_field_id' => $customField->id, | |
180 | 'custom_group_id' => $customGroup->id, | |
181 | 'table_name' => 'civicrm_value_test_group_' . $customGroup->id, | |
182 | 'column_name' => 'test_Memo_' . $customField->id, | |
183 | 'file_id' => '', | |
184 | )); | |
185 | ||
186 | CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID); | |
187 | // $this->assertDBCompareValue('CRM_Custom_DAO_CustomValue', ) | |
188 | ||
189 | Custom::deleteField($customField); | |
190 | Custom::deleteGroup($customGroup); | |
191 | Contact::delete($contactID); | |
192 | } | |
193 | ||
194 | /* | |
195 | * function to test getEntityValues function for stored value | |
196 | * | |
197 | */ | |
198 | function testgetEntityValues() { | |
199 | ||
200 | $params = array(); | |
201 | $contactID = Contact::createIndividual(); | |
202 | $customGroup = Custom::createGroup($params, 'Individual'); | |
203 | $fields = array( | |
204 | 'groupId' => $customGroup->id, | |
205 | 'htmlType' => 'RichTextEditor', | |
206 | 'dataType' => 'Memo', | |
207 | ); | |
208 | ||
209 | $customField = Custom::createField($params, $fields); | |
210 | ||
211 | $params[] = array( | |
212 | $customField->id => array( | |
213 | 'value' => '<p><strong>This is a <u>test</u></p>', | |
214 | 'type' => 'Memo', | |
215 | 'custom_field_id' => $customField->id, | |
216 | 'custom_group_id' => $customGroup->id, | |
217 | 'table_name' => 'civicrm_value_test_group_' . $customGroup->id, | |
218 | 'column_name' => 'test_Memo_' . $customField->id, | |
219 | 'file_id' => '', | |
220 | )); | |
221 | ||
222 | CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID); | |
223 | // $this->assertDBCompareValue('CRM_Custom_DAO_CustomValue', ) | |
224 | ||
225 | $entityValues = CRM_Core_BAO_CustomValueTable::getEntityValues($contactID, 'Individual'); | |
226 | ||
227 | $this->assertEquals($entityValues[$customField->id], '<p><strong>This is a <u>test</u></p>', | |
228 | 'Checking same for returned value.' | |
229 | ); | |
230 | Custom::deleteField($customField); | |
231 | Custom::deleteGroup($customGroup); | |
232 | Contact::delete($contactID); | |
233 | } | |
234 | ||
235 | function testCustomGroupMultiple() { | |
236 | $params = array(); | |
237 | $contactID = Contact::createIndividual(); | |
238 | $customGroup = Custom::createGroup($params, 'Individual'); | |
239 | ||
240 | $fields = array( | |
241 | 'groupId' => $customGroup->id, | |
242 | 'dataType' => 'String', | |
243 | 'htmlType' => 'Text', | |
244 | ); | |
245 | ||
246 | $customField = Custom::createField($params, $fields); | |
247 | ||
248 | $params = array( | |
249 | 'entityID' => $contactID, | |
250 | 'custom_' . $customField->id . '_-1' => 'First String', | |
251 | ); | |
252 | $error = CRM_Core_BAO_CustomValueTable::setValues($params); | |
253 | ||
254 | $newParams = array( | |
255 | 'entityID' => $contactID, | |
256 | 'custom_' . $customField->id => 1, | |
257 | ); | |
258 | $result = CRM_Core_BAO_CustomValueTable::getValues($newParams); | |
259 | ||
260 | $this->assertEquals($params['custom_' . $customField->id . '_-1'], $result['custom_' . $customField->id]); | |
261 | $this->assertEquals($params['entityID'], $result['entityID']); | |
262 | ||
263 | Custom::deleteField($customField); | |
264 | Custom::deleteGroup($customGroup); | |
265 | Contact::delete($contactID); | |
266 | } | |
267 | } | |
268 |