4 * Class CRM_Core_BAO_CustomValueTableTest
7 class CRM_Core_BAO_CustomValueTableTest
extends CiviUnitTestCase
{
10 * Test store function for country.
12 public function testStoreCountry() {
14 $contactID = $this->individualCreate();
15 $customGroup = $this->customGroupCreate();
17 'custom_group_id' => $customGroup['id'],
18 'data_type' => 'Country',
19 'html_type' => 'Select Country',
20 'default_value' => '',
23 $customField = $this->customFieldCreate($fields);
26 $customField['id'] => [
29 'custom_field_id' => $customField['id'],
30 'custom_group_id' => $customGroup['id'],
31 'table_name' => $customGroup['values'][$customGroup['id']]['table_name'],
32 'column_name' => $customField['values'][$customField['id']]['column_name'],
37 CRM_Core_BAO_CustomValueTable
::store($params, 'civicrm_contact', $contactID);
39 $this->customFieldDelete($customField['id']);
40 $this->customGroupDelete($customGroup['id']);
41 $this->contactDelete($contactID);
45 * Test store function for file.
47 public function testStoreFile() {
48 $contactID = $this->individualCreate();
49 $file = $this->callAPISuccess('File', 'create', ['uri' => 'dummy_data']);
50 $customGroup = $this->customGroupCreate();
52 'custom_group_id' => $customGroup['id'],
53 'data_type' => 'File',
54 'html_type' => 'File',
55 'default_value' => '',
58 $customField = $this->customFieldCreate($fields);
61 $customField['id'] => [
62 'value' => 'i/contact_house.png',
64 'custom_field_id' => $customField['id'],
65 'custom_group_id' => $customGroup['id'],
66 'table_name' => $customGroup['values'][$customGroup['id']]['table_name'],
67 'column_name' => $customField['values'][$customField['id']]['column_name'],
68 'file_id' => $file['id'],
72 CRM_Core_BAO_CustomValueTable
::store($params, 'civicrm_contact', $contactID);
74 $this->customFieldDelete($customField['id']);
75 $this->customGroupDelete($customGroup['id']);
76 $this->contactDelete($contactID);
80 * Test store function for state province.
82 public function testStoreStateProvince() {
83 $contactID = $this->individualCreate();
84 $customGroup = $this->customGroupCreate();
86 'custom_group_id' => $customGroup['id'],
87 'data_type' => 'StateProvince',
88 'html_type' => 'Select',
89 'default_value' => '',
92 $customField = $this->customFieldCreate($fields);
95 $customField['id'] => [
97 'type' => 'StateProvince',
98 'custom_field_id' => $customField['id'],
99 'custom_group_id' => $customGroup['id'],
100 'table_name' => $customGroup['values'][$customGroup['id']]['table_name'],
101 'column_name' => $customField['values'][$customField['id']]['column_name'],
106 CRM_Core_BAO_CustomValueTable
::store($params, 'civicrm_contact', $contactID);
108 $this->customFieldDelete($customField['id']);
109 $this->customGroupDelete($customGroup['id']);
110 $this->contactDelete($contactID);
114 * Test store function for date.
116 public function testStoreDate() {
118 $contactID = $this->individualCreate();
119 $customGroup = $this->customGroupCreate();
121 'custom_group_id' => $customGroup['id'],
122 'data_type' => 'Date',
123 'html_type' => 'Select Date',
124 'default_value' => '',
127 $customField = $this->customFieldCreate($fields);
130 $customField['id'] => [
131 'value' => '20080608000000',
133 'custom_field_id' => $customField['id'],
134 'custom_group_id' => $customGroup['id'],
135 'table_name' => $customGroup['values'][$customGroup['id']]['table_name'],
136 'column_name' => $customField['values'][$customField['id']]['column_name'],
141 CRM_Core_BAO_CustomValueTable
::store($params, 'civicrm_contact', $contactID);
143 $this->customFieldDelete($customField['id']);
144 $this->customGroupDelete($customGroup['id']);
145 $this->contactDelete($contactID);
149 * Test store function for rich text editor.
151 public function testStoreRichTextEditor() {
153 $contactID = $this->individualCreate();
154 $customGroup = $this->customGroupCreate();
156 'custom_group_id' => $customGroup['id'],
157 'html_type' => 'RichTextEditor',
158 'data_type' => 'Memo',
161 $customField = $this->customFieldCreate($fields);
164 $customField['id'] => [
165 'value' => '<p><strong>This is a <u>test</u></p>',
167 'custom_field_id' => $customField['id'],
168 'custom_group_id' => $customGroup['id'],
169 'table_name' => $customGroup['values'][$customGroup['id']]['table_name'],
170 'column_name' => $customField['values'][$customField['id']]['column_name'],
175 CRM_Core_BAO_CustomValueTable
::store($params, 'civicrm_contact', $contactID);
177 $this->customFieldDelete($customField['id']);
178 $this->customGroupDelete($customGroup['id']);
179 $this->contactDelete($contactID);
183 * Test getEntityValues function for stored value.
185 public function testGetEntityValues() {
188 $contactID = $this->individualCreate();
189 $customGroup = $this->customGroupCreate(['extends' => 'Individual']);
191 'custom_group_id' => $customGroup['id'],
192 'html_type' => 'RichTextEditor',
193 'data_type' => 'Memo',
196 $customField = $this->customFieldCreate($fields);
199 $customField['id'] => [
200 'value' => '<p><strong>This is a <u>test</u></p>',
202 'custom_field_id' => $customField['id'],
203 'custom_group_id' => $customGroup['id'],
204 'table_name' => $customGroup['values'][$customGroup['id']]['table_name'],
205 'column_name' => $customField['values'][$customField['id']]['column_name'],
210 CRM_Core_BAO_CustomValueTable
::store($params, 'civicrm_contact', $contactID);
212 $entityValues = CRM_Core_BAO_CustomValueTable
::getEntityValues($contactID, 'Individual');
214 $this->assertEquals($entityValues[$customField['id']], '<p><strong>This is a <u>test</u></p>',
215 'Checking same for returned value.'
217 $this->customFieldDelete($customField['id']);
218 $this->customGroupDelete($customGroup['id']);
219 $this->contactDelete($contactID);
222 public function testCustomGroupMultiple() {
224 $contactID = $this->individualCreate();
225 $customGroup = $this->customGroupCreate();
228 'custom_group_id' => $customGroup['id'],
229 'data_type' => 'String',
230 'html_type' => 'Text',
233 $customField = $this->customFieldCreate($fields);
236 'entityID' => $contactID,
237 'custom_' . $customField['id'] . '_-1' => 'First String',
239 $error = CRM_Core_BAO_CustomValueTable
::setValues($params);
242 'entityID' => $contactID,
243 'custom_' . $customField['id'] => 1,
245 $result = CRM_Core_BAO_CustomValueTable
::getValues($newParams);
247 $this->assertEquals($params['custom_' . $customField['id'] . '_-1'], $result['custom_' . $customField['id']]);
248 $this->assertEquals($params['entityID'], $result['entityID']);
250 $this->customFieldDelete($customField['id']);
251 $this->customGroupDelete($customGroup['id']);
252 $this->contactDelete($contactID);