From: Daniƫl <9696905+DanielvV@users.noreply.github.com> Date: Tue, 3 Oct 2017 09:22:56 +0000 (+0200) Subject: CRM-21249 - Geocode warns hitting Google limit X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=b83ea84c1342e0a76e3b7acbe3b12c6eb7ec47cd;p=civicrm-core.git CRM-21249 - Geocode warns hitting Google limit Instead of throwing an error --- diff --git a/tests/phpunit/CRM/Utils/GeocodeTest.php b/tests/phpunit/CRM/Utils/GeocodeTest.php index c10b887b88..c59461abad 100644 --- a/tests/phpunit/CRM/Utils/GeocodeTest.php +++ b/tests/phpunit/CRM/Utils/GeocodeTest.php @@ -16,6 +16,9 @@ class CRM_Utils_GeocodeTest extends CiviUnitTestCase { public function testStateProvinceFormat() { $params = array('state_province_id' => 1022, 'country' => 'U.S.A'); $formatted = CRM_Utils_Geocode_Google::format($params); + if (isset($params['geo_code_error']) && $params['geo_code_error'] == 'OVER_QUERY_LIMIT') { + $this->markTestIncomplete('geo_code_error: OVER_QUERY_LIMIT'); + } $this->assertTrue($formatted); $this->assertApproxEquals('46.72', $params['geo_code_1'], 1); $this->assertApproxEquals('-94.68', $params['geo_code_2'], 1); @@ -27,7 +30,11 @@ class CRM_Utils_GeocodeTest extends CiviUnitTestCase { 'geoProvider' => "Google", )); - // Save a contact without disabling geo coding. + // Set geocodeMethod to empty. + $config = CRM_Core_Config::singleton(); + $config->geocodeMethod = ''; + + // Save a contact with geo coding disabled. $params = array( 'first_name' => 'Abraham', 'last_name' => 'Lincoln', @@ -42,18 +49,33 @@ class CRM_Utils_GeocodeTest extends CiviUnitTestCase { $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', CRM_Utils_Array::value('geo_code_1', $address_values), 1); - // Set geocodeMethod to empty. - $config = CRM_Core_Config::singleton(); - $config->geocodeMethod = ''; + $this->assertArrayNotHasKey('geo_code_1', $address_values, 'No geocoding when geocodeMethod is empty'); + + // Run the geocode job on that specific contact + $config->geocodeMethod = 'CRM_Utils_Geocode_Google'; - // 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'); + try { + $params_geocode = array( + 'start' => $contact_values['id'], + 'end' => $contact_values['id'] + 1, + 'geocoding' => 1, + 'parse' => 0, + ); + $result_geocode = civicrm_api3('Job', 'geocode', $params_geocode); + } + catch (CiviCRM_API3_Exception $e) { + if ($e->getMessage() == 'A fatal error was triggered: Aborting batch geocoding. Hit the over query limit on geocoder.') { + $this->markTestIncomplete('Job.geocode error_message: A fatal error was triggered: Aborting batch geocoding. Hit the over query limit on geocoder.'); + } + } + $params_address_getsingle = array( + 'contact_id' => $contact_values['id'], + ); + $result_address_getsingle = civicrm_api3('Address', 'getsingle', $params_address_getsingle); + + // We should get a geo code setting. + $this->assertApproxEquals('38.89', CRM_Utils_Array::value('geo_code_1', $result_address_getsingle), 1); } }