3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 * Class CRM_Core_BAO_LocationTest
24 class CRM_Core_BAO_LocationTest
extends CiviUnitTestCase
{
26 public function setUp() {
40 * Tears down the fixture, for example, closes a network connection.
41 * This method is called after a test is executed.
43 public function tearDown() {
49 $this->quickCleanup($tablesToTruncate);
52 public function testCreateWithMissingParams() {
53 $contactId = $this->individualCreate();
55 'contact_id' => $contactId,
56 'street_address' => 'Saint Helier St',
59 CRM_Core_BAO_Location
::create($params);
61 //Now check DB for Address
62 $this->assertDBNull('CRM_Core_DAO_Address', 'Saint Helier St', 'id', 'street_address',
63 'Database check, Address created successfully.'
66 $this->contactDelete($contactId);
71 * create various elements of location block
72 * without civicrm_loc_block entry
74 public function testCreateWithoutLocBlock() {
75 $contactId = $this->individualCreate();
77 //create various element of location block
78 //like address, phone, email, openid, im.
82 'street_address' => 'Saint Helier St',
83 'supplemental_address_1' => 'Hallmark Ct',
84 'supplemental_address_2' => 'Jersey Village',
85 'supplemental_address_3' => 'My Town',
87 'postal_code' => '01903',
89 'state_province_id' => 1029,
90 'geo_code_1' => '18.219023',
91 'geo_code_2' => '-105.00973',
93 'location_type_id' => 1,
98 'email' => 'john.smith@example.org',
100 'location_type_id' => 1,
105 'phone_type_id' => 1,
106 'phone' => '303443689',
108 'location_type_id' => 1,
111 'phone_type_id' => 2,
112 'phone' => '9833910234',
113 'location_type_id' => 1,
118 'openid' => 'http://civicrm.org/',
119 'location_type_id' => 1,
125 'name' => 'jane.doe',
127 'location_type_id' => 1,
133 $params['contact_id'] = $contactId;
135 $locBlockId = CRM_Core_BAO_Location
::create($params);
137 //Now check DB for contact
139 'contact_id' => $contactId,
140 'location_type_id' => 1,
144 'street_address' => 'Saint Helier St',
145 'supplemental_address_1' => 'Hallmark Ct',
146 'supplemental_address_2' => 'Jersey Village',
147 'supplemental_address_3' => 'My Town',
149 'postal_code' => '01903',
150 'country_id' => 1228,
151 'state_province_id' => 1029,
152 'geo_code_1' => '18.219023',
153 'geo_code_2' => '-105.00973',
155 $this->assertDBCompareValues('CRM_Core_DAO_Address', $searchParams, $compareParams);
157 $compareParams = ['email' => 'john.smith@example.org'];
158 $this->assertDBCompareValues('CRM_Core_DAO_Email', $searchParams, $compareParams);
160 $compareParams = ['openid' => 'http://civicrm.org/'];
161 $this->assertDBCompareValues('CRM_Core_DAO_OpenID', $searchParams, $compareParams);
164 'name' => 'jane.doe',
167 $this->assertDBCompareValues('CRM_Core_DAO_IM', $searchParams, $compareParams);
170 'contact_id' => $contactId,
171 'location_type_id' => 1,
173 'phone_type_id' => 1,
175 $compareParams = ['phone' => '303443689'];
176 $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams);
179 'contact_id' => $contactId,
180 'location_type_id' => 1,
181 'phone_type_id' => 2,
183 $compareParams = ['phone' => '9833910234'];
184 $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams);
186 $this->contactDelete($contactId);
191 * create various elements of location block
192 * with civicrm_loc_block
194 public function testCreateWithLocBlock() {
195 $this->_contactId
= $this->individualCreate();
196 $event = $this->eventCreate();
200 'street_address' => 'Saint Helier St',
201 'supplemental_address_1' => 'Hallmark Ct',
202 'supplemental_address_2' => 'Jersey Village',
203 'supplemental_address_3' => 'My Town',
205 'postal_code' => '01903',
206 'country_id' => 1228,
207 'state_province_id' => 1029,
208 'geo_code_1' => '18.219023',
209 'geo_code_2' => '-105.00973',
211 'location_type_id' => 1,
216 'email' => 'john.smith@example.org',
218 'location_type_id' => 1,
223 'phone_type_id' => 1,
224 'phone' => '303443689',
226 'location_type_id' => 1,
229 'phone_type_id' => 2,
230 'phone' => '9833910234',
231 'location_type_id' => 1,
236 'name' => 'jane.doe',
238 'location_type_id' => 1,
244 $params['entity_id'] = $event['id'];
245 $params['entity_table'] = 'civicrm_event';
247 //create location block.
248 //with various element of location block
249 //like address, phone, email, im.
250 $locBlockId = CRM_Core_BAO_Location
::create($params, NULL, TRUE)['id'];
252 //update event record with location block id
254 'id' => $event['id'],
255 'loc_block_id' => $locBlockId,
258 CRM_Event_BAO_Event
::add($eventParams);
260 //Now check DB for location block
262 $this->assertDBCompareValue('CRM_Event_DAO_Event',
267 'Checking database for the record.'
270 $locParams = ['id' => $locBlockId];
271 CRM_Core_DAO
::commonRetrieve('CRM_Core_DAO_LocBlock',
276 //Now check DB for location elements.
278 'id' => CRM_Utils_Array
::value('address_id', $locElementIds),
279 'location_type_id' => 1,
283 'street_address' => 'Saint Helier St',
284 'supplemental_address_1' => 'Hallmark Ct',
285 'supplemental_address_2' => 'Jersey Village',
286 'supplemental_address_3' => 'My Town',
288 'postal_code' => '01903',
289 'country_id' => 1228,
290 'state_province_id' => 1029,
291 'geo_code_1' => '18.219023',
292 'geo_code_2' => '-105.00973',
294 $this->assertDBCompareValues('CRM_Core_DAO_Address', $searchParams, $compareParams);
297 'id' => CRM_Utils_Array
::value('email_id', $locElementIds),
298 'location_type_id' => 1,
301 $compareParams = ['email' => 'john.smith@example.org'];
302 $this->assertDBCompareValues('CRM_Core_DAO_Email', $searchParams, $compareParams);
305 'id' => CRM_Utils_Array
::value('phone_id', $locElementIds),
306 'location_type_id' => 1,
308 'phone_type_id' => 1,
310 $compareParams = ['phone' => '303443689'];
311 $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams);
314 'id' => CRM_Utils_Array
::value('phone_2_id', $locElementIds),
315 'location_type_id' => 1,
316 'phone_type_id' => 2,
318 $compareParams = ['phone' => '9833910234'];
319 $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams);
322 'id' => CRM_Utils_Array
::value('im_id', $locElementIds),
323 'location_type_id' => 1,
327 'name' => 'jane.doe',
330 $this->assertDBCompareValues('CRM_Core_DAO_IM', $searchParams, $compareParams);
333 CRM_Core_BAO_Location
::deleteLocBlock($locBlockId);
334 $this->eventDelete($event['id']);
335 $this->contactDelete($this->_contactId
);
340 * get the values of various location elements
342 public function testLocBlockgetValues() {
343 $contactId = $this->individualCreate();
345 //create various element of location block
346 //like address, phone, email, openid, im.
350 'street_address' => 'Saint Helier St',
351 'supplemental_address_1' => 'Hallmark Ct',
352 'supplemental_address_2' => 'Jersey Village',
353 'supplemental_address_3' => 'My Town',
355 'postal_code' => '01903',
356 'country_id' => 1228,
357 'state_province_id' => 1029,
358 'geo_code_1' => '18.219023',
359 'geo_code_2' => '-105.00973',
361 'location_type_id' => 1,
366 'email' => 'john.smith@example.org',
368 'location_type_id' => 1,
373 'phone_type_id' => 1,
374 'phone' => '303443689',
376 'location_type_id' => 1,
379 'phone_type_id' => 2,
380 'phone' => '9833910234',
381 'location_type_id' => 1,
386 'openid' => 'http://civicrm.org/',
387 'location_type_id' => 1,
393 'name' => 'jane.doe',
395 'location_type_id' => 1,
401 $params['contact_id'] = $contactId;
403 //create location elements.
404 CRM_Core_BAO_Location
::create($params);
406 //get the values from DB
407 $values = CRM_Core_BAO_Location
::getValues($params);
409 //Now check values of address
410 $this->assertAttributesEquals(CRM_Utils_Array
::value('1', $params['address']),
411 CRM_Utils_Array
::value('1', $values['address'])
414 //Now check values of email
415 $this->assertAttributesEquals(CRM_Utils_Array
::value('1', $params['email']),
416 CRM_Utils_Array
::value('1', $values['email'])
419 //Now check values of phone
420 $this->assertAttributesEquals(CRM_Utils_Array
::value('1', $params['phone']),
421 CRM_Utils_Array
::value('1', $values['phone'])
424 //Now check values of mobile
425 $this->assertAttributesEquals(CRM_Utils_Array
::value('2', $params['phone']),
426 CRM_Utils_Array
::value('2', $values['phone'])
429 //Now check values of openid
430 $this->assertAttributesEquals(CRM_Utils_Array
::value('1', $params['openid']),
431 CRM_Utils_Array
::value('1', $values['openid'])
434 //Now check values of im
435 $this->assertAttributesEquals(CRM_Utils_Array
::value('1', $params['im']),
436 CRM_Utils_Array
::value('1', $values['im'])
438 $this->contactDelete($contactId);