2 require_once 'CiviTest/CiviUnitTestCase.php';
3 require_once 'CiviTest/Contact.php';
4 require_once 'CiviTest/Custom.php';
7 * Class CRM_Core_BAO_CustomValueTableTest
9 class CRM_Core_BAO_CustomValueTableTest
extends CiviUnitTestCase
{
11 public function setUp() {
17 * Test store function for country.
19 public function testStoreCountry() {
21 $contactID = Contact
::createIndividual();
22 $customGroup = Custom
::createGroup($params, 'Individual');
24 'groupId' => $customGroup->id
,
25 'dataType' => 'Country',
26 'htmlType' => 'Select Country',
29 $customField = Custom
::createField($params, $fields);
32 $customField->id
=> array(
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
,
43 CRM_Core_BAO_CustomValueTable
::store($params, 'civicrm_contact', $contactID);
44 // $this->assertDBCompareValue('CRM_Custom_DAO_CustomValue', )
46 Custom
::deleteField($customField);
47 Custom
::deleteGroup($customGroup);
48 Contact
::delete($contactID);
52 * Test store function for file.
54 public function atestStoreFile() {
56 $contactID = Contact
::createIndividual();
57 $customGroup = Custom
::createGroup($params, 'Individual');
59 'groupId' => $customGroup->id
,
64 $customField = Custom
::createField($params, $fields);
67 $customField->id
=> array(
68 'value' => 'i/contact_house.png',
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
,
78 CRM_Core_BAO_CustomValueTable
::store($params, 'civicrm_contact', $contactID);
79 // $this->assertDBCompareValue('CRM_Custom_DAO_CustomValue', )
81 Custom
::deleteField($customField);
82 Custom
::deleteGroup($customGroup);
83 Contact
::delete($contactID);
87 * Test store function for state province.
89 public function testStoreStateProvince() {
91 $contactID = Contact
::createIndividual();
92 $customGroup = Custom
::createGroup($params, 'Individual');
94 'groupId' => $customGroup->id
,
95 'dataType' => 'StateProvince',
96 'htmlType' => 'Select State/Province',
99 $customField = Custom
::createField($params, $fields);
102 $customField->id
=> array(
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
,
113 CRM_Core_BAO_CustomValueTable
::store($params, 'civicrm_contact', $contactID);
115 Custom
::deleteField($customField);
116 Custom
::deleteGroup($customGroup);
117 Contact
::delete($contactID);
121 * Test store function for date.
123 public function testStoreDate() {
125 $contactID = Contact
::createIndividual();
126 $customGroup = Custom
::createGroup($params, 'Individual');
128 'groupId' => $customGroup->id
,
129 'dataType' => 'Date',
130 'htmlType' => 'Select Date',
133 $customField = Custom
::createField($params, $fields);
136 $customField->id
=> array(
137 'value' => '20080608000000',
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
,
147 CRM_Core_BAO_CustomValueTable
::store($params, 'civicrm_contact', $contactID);
148 // $this->assertDBCompareValue('CRM_Custom_DAO_CustomValue', )
150 Custom
::deleteField($customField);
151 Custom
::deleteGroup($customGroup);
152 Contact
::delete($contactID);
156 * Test store function for rich text editor.
158 public function testStoreRichTextEditor() {
160 $contactID = Contact
::createIndividual();
161 $customGroup = Custom
::createGroup($params, 'Individual');
163 'groupId' => $customGroup->id
,
164 'htmlType' => 'RichTextEditor',
165 'dataType' => 'Memo',
168 $customField = Custom
::createField($params, $fields);
171 $customField->id
=> array(
172 'value' => '<p><strong>This is a <u>test</u></p>',
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
,
182 CRM_Core_BAO_CustomValueTable
::store($params, 'civicrm_contact', $contactID);
183 // $this->assertDBCompareValue('CRM_Custom_DAO_CustomValue', )
185 Custom
::deleteField($customField);
186 Custom
::deleteGroup($customGroup);
187 Contact
::delete($contactID);
191 * Test getEntityValues function for stored value.
193 public function testgetEntityValues() {
196 $contactID = Contact
::createIndividual();
197 $customGroup = Custom
::createGroup($params, 'Individual');
199 'groupId' => $customGroup->id
,
200 'htmlType' => 'RichTextEditor',
201 'dataType' => 'Memo',
204 $customField = Custom
::createField($params, $fields);
207 $customField->id
=> array(
208 'value' => '<p><strong>This is a <u>test</u></p>',
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
,
218 CRM_Core_BAO_CustomValueTable
::store($params, 'civicrm_contact', $contactID);
219 // $this->assertDBCompareValue('CRM_Custom_DAO_CustomValue', )
221 $entityValues = CRM_Core_BAO_CustomValueTable
::getEntityValues($contactID, 'Individual');
223 $this->assertEquals($entityValues[$customField->id
], '<p><strong>This is a <u>test</u></p>',
224 'Checking same for returned value.'
226 Custom
::deleteField($customField);
227 Custom
::deleteGroup($customGroup);
228 Contact
::delete($contactID);
231 public function testCustomGroupMultiple() {
233 $contactID = Contact
::createIndividual();
234 $customGroup = Custom
::createGroup($params, 'Individual');
237 'groupId' => $customGroup->id
,
238 'dataType' => 'String',
239 'htmlType' => 'Text',
242 $customField = Custom
::createField($params, $fields);
245 'entityID' => $contactID,
246 'custom_' . $customField->id
. '_-1' => 'First String',
248 $error = CRM_Core_BAO_CustomValueTable
::setValues($params);
251 'entityID' => $contactID,
252 'custom_' . $customField->id
=> 1,
254 $result = CRM_Core_BAO_CustomValueTable
::getValues($newParams);
256 $this->assertEquals($params['custom_' . $customField->id
. '_-1'], $result['custom_' . $customField->id
]);
257 $this->assertEquals($params['entityID'], $result['entityID']);
259 Custom
::deleteField($customField);
260 Custom
::deleteGroup($customGroup);
261 Contact
::delete($contactID);