CRM-20381 - use '' to indicate no geocode method
authorJamie McClelland <jm@mayfirst.org>
Sat, 3 Jun 2017 01:50:11 +0000 (21:50 -0400)
committerJamie McClelland <jm@mayfirst.org>
Sat, 3 Jun 2017 01:50:11 +0000 (21:50 -0400)
'' means empty, NULL means not set, which confuses MagicMerge.

CRM/Contact/Import/Parser/Contact.php
CRM/Core/Config/MagicMerge.php
tests/phpunit/CRM/Utils/GeocodeTest.php

index 3358247de06dfd9f22a6bc57dcd4830d7b5f147e..2923a6c6879f103cdb96976ffbb49549ac376e3e 100644 (file)
@@ -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
index e096c4c097d8609b4f1eb51444d2216210f94558..2fd2c6015dbed6ed359b781466c8642608fc90b9 100644 (file)
@@ -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];
     }
 
index 980cb28309105570be9af003833f2feead07b1ba..9c540572db4c33b8c677ea4d7afcc17d3582e18c 100644 (file)
@@ -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');
+
+  }
 }