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