From: jitendrapurohit Date: Fri, 16 Oct 2015 12:27:49 +0000 (+0530) Subject: remove hack and add test cases X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=d0bfb983451292f0e37c2d86edff64d66039952b;p=civicrm-core.git remove hack and add test cases --- diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 861d278e7b..d3a3d443ae 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -3330,7 +3330,10 @@ LEFT JOIN civicrm_address add2 ON ( add1.master_id = add2.id ) return CRM_Core_BAO_EntityTag::buildOptions('tag_id', $context, $props); case 'state_province_id': + case 'state_province': + case 'state_province_name': case 'country_id': + case 'country': case 'county_id': case 'worldregion': case 'worldregion_id': diff --git a/CRM/Core/BAO/Address.php b/CRM/Core/BAO/Address.php index de371b237e..ff2d4cf3e6 100644 --- a/CRM/Core/BAO/Address.php +++ b/CRM/Core/BAO/Address.php @@ -1249,6 +1249,10 @@ SELECT is_primary, switch ($fieldName) { // Filter state_province list based on chosen country or site defaults case 'state_province_id': + case 'state_province_name': + case 'state_province': + // change $fieldName to DB specific names. + $fieldName = 'state_province_id'; if (empty($props['country_id'])) { $config = CRM_Core_Config::singleton(); if (!empty($config->provinceLimit)) { @@ -1265,6 +1269,9 @@ SELECT is_primary, // Filter country list based on site defaults case 'country_id': + case 'country': + // change $fieldName to DB specific names. + $fieldName = 'country_id'; if ($context != 'get' && $context != 'validate') { $config = CRM_Core_Config::singleton(); if (!empty($config->countryLimit) && is_array($config->countryLimit)) { diff --git a/api/v3/utils.php b/api/v3/utils.php index 8dc1dd4048..d0c8ce0f19 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -2192,9 +2192,6 @@ function _civicrm_api_get_fields($entity, $unique = FALSE, &$params = array()) { } } $fields += _civicrm_api_get_custom_fields($entity, $params); - if ($entity == 'Contact') { - $fields += _civicrm_api_get_fields('Address'); - } return $fields; } diff --git a/tests/phpunit/api/v3/ContactTest.php b/tests/phpunit/api/v3/ContactTest.php index 86bf055ce7..64afedbe0c 100644 --- a/tests/phpunit/api/v3/ContactTest.php +++ b/tests/phpunit/api/v3/ContactTest.php @@ -1588,6 +1588,55 @@ class api_v3_ContactTest extends CiviUnitTestCase { $this->assertEquals(date('Y-m-d', strtotime('first day of next month -5 years')), $result['values'][$contact2['id']]['birth_date']); } + /** + * Test Address parameters + * + * This include state_province, state_province_name, country + */ + public function testContactGetWithAddressFields() { + $individuals = array( + array( + 'first_name' => 'abc1', + 'contact_type' => 'Individual', + 'last_name' => 'xyz1', + 'api.address.create' => array( + 'country' => 'United States', + 'state_province_id' => 'Michigan', + 'location_type_id' => 1, + ), + ), + array( + 'first_name' => 'abc2', + 'contact_type' => 'Individual', + 'last_name' => 'xyz2', + 'api.address.create' => array( + 'country' => 'United States', + 'state_province_id' => 'Alabama', + 'location_type_id' => 1, + ), + ), + ); + foreach ($individuals as $params) { + $contact = $this->callAPISuccess('contact', 'create', $params); + } + + // Check whether Contact get API return successfully with below Address params. + $fieldsToTest = array( + 'state_province_name' => 'Michigan', + 'state_province' => 'Michigan', + 'country' => 'United States', + 'state_province_name' => array('IN' => array('Michigan', 'Alabama')), + 'state_province' => array('IN' => array('Michigan', 'Alabama')), + ); + foreach ($fieldsToTest as $field => $value) { + $getParams = array( + 'id' => $contact['id'], + $field => $value, + ); + $this->callAPISuccess('Contact', 'get', $getParams); + } + } + /** * Test Deceased date parameters. *