3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
37 * Class CRM_Core_BAO_LocationTest
40 class CRM_Core_BAO_LocationTest
extends CiviUnitTestCase
{
42 public function setUp() {
56 * Tears down the fixture, for example, closes a network connection.
57 * This method is called after a test is executed.
59 public function tearDown() {
65 $this->quickCleanup($tablesToTruncate);
68 public function testCreateWithMissingParams() {
69 $contactId = $this->individualCreate();
71 'contact_id' => $contactId,
72 'street_address' => 'Saint Helier St',
75 CRM_Core_BAO_Location
::create($params);
77 //Now check DB for Address
78 $this->assertDBNull('CRM_Core_DAO_Address', 'Saint Helier St', 'id', 'street_address',
79 'Database check, Address created successfully.'
82 $this->contactDelete($contactId);
87 * create various elements of location block
88 * without civicrm_loc_block entry
90 public function testCreateWithoutLocBlock() {
91 $contactId = $this->individualCreate();
93 //create various element of location block
94 //like address, phone, email, openid, im.
98 'street_address' => 'Saint Helier St',
99 'supplemental_address_1' => 'Hallmark Ct',
100 'supplemental_address_2' => 'Jersey Village',
101 'supplemental_address_3' => 'My Town',
103 'postal_code' => '01903',
104 'country_id' => 1228,
105 'state_province_id' => 1029,
106 'geo_code_1' => '18.219023',
107 'geo_code_2' => '-105.00973',
109 'location_type_id' => 1,
114 'email' => 'john.smith@example.org',
116 'location_type_id' => 1,
121 'phone_type_id' => 1,
122 'phone' => '303443689',
124 'location_type_id' => 1,
127 'phone_type_id' => 2,
128 'phone' => '9833910234',
129 'location_type_id' => 1,
134 'openid' => 'http://civicrm.org/',
135 'location_type_id' => 1,
141 'name' => 'jane.doe',
143 'location_type_id' => 1,
149 $params['contact_id'] = $contactId;
151 $locBlockId = CRM_Core_BAO_Location
::create($params);
153 //Now check DB for contact
155 'contact_id' => $contactId,
156 'location_type_id' => 1,
160 'street_address' => 'Saint Helier St',
161 'supplemental_address_1' => 'Hallmark Ct',
162 'supplemental_address_2' => 'Jersey Village',
163 'supplemental_address_3' => 'My Town',
165 'postal_code' => '01903',
166 'country_id' => 1228,
167 'state_province_id' => 1029,
168 'geo_code_1' => '18.219023',
169 'geo_code_2' => '-105.00973',
171 $this->assertDBCompareValues('CRM_Core_DAO_Address', $searchParams, $compareParams);
173 $compareParams = ['email' => 'john.smith@example.org'];
174 $this->assertDBCompareValues('CRM_Core_DAO_Email', $searchParams, $compareParams);
176 $compareParams = ['openid' => 'http://civicrm.org/'];
177 $this->assertDBCompareValues('CRM_Core_DAO_OpenID', $searchParams, $compareParams);
180 'name' => 'jane.doe',
183 $this->assertDBCompareValues('CRM_Core_DAO_IM', $searchParams, $compareParams);
186 'contact_id' => $contactId,
187 'location_type_id' => 1,
189 'phone_type_id' => 1,
191 $compareParams = ['phone' => '303443689'];
192 $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams);
195 'contact_id' => $contactId,
196 'location_type_id' => 1,
197 'phone_type_id' => 2,
199 $compareParams = ['phone' => '9833910234'];
200 $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams);
202 $this->contactDelete($contactId);
207 * create various elements of location block
208 * with civicrm_loc_block
210 public function testCreateWithLocBlock() {
211 $this->_contactId
= $this->individualCreate();
212 $event = $this->eventCreate();
216 'street_address' => 'Saint Helier St',
217 'supplemental_address_1' => 'Hallmark Ct',
218 'supplemental_address_2' => 'Jersey Village',
219 'supplemental_address_3' => 'My Town',
221 'postal_code' => '01903',
222 'country_id' => 1228,
223 'state_province_id' => 1029,
224 'geo_code_1' => '18.219023',
225 'geo_code_2' => '-105.00973',
227 'location_type_id' => 1,
232 'email' => 'john.smith@example.org',
234 'location_type_id' => 1,
239 'phone_type_id' => 1,
240 'phone' => '303443689',
242 'location_type_id' => 1,
245 'phone_type_id' => 2,
246 'phone' => '9833910234',
247 'location_type_id' => 1,
252 'name' => 'jane.doe',
254 'location_type_id' => 1,
260 $params['entity_id'] = $event['id'];
261 $params['entity_table'] = 'civicrm_event';
263 //create location block.
264 //with various element of location block
265 //like address, phone, email, im.
266 $locBlockId = CRM_Core_BAO_Location
::create($params, NULL, TRUE)['id'];
268 //update event record with location block id
270 'id' => $event['id'],
271 'loc_block_id' => $locBlockId,
274 CRM_Event_BAO_Event
::add($eventParams);
276 //Now check DB for location block
278 $this->assertDBCompareValue('CRM_Event_DAO_Event',
283 'Checking database for the record.'
286 $locParams = ['id' => $locBlockId];
287 CRM_Core_DAO
::commonRetrieve('CRM_Core_DAO_LocBlock',
292 //Now check DB for location elements.
294 'id' => CRM_Utils_Array
::value('address_id', $locElementIds),
295 'location_type_id' => 1,
299 'street_address' => 'Saint Helier St',
300 'supplemental_address_1' => 'Hallmark Ct',
301 'supplemental_address_2' => 'Jersey Village',
302 'supplemental_address_3' => 'My Town',
304 'postal_code' => '01903',
305 'country_id' => 1228,
306 'state_province_id' => 1029,
307 'geo_code_1' => '18.219023',
308 'geo_code_2' => '-105.00973',
310 $this->assertDBCompareValues('CRM_Core_DAO_Address', $searchParams, $compareParams);
313 'id' => CRM_Utils_Array
::value('email_id', $locElementIds),
314 'location_type_id' => 1,
317 $compareParams = ['email' => 'john.smith@example.org'];
318 $this->assertDBCompareValues('CRM_Core_DAO_Email', $searchParams, $compareParams);
321 'id' => CRM_Utils_Array
::value('phone_id', $locElementIds),
322 'location_type_id' => 1,
324 'phone_type_id' => 1,
326 $compareParams = ['phone' => '303443689'];
327 $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams);
330 'id' => CRM_Utils_Array
::value('phone_2_id', $locElementIds),
331 'location_type_id' => 1,
332 'phone_type_id' => 2,
334 $compareParams = ['phone' => '9833910234'];
335 $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams);
338 'id' => CRM_Utils_Array
::value('im_id', $locElementIds),
339 'location_type_id' => 1,
343 'name' => 'jane.doe',
346 $this->assertDBCompareValues('CRM_Core_DAO_IM', $searchParams, $compareParams);
349 CRM_Core_BAO_Location
::deleteLocBlock($locBlockId);
350 $this->eventDelete($event['id']);
351 $this->contactDelete($this->_contactId
);
356 * get the values of various location elements
358 public function testLocBlockgetValues() {
359 $contactId = $this->individualCreate();
361 //create various element of location block
362 //like address, phone, email, openid, im.
366 'street_address' => 'Saint Helier St',
367 'supplemental_address_1' => 'Hallmark Ct',
368 'supplemental_address_2' => 'Jersey Village',
369 'supplemental_address_3' => 'My Town',
371 'postal_code' => '01903',
372 'country_id' => 1228,
373 'state_province_id' => 1029,
374 'geo_code_1' => '18.219023',
375 'geo_code_2' => '-105.00973',
377 'location_type_id' => 1,
382 'email' => 'john.smith@example.org',
384 'location_type_id' => 1,
389 'phone_type_id' => 1,
390 'phone' => '303443689',
392 'location_type_id' => 1,
395 'phone_type_id' => 2,
396 'phone' => '9833910234',
397 'location_type_id' => 1,
402 'openid' => 'http://civicrm.org/',
403 'location_type_id' => 1,
409 'name' => 'jane.doe',
411 'location_type_id' => 1,
417 $params['contact_id'] = $contactId;
419 //create location elements.
420 CRM_Core_BAO_Location
::create($params);
422 //get the values from DB
423 $values = CRM_Core_BAO_Location
::getValues($params);
425 //Now check values of address
426 $this->assertAttributesEquals(CRM_Utils_Array
::value('1', $params['address']),
427 CRM_Utils_Array
::value('1', $values['address'])
430 //Now check values of email
431 $this->assertAttributesEquals(CRM_Utils_Array
::value('1', $params['email']),
432 CRM_Utils_Array
::value('1', $values['email'])
435 //Now check values of phone
436 $this->assertAttributesEquals(CRM_Utils_Array
::value('1', $params['phone']),
437 CRM_Utils_Array
::value('1', $values['phone'])
440 //Now check values of mobile
441 $this->assertAttributesEquals(CRM_Utils_Array
::value('2', $params['phone']),
442 CRM_Utils_Array
::value('2', $values['phone'])
445 //Now check values of openid
446 $this->assertAttributesEquals(CRM_Utils_Array
::value('1', $params['openid']),
447 CRM_Utils_Array
::value('1', $values['openid'])
450 //Now check values of im
451 $this->assertAttributesEquals(CRM_Utils_Array
::value('1', $params['im']),
452 CRM_Utils_Array
::value('1', $values['im'])
454 $this->contactDelete($contactId);