CRM-13284 fix empty billing profile for autofill
authoreileen <eileen@fuzion.co.nz>
Wed, 28 Aug 2013 09:12:59 +0000 (21:12 +1200)
committereileen <eileen@fuzion.co.nz>
Wed, 28 Aug 2013 09:12:59 +0000 (21:12 +1200)
api/v3/Profile.php
api/v3/examples/ProfileSubmit.php
tests/phpunit/api/v3/ProfileTest.php

index a7196eeb1047a5e8cbca203e18da0e7bf935bc44..73b0c83310b39877b667c66de6a47aaab0d1fe77 100644 (file)
@@ -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),
index 910c21ec7dd90b71544bf60d436799451757622d..0562485f370cb0e54fa177acc9ea57f49a4fc47e 100644 (file)
@@ -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' => '',
index b2e699e0154e318ecd1c58bd33504833ef860536..145a00b48f603e27e1377f560c335377a9ae044e 100644 (file)
@@ -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