4 * Class CRM_Core_BAO_CustomValueTableTest
7 class CRM_Core_BAO_CustomValueTableTest
extends CiviUnitTestCase
{
9 public function setUp() {
14 * Test store function for country.
16 public function testStoreCountry() {
18 $contactID = $this->individualCreate();
19 $customGroup = $this->customGroupCreate();
21 'custom_group_id' => $customGroup['id'],
22 'data_type' => 'Country',
23 'html_type' => 'Select Country',
24 'default_value' => '',
27 $customField = $this->customFieldCreate($fields);
30 $customField['id'] => [
33 'custom_field_id' => $customField['id'],
34 'custom_group_id' => $customGroup['id'],
35 'table_name' => $customGroup['values'][$customGroup['id']]['table_name'],
36 'column_name' => $customField['values'][$customField['id']]['column_name'],
41 CRM_Core_BAO_CustomValueTable
::store($params, 'civicrm_contact', $contactID);
43 $this->customFieldDelete($customField['id']);
44 $this->customGroupDelete($customGroup['id']);
45 $this->contactDelete($contactID);
49 * Test store function for file.
51 public function testStoreFile() {
52 $contactID = $this->individualCreate();
53 $file = $this->callAPISuccess('File', 'create', ['uri' => 'dummy_data']);
54 $customGroup = $this->customGroupCreate();
56 'custom_group_id' => $customGroup['id'],
57 'data_type' => 'File',
58 'html_type' => 'File',
59 'default_value' => '',
62 $customField = $this->customFieldCreate($fields);
65 $customField['id'] => [
66 'value' => 'i/contact_house.png',
68 'custom_field_id' => $customField['id'],
69 'custom_group_id' => $customGroup['id'],
70 'table_name' => $customGroup['values'][$customGroup['id']]['table_name'],
71 'column_name' => $customField['values'][$customField['id']]['column_name'],
72 'file_id' => $file['id'],
76 CRM_Core_BAO_CustomValueTable
::store($params, 'civicrm_contact', $contactID);
78 $this->customFieldDelete($customField['id']);
79 $this->customGroupDelete($customGroup['id']);
80 $this->contactDelete($contactID);
84 * Test store function for state province.
86 public function testStoreStateProvince() {
87 $contactID = $this->individualCreate();
88 $customGroup = $this->customGroupCreate();
90 'custom_group_id' => $customGroup['id'],
91 'data_type' => 'StateProvince',
92 'html_type' => 'Select State/Province',
93 'default_value' => '',
96 $customField = $this->customFieldCreate($fields);
99 $customField['id'] => [
101 'type' => 'StateProvince',
102 'custom_field_id' => $customField['id'],
103 'custom_group_id' => $customGroup['id'],
104 'table_name' => $customGroup['values'][$customGroup['id']]['table_name'],
105 'column_name' => $customField['values'][$customField['id']]['column_name'],
110 CRM_Core_BAO_CustomValueTable
::store($params, 'civicrm_contact', $contactID);
112 $this->customFieldDelete($customField['id']);
113 $this->customGroupDelete($customGroup['id']);
114 $this->contactDelete($contactID);
118 * Test store function for date.
120 public function testStoreDate() {
122 $contactID = $this->individualCreate();
123 $customGroup = $this->customGroupCreate();
125 'custom_group_id' => $customGroup['id'],
126 'data_type' => 'Date',
127 'html_type' => 'Select Date',
128 'default_value' => '',
131 $customField = $this->customFieldCreate($fields);
134 $customField['id'] => [
135 'value' => '20080608000000',
137 'custom_field_id' => $customField['id'],
138 'custom_group_id' => $customGroup['id'],
139 'table_name' => $customGroup['values'][$customGroup['id']]['table_name'],
140 'column_name' => $customField['values'][$customField['id']]['column_name'],
145 CRM_Core_BAO_CustomValueTable
::store($params, 'civicrm_contact', $contactID);
147 $this->customFieldDelete($customField['id']);
148 $this->customGroupDelete($customGroup['id']);
149 $this->contactDelete($contactID);
153 * Test store function for rich text editor.
155 public function testStoreRichTextEditor() {
157 $contactID = $this->individualCreate();
158 $customGroup = $this->customGroupCreate();
160 'custom_group_id' => $customGroup['id'],
161 'html_type' => 'RichTextEditor',
162 'data_type' => 'Memo',
165 $customField = $this->customFieldCreate($fields);
168 $customField['id'] => [
169 'value' => '<p><strong>This is a <u>test</u></p>',
171 'custom_field_id' => $customField['id'],
172 'custom_group_id' => $customGroup['id'],
173 'table_name' => $customGroup['values'][$customGroup['id']]['table_name'],
174 'column_name' => $customField['values'][$customField['id']]['column_name'],
179 CRM_Core_BAO_CustomValueTable
::store($params, 'civicrm_contact', $contactID);
181 $this->customFieldDelete($customField['id']);
182 $this->customGroupDelete($customGroup['id']);
183 $this->contactDelete($contactID);
187 * Test getEntityValues function for stored value.
189 public function testGetEntityValues() {
192 $contactID = $this->individualCreate();
193 $customGroup = $this->customGroupCreate(['extends' => 'Individual']);
195 'custom_group_id' => $customGroup['id'],
196 'html_type' => 'RichTextEditor',
197 'data_type' => 'Memo',
200 $customField = $this->customFieldCreate($fields);
203 $customField['id'] => [
204 'value' => '<p><strong>This is a <u>test</u></p>',
206 'custom_field_id' => $customField['id'],
207 'custom_group_id' => $customGroup['id'],
208 'table_name' => $customGroup['values'][$customGroup['id']]['table_name'],
209 'column_name' => $customField['values'][$customField['id']]['column_name'],
214 CRM_Core_BAO_CustomValueTable
::store($params, 'civicrm_contact', $contactID);
216 $entityValues = CRM_Core_BAO_CustomValueTable
::getEntityValues($contactID, 'Individual');
218 $this->assertEquals($entityValues[$customField['id']], '<p><strong>This is a <u>test</u></p>',
219 'Checking same for returned value.'
221 $this->customFieldDelete($customField['id']);
222 $this->customGroupDelete($customGroup['id']);
223 $this->contactDelete($contactID);
226 public function testCustomGroupMultiple() {
228 $contactID = $this->individualCreate();
229 $customGroup = $this->customGroupCreate();
232 'custom_group_id' => $customGroup['id'],
233 'data_type' => 'String',
234 'html_type' => 'Text',
237 $customField = $this->customFieldCreate($fields);
240 'entityID' => $contactID,
241 'custom_' . $customField['id'] . '_-1' => 'First String',
243 $error = CRM_Core_BAO_CustomValueTable
::setValues($params);
246 'entityID' => $contactID,
247 'custom_' . $customField['id'] => 1,
249 $result = CRM_Core_BAO_CustomValueTable
::getValues($newParams);
251 $this->assertEquals($params['custom_' . $customField['id'] . '_-1'], $result['custom_' . $customField['id']]);
252 $this->assertEquals($params['entityID'], $result['entityID']);
254 $this->customFieldDelete($customField['id']);
255 $this->customGroupDelete($customGroup['id']);
256 $this->contactDelete($contactID);