From 5a9e14522d7bc658657fffdabb77ed1eea4468db Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 28 Aug 2013 21:12:59 +1200 Subject: [PATCH] CRM-13284 fix empty billing profile for autofill --- api/v3/Profile.php | 15 +++++++++++---- api/v3/examples/ProfileSubmit.php | 5 +---- tests/phpunit/api/v3/ProfileTest.php | 23 +++++++++++++++++++++++ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/api/v3/Profile.php b/api/v3/Profile.php index a7196eeb10..73b0c83310 100644 --- a/api/v3/Profile.php +++ b/api/v3/Profile.php @@ -364,21 +364,28 @@ function civicrm_api3_profile_apply($params) { * interim solution is just to return an empty array */ function _civicrm_api3_profile_getbillingpseudoprofile(&$params) { - $addressFields = array('street_address', 'city', 'state_province_id', 'country_id', 'postal_code'); + $locations = civicrm_api3('address', 'getoptions', array('field' => 'location_type_id')); $locationTypeID = array_search('Billing', $locations['values']); if(empty($params['contact_id'])) { + $config = CRM_Core_Config::singleton(); $blanks = array( 'billing_first_name' => '', 'billing_middle_name' => '', 'billing_last_name' => '', + 'email-' . $locationTypeID => '', + 'billing_email-' . $locationTypeID => '', + 'billing_city-' . $locationTypeID => '', + 'billing_postal_code-' . $locationTypeID => '', + 'billing_street_address-' . $locationTypeID => '', + 'billing_country_id-' . $locationTypeID => $config->defaultContactCountry, + 'billing_state_province_id-' . $locationTypeID => $config->defaultContactStateProvince, ); - foreach ($addressFields as $field) { - $blanks['billing_' . $field . '_' . $locationTypeID] = ''; - } return $blanks; } + + $addressFields = array('street_address', 'city', 'state_province_id', 'country_id', 'postal_code'); $result = civicrm_api3('contact', 'getsingle', array( 'id' => $params['contact_id'], 'api.address.get.1' => array('location_type_id' => 'Billing', 'return' => $addressFields), diff --git a/api/v3/examples/ProfileSubmit.php b/api/v3/examples/ProfileSubmit.php index 910c21ec7d..0562485f37 100644 --- a/api/v3/examples/ProfileSubmit.php +++ b/api/v3/examples/ProfileSubmit.php @@ -65,8 +65,6 @@ function profile_submit_expectedresult(){ 'first_name' => 'abc2', 'middle_name' => 'J.', 'last_name' => 'xyz2', - 'prefix_id' => '3', - 'suffix_id' => '3', 'email_greeting_id' => '1', 'email_greeting_custom' => '', 'email_greeting_display' => 'Dear abc1', @@ -75,9 +73,8 @@ function profile_submit_expectedresult(){ 'postal_greeting_display' => 'Dear abc1', 'addressee_id' => '1', 'addressee_custom' => '', - 'addressee_display' => '{contact.individual_prefix} abc1 J. xyz1 {contact.individual_suffix}', + 'addressee_display' => 'Mr. abc1 J. xyz1 II', 'job_title' => '', - 'gender_id' => '', 'birth_date' => '', 'is_deceased' => 0, 'deceased_date' => '', diff --git a/tests/phpunit/api/v3/ProfileTest.php b/tests/phpunit/api/v3/ProfileTest.php index b2e699e015..145a00b48f 100644 --- a/tests/phpunit/api/v3/ProfileTest.php +++ b/tests/phpunit/api/v3/ProfileTest.php @@ -201,6 +201,29 @@ class api_v3_ProfileTest extends CiviUnitTestCase { )); } + /** + * get Billing empty contact - this will return generic defaults + */ + function testProfileGetBillingEmptyContact() { + + $params = array( + 'profile_id' => array('Billing'), + ); + + $result = $this->callAPISuccess('profile', 'get', $params); + $this->assertEquals(array( + 'billing_first_name' => '', + 'billing_middle_name' => '', + 'billing_last_name' => '', + 'billing_street_address-5' => '', + 'billing_city-5' => '', + 'billing_state_province_id-5' => '', + 'billing_country_id-5' => '1228', + 'billing_email-5' => '', + 'email-5' => '', + 'billing_postal_code-5' => '', + ), $result['values']['Billing']); + } /** * check contact activity profile without activity id -- 2.25.1