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