commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / tests / phpunit / CRM / Core / BAO / CustomValueTableTest.php
1 <?php
2 require_once 'CiviTest/CiviUnitTestCase.php';
3 require_once 'CiviTest/Contact.php';
4 require_once 'CiviTest/Custom.php';
5
6 /**
7 * Class CRM_Core_BAO_CustomValueTableTest
8 */
9 class CRM_Core_BAO_CustomValueTableTest extends CiviUnitTestCase {
10
11 public function setUp() {
12 parent::setUp();
13 }
14
15
16 /**
17 * Test store function for country.
18 */
19 public function testStoreCountry() {
20 $params = array();
21 $contactID = Contact::createIndividual();
22 $customGroup = Custom::createGroup($params, 'Individual');
23 $fields = array(
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' => '',
40 ),
41 );
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
51 /**
52 * Test store function for file.
53 */
54 public function atestStoreFile() {
55 $params = array();
56 $contactID = Contact::createIndividual();
57 $customGroup = Custom::createGroup($params, 'Individual');
58 $fields = array(
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,
75 ),
76 );
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
86 /**
87 * Test store function for state province.
88 */
89 public function testStoreStateProvince() {
90 $params = array();
91 $contactID = Contact::createIndividual();
92 $customGroup = Custom::createGroup($params, 'Individual');
93 $fields = array(
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,
110 ),
111 );
112
113 CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID);
114
115 Custom::deleteField($customField);
116 Custom::deleteGroup($customGroup);
117 Contact::delete($contactID);
118 }
119
120 /**
121 * Test store function for date.
122 */
123 public function testStoreDate() {
124 $params = array();
125 $contactID = Contact::createIndividual();
126 $customGroup = Custom::createGroup($params, 'Individual');
127 $fields = array(
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' => '',
144 ),
145 );
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
155 /**
156 * Test store function for rich text editor.
157 */
158 public function testStoreRichTextEditor() {
159 $params = array();
160 $contactID = Contact::createIndividual();
161 $customGroup = Custom::createGroup($params, 'Individual');
162 $fields = array(
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' => '',
179 ),
180 );
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
190 /**
191 * Test getEntityValues function for stored value.
192 */
193 public function testgetEntityValues() {
194
195 $params = array();
196 $contactID = Contact::createIndividual();
197 $customGroup = Custom::createGroup($params, 'Individual');
198 $fields = array(
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' => '',
215 ),
216 );
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
231 public function testCustomGroupMultiple() {
232 $params = array();
233 $contactID = Contact::createIndividual();
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 }
263
264 }