4 * Class CRM_Core_BAO_CustomValueTableTest
7 class CRM_Core_BAO_CustomValueTableTest
extends CiviUnitTestCase
{
9 public function setUp() {
15 * Test store function for country.
17 public function testStoreCountry() {
19 $contactID = Contact
::createIndividual();
20 $customGroup = Custom
::createGroup($params, 'Individual');
22 'groupId' => $customGroup->id
,
23 'dataType' => 'Country',
24 'htmlType' => 'Select Country',
27 $customField = Custom
::createField($params, $fields);
30 $customField->id
=> array(
33 'custom_field_id' => $customField->id
,
34 'custom_group_id' => $customGroup->id
,
35 'table_name' => 'civicrm_value_test_group_' . $customGroup->id
,
36 'column_name' => 'test_Country_' . $customField->id
,
41 CRM_Core_BAO_CustomValueTable
::store($params, 'civicrm_contact', $contactID);
42 // $this->assertDBCompareValue('CRM_Custom_DAO_CustomValue', )
44 Custom
::deleteField($customField);
45 Custom
::deleteGroup($customGroup);
46 $this->contactDelete($contactID);
50 * Test store function for file.
52 public function atestStoreFile() {
54 $contactID = Contact
::createIndividual();
55 $customGroup = Custom
::createGroup($params, 'Individual');
57 'groupId' => $customGroup->id
,
62 $customField = Custom
::createField($params, $fields);
65 $customField->id
=> array(
66 'value' => 'i/contact_house.png',
68 'custom_field_id' => $customField->id
,
69 'custom_group_id' => $customGroup->id
,
70 'table_name' => 'civicrm_value_test_group_' . $customGroup->id
,
71 'column_name' => 'test_File_' . $customField->id
,
76 CRM_Core_BAO_CustomValueTable
::store($params, 'civicrm_contact', $contactID);
77 // $this->assertDBCompareValue('CRM_Custom_DAO_CustomValue', )
79 Custom
::deleteField($customField);
80 Custom
::deleteGroup($customGroup);
81 $this->contactDelete($contactID);
85 * Test store function for state province.
87 public function testStoreStateProvince() {
89 $contactID = Contact
::createIndividual();
90 $customGroup = Custom
::createGroup($params, 'Individual');
92 'groupId' => $customGroup->id
,
93 'dataType' => 'StateProvince',
94 'htmlType' => 'Select State/Province',
97 $customField = Custom
::createField($params, $fields);
100 $customField->id
=> array(
102 'type' => 'StateProvince',
103 'custom_field_id' => $customField->id
,
104 'custom_group_id' => $customGroup->id
,
105 'table_name' => 'civicrm_value_test_group_' . $customGroup->id
,
106 'column_name' => 'test_StateProvince_' . $customField->id
,
111 CRM_Core_BAO_CustomValueTable
::store($params, 'civicrm_contact', $contactID);
113 Custom
::deleteField($customField);
114 Custom
::deleteGroup($customGroup);
115 $this->contactDelete($contactID);
119 * Test store function for date.
121 public function testStoreDate() {
123 $contactID = Contact
::createIndividual();
124 $customGroup = Custom
::createGroup($params, 'Individual');
126 'groupId' => $customGroup->id
,
127 'dataType' => 'Date',
128 'htmlType' => 'Select Date',
131 $customField = Custom
::createField($params, $fields);
134 $customField->id
=> array(
135 'value' => '20080608000000',
137 'custom_field_id' => $customField->id
,
138 'custom_group_id' => $customGroup->id
,
139 'table_name' => 'civicrm_value_test_group_' . $customGroup->id
,
140 'column_name' => 'test_Date_' . $customField->id
,
145 CRM_Core_BAO_CustomValueTable
::store($params, 'civicrm_contact', $contactID);
146 // $this->assertDBCompareValue('CRM_Custom_DAO_CustomValue', )
148 Custom
::deleteField($customField);
149 Custom
::deleteGroup($customGroup);
150 $this->contactDelete($contactID);
154 * Test store function for rich text editor.
156 public function testStoreRichTextEditor() {
158 $contactID = Contact
::createIndividual();
159 $customGroup = Custom
::createGroup($params, 'Individual');
161 'groupId' => $customGroup->id
,
162 'htmlType' => 'RichTextEditor',
163 'dataType' => 'Memo',
166 $customField = Custom
::createField($params, $fields);
169 $customField->id
=> array(
170 'value' => '<p><strong>This is a <u>test</u></p>',
172 'custom_field_id' => $customField->id
,
173 'custom_group_id' => $customGroup->id
,
174 'table_name' => 'civicrm_value_test_group_' . $customGroup->id
,
175 'column_name' => 'test_Memo_' . $customField->id
,
180 CRM_Core_BAO_CustomValueTable
::store($params, 'civicrm_contact', $contactID);
181 // $this->assertDBCompareValue('CRM_Custom_DAO_CustomValue', )
183 Custom
::deleteField($customField);
184 Custom
::deleteGroup($customGroup);
185 $this->contactDelete($contactID);
189 * Test getEntityValues function for stored value.
191 public function testgetEntityValues() {
194 $contactID = Contact
::createIndividual();
195 $customGroup = Custom
::createGroup($params, 'Individual');
197 'groupId' => $customGroup->id
,
198 'htmlType' => 'RichTextEditor',
199 'dataType' => 'Memo',
202 $customField = Custom
::createField($params, $fields);
205 $customField->id
=> array(
206 'value' => '<p><strong>This is a <u>test</u></p>',
208 'custom_field_id' => $customField->id
,
209 'custom_group_id' => $customGroup->id
,
210 'table_name' => 'civicrm_value_test_group_' . $customGroup->id
,
211 'column_name' => 'test_Memo_' . $customField->id
,
216 CRM_Core_BAO_CustomValueTable
::store($params, 'civicrm_contact', $contactID);
217 // $this->assertDBCompareValue('CRM_Custom_DAO_CustomValue', )
219 $entityValues = CRM_Core_BAO_CustomValueTable
::getEntityValues($contactID, 'Individual');
221 $this->assertEquals($entityValues[$customField->id
], '<p><strong>This is a <u>test</u></p>',
222 'Checking same for returned value.'
224 Custom
::deleteField($customField);
225 Custom
::deleteGroup($customGroup);
226 $this->contactDelete($contactID);
229 public function testCustomGroupMultiple() {
231 $contactID = Contact
::createIndividual();
232 $customGroup = Custom
::createGroup($params, 'Individual');
235 'groupId' => $customGroup->id
,
236 'dataType' => 'String',
237 'htmlType' => 'Text',
240 $customField = Custom
::createField($params, $fields);
243 'entityID' => $contactID,
244 'custom_' . $customField->id
. '_-1' => 'First String',
246 $error = CRM_Core_BAO_CustomValueTable
::setValues($params);
249 'entityID' => $contactID,
250 'custom_' . $customField->id
=> 1,
252 $result = CRM_Core_BAO_CustomValueTable
::getValues($newParams);
254 $this->assertEquals($params['custom_' . $customField->id
. '_-1'], $result['custom_' . $customField->id
]);
255 $this->assertEquals($params['entityID'], $result['entityID']);
257 Custom
::deleteField($customField);
258 Custom
::deleteGroup($customGroup);
259 $this->contactDelete($contactID);