From: Jamie McClelland Date: Sat, 3 Jun 2017 01:50:11 +0000 (-0400) Subject: CRM-20381 - use '' to indicate no geocode method X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=fd78a9e5052abac20e9d2c0ef1ba1a17b0b62495;p=civicrm-core.git CRM-20381 - use '' to indicate no geocode method '' means empty, NULL means not set, which confuses MagicMerge. --- diff --git a/CRM/Contact/Import/Parser/Contact.php b/CRM/Contact/Import/Parser/Contact.php index 3358247de0..2923a6c687 100644 --- a/CRM/Contact/Import/Parser/Contact.php +++ b/CRM/Contact/Import/Parser/Contact.php @@ -472,7 +472,7 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser { $this->_unparsedStreetAddressContacts = array(); if (!$doGeocodeAddress) { // CRM-5854, reset the geocode method to null to prevent geocoding - $config->geocodeMethod = NULL; + $config->geocodeMethod = ''; } // first make sure this is a valid line diff --git a/CRM/Core/Config/MagicMerge.php b/CRM/Core/Config/MagicMerge.php index e096c4c097..2fd2c6015d 100644 --- a/CRM/Core/Config/MagicMerge.php +++ b/CRM/Core/Config/MagicMerge.php @@ -222,7 +222,7 @@ class CRM_Core_Config_MagicMerge { if (!isset($this->map[$k])) { throw new \CRM_Core_Exception("Cannot read unrecognized property CRM_Core_Config::\${$k}."); } - if (array_key_exists($k, $this->cache)) { + if (isset($this->cache[$k])) { return $this->cache[$k]; } diff --git a/tests/phpunit/CRM/Utils/GeocodeTest.php b/tests/phpunit/CRM/Utils/GeocodeTest.php index 980cb28309..9c540572db 100644 --- a/tests/phpunit/CRM/Utils/GeocodeTest.php +++ b/tests/phpunit/CRM/Utils/GeocodeTest.php @@ -21,4 +21,39 @@ class CRM_Utils_GeocodeTest extends CiviUnitTestCase { $this->assertApproxEquals('-94.68', $params['geo_code_2'], 1); } + public function testGeocodeMethodOff() { + // Set a geocoding provider. + $result = civicrm_api3('Setting', 'create', array( + 'geoProvider' => "Google", + )); + + // Save a contact without disabling geo coding. + $params = array( + 'first_name' => 'Abraham', + 'last_name' => 'Lincoln', + 'contact_type' => 'Individual', + 'api.Address.create' => array( + 'street_address' => '1600 Pennsylvania Avenue', + 'city' => 'Washington', + 'state_province' => 'DC', + 'location_type_id' => 1 + ) + ); + $result = civicrm_api3('Contact', 'create', $params); + $contact_values = array_pop($result['values']); + $address_values = array_pop($contact_values['api.Address.create']['values']); + // We should get a geo code setting. + $this->assertApproxEquals('38.89', $address_values['geo_code_1'], 1); + + // Set geocodeMethod to empty. + $config = CRM_Core_Config::singleton(); + $config->geocodeMethod = ''; + + // Do it again. This time, we should not geocode. + $new_result = civicrm_api3('Contact', 'create', $params); + $new_contact_values = array_pop($new_result['values']); + $new_address_values = array_pop($new_contact_values['api.Address.create']['values']); + $this->assertArrayNotHasKey('geo_code_1', $new_address_values, 'No geocoding when geocodeMethod is empty'); + + } }